:root {
  --blue: #1a4d8f;
  --blue-dark: #123a6b;
  --border: #dde3ea;
  --bg: #f5f7fa;
  --text: #1e2530;
  --muted: #7a8494;
  --green: #1e7d34;
  --red: #c0392b;
  --amber: #b7791f;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }

/* ---------- Основная оболочка ---------- */
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--blue-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
}
.admin-sidebar__brand { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 32px; }
.admin-sidebar__logo { width: 64px; height: auto; margin-bottom: 12px; }
.admin-sidebar__title { font-size: 13px; line-height: 1.4; font-weight: 600; opacity: 0.95; }
.admin-sidebar__nav { display: flex; flex-direction: column; gap: 6px; }
.admin-sidebar__item {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0.8;
  transition: all 0.2s;
}
.admin-sidebar__item:hover { background: rgba(255,255,255,0.1); opacity: 1; }
.admin-sidebar__item.active { background: var(--blue); opacity: 1; font-weight: 600; }
.admin-sidebar__icon { width: 20px; text-align: center; }

.admin-main { flex: 1; min-width: 0; padding: 32px 40px; background: var(--bg); }
.admin-page { max-width: 100%; width: 100%; margin: 0 auto; }
.admin-page__header h1 { font-size: 22px; margin: 0 0 24px; color: var(--blue-dark); font-weight: 700; line-height: 1.3; }

.admin-card { background: #fff; border-radius: 12px; padding: 32px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); }

/* ---------- Секции формы ---------- */
.form-section { margin-bottom: 40px; border-bottom: 1px solid var(--border); padding-bottom: 32px; }
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section__header { margin-bottom: 24px; }
.form-section__header h2 { font-size: 18px; margin: 0 0 8px; color: var(--blue-dark); }
.form-section__header p { font-size: 14px; color: var(--muted); margin: 0; }

.header-flex { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Сетка полей ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.ui-field { display: flex; flex-direction: column; }
.ui-field span { font-size: 13px; font-weight: 600; color: #445; margin-bottom: 8px; }
.ui-field .required { color: var(--red); margin-left: 2px; }
.ui-field input, .ui-field select, .ui-field textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit;
}
.ui-field--wide { grid-column: 1 / -1; }

/* ---------- Точки ТО ---------- */
.point-card { background: #fcfdfe; border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 24px; }
.point-card__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.point-card__header strong { font-size: 15px; color: var(--blue-dark); }
.point-remove { background: transparent; color: var(--red); border: 1px solid var(--red); padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; transition: all 0.2s; }
.point-remove:hover { background: var(--red); color: #fff; }

.weekdays { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.weekdays label { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: normal; cursor: pointer; }
.weekdays input { width: auto; margin: 0; }

/* ---------- Кнопки и Действия ---------- */
.form-actions { display: flex; justify-content: flex-end; margin-top: 32px; }
.ui-btn { padding: 12px 24px; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; }
.ui-btn--primary { background: var(--blue); color: #fff; }
.ui-btn--primary:hover { background: var(--blue-dark); }
.ui-btn--secondary { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.ui-btn--secondary:hover { background: #f0f7ff; }

.btn { background: var(--blue); color: #fff; text-decoration: none; padding: 12px 24px; border-radius: 6px; font-size: 15px; border: none; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--blue-dark); }

.btn-view-cert {
  display: inline-block;
  padding: 6px 12px;
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}
/* Existing styles ... */
.btn-view-cert:hover {
  background: var(--blue-dark);
}

/* Modal Styles for Notifications */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: #fff; padding: 32px; border-radius: 12px;
  width: 100%; max-width: 400px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  text-align: center;
}
.modal-header { font-size: 20px; font-weight: 600; margin-bottom: 16px; color: var(--blue-dark); }
.modal-body { font-size: 15px; color: var(--text); margin-bottom: 24px; line-height: 1.5; }
.modal-footer { display: flex; justify-content: center; }
.modal-footer .btn { min-width: 120px; }

.msg { padding: 12px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; display: none; }
.msg.ok { background: #e6f4ea; color: var(--green); display: block; }
.msg.err { background: #fdecea; color: var(--red); display: block; }

/* Advanced Registry Styles */
.admin-card--flush {
  box-shadow: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 24px;
}

.registry-filters {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 24px;
}

.filters-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.filters-bottom-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.filters-top-row .ui-field, .filters-bottom-row .ui-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filters-top-row .ui-field {
  flex: 1;
  min-width: 140px;
}

.address-field {
  flex: 1;
}

.filter-actions {
  display: flex;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -24px;
  padding: 0 24px;
}

.data-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #f8f9fa;
  text-align: center;
  padding: 12px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow-wrap: anywhere;
  word-break: normal;
}

/* Фиксированные ширины столбцов реестра — только для десктопа */
@media (min-width: 901px) {
  .data-table th:nth-child(1),
  .data-table td:nth-child(1) { width: 5%; }

  .data-table th:nth-child(2),
  .data-table td:nth-child(2) { width: 14%; }

  .data-table th:nth-child(3),
  .data-table td:nth-child(3) { width: 8%; }

  .data-table th:nth-child(4),
  .data-table td:nth-child(4) { width: 9%; }

  /* График */
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) { width: 9%; }

  /* Адрес */
  .data-table th:nth-child(6),
  .data-table td:nth-child(6) { width: 19%; }

  .data-table th:nth-child(7),
  .data-table td:nth-child(7) { width: 8%; }

  .data-table th:nth-child(8),
  .data-table td:nth-child(8) { width: 8%; }

  /* Результат */
  .data-table th:nth-child(9),
  .data-table td:nth-child(9) { width: 7%; }

  /* Дата решения */
  .data-table th:nth-child(10),
  .data-table td:nth-child(10) { width: 6%; }

  /* Выписка */
  .data-table th:nth-child(11),
  .data-table td:nth-child(11) { width: 7%; }

  .data-table td:nth-child(9),
  .data-table td:nth-child(11) {
    white-space: nowrap;
  }
}

.text-center { text-align: center; }

.cell-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.status--success { background: #e6f4ea; color: var(--green); }
.status--error { background: #fdecea; color: var(--red); }

.cell-points-list {
  display: block;
}

.cell-point-item {
  padding: 8px 0;
  border-bottom: 1px solid #ddd;
}

.cell-point-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}

.pagination {
  display: flex;
  gap: 4px;
}

.page-size {
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

/* ============================================
   MOBILE ADAPTATION
   ============================================ */

/* Sidebar / hamburger styles live in shared /lib/sidebar.css */

/* Viewport-based toggling: desktop table vs mobile grouped cards */
.mobile-grouped {
  display: none;
}

@media (max-width: 900px) {
  /* Main content */
  .admin-main {
    padding: 70px 16px 24px;
  }

  /* Header */
  .admin-page__header h1 {
    font-size: 18px;
    margin-bottom: 16px;
    line-height: 1.4;
    word-break: break-word;
    hyphens: auto;
  }

  /* Card */
  .admin-card,
  .admin-card--flush {
    padding: 16px;
    border-radius: 8px;
  }

  /* Filters */
  .registry-filters {
    margin-bottom: 16px;
    gap: 12px;
  }

  .registry-filters .ui-field span {
    font-size: 12px;
    margin-bottom: 4px;
  }

  .registry-filters .ui-field input,
  .registry-filters .ui-field select {
    font-size: 14px;
    padding: 10px 12px;
  }

  .filters-top-row,
  .filters-bottom-row {
    flex-direction: column;
    gap: 12px;
  }

  .filters-top-row .ui-field,
  .filters-bottom-row .ui-field {
    flex: 1;
    min-width: 100%;
  }

  .address-field {
    width: 100%;
  }

  .filter-actions {
    width: 100%;
    justify-content: stretch;
  }

  .filter-actions .ui-btn {
    flex: 1;
  }

  /* Table wrapper */
  .table-wrap {
    margin: 0 -16px;
    padding: 0 16px;
  }

  /* Mobile grouped cards */
  .application-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  }

  .application-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  .application-card__id {
    font-size: 14px;
    font-weight: 700;
    color: var(--blue-dark);
  }

  .application-card__info {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
  }

  .application-card__points {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
  }

  .application-card__footer {
    text-align: center;
  }

  .application-card__footer .btn-view-cert {
    display: inline-block;
    padding: 10px 24px;
    font-size: 14px;
  }

  .point-card {
    padding: 12px;
    margin-bottom: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #eef0f2;
  }

  .point-card:last-child {
    margin-bottom: 0;
  }

  .point-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eef0f2;
  }

  .point-card__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  .point-card__number {
    font-size: 12px;
    font-weight: 700;
    color: var(--blue-dark);
    background: var(--blue);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
  }

  .point-card__row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
  }

  .point-card__row:last-child {
    margin-bottom: 0;
  }

  .point-card__value {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
  }

  .point-card__value a {
    color: var(--blue);
    text-decoration: none;
  }

  .point-card__value a:hover {
    text-decoration: underline;
  }

  /* Table to Cards (legacy single-row) */
  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    position: relative;
  }

  .data-table tr td:first-child {
    padding-top: 0;
  }

  .data-table tr td:last-child {
    padding-bottom: 0;
  }

  .data-table td {
    padding: 8px 0;
    text-align: left;
    border: none;
    font-size: 14px;
    line-height: 1.5;
    vertical-align: top;
  }

  .data-table td:before {
    content: attr(data-label);
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 2px;
    margin-right: 6px;
    white-space: nowrap;
  }

  .data-table td a {
    word-break: break-all;
  }

  .data-table td.text-center {
    text-align: left;
  }

  /* Button in table */
  .data-table .btn-view-cert {
    display: inline-block;
    padding: 8px 16px;
    font-size: 13px;
    margin-top: 4px;
  }

  /* Status badge */
  .data-table .status {
    display: inline-block;
    padding: 5px 10px;
  }

  /* Bold labels in mobile cards */
  .data-table td strong {
    font-weight: 600;
  }

  /* Separator between fields */
  .data-table td + td {
    border-top: 1px solid #f0f0f0;
    margin-top: 4px;
    padding-top: 12px;
  }

  /* Viewport-based toggling: desktop table vs mobile grouped cards */
  .desktop-only {
    display: none !important;
  }

  .mobile-grouped {
    display: block;
  }

  /* Footer */
  .table-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    text-align: center;
  }

  .pagination {
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
  }

  .pagination a,
  .pagination button {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    font-size: 14px;
  }

  .page-size {
    width: 100%;
    text-align: center;
  }

  /* Form grid */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .form-section {
    margin-bottom: 28px;
    padding-bottom: 20px;
  }

  .form-section__header h2 {
    font-size: 16px;
  }

  .form-section__header p {
    font-size: 13px;
  }

  /* Point cards */
  .point-card {
    padding: 16px;
    margin-bottom: 16px;
  }

  .weekdays {
    gap: 8px;
  }

  .weekdays label {
    font-size: 14px;
    padding: 6px 10px;
    background: #f5f7fa;
    border-radius: 6px;
    border: 1px solid var(--border);
  }

  /* Buttons */
  .ui-btn {
    padding: 14px 20px;
    font-size: 15px;
    min-height: 48px;
  }

  .btn {
    padding: 14px 24px;
    font-size: 16px;
    min-height: 48px;
    width: 100%;
    text-align: center;
  }

  .form-actions {
    margin-top: 20px;
  }

  /* Modal */
  .modal-content {
    margin: 16px;
    padding: 24px 20px;
    max-width: calc(100% - 32px);
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
    min-width: auto;
  }

  /* Extract page */
  .public-extract-card {
    padding: 20px 16px;
  }

  .public-extract-header {
    flex-direction: column;
    gap: 16px;
  }

  .public-extract-header h1 {
    font-size: 22px;
  }

  .public-extract-info {
    grid-template-columns: 1fr;
  }

  .public-extract-footer {
    flex-direction: column;
    gap: 16px;
  }

  .public-extract-downloads {
    width: 100%;
  }

  .public-extract-btn {
    flex: 1;
    text-align: center;
  }

  .public-extract-table-wrap {
    margin: 0 -16px;
    padding: 0 16px;
    border-radius: 0;
  }

  .public-extract-table th,
  .public-extract-table td {
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* ---------- Small phones ---------- */
@media (max-width: 480px) {
  .admin-main {
    padding: 64px 12px 20px;
  }

  .admin-page__header h1 {
    font-size: 16px;
  }

  .admin-card,
  .admin-card--flush {
    padding: 12px;
  }

  .data-table td {
    font-size: 13px;
    padding: 4px 0;
  }

  .data-table td:before {
    font-size: 10px;
  }

  .data-table td {
    font-size: 13px;
  }

  .data-table td strong {
    font-size: 13px;
  }

  .data-table tr {
    padding: 12px;
    margin-bottom: 10px;
  }

  .ui-field input,
  .ui-field select,
  .ui-field textarea {
    padding: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ---------- Landscape phones ---------- */
@media (max-width: 700px) and (orientation: landscape) {
  .admin-main {
    padding: 60px 16px 16px;
  }

  .admin-page__header h1 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .data-table tr {
    margin-bottom: 8px;
  }
}

