/* Final shared responsive contract. Loaded last to resolve legacy scale layers. */
:root {
  --shell-sidebar: 248px;
  --shell-header: 92px;
  --shell-gap: 16px;
  --page-pad-x: clamp(16px, 2.1vw, 30px);
}

html, body { width: 100%; max-width: 100%; overflow: hidden; }
body { min-width: 320px; }
*, *::before, *::after { box-sizing: border-box; }
.crm-date-input { min-width: 0; width: 100%; font-variant-numeric: tabular-nums; }

.no-overlap, .cell-safe, .text-safe, .cell-flex-safe,
.responsive-grid > *, .action-group > *, .table-responsive-safe > * { min-width: 0; }
.text-safe { overflow-wrap: anywhere; }
.truncate-safe { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.responsive-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 14px; }
.action-group, .cell-flex-safe { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.table-responsive-safe { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.app-shell {
  display: grid;
  grid-template-columns: var(--shell-sidebar) minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 0;
}
.app-shell > main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  overflow: auto;
  overscroll-behavior: contain;
}
.sidebar {
  position: sticky;
  inset: 0 auto auto 0;
  width: var(--shell-sidebar);
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}
#navigation { min-height: 0; }
.nav-item, .nav-item > span { min-width: 0; }
.nav-item > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { flex: 0 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto auto auto minmax(150px, auto) minmax(220px, 1fr) auto;
  grid-template-areas: "menu toggle back heading search actions";
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: var(--shell-header);
  height: auto;
  padding: 16px var(--page-pad-x);
}
.menu-button { grid-area: menu; }
#sidebarToggleButton { grid-area: toggle; }
#backTopButton { grid-area: back; }
.page-heading { grid-area: heading; }
.global-search { grid-area: search; }
.topbar-actions { grid-area: actions; }
.menu-button { display: none; }
.page-heading, .global-search, .topbar-actions, .profile-button, .profile-copy { min-width: 0; }
.page-heading { width: auto; }
.page-heading h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-search { width: 100%; max-width: 560px; margin: 0 auto; }
.global-search input { width: 100%; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: nowrap; gap: 7px; }
.topbar-actions > * { flex: 0 0 auto; }
.profile-button { max-width: 220px; }
.profile-copy { overflow: hidden; }
.profile-copy strong, .profile-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1600px;
  min-width: 0;
  margin: 0 auto;
  padding: 24px var(--page-pad-x) 42px;
}
.content > *, .panel, .metric, .form-card, .table-wrap, .table-toolbar,
.filter-cluster, .section-heading, .heading-actions, .panel-header { min-width: 0; max-width: 100%; }
.section-heading, .panel-header, .exam-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 18px;
}
.section-heading > div:first-child, .panel-header > div:first-child, .exam-page-head > div:first-child { min-width: min(100%, 260px); flex: 1 1 320px; }
.section-heading h2, .section-heading p, .panel-header h2, .panel-subtitle, .exam-page-head h1, .exam-page-head p { overflow-wrap: anywhere; }
.heading-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }

.dashboard-kpis, .module-metrics, .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dashboard-operations-grid, .viewer-dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-kpis > *, .module-metrics > *, .metrics > *, .dashboard-operations-grid > *,
.viewer-dashboard-grid > *, .status-strip > * { min-width: 0; }
.status-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-label, .metric-note, .status-card, .status-card > div { min-width: 0; overflow-wrap: anywhere; }
.page-dashboard .exam-schedule > button {
  grid-template-columns: minmax(44px, auto) minmax(0, 1fr) minmax(64px, auto);
  width: 100%;
  min-width: 0;
}
.page-dashboard .exam-schedule > button > * { min-width: 0; }
.page-dashboard .exam-schedule strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.table-wrap, .permission-table-wrap, .exam-table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}
.table-wrap table, .permission-table-wrap table, .exam-table-wrap table { width: 100%; max-width: none; }
th, td { box-sizing: border-box; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 4; background-clip: padding-box; }
td, td > *, th > * { min-width: 0; }
.student-name, .col-school, .missing-list { overflow-wrap: anywhere; }
.students-page-table .student-name b,
.students-page-table .col-group,
.students-page-table .col-school {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.students-page-table .student-name b { display: block; }
.row-action, .table-action, .badge { max-width: 100%; }

.exam-workspace, .exam-date-group, .exam-date-group summary, .exam-kpi { min-width: 0; }
.exam-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.exam-date-group summary { flex-wrap: wrap; }
.exam-date-group summary > * { min-width: 0; }
.exam-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: 146px;
  white-space: nowrap;
  overflow: visible !important;
}
.exam-actions button { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; min-width: 30px; min-height: 30px; margin: 0; padding: 5px 7px; white-space: nowrap; }
.exam-actions button span { display: none; }
.exam-risk-options { display: flex; flex-wrap: wrap; min-width: 0; }
.exam-risk-options label { flex: 1 1 170px; min-width: 0; overflow-wrap: anywhere; }

.modal-backdrop { padding: clamp(8px, 2vw, 20px); overflow: auto; }
.modal-card, .confirm-modal, .utility-panel {
  width: min(760px, 100%);
  max-width: 100%;
  max-height: calc(100dvh - clamp(16px, 4vw, 40px));
  overflow-y: auto;
  overflow-x: hidden;
}
.modal-form-grid, .form-grid { min-width: 0; }
.modal-form-grid > *, .form-grid > * { min-width: 0; }
.modal-actions, .form-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.modal-actions > *, .form-actions > * { max-width: 100%; }
button, input, select, textarea { max-width: 100%; }

body.sidebar-collapsed .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
body.sidebar-collapsed .sidebar { width: 82px; }

@media (min-width: 1440px) {
  :root { --shell-sidebar: 248px; }
  .content { padding-inline: 30px; }
}

@media (min-width: 1200px) and (max-width: 1439px) {
  :root { --shell-sidebar: 224px; --page-pad-x: 20px; }
  .topbar { grid-template-columns: auto auto auto minmax(130px, auto) minmax(180px, 1fr) auto; gap: 9px; }
  .topbar h1 { font-size: 27px; }
  .global-search { max-width: 420px; }
  .profile-button { max-width: 180px; }
  .content { padding-top: 20px; }
  .students-page-table th, .students-page-table td { padding-inline: 6px; font-size: 14px; }
}

@media (max-width: 1199px) {
  :root { --shell-header: auto; --page-pad-x: 18px; }
  .app-shell, body.sidebar-collapsed .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar, body.sidebar-collapsed .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 70;
    width: min(300px, 86vw);
    padding: 22px 16px 16px;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 18px 0 42px rgba(8, 31, 54, .2);
  }
  .sidebar.open { left: 0; transform: translateX(0); }
  .sidebar-overlay.open { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(8, 31, 54, .38); }
  .menu-button { display: grid; place-items: center; }
  .sidebar-toggle-button { display: none; }
  .topbar {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "menu back heading actions"
      "search search search search";
    gap: 10px;
    padding: 13px var(--page-pad-x);
  }
  .page-heading { grid-column: auto; }
  .page-heading h1 { font-size: 28px; }
  .global-search { grid-column: auto; grid-row: auto; max-width: none; margin: 0; }
  .topbar-actions { grid-column: auto; grid-row: auto; }
  .content { padding-top: 20px; }
  .dashboard-kpis, .module-metrics, .metrics, .status-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-operations-grid, .viewer-dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .students-page-table .students-table { min-width: 1040px !important; table-layout: fixed; }
  .inactive-table { min-width: 760px !important; table-layout: fixed; }
  .exam-workspace table { min-width: 780px; table-layout: fixed; }
  .exam-workspace th:last-child, .exam-workspace td:last-child { width: 176px; overflow: visible; }
  .table-wrap th, .table-wrap td, .exam-workspace th, .exam-workspace td { height: auto; padding: 8px; }
}

@media (max-width: 900px) {
  :root { --page-pad-x: 16px; }
  .topbar-actions .profile-copy { display: none; }
  .profile-button { width: 42px; padding: 0; justify-content: center; }
  .profile-button > b { display: none; }
  .dashboard-operations-grid, .viewer-dashboard-grid { grid-template-columns: 1fr; }
  .section-heading, .exam-page-head { align-items: flex-start; }
  .heading-actions { flex: 1 1 100%; justify-content: flex-start; }
  .inactive-filter-card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  :root { --page-pad-x: 13px; }
  .topbar {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "menu back heading"
      "actions actions actions"
      "search search search";
    padding: 11px var(--page-pad-x);
  }
  .page-heading { grid-column: auto; grid-row: auto; }
  .page-heading h1 { font-size: 25px; }
  .topbar-actions { grid-column: auto; grid-row: auto; justify-content: flex-start; }
  .global-search { grid-column: auto; grid-row: auto; }
  .topbar-actions .profile-button { margin-left: auto; }
  .content { padding: 16px var(--page-pad-x) 28px; }
  .dashboard-kpis, .module-metrics, .metrics, .status-strip,
  .dashboard-operations-grid, .viewer-dashboard-grid, .responsive-grid { grid-template-columns: 1fr; }
  .section-heading > div:first-child, .panel-header > div:first-child, .exam-page-head > div:first-child { flex-basis: 100%; }
  .heading-actions { width: 100%; }
  .heading-actions > button { flex: 1 1 160px; }
  .table-toolbar, .filter-cluster { display: grid; grid-template-columns: 1fr; width: 100%; }
  .table-toolbar .search-wrap, .table-toolbar .search, .filter-field, .filter-field .filter { width: 100%; min-width: 0; max-width: none; }
  .inactive-filter-card { grid-template-columns: 1fr; }
  .exam-kpis { grid-template-columns: 1fr; }
  .exam-pills { flex-wrap: wrap; }
  .modal-form-grid, .form-grid { grid-template-columns: 1fr; }
  .modal-form-grid .full-field { grid-column: auto; }
  .modal-actions, .form-actions { width: 100%; }
  .modal-actions > button, .form-actions > button { flex: 1 1 150px; }
}

@media (max-width: 430px) {
  .topbar-actions { gap: 5px; }
  .topbar-actions .icon-button, .menu-button, .back-top-button, .profile-button { width: 38px; height: 38px; min-height: 38px; }
  .page-heading h1 { font-size: 22px; }
  .section-heading h2, .exam-page-head h1 { font-size: 25px; }
  .metric, .panel { padding: 13px; }
  .modal-actions > button, .form-actions > button, .heading-actions > button { flex-basis: 100%; }
}

/* Live Safari repair: deterministic Students columns on wide screens. */
@media (min-width: 1100px) {
  .students-page-table { overflow-x: hidden; }
  .students-page-table .students-table {
    width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
  }
  .students-page-table th,
  .students-page-table td {
    min-width: 0 !important;
    padding-inline: 7px;
    font-size: 14px;
    overflow: hidden;
  }
  .students-page-table thead th {
    font-size: 11px;
    letter-spacing: .02em;
  }
  .students-page-table .col-roll { width: 7% !important; }
  .students-page-table .col-name { width: 19% !important; }
  .students-page-table .col-group { width: 8% !important; }
  .students-page-table .col-school { width: 10% !important; }
  .students-page-table .col-money { width: 7% !important; }
  .students-page-table .col-status { width: 9% !important; }
  .students-page-table .col-row-action { width: 6.5% !important; min-width: 0; }
  .students-page-table .action-column-heading {
    padding-inline: 3px;
    overflow: hidden;
    font-size: 10px;
    letter-spacing: 0;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .students-page-table .student-name,
  .students-page-table .student-name b,
  .students-page-table .col-group,
  .students-page-table .col-school {
    display: table-cell;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .students-page-table .student-name b { display: block; }
  .students-page-table .badge,
  .students-page-table .row-action,
  .students-page-table .inactive-toggle { white-space: nowrap; }
  .students-page-table .row-action { width: 32px; min-width: 32px; padding-inline: 7px; }
  .students-page-table .row-action span { display: none; }
}

/* Between card mode and full desktop, keep scrolling inside the table only. */
@media (min-width: 901px) and (max-width: 1099px) {
  .students-page-table { overflow-x: auto; }
  .students-page-table .students-table { width: 1040px; min-width: 1040px !important; }
  .students-page-table th, .students-page-table td { font-size: 14px; }
  .students-page-table .col-status .badge {
    display: inline-flex;
    min-width: 0;
    max-width: 100%;
    padding-inline: 4px;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
  }
}

/* Students becomes a labelled card collection instead of a squeezed table. */
@media (max-width: 900px) {
  .students-page-table {
    max-height: none;
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  .students-page-table .students-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    background: transparent;
  }
  .students-page-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .students-page-table tbody {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
  }
  .students-page-table .student-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--card);
    box-shadow: 0 4px 14px rgba(22, 67, 115, .06);
  }
  .students-page-table .student-row > td {
    display: grid;
    grid-template-columns: minmax(76px, .42fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: auto !important;
    min-width: 0 !important;
    height: auto;
    min-height: 42px;
    padding: 7px 8px;
    overflow: hidden;
    border: 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    white-space: normal;
  }
  .students-page-table .student-row > td::before {
    content: attr(data-label);
    min-width: 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .students-page-table .student-row > .student-name {
    grid-column: 1 / -1;
    grid-template-columns: minmax(76px, .2fr) minmax(0, 1fr);
  }
  .students-page-table .student-name b {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.35;
    white-space: normal;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .students-page-table .col-group,
  .students-page-table .col-school,
  .students-page-table .col-status,
  .students-page-table .col-money { overflow: hidden; text-overflow: ellipsis; }
  .students-page-table .col-row-action { text-align: left; white-space: normal; }
  .students-page-table .col-row-action .row-action {
    justify-self: start;
    width: auto;
    max-width: 100%;
  }
  .students-page-table .student-row > td:nth-last-child(-n+2) { border-bottom: 0; }
  .table-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    width: 100%;
  }
  .table-toolbar .search-wrap,
  .table-toolbar .search { width: 100%; min-width: 0; max-width: none; }
  .table-toolbar .filter-cluster {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }
  .filter-cluster .filter-field,
  .filter-cluster .filter { width: 100%; min-width: 0; max-width: none; }
  .student-list-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
    gap: 10px;
    margin-top: 0;
  }
  .student-list-actions .filter-field,
  .student-list-actions .filter,
  .student-list-actions .secondary-button { width: 100%; min-width: 0; }
}

@media (max-width: 600px) {
  .students-page-table .student-row { grid-template-columns: minmax(0, 1fr); }
  .students-page-table .student-row > td,
  .students-page-table .student-row > .student-name { grid-column: 1; }
  .students-page-table .student-row > td:nth-last-child(-n+2) { border-bottom: 1px solid var(--line); }
  .students-page-table .student-row > td:last-child { border-bottom: 0; }
  .table-toolbar .filter-cluster,
  .student-list-actions { grid-template-columns: minmax(0, 1fr); }
}

/* Complete dark token contract, loaded after every legacy visual layer. */
[data-theme="dark"] {
  --app-bg: #0B1220;
  --surface: #111D2E;
  --surface-2: #162438;
  --surface-3: #1C2D44;
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --border: #334155;
  --input-bg: #111D2E;
  --input-text: #F8FAFC;
  --canvas: var(--app-bg);
  --card: var(--surface);
  --ink: var(--text-primary);
  --muted: var(--text-muted);
  --line: var(--border);
  --ref-canvas: var(--app-bg);
  --ref-card: var(--surface);
  --ref-ink: var(--text-primary);
  --ref-muted: var(--text-muted);
  --ref-line: var(--border);
  color-scheme: dark;
}
[data-theme="dark"] body,
[data-theme="dark"] .page-dashboard,
[data-theme="dark"] .content { background: var(--app-bg); color: var(--text-primary); }
[data-theme="dark"] .topbar,
[data-theme="dark"] .metric,
[data-theme="dark"] .panel,
[data-theme="dark"] .status-card,
[data-theme="dark"] .detail-card,
[data-theme="dark"] .table-toolbar,
[data-theme="dark"] .table-wrap,
[data-theme="dark"] .inactive-filter-card,
[data-theme="dark"] .inactive-summary-card,
[data-theme="dark"] .form-card,
[data-theme="dark"] .modal-card,
[data-theme="dark"] .confirm-modal,
[data-theme="dark"] .utility-panel,
[data-theme="dark"] .dropdown-menu,
[data-theme="dark"] .profile-menu,
[data-theme="dark"] .global-results,
[data-theme="dark"] .exam-kpi,
[data-theme="dark"] .exam-date-group,
[data-theme="dark"] table,
[data-theme="dark"] tbody tr { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
[data-theme="dark"] .metric-value,
[data-theme="dark"] .metric-label,
[data-theme="dark"] .panel h2,
[data-theme="dark"] .section-heading h2,
[data-theme="dark"] .dashboard-intro h2,
[data-theme="dark"] .page-heading h1,
[data-theme="dark"] .student-name b,
[data-theme="dark"] td,
[data-theme="dark"] strong,
[data-theme="dark"] label { color: var(--text-primary); }
[data-theme="dark"] .metric-note,
[data-theme="dark"] .panel-subtitle,
[data-theme="dark"] .section-heading p,
[data-theme="dark"] .dashboard-intro p,
[data-theme="dark"] small,
[data-theme="dark"] .filter-field > span,
[data-theme="dark"] .result-count,
[data-theme="dark"] .muted { color: var(--text-muted); }
[data-theme="dark"] th,
[data-theme="dark"] .students-page-table thead th,
[data-theme="dark"] .inactive-table thead th { background: var(--surface-2); color: var(--text-secondary); border-color: var(--border); }
[data-theme="dark"] table tbody tr:nth-child(even),
[data-theme="dark"] .students-page-table .student-row:nth-child(even) { background: var(--surface-2); }
[data-theme="dark"] table tbody tr:hover,
[data-theme="dark"] .compact-table tbody tr:hover { background: var(--surface-3) !important; }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .search,
[data-theme="dark"] .filter,
[data-theme="dark"] .global-search input {
  border-color: var(--border) !important;
  background: var(--input-bg) !important;
  color: var(--input-text) !important;
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--text-muted); opacity: 1; }
[data-theme="dark"] option { background: var(--surface); color: var(--input-text); }
[data-theme="dark"] .icon-button,
[data-theme="dark"] .menu-button,
[data-theme="dark"] .back-top-button,
[data-theme="dark"] .profile-button,
[data-theme="dark"] .secondary-button,
[data-theme="dark"] .row-action,
[data-theme="dark"] .table-action,
[data-theme="dark"] .panel-link { border-color: var(--border); background: var(--surface-2); color: var(--text-secondary); }
[data-theme="dark"] .students-page-table .student-row { background: var(--surface); border-color: var(--border); }

/* Atomic surface overrides prevent legacy white backgrounds surviving in Safari. */
html[data-theme="dark"] .metric { background: #111D2E !important; }
html[data-theme="dark"] .panel { background: #111D2E !important; }
html[data-theme="dark"] .status-card { background: #111D2E !important; }
html[data-theme="dark"] .detail-card { background: #111D2E !important; }
html[data-theme="dark"] .table-toolbar { background: #111D2E !important; }
html[data-theme="dark"] .inactive-filter-card { background: #111D2E !important; }
html[data-theme="dark"] .inactive-summary-card { background: #111D2E !important; }
html[data-theme="dark"] .form-card { background: #111D2E !important; }
html[data-theme="dark"] .modal-card { background: #111D2E !important; }
html[data-theme="dark"] .confirm-modal { background: #111D2E !important; }
html[data-theme="dark"] .utility-panel { background: #111D2E !important; }
html[data-theme="dark"] .exam-kpi { background: #111D2E !important; }
html[data-theme="dark"] .exam-date-group { background: #111D2E !important; }
html[data-theme="dark"] .students-page-table tbody tr:nth-child(odd) > td { background: #111D2E !important; }
html[data-theme="dark"] .students-page-table tbody tr:nth-child(even) > td { background: #162438 !important; }
html[data-theme="dark"] input { background: #111D2E !important; color: #F8FAFC !important; }
html[data-theme="dark"] select { background: #111D2E !important; color: #F8FAFC !important; }
html[data-theme="dark"] textarea { background: #111D2E !important; color: #F8FAFC !important; }
html[data-theme="dark"] .page-dashboard .dashboard-kpis .metric-label { color: #F1F5F9 !important; }
html[data-theme="dark"] .page-dashboard .dashboard-kpis .metric-note { color: #94A3B8 !important; }

/* Keep the theme switch available where older tablet rules hide utilities. */
#themeButton.topbar-utility { display: grid; place-items: center; }

/* Shared hybrid date control: the visible value remains DD/MM/YYYY while the
   native input supplies a consistent calendar on desktop and tablet. */
.crm-date-control {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.5rem;
  align-items: center;
  gap: .4rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.crm-date-control > .crm-date-input { width: 100%; min-width: 0; box-sizing: border-box; }
.crm-calendar-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line, #dce5f1);
  border-radius: 10px;
  background: var(--card, #fff);
  color: var(--primary, #0869ed);
  cursor: pointer;
}
.crm-calendar-button:hover { border-color: var(--primary, #0869ed); background: color-mix(in srgb, var(--primary, #0869ed) 7%, var(--card, #fff)); }
.crm-calendar-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary, #0869ed) 22%, transparent); outline-offset: 2px; }
.crm-calendar-button svg { width: 17px; height: 17px; pointer-events: none; }
.crm-date-native {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.available-dates-field,
.settings-group-date-control { min-width: 0; }
.available-dates-field > label,
.settings-group-date-control > span { display: block; margin-bottom: .4rem; font-weight: 700; }
.available-date-row { display: grid; grid-template-columns: minmax(0, 1fr) 2.15rem; align-items: center; gap: .45rem; min-width: 0; }
.available-date-row .crm-date-control { min-width: 0; }
.available-date-row .icon-button { width: 2.15rem; min-width: 2.15rem; height: 2.15rem; }
.settings-group-date-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .45rem; }
.settings-group-date-control > span,
.settings-group-date-control > small { grid-column: 1 / -1; }
.settings-group-date-control .secondary-button { min-height: 2.5rem; white-space: nowrap; }
[data-theme="dark"] .crm-calendar-button { border-color: var(--border); background: var(--surface-2); color: #93c5fd; }

@media (max-width: 820px) {
  .crm-date-control { grid-template-columns: minmax(0, 1fr) 2.75rem; }
  .crm-calendar-button { width: 2.75rem; min-width: 2.75rem; height: 2.75rem; }
  .settings-group-date-control { grid-template-columns: minmax(0, 1fr); }
  .settings-group-date-control .secondary-button { width: 100%; }
}

/* Rotating the whole square control enlarges its visual bounding box and can
   collide with adjacent controls on iPad. Keep the loading feedback in-place. */
.icon-button.loading { animation: responsive-control-pulse .8s ease-in-out infinite; }
@keyframes responsive-control-pulse { 50% { opacity: .55; } }

/* Student table: Safari does not reliably clip a bare text node on a
   table-cell. Keep Group and School in a constrained inner box so adjacent
   values can never paint into one another. */
.students-page-table .student-table-cell-value {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 1100px) {
  .students-page-table .col-name { width: 17% !important; }
  .students-page-table .col-group { width: 9.5% !important; padding-inline: 6px; }
  .students-page-table .col-school { width: 10.5% !important; padding-inline: 6px; }
  .students-page-table .col-row-action { width: 6.5% !important; }
}

@media (min-width: 901px) and (max-width: 1099px) {
  .students-page-table { overflow-x: auto; overflow-y: auto; }
  .students-page-table .students-table {
    width: 1100px;
    min-width: 1100px !important;
    table-layout: fixed;
  }
  .students-page-table .col-name { width: 17% !important; }
  .students-page-table .col-group { width: 9.5% !important; padding-inline: 6px; }
  .students-page-table .col-school { width: 10.5% !important; padding-inline: 6px; }
  .students-page-table .col-row-action { width: 6.5% !important; }
}

/* Theme surfaces must switch atomically: a light background must never linger
   while the foreground has already changed to the dark-theme palette. */
html[data-theme="dark"] .metric,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .status-card,
html[data-theme="dark"] .detail-card,
html[data-theme="dark"] .table-toolbar,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .inactive-filter-card,
html[data-theme="dark"] .inactive-summary-card,
html[data-theme="dark"] .form-card,
html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .confirm-modal,
html[data-theme="dark"] .utility-panel,
html[data-theme="dark"] .exam-kpi,
html[data-theme="dark"] .exam-date-group {
  transition-property: border-color, color, box-shadow, transform;
}
