@import url("./tokens.css");

:root,
[data-theme="dark"],
[data-theme="light"] {
  --bg: var(--ux-color-bg);
  --surface: var(--ux-color-surface);
  --surface-2: var(--ux-color-surface2);
  --surface-glass: var(--ux-color-glass);
  --border: var(--ux-color-border);
  --text-primary: var(--ux-color-text-primary);
  --text-secondary: var(--ux-color-text-secondary);
  --text-muted: var(--ux-color-text-muted);
  --text-inverse: var(--ux-color-text-inverse);
  --accent: var(--ux-color-accent-primary);
  --accent-2: var(--ux-color-accent-secondary);
  --success: var(--ux-color-status-success);
  --warning: var(--ux-color-status-warning);
  --danger: var(--ux-color-status-danger);
  --status-info: var(--ux-color-status-info);
  --focus-ring: var(--ux-color-focus-ring);
  --chart-grid: var(--ux-color-viz-grid);
  --chart-axis: var(--ux-color-viz-axis);
  --viz-seq-low: var(--ux-color-viz-sequential-low);
  --viz-seq-mid: var(--ux-color-viz-sequential-mid);
  --viz-seq-high: var(--ux-color-viz-sequential-high);
  --viz-div-neg: var(--ux-color-viz-diverging-neg);

  --font: var(--ux-type-font-family-sans);
  --display: var(--ux-type-font-size-display);
  --h1: var(--ux-type-font-size-h1);
  --h2: var(--ux-type-font-size-h2);
  --h3: var(--ux-type-font-size-h3);
  --body: var(--ux-type-font-size-body);
  --small: var(--ux-type-font-size-small);
  --caption: var(--ux-type-font-size-caption);
  --lh-display: var(--ux-type-line-height-display);
  --lh-heading: var(--ux-type-line-height-heading);
  --lh-body: var(--ux-type-line-height-body);
  --kpi-numerals: var(--ux-type-numerals-kpi);

  --radius-card: var(--ux-radius-card);
  --radius-button: var(--ux-radius-button);
  --radius-chip: var(--ux-radius-chip);
  --radius-input: var(--ux-radius-input);
  --radius-chart: var(--ux-radius-chart);

  --shadow-card: var(--ux-shadow-card);
  --shadow-hover: var(--ux-shadow-hover);
  --shadow-popover: var(--ux-shadow-popover);
  --border-thin: var(--ux-border-thin);

  --fast: var(--ux-motion-duration-fast);
  --base: var(--ux-motion-duration-base);
  --slow: var(--ux-motion-duration-slow);
  --ease: var(--ux-motion-ease-standard);

  --max-width: var(--ux-layout-max-width);
  --gutter: var(--ux-layout-gutter);
  --section-space: var(--ux-layout-section-gap);
  --grid-gap: var(--ux-layout-grid-gap);
  --header-height: calc(var(--ux-space-32) + var(--ux-space-32));
  --filter-top: var(--header-height);
  --side-rail-width: calc(var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-8));
  --side-rail-top: calc(var(--header-height) + var(--header-height));
  --chart-min-height: calc(var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-20));
  --menu-min-width: calc(var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-20));
  --menu-top: calc(var(--ux-space-24) + var(--ux-space-24) + var(--ux-space-24));
  --tooltip-max-width: calc(var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40));
  --drawer-width: calc(var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-40) + var(--ux-space-20));
  --rail-main-padding-bottom: var(--ux-space-40);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font); background: radial-gradient(ellipse at 20% -10%, var(--viz-seq-low), transparent), var(--bg); color: var(--text-primary); font-size: var(--body); }

body { min-height: 100vh; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.skip-link {
  position: absolute;
  inset-inline-start: 0;
  top: var(--ux-space-8);
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: translateY(0);
  inset-inline-start: var(--ux-space-8);
  z-index: 999;
  background: var(--surface);
  color: var(--text-primary);
  padding: var(--ux-space-8) var(--ux-space-12);
  border-radius: var(--radius-input);
  border: var(--border-thin);
}

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background: var(--surface-glass);
  background: color-mix(in oklab, var(--surface-glass) 85%, transparent);
  border-bottom: var(--border-thin);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ux-space-12);
  height: 100%;
}

.logo-wrap { display: flex; align-items: center; gap: var(--ux-space-8); }
.logo-dot {
  width: var(--ux-space-12);
  height: var(--ux-space-12);
  border-radius: var(--radius-chip);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 var(--ux-space-4) var(--viz-seq-low);
}
.logo-title { font-size: var(--small); font-weight: 600; }
.logo-subtitle { font-size: var(--caption); color: var(--text-muted); }

.top-nav { display: flex; gap: var(--ux-space-8); flex-wrap: wrap; }
.top-nav a, .side-rail a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: var(--ux-space-8) var(--ux-space-12);
  border-radius: var(--radius-input);
  font-size: var(--small);
}
.top-nav a:hover, .side-rail a:hover,
.top-nav a.active, .side-rail a.active {
  color: var(--text-primary);
  background: var(--surface-glass);
}

.header-tools { display: flex; align-items: center; gap: var(--ux-space-8); }
.chip-row { display: flex; gap: var(--ux-space-8); flex-wrap: wrap; }

.global-filter-bar {
  position: sticky;
  top: var(--filter-top);
  z-index: 45;
  border-bottom: var(--border-thin);
  background: var(--surface-glass);
}

.filter-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--ux-space-12);
  padding-top: var(--ux-space-12);
  padding-bottom: var(--ux-space-12);
}

.filter-group {
  display: grid;
  gap: var(--ux-space-4);
}

.filter-label {
  font-size: var(--caption);
  color: var(--text-muted);
}

.filter-select {
  min-height: calc(var(--ux-space-24) + var(--ux-space-12));
  border-radius: var(--radius-input);
  border: var(--border-thin);
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 0 var(--ux-space-8);
}

.filter-select:focus-visible {
  outline: var(--border-thin);
  outline-color: var(--focus-ring);
  outline-offset: 0;
}

.app-shell { display: flex; gap: var(--ux-space-20); padding-top: var(--ux-space-20); }
.side-rail {
  width: var(--side-rail-width);
  display: none;
  position: sticky;
  top: var(--side-rail-top);
  align-self: flex-start;
  border: var(--border-thin);
  border-radius: var(--radius-card);
  background: var(--surface-glass);
  padding: var(--ux-space-12);
}
.side-rail a { display: block; }

.main {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--grid-gap);
  align-items: start;
  padding-bottom: var(--rail-main-padding-bottom);
}

.section { min-width: 0; }
.section.span-12 { grid-column: span 12; }
.section.span-8 { grid-column: span 8; }
.section.span-7 { grid-column: span 7; }
.section.span-5 { grid-column: span 5; }
.section.span-4 { grid-column: span 4; }

.card {
  background: var(--surface-glass);
  border: var(--border-thin);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--ux-space-20);
}
.card h1, .card h2, .card h3 { margin-top: 0; }
.card h1 { font-size: var(--h1); line-height: var(--lh-heading); }
.card h2 { font-size: var(--h2); line-height: var(--lh-heading); }
.card h3 { font-size: var(--h3); line-height: var(--lh-heading); }

.btn {
  height: calc(var(--ux-space-24) + var(--ux-space-20));
  border-radius: var(--radius-button);
  border: var(--border-thin);
  border-color: transparent;
  padding: 0 var(--ux-space-12);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease), background var(--base) var(--ease);
}
.btn:focus-visible,
.chip:focus-visible,
.top-nav a:focus-visible,
.side-rail a:focus-visible,
.menu-item:focus-visible {
  outline: var(--border-thin);
  outline-color: var(--focus-ring);
  outline-offset: 0;
}
.btn:hover { box-shadow: var(--shadow-hover); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--text-inverse); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--danger); color: var(--text-inverse); }

.chip {
  height: var(--ux-space-32);
  border-radius: var(--radius-chip);
  border: var(--border-thin);
  color: var(--text-primary);
  background: var(--surface-2);
  padding: 0 var(--ux-space-12);
  cursor: pointer;
}
.chip-filter { background: color-mix(in srgb, var(--surface-2) 75%, var(--accent) 10%); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--ux-space-12);
}
.kpi {
  border: var(--border-thin);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  padding: var(--ux-space-12);
}
.kpi-label { font-size: var(--small); color: var(--text-secondary); margin-bottom: var(--ux-space-8); }
.kpi-value {
  font-size: var(--display);
  line-height: var(--lh-display);
  font-weight: 600;
  font-variant-numeric: var(--kpi-numerals);
}
.kpi-value-compact {
  font-size: var(--h2);
  line-height: var(--lh-heading);
}
.kpi-trend { margin-top: var(--ux-space-8); font-size: var(--small); color: var(--text-muted); }

.chart-frame {
  border: var(--border-thin);
  border-radius: var(--radius-chart);
  background: var(--surface-2);
  padding: var(--ux-space-12);
}
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--ux-space-12);
}
.chart-head > div:first-child { min-width: 0; }
.chart-title {
  font-size: var(--h3);
  margin: 0;
  overflow-wrap: anywhere;
}
.chart-subtitle {
  color: var(--text-secondary);
  font-size: var(--small);
  overflow-wrap: anywhere;
}
.chart-canvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: var(--chart-min-height);
  margin-top: var(--ux-space-12);
  border-radius: var(--radius-input);
  background-image: linear-gradient(to top, transparent 0 95%, var(--chart-grid) 95% 96%, transparent 96% 100%);
  background-size: 100% var(--ux-space-28);
  border: var(--border-thin);
}
.chart-canvas [data-college-id] { cursor: pointer; }
.chart-canvas rect:focus-visible,
.chart-canvas circle:focus-visible,
.chart-canvas g[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
.chart-tools { display: flex; gap: var(--ux-space-8); }

.table-eq {
  margin-top: var(--ux-space-12);
  width: 100%;
  border-collapse: collapse;
  font-size: var(--caption);
}
.table-eq th, .table-eq td {
  border-bottom: var(--border-thin);
  padding: var(--ux-space-8);
  text-align: left;
}

.info-list { margin: 0; padding-left: var(--ux-space-20); color: var(--text-secondary); }
.info-list li { margin-bottom: var(--ux-space-8); }

.story-strip { display: grid; gap: var(--ux-space-8); }
.story-link {
  display: block;
  border: var(--border-thin);
  border-radius: var(--radius-input);
  padding: var(--ux-space-12);
  color: var(--text-primary);
  background: var(--surface-2);
  text-decoration: none;
}

.control-row {
  display: flex;
  gap: var(--ux-space-12);
  flex-wrap: wrap;
}

.ranked-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.ranked-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: calc(var(--ux-space-24) + var(--ux-space-24));
  border-bottom: var(--border-thin);
  padding: 0 var(--ux-space-8);
  cursor: pointer;
}
.ranked-item:hover { background: var(--surface-2); }

.accordion summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
}
.accordion summary:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-input);
}
.accordion p, .accordion li { color: var(--text-secondary); }

.tabs {
  display: flex;
  gap: var(--ux-space-8);
  margin-bottom: var(--ux-space-12);
}
.tab-content { color: var(--text-secondary); }

.menu {
  position: fixed;
  top: var(--menu-top);
  right: var(--ux-space-20);
  background: var(--surface-2);
  border: var(--border-thin);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow-popover);
  min-width: var(--menu-min-width);
  z-index: 70;
  overflow: hidden;
}
.menu[hidden] { display: none !important; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--ux-space-12);
  border: 0;
  color: var(--text-primary);
  background: transparent;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-glass); }

.tooltip-wrap { position: relative; display: inline-block; }
.tooltip-btn {
  border: var(--border-thin);
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--radius-chip);
  width: var(--ux-space-24);
  height: var(--ux-space-24);
  line-height: var(--ux-space-20);
  text-align: center;
  font-size: var(--caption);
  cursor: pointer;
}
.tooltip {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--ux-space-8));
  width: min(var(--tooltip-max-width), 70vw);
  padding: var(--ux-space-12);
  background: var(--surface-2);
  border: var(--border-thin);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow-popover);
  color: var(--text-secondary);
  font-size: var(--caption);
  display: none;
  z-index: 80;
}
.tooltip-wrap:focus-within .tooltip,
.tooltip-wrap:hover .tooltip { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: calc(var(--drawer-width) * -1);
  width: var(--drawer-width);
  max-width: 90vw;
  height: 100vh;
  background: var(--surface);
  border-left: var(--border-thin);
  box-shadow: var(--shadow-popover);
  z-index: 90;
  transition: right var(--slow) var(--ease);
  padding: var(--ux-space-16);
}

/* Progressive enhancement: keep glass blur only on browsers that support it. */
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .header,
  .global-filter-bar,
  .side-rail,
  .card,
  .drawer {
    -webkit-backdrop-filter: blur(var(--ux-glass-blur));
    backdrop-filter: blur(var(--ux-glass-blur));
  }
}
.drawer.open { right: 0; }
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--ux-space-12);
}
.drawer-content { color: var(--text-secondary); }

.backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  z-index: 85;
}

.page-header p,
.copy,
.note {
  color: var(--text-secondary);
}
.microcopy {
  margin-top: var(--ux-space-12);
  color: var(--text-muted);
  font-size: var(--small);
}

.qa-banner {
  margin-top: var(--ux-space-12);
  border: var(--border-thin);
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-radius: var(--radius-input);
  padding: var(--ux-space-12);
  color: var(--text-primary);
  font-size: var(--small);
}

.footer-note {
  grid-column: span 12;
  border-top: var(--border-thin);
  padding-top: var(--ux-space-12);
  color: var(--text-muted);
  font-size: var(--small);
}

.sr-only {
  position: absolute;
  width: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.site-footer {
  border-top: var(--border-thin);
  padding-top: var(--ux-space-12);
  padding-bottom: var(--ux-space-20);
}

.site-footer-inner {
  color: var(--text-muted);
  display: flex;
  gap: var(--ux-space-16);
  justify-content: space-between;
  font-size: var(--small);
  flex-wrap: wrap;
}

@media (min-width: 1024px) {
  .side-rail { display: block; }
}

@media (max-width: 1024px) {
  .filter-inner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-nav { display: none; }
  .section.span-8,
  .section.span-7,
  .section.span-5,
  .section.span-4 { grid-column: span 12; }
}

@media (max-width: 640px) {
  .filter-inner { grid-template-columns: 1fr; }
}

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

/* ============================================
   VISUAL POLISH - Hero Glow & Textures
   ============================================ */

/* Hero Background Glow */
.hero-section, [id*="hero"], .section:first-child {
  position: relative;
  overflow: hidden;
}
.hero-section::before, [id*="hero"]::before, .section:first-child::before {
  content: "";
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 150%;
  height: 200%;
  background: radial-gradient(ellipse at center, 
    rgba(110, 231, 255, 0.12) 0%, 
    rgba(167, 139, 250, 0.06) 35%, 
    transparent 70%);
  pointer-events: none;
  z-index: 0;
}
.hero-section > *, [id*="hero"] > *, .section:first-child > * {
  position: relative;
  z-index: 1;
}

/* Subtle Grid Texture Overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: 
    linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 48px 48px;
}

/* Enhanced KPI Tiles */
.kpi-tile {
  position: relative;
  overflow: hidden;
}
.kpi-tile::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, 
    var(--ux-color-accent-primary), 
    var(--ux-color-accent-secondary));
  opacity: 0.8;
}
.kpi-tile .value, .kpi-tile strong {
  font-size: var(--ux-type-font-size-display, 34px);
  font-weight: var(--ux-type-font-weight-bold, 700);
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, 
    var(--ux-color-accent-primary, #6EE7FF), 
    var(--ux-color-accent-secondary, #A78BFA));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Card Hover Enhancement */
.card {
  transition: transform var(--ux-motion-duration-base, 180ms) var(--ux-motion-ease-standard, ease),
              box-shadow var(--ux-motion-duration-base, 180ms) var(--ux-motion-ease-standard, ease);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--ux-shadow-hover, 0 14px 40px rgba(0,0,0,0.45));
}

/* Larger Headlines */
.page-header h1, .section:first-child h1 {
  font-size: clamp(28px, 4vw, 38px);
  letter-spacing: var(--ux-type-letter-spacing-tight, -0.01em);
  line-height: var(--ux-type-line-height-display, 1.15);
}

/* Page Header Enhancement */
.page-header {
  margin-bottom: var(--ux-space-32, 32px);
}
.page-header h1 {
  margin-bottom: var(--ux-space-8, 8px);
}
.page-header .subtitle {
  color: var(--ux-color-text-secondary);
  font-size: var(--ux-type-font-size-h3, 18px);
}

/* Chart Canvas Polish */
.chart-canvas {
  border-radius: var(--ux-radius-chart, 18px);
  overflow: hidden;
}

/* Accent Border for Active States */
.card.active, .kpi-tile.active {
  border-color: var(--ux-color-accent-primary);
  box-shadow: 0 0 0 1px var(--ux-color-accent-primary), var(--ux-shadow-card);
}
