:root {
  color-scheme: light;
  --ink: #13221b;
  --muted: #617069;
  --line: #dfe7e2;
  --canvas: #f3f6f4;
  --surface: #ffffff;
  --forest: #123b2a;
  --green: #16834f;
  --green-soft: #dff3e8;
  --blue: #3268dc;
  --blue-soft: #e5edff;
  --amber: #c67a13;
  --red: #c33f45;
  --shadow: 0 10px 30px rgba(21, 52, 38, .08);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, select { font: inherit; }
.app-shell { width: min(1460px, 100%); margin: 0 auto; padding: 28px 28px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 24px; padding: 24px 28px; color: white; background: linear-gradient(135deg, #0f3022, #145c3a); border-radius: 20px; box-shadow: var(--shadow); }
.brand-kicker, .section-kicker { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 800; }
.brand-kicker { color: #9fe0bd; }
h1 { margin: 5px 0 4px; font-size: clamp(1.7rem, 3vw, 2.45rem); line-height: 1.05; }
.topbar p { margin: 0; color: #cce7d8; font-size: .9rem; }
.freshness { display: flex; align-items: center; gap: 10px; min-width: 180px; padding: 10px 12px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); border-radius: 12px; }
.freshness[hidden] { display: none; }
.freshness-dot { width: 10px; height: 10px; background: #54d58a; border-radius: 50%; box-shadow: 0 0 0 4px rgba(84,213,138,.16); }
.freshness-dot.is-stale { background: #f2b24a; box-shadow: 0 0 0 4px rgba(242,178,74,.18); }
.freshness strong, .freshness span { display: block; }
.freshness strong { font-size: .85rem; }
.freshness span { margin-top: 2px; color: #cce7d8; font-size: .67rem; text-transform: uppercase; letter-spacing: .06em; }

.filter-bar { position: sticky; top: 12px; z-index: 20; display: grid; grid-template-columns: minmax(185px, .55fr) minmax(230px, .72fr) minmax(390px, 1.3fr); gap: 14px; margin: 18px 0 26px; padding: 12px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.filter-field, .level-switcher { min-width: 0; }
.filter-field { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.filter-field--year { grid-template-columns: 1fr; align-content: center; gap: 4px; }
.filter-field--year select { min-width: 132px; }
.filter-field > span, .level-switcher legend { color: var(--muted); font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.filter-field select { width: 100%; min-width: 0; padding: 11px 34px 11px 12px; color: var(--ink); background: #f8faf9; border: 1px solid var(--line); border-radius: 10px; font-weight: 700; }
.level-switcher { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; margin: 0; padding: 0; border: 0; }
.level-switcher > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 4px; background: #edf2ef; border-radius: 11px; }
.level-switcher button { padding: 8px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-weight: 750; cursor: pointer; }
.level-switcher button[aria-pressed="true"] { color: white; background: var(--forest); box-shadow: 0 3px 8px rgba(18,59,42,.18); }

.view-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 0 2px 16px; }
.section-kicker { color: var(--green); }
.view-heading h2 { margin: 3px 0 0; font-size: clamp(1.35rem, 2vw, 1.9rem); }
.view-heading p { margin: 0 0 2px; color: var(--muted); font-size: .85rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi-grid.kpi-grid--region { grid-template-columns: repeat(3, 1fr); }
.kpi { min-height: 126px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.kpi-label { color: var(--muted); font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.kpi-icon { display: grid; place-items: center; width: 30px; height: 30px; color: var(--green); background: var(--green-soft); border-radius: 9px; font-size: .82rem; font-weight: 900; }
.kpi-value { margin-top: 13px; font-size: clamp(1.65rem, 3vw, 2.2rem); font-weight: 800; letter-spacing: -.04em; }
.kpi-detail { margin-top: 5px; color: var(--muted); font-size: .75rem; }
.kpi-detail:empty { display: none; }
.delta-up { color: var(--green); font-weight: 750; }
.delta-down { color: var(--red); font-weight: 750; }

.insight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { min-width: 0; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.panel-wide { grid-column: 1 / -1; }
.weekly-grade-panel { grid-column: 1 / -1; grid-row: 2; }
#attendance-history-panel { grid-column: 1 / -1; grid-row: 3; }
.access-history-panel { grid-column: 1 / -1; grid-row: 4; }
.quality-panel { grid-column: 1 / -1; grid-row: 5; }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 14px; }
.panel-heading span { color: var(--green); font-size: .67rem; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.panel-heading h3 { margin: 3px 0 0; font-size: 1rem; }
.panel-note { margin: 2px 0 0; color: var(--muted); font-size: .72rem; }
.help-tip { position: relative; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 4px; color: var(--forest); background: var(--green-soft); border: 1px solid #a9d8bb; border-radius: 50%; font-size: .65rem; font-style: normal; font-weight: 900; line-height: 1; cursor: help; vertical-align: 1px; }
.help-tip::after { position: absolute; z-index: 10; left: 50%; bottom: calc(100% + 8px); width: min(250px, 65vw); padding: 9px 10px; color: white; background: #173527; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.18); content: attr(data-tooltip); font-size: .72rem; font-style: normal; font-weight: 500; line-height: 1.35; letter-spacing: 0; opacity: 0; pointer-events: none; text-align: left; text-transform: none; transform: translate(-50%, 4px); transition: opacity .15s ease, transform .15s ease; visibility: hidden; white-space: normal; }
.help-tip:hover::after, .help-tip:focus-visible::after { opacity: 1; transform: translate(-50%, 0); visibility: visible; }
.help-tip:focus-visible { outline: 2px solid #70be90; outline-offset: 2px; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .7rem; white-space: nowrap; }
.legend i { width: 15px; height: 7px; margin-left: 8px; border-radius: 4px; }
.legend-current { background: var(--green); }
.legend-prior { background: #3268dc; }
.legend-region { background: #d78b1d; }
.legend .legend-region-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: inherit; font-weight: inherit; letter-spacing: normal; text-transform: none; }
.grade-line-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.grade-legend-button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; color: var(--muted); background: #f4f8f6; border: 1px solid var(--line); border-radius: 999px; font-size: .7rem; font-weight: 750; cursor: pointer; }
.grade-legend-button i { width: 12px; height: 4px; border-radius: 3px; }
.grade-legend-button:hover, .grade-legend-button:focus-visible { color: var(--forest); border-color: #8ab79b; outline: none; }
.grade-legend-button[aria-pressed="true"] { color: white; background: var(--forest); border-color: var(--forest); }
.grade-legend-button[aria-pressed="true"] i { background: #9fe0bd !important; }
.chart { position: relative; min-height: 300px; }
.chart-compact { min-height: 245px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.empty-chart { display: grid; place-items: center; height: 230px; color: var(--muted); font-size: .82rem; }
.chart-gridline { stroke: #e5ebe7; stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; }
.chart-count { fill: var(--muted); font-size: 9px; font-weight: 700; }
.chart-line { fill: none; stroke: var(--green); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: url(#attendanceGradient); opacity: .52; }
.chart-dot { fill: white; stroke: var(--green); stroke-width: 2.5; }
.chart-dot--interactive { cursor: crosshair; }
.chart-dot--interactive:hover, .chart-dot--interactive:focus { fill: #dff3e8; stroke-width: 3.5; outline: none; }
.chart-hover-tooltip { position: absolute; z-index: 5; padding: 6px 9px; color: white; background: #123b2a; border-radius: 7px; box-shadow: 0 4px 14px rgba(21,52,38,.2); font-size: .74rem; font-weight: 750; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; }
.chart-value { fill: var(--ink); font-size: 11px; font-weight: 750; }
.access-band { cursor: pointer; outline: none; transition: opacity .15s ease; }
.access-band:hover, .access-band:focus { opacity: .78; }
.access-band[aria-pressed="true"] { stroke: var(--ink); stroke-width: 3; }
.bar-current { fill: var(--green); }
.bar-prior { fill: #3268dc; }
.bar-region { fill: #d78b1d; }
.quality-row { display: grid; grid-template-columns: 92px 1fr 46px; align-items: center; gap: 10px; margin: 16px 0; }
.quality-label { color: var(--ink); font-size: .76rem; font-weight: 700; }
.quality-track { height: 12px; overflow: hidden; background: #edf2ef; border-radius: 7px; }
.quality-fill { height: 100%; border-radius: 7px; }
.quality-value { text-align: right; font-size: .76rem; font-weight: 800; }
.access-selector { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -2px 0 5px; }
.access-selector > span { color: var(--muted); font-size: .69rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
#access-band-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
#access-band-buttons button { padding: 6px 11px; color: var(--muted); background: #f1f5f2; border: 1px solid var(--line); border-radius: 999px; font-size: .74rem; font-weight: 800; cursor: pointer; }
#access-band-buttons button:hover, #access-band-buttons button:focus-visible { color: var(--forest); border-color: #8ab79b; outline: none; }
#access-band-buttons button[aria-pressed="true"] { color: white; background: var(--forest); border-color: var(--forest); }
.access-selection-note { min-height: 18px; margin: 4px 0 0; color: var(--muted); font-size: .72rem; }
.absence-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.absence-filters label { display: grid; gap: 5px; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.absence-filters select { width: 100%; padding: 9px 30px 9px 10px; color: var(--ink); background: #f8faf9; border: 1px solid var(--line); border-radius: 9px; font-size: .8rem; font-weight: 700; text-transform: none; }
.absence-summary { margin-bottom: 12px; color: var(--muted); font-size: .78rem; }
.absence-summary strong { color: var(--ink); }
.absence-table-wrap { max-height: 340px; }
#absence-table th, #absence-table td { text-align: right; }
#absence-table th:first-child, #absence-table td:first-child { text-align: left; }
.watchlist-table-wrap { max-height: 360px; }
.watchlist-table-wrap th, .watchlist-table-wrap td { text-align: right; }
.watchlist-table-wrap th:first-child, .watchlist-table-wrap td:first-child { text-align: left; }
.watchlist-alert { color: var(--red); font-weight: 800; }
.cohort-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.cohort-metric { padding: 12px; background: #f4f8f6; border: 1px solid var(--line); border-radius: 11px; }
.cohort-metric span { display: block; color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.cohort-metric strong { display: block; margin-top: 4px; color: var(--ink); font-size: 1.22rem; }
.cohort-detail-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); gap: 18px; }
.cohort-detail-grid h4 { margin: 0 0 8px; font-size: .82rem; }
#cohort-absence-table th, #cohort-absence-table td { text-align: right; }
#cohort-absence-table th:first-child, #cohort-absence-table td:first-child { text-align: left; }

.table-panel { margin-top: 16px; }
.table-heading { align-items: end; }
.table-heading p { margin: 0; color: var(--muted); font-size: .72rem; }
.table-wrap { overflow: auto; max-height: 540px; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .78rem; }
th { position: sticky; top: 0; z-index: 2; padding: 11px 12px; color: #e9f6ee; background: var(--forest); text-align: right; white-space: nowrap; }
th:first-child { left: 0; z-index: 3; text-align: left; }
.sort-button { width: 100%; padding: 0; color: inherit; background: transparent; border: 0; font: inherit; font-weight: inherit; text-align: inherit; cursor: pointer; }
.sort-button:hover, .sort-button:focus-visible { color: #9fe0bd; outline: none; }
.sort-button:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
#summary-table th:nth-child(5), #summary-table th:nth-child(6) { width: 124px; min-width: 124px; padding: 10px 8px; white-space: normal; }
#summary-table th:nth-child(5) .sort-button, #summary-table th:nth-child(6) .sort-button { line-height: 1.15; white-space: normal; }
/* Header help popovers open into the table body instead of being clipped above
   the scrollable table container. */
#summary-table th .help-tip::after { top: calc(100% + 8px); bottom: auto; transform: translate(-50%, -4px); }
#summary-table th .help-tip:hover::after, #summary-table th .help-tip:focus-visible::after { transform: translate(-50%, 0); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
td:first-child { position: sticky; left: 0; z-index: 1; color: var(--ink); background: white; text-align: left; font-weight: 750; }
tr:nth-child(even) td { background: #f8faf9; }
tr:nth-child(even) td:first-child { background: #f8faf9; }
tr:hover td { background: #eef7f2; }
tr:hover td:first-child { background: #eef7f2; }
.status-stale { color: var(--amber); font-weight: 750; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px 3px 0; color: var(--muted); font-size: .72rem; }
.error-state { width: min(560px, calc(100% - 32px)); margin: 15vh auto; padding: 30px; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); text-align: center; }
.error-state code { color: var(--green); }

@media (max-width: 900px) {
  .app-shell { padding: 16px 14px 36px; }
  .topbar { align-items: start; }
  .filter-bar { position: static; grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .insight-grid { grid-template-columns: 1fr; }
  .panel-wide { grid-column: auto; }
  .cohort-detail-grid { grid-template-columns: 1fr; }
  .weekly-grade-panel, #attendance-history-panel, .access-history-panel, .quality-panel { grid-column: auto; grid-row: auto; }
}

@media (max-width: 560px) {
  .topbar, .view-heading, footer { flex-direction: column; align-items: stretch; }
  .freshness { min-width: 0; }
  .filter-field, .level-switcher { grid-template-columns: 1fr; gap: 6px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .absence-filters { grid-template-columns: 1fr; }
  .cohort-metrics { grid-template-columns: 1fr; }
  .grade-line-legend { justify-content: flex-start; }
  .panel { padding: 14px; }
  .table-heading { align-items: start; }
}
