:root {
  --bg-canvas: #ffffff;
  --bg-surface: #ffffff;
  --bg-sidebar: #fafafa;
  --bg-soft: #f7f7f8;
  --border: #dfe3e8;
  --border-strong: #c7cdd4;
  --text-primary: #17141f;
  --text-secondary: #2c3440;
  --text-muted: #667085;
  --text-subtle: #98a2b3;
  --accent: #8257e5;
  --accent-rgb: 130, 87, 229;
  --accent-hover: #6f44d4;
  --accent-light: #f5f3ff;
  --success: #10b981;
  --danger: #ef4444;
  --shell-header-height: 48px;
  --sidebar-width: 220px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-full: 9999px;
  --font-sans: "SF Pro Text", "PingFang SC", "Segoe UI", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 14px;
  scrollbar-gutter: stable;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
  font-family: var(--font-sans);
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg-canvas);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  min-height: var(--shell-header-height);
  padding: 0 12px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.sidebar-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-version {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow: auto;
}

.nav-section {
  margin-bottom: 14px;
}

.nav-section-title {
  padding: 6px 8px;
  color: var(--text-subtle);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-light);
  border-color: rgba(var(--accent-rgb), 0.18);
  color: var(--accent-hover);
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: currentColor;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.nav-badge {
  margin-left: auto;
  padding: 2px 6px;
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--accent-hover);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.method-note {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.note-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
}

.method-note p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.workspace {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  background: #ffffff;
  overflow-x: clip;
}

.main-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--shell-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

.page-heading {
  min-width: 0;
}

.page-title {
  margin: 0;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
}

.page-subtitle {
  max-width: 64ch;
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}

.header-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn,
button,
a.btn {
  min-height: 30px;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  background: #ffffff;
  box-shadow: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-decoration: none;
  touch-action: manipulation;
  transition: transform 0.1s ease, background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.btn:active,
button:active,
a.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn-primary {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: #000000;
  border-color: #000000;
}

.btn-secondary,
.btn-ghost,
.segmented button:not(.is-active) {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover,
.btn-ghost:hover,
.segmented button:not(.is-active):hover {
  background: #fafafa;
  border-color: var(--border-strong);
}

.workspace > .toolbar,
.workspace > .stats-grid,
.workspace > .compare-panel,
.workspace > .table-wrap {
  margin: 8px 12px 0;
}

.card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: none;
}

.table-head,
.compare-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.toolbar-head {
  display: none;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

.filter-grid {
  margin-top: 0;
  display: grid;
  grid-template-columns: minmax(260px, 1.35fr) repeat(4, minmax(132px, 1fr));
  gap: 7px 10px;
}

.field,
.year-group {
  min-width: 0;
  min-inline-size: 0;
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-wide {
  grid-column: span 2;
}

.field span,
.year-group legend {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:hover,
select:hover {
  border-color: var(--border-strong);
}

input:focus,
select:focus {
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.12);
  outline: none;
}

input::placeholder {
  color: var(--text-subtle);
}

.segmented {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.segmented button {
  min-width: 0;
  min-height: 30px;
  padding-inline: 4px;
  border-radius: var(--radius-md);
}

.segmented button.is-active {
  background: var(--accent-light);
  border-color: rgba(var(--accent-rgb), 0.2);
  color: var(--accent-hover);
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.08);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(132px, 1fr));
  gap: 8px;
}

.stat {
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: none;
}

.stat span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.compare-panel {
  align-items: center;
}

.detail-body {
  max-width: 72%;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--text-secondary);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.pill strong {
  margin-left: 6px;
  color: var(--text-primary);
}

.table-wrap {
  margin-bottom: 16px;
  padding: 0;
  overflow: hidden;
}

.table-head {
  padding: 9px 10px 7px;
  align-items: center;
}

.result-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.table-scroll {
  max-height: calc(100vh - 168px);
  overflow: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 1476px;
  min-width: 1476px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

col.col-year {
  width: 4%;
}

col.col-school {
  width: 22%;
}

col.col-code {
  width: 6%;
}

col.col-category {
  width: 4%;
}

col.col-boarding {
  width: 4%;
}

col.col-score,
col.col-delta {
  width: 4%;
}

col.col-condition {
  width: 16%;
}

col.col-scope {
  width: 18%;
}

col.col-district {
  width: 10%;
}

col.col-source {
  width: 8%;
}

th,
td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafafa;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.sortable-th {
  padding-top: 0;
  padding-bottom: 0;
}

.sort-button {
  width: 100%;
  min-height: 30px;
  justify-content: flex-end;
  gap: 4px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  box-shadow: none;
  font-size: inherit;
  font-weight: inherit;
}

.sort-button:hover {
  background: rgba(var(--accent-rgb), 0.07);
  color: var(--accent-hover);
}

.sort-button.is-active {
  color: var(--text-primary);
}

.sort-icon {
  width: 12px;
  display: inline-flex;
  justify-content: center;
  color: var(--accent-hover);
  font-size: 11px;
  line-height: 1;
}

tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background: #fcfcfd;
}

tbody tr.is-selected {
  background: #faf8ff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.school-cell {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.school-cell strong {
  display: inline;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 13px;
}

.school-cell span {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 8px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  vertical-align: baseline;
}

.condition-cell,
.scope-cell,
.district-cell {
  white-space: nowrap;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta-up {
  color: var(--danger);
  font-weight: 700;
}

.delta-down {
  color: var(--success);
  font-weight: 700;
}

.source-links {
  display: inline-flex;
  gap: 8px;
  white-space: nowrap;
}

.source-links a {
  color: var(--accent-hover);
  font-weight: 700;
}

.empty-row {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 1180px) {
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-wide {
    grid-column: span 2;
  }

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

  .detail-body {
    max-width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 768px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .nav-section {
    margin-bottom: 0;
  }

  .method-note {
    display: none;
  }

  .workspace {
    margin-left: 0;
  }

  .main-header {
    position: static;
    display: grid;
    padding: 12px 14px;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .workspace > .toolbar,
  .workspace > .stats-grid,
  .workspace > .compare-panel,
  .workspace > .table-wrap {
    margin: 8px 10px 0;
  }

  .filter-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: span 1;
  }

  .toolbar-head,
  .table-head,
  .compare-panel {
    display: grid;
  }
}

@media (max-width: 480px) {
  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 10px;
  }

  .page-title {
    font-size: 15px;
  }

  .header-actions .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
