/* Статистика прохождения ГГЭ — responsive overrides (load after style.css) */

/* Breakpoints: desktop >1200 | tablet 768–1200 | mobile <768 | small <520 */

@media (max-width: 1200px) {
  body {
    display: block;
    overflow-x: hidden;
  }

  .sidebar {
    position: static;
    top: auto;
    width: 100%;
    height: auto;
    z-index: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
  }

  .content {
    margin-left: 0;
    padding: 20px 16px;
    max-width: none;
  }

  .brand {
    margin-bottom: 8px;
  }

  .sidebar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .sidebar nav a {
    white-space: nowrap;
    margin: 0;
    padding: 9px 12px;
    font-size: 13px;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .kpi-grid.compact,
  .kpi-grid.modern-kpi {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2,
  .grid-3,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .admin-catalog {
    grid-template-columns: 1fr;
  }

  .catalog-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .page-header {
    display: grid;
    gap: 12px;
  }

  .header-actions,
  .dashboard-actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }
}

@media (max-width: 768px) {
  .content {
    padding: 16px 14px;
  }

  /* v2 collapsible sidebar — not sticky/fixed */
  .sidebar {
    position: static !important;
    top: auto !important;
    padding: 0 !important;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    min-height: 48px;
  }

  .sidebar-topbar .brand {
    margin-bottom: 0;
    min-width: 0;
    flex: 1 1 auto;
  }

  .sidebar-toggle {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    min-height: 40px;
  }

  .sidebar-nav-panel {
    display: none;
    padding: 0 14px 12px;
    border-top: 1px solid var(--line);
  }

  .sidebar.is-nav-open .sidebar-nav-panel {
    display: block;
  }

  .sidebar-nav-panel .admin-ui-mode-plaque {
    margin: 10px 0;
  }

  .sidebar-nav-panel nav {
    display: grid !important;
    gap: 6px;
    margin-top: 0 !important;
    overflow: visible;
    flex-wrap: unset;
  }

  .sidebar-nav-panel nav a {
    white-space: normal;
    width: 100%;
  }

  .executive-body .executive-sidebar .executive-sidebar-title--compact {
    margin: 0;
    min-width: 0;
  }

  .executive-body .executive-sidebar .executive-sidebar-title--compact strong {
    font-size: 14px;
    line-height: 1.2;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .executive-body .executive-sidebar .sidebar-nav-panel .executive-sidebar-brand,
  .executive-body .executive-sidebar .sidebar-nav-panel > .executive-sidebar-title:not(.executive-sidebar-title--compact) {
    display: none;
  }

  .executive-body .executive-sidebar .sidebar-nav-panel .executive-back-button {
    width: 100%;
    margin: 0 0 10px;
  }

  .page-header h1 {
    font-size: 24px;
    line-height: 1.15;
  }

  .kpi-grid,
  .kpi-grid.compact,
  .kpi-grid.modern-kpi {
    grid-template-columns: 1fr 1fr;
  }

  .kpi strong {
    font-size: 26px;
  }

  .excel-filter-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .search-input {
    min-width: 0;
    width: 100%;
  }

  .filter-dd summary {
    width: 100%;
  }

  .filter-menu {
    position: static;
    box-shadow: none;
    margin-top: 8px;
    min-width: 0 !important;
  }

  .registry-card,
  .table-card:not(.direction-card) {
    overflow: visible;
  }

  .registry-table:not(.registry-desktop-table) thead {
    display: none;
  }

  .registry-table:not(.registry-desktop-table),
  .registry-table:not(.registry-desktop-table) tbody,
  .registry-table:not(.registry-desktop-table) tr,
  .registry-table:not(.registry-desktop-table) td {
    display: block;
    width: 100%;
  }

  .registry-table:not(.registry-desktop-table) tr {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
  }

  .registry-table:not(.registry-desktop-table) td {
    border: none !important;
    padding: 6px 2px;
  }

  .registry-table:not(.registry-desktop-table) td::before {
    display: block;
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 2px;
  }

  .registry-table.v2-registry-table td:nth-child(1) { display: none; }
  .registry-table.v2-registry-table td:nth-child(2)::before { content: "ID замечания"; }
  .registry-table.v2-registry-table td:nth-child(3)::before { content: "Объект"; }
  .registry-table.v2-registry-table td:nth-child(4)::before { content: "Итерация"; }
  .registry-table.v2-registry-table td:nth-child(5)::before { content: "Статус"; }
  .registry-table.v2-registry-table td:nth-child(6)::before { content: "В статусе с"; }
  .registry-table.v2-registry-table td:nth-child(7)::before { content: "Направление"; }
  .registry-table.v2-registry-table td:nth-child(8)::before { content: "Эксперт"; }
  .registry-table.v2-registry-table td:nth-child(9)::before { content: "Раздел документации"; }
  .registry-table.v2-registry-table td:nth-child(10)::before { content: "Вывод о несоответствии"; }
  .registry-table.v2-registry-table td:nth-child(11)::before { content: "Ответ на замечание"; }
  .registry-table.v2-registry-table td:nth-child(12)::before { content: "Ожидаемый результат"; }
  .registry-table.v2-registry-table td:nth-child(13)::before { content: "Причина повторного направления"; }
  .registry-table.v2-registry-table td:nth-child(14)::before { content: "Критичность"; }

  .critical-mode-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .critical-mode-form button {
    width: 100%;
    padding: 10px 12px;
    font-size: 13px;
  }

  .remark-card-grid {
    grid-template-columns: 1fr;
  }

  .admin-section-grid {
    grid-template-columns: 1fr;
  }

  .diff-summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .service-actions {
    display: grid;
    min-width: 0;
  }

  .table-card.direction-card {
    overflow: visible;
  }

  .direction-table {
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .content {
    padding: 12px;
  }

  .kpi-grid,
  .kpi-grid.compact,
  .kpi-grid.modern-kpi {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 21px;
  }

  .primary-link,
  .secondary-link,
  button,
  .secondary-button {
    min-height: 42px;
  }

  .header-actions .primary-link,
  .header-actions .secondary-link,
  .header-actions button {
    flex: 1 1 calc(50% - 4px);
    min-width: 140px;
  }

  .diff-summary-grid {
    grid-template-columns: 1fr;
  }

  .brand-title {
    white-space: nowrap;
  }
}

/* Login */
.login-card {
  width: min(410px, calc(100vw - 24px));
}

/* Remark card layout */
.remark-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.remark-field {
  background: #f8fbfe;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.remark-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.remark-field strong,
.remark-field p {
  margin: 0;
  font-weight: 600;
}

.remark-field.wide {
  grid-column: 1 / -1;
}

/* Admin v2 sections */
.admin-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.admin-danger-zone {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #fecaca;
  border-radius: 16px;
  background: #fff5f5;
}

.admin-danger-zone h2 {
  margin: 0 0 10px;
  color: #991b1b;
}

/* Diff */
.diff-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.diff-kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.diff-kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.diff-kpi strong {
  font-size: 28px;
}

.critical-actions-menu summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 6px;
}

.critical-actions-menu .critical-mode-form {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.critical-actions-menu button {
  width: 100%;
}

.object-filter-select {
  max-width: 360px;
}

.table-scroll-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.diff-id-list {
  margin: 0;
  padding-left: 18px;
}

.diff-history-card {
  margin-bottom: 10px;
}

/* Nav legacy block */
.nav-legacy {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.nav-legacy summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.nav-legacy nav {
  display: grid;
  gap: 6px;
  margin-top: 0;
}

.nav-legacy a {
  font-size: 12px;
  padding: 8px 10px;
}

/* Hide desktop-only table on small screens when card mode enabled */
@media (max-width: 768px) {
  .registry-desktop-only {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .registry-mobile-only {
    display: none !important;
  }
}

/* Override v1 registry mobile labels for v2 column set */
@media (max-width: 980px) {
  .registry-table.v2-registry-table td:nth-child(1) { display: none !important; }
  .registry-table.v2-registry-table td:nth-child(2)::before { content: "ID замечания" !important; }
  .registry-table.v2-registry-table td:nth-child(3)::before { content: "Объект" !important; }
  .registry-table.v2-registry-table td:nth-child(4)::before { content: "Итерация" !important; }
  .registry-table.v2-registry-table td:nth-child(5)::before { content: "Статус" !important; }
  .registry-table.v2-registry-table td:nth-child(6)::before { content: "В статусе с" !important; }
  .registry-table.v2-registry-table td:nth-child(7)::before { content: "Направление" !important; }
  .registry-table.v2-registry-table td:nth-child(8)::before { content: "Эксперт" !important; }
  .registry-table.v2-registry-table td:nth-child(9)::before { content: "Раздел документации" !important; }
  .registry-table.v2-registry-table td:nth-child(10)::before { content: "Вывод о несоответствии" !important; }
  .registry-table.v2-registry-table td:nth-child(11)::before { content: "Ответ на замечание" !important; }
  .registry-table.v2-registry-table td:nth-child(12)::before { content: "Ожидаемый результат" !important; }
  .registry-table.v2-registry-table td:nth-child(13)::before { content: "Причина повторного направления" !important; }
  .registry-table.v2-registry-table td:nth-child(14)::before { content: "Критичность" !important; }
}

/* v2 sidebar: desktop keeps inline layout; mobile uses collapsible topbar */
@media (min-width: 769px) {
  .sidebar-topbar {
    display: contents;
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-nav-panel {
    display: contents;
  }

  .executive-sidebar-title--compact {
    display: none;
  }
}
