/* ================================
   DESIGN TOKENS
   ================================ */
:root, [data-theme="light"] {
  --color-bg: #f7f6f2;
  --color-surface: #ffffff;
  --color-surface-2: #eeece6;
  --color-surface-offset: #f0eeea;
  --color-border: #e0ddd7;
  --color-border-light: #eae8e3;
  --color-text: #1a1a1a;
  --color-text-secondary: #4a4a4a;
  --color-text-muted: #6b6b6b;
  --color-text-faint: #999999;
  --color-accent: #5ba3d9;
  --color-accent-light: #6fb4e8;
  --color-accent-subtle: #e8f2fb;
  --color-accent-border: #b3d4f0;
  --color-success: #1a7a3a;
  --color-success-subtle: #e6f4ec;
  --color-success-border: #a8d8b8;
  --color-warning: #9a6400;
  --color-warning-subtle: #fef3e2;
  --color-warning-border: #f0d6a0;
  --color-danger: #c53030;
  --font-display: 'Newsreader', Georgia, serif;
  --font-body: 'Inter', -apple-system, system-ui, sans-serif;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.07);
  --nav-height: 0px;
}

[data-theme="dark"] {
  --color-bg: #111111;
  --color-surface: #1a1a1a;
  --color-surface-2: #222222;
  --color-surface-offset: #1e1e1e;
  --color-border: #404040;
  --color-border-light: #2a2a2a;
  --color-text: #e2e2e0;
  --color-text-secondary: #b0b0ae;
  --color-text-muted: #808080;
  --color-text-faint: #666666;
  --color-accent: #7bbef5;
  --color-accent-light: #90cbf8;
  --color-accent-subtle: #102540;
  --color-accent-border: #1e4060;
  --color-success: #4ade80;
  --color-success-subtle: #0a2015;
  --color-success-border: #1a4030;
  --color-warning: #e5a91a;
  --color-warning-subtle: #201a08;
  --color-warning-border: #403510;
  --color-danger: #fc8181;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.25);
  --nav-height: 0px;
}

/* ================================
   BASE
   ================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background 200ms ease, color 200ms ease;
  overflow-wrap: break-word;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; background: none; border: none; color: var(--color-text); font-family: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ================================
   LAYOUT
   ================================ */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ================================
   HEADER
   ================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header .header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-header .logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-header .logo a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.3px;
}

.app-header .logo svg { flex-shrink: 0; color: var(--color-accent); }

/* Tab Navigation */
.app-header .header-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.app-header .nav-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: 6px;
  transition: all 150ms ease;
  white-space: nowrap;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.app-header .nav-tab:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.nav-tab.active {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.app-header .header-meta {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Theme Toggle */
.app-header [data-theme-toggle] {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 150ms ease;
  color: var(--color-text-muted);
}
.app-header [data-theme-toggle]:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* Sun/Moon icon toggle */

/* ================================
   TAB CONTENT
   ================================ */
.tab-content {
  display: none;
  animation: fadeIn 200ms ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================================
   PAGE HERO
   ================================ */
.page-hero {
  padding: 20px 0 14px;
  border-bottom: 1px solid var(--color-border-light);
}

.part-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--color-accent);
  margin-bottom: 6px;
}

.page-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(20px, 3vw, 26px);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.5px;
  color: var(--color-text);
  margin-bottom: 4px;
  text-wrap: balance;
}

.page-hero .subtitle {
  font-size: 15px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ================================
   TOOLBAR — Search & Filters
   ================================ */
.toolbar {
  padding: 24px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-wrap {
  position: relative;
  max-width: 400px;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-faint);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  min-height: 44px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search-wrap input::placeholder {
  color: var(--color-text-faint);
}

.search-wrap input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

/* Filter Chips */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  font-size: 12px;
  min-height: 36px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  transition: all 150ms ease;
}

.chip:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.chip.active {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  border-color: var(--color-accent-border);
}

/* Results Count */
.results-count {
  font-size: 13px;
  color: var(--color-text-faint);
  padding-bottom: 12px;
}

/* ================================
   DATA TABLE
   ================================ */
.data-table-wrap {
  margin: 0 0 24px;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-xs);
}

.data-table {
  font-size: 13.5px;
  line-height: 1.5;
}

.data-table thead {
  background: var(--color-surface-2);
}

.data-table th {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-muted);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
  transition: color 150ms ease;
}

.data-table th.sortable:hover {
  color: var(--color-text);
}

.data-table th.sortable.sort-active {
  color: var(--color-accent);
}

.sort-arrow {
  font-size: 11px;
  margin-left: 4px;
  opacity: 0.4;
}

.sort-active .sort-arrow {
  opacity: 1;
}

.data-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-light);
  vertical-align: middle;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums lining-nums;
}

.data-table tbody tr:first-child td { border-top: none; }

.data-table tbody tr {
  transition: background 100ms ease;
}
/* Banded rows */
.data-table tbody tr:nth-child(even) {
  background: var(--color-surface-2);
}
.data-table tbody tr:hover {
  background: var(--color-accent-subtle) !important;
}


/* Clickable rows on carriers tab */
#carrier-tbody tr {
  cursor: pointer;
}

#carrier-tbody tr:active {
  background: var(--color-accent-subtle);
}

.carrier-name {
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.carrier-name a {
  color: inherit;
  text-decoration: none;
}

.carrier-name a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* Dashboard carrier links */
.carrier-name-linked {
  cursor: pointer;
}

#tab-dashboard .carrier-name {
  cursor: pointer;
  transition: color 150ms ease;
}

#tab-dashboard .carrier-name:hover {
  color: var(--color-accent);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 20px;
}

.badge-active {
  color: var(--color-success);
  background: var(--color-success-subtle);
  border: 1px solid var(--color-success-border);
}

.badge-exited {
  color: var(--color-warning);
  background: var(--color-warning-subtle);
  border: 1px solid var(--color-warning-border);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-reviewed {
  color: #5ba3d9;
  background: rgba(91, 163, 217, 0.1);
  border: 1px solid rgba(91, 163, 217, 0.3);
}

.badge-reviewed .badge-dot {
  background: #5ba3d9;
}

.badge-profiled {
  color: #e5a91a;
  background: rgba(229, 169, 26, 0.1);
  border: 1px solid rgba(229, 169, 26, 0.3);
}

.badge-profiled .badge-dot {
  background: #e5a91a;
}

.badge-barebones {
  color: #8e8e8e;
  background: rgba(142, 142, 142, 0.1);
  border: 1px solid rgba(142, 142, 142, 0.3);
}

.badge-barebones .badge-dot {
  background: #8e8e8e;
}

/* Premium Badge (mobile) */
.premium-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  border: 1px solid var(--color-accent-border);
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}

/* YoY coloring */
.yoy-positive { color: var(--color-success) !important; font-weight: 600; }
.yoy-negative { color: var(--color-danger) !important; font-weight: 600; }

/* Profile Link */
.profile-link {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* ================================
   MOBILE CARD VIEW
   ================================ */
.card-list {
  display: none;
}

/* ================================
   DASHBOARD — Stats Row
   ================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 32px 0;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-xs);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 500;
  color: var(--color-text);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-active { color: var(--color-success); }
.stat-bcbs { color: var(--color-accent); }
.stat-exited { color: var(--color-warning); }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-muted);
}

/* ================================
   DASHBOARD — Chart Cards
   ================================ */
.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 20px;
  min-width: 0; /* Prevent overflow in grid/flex contexts */
  overflow: hidden;
}

.chart-card-wide {
  margin-bottom: 20px;
}

.chart-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 4px;
  text-wrap: balance;
}
.chart-subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 24px;
}
  line-height: 1.4;
}

.chart-canvas-wrap {
  position: relative;
  height: 300px;
  max-width: 100%;
  overflow: hidden;
}

.chart-canvas-tall {
  height: 520px;
}

/* Charts Grid — 2 column */
.charts-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.charts-grid-2col .chart-card {
  margin-bottom: 0;
  min-width: 0; /* Prevent grid children from overflowing */
}

/* ================================
   DASHBOARD FILTER — Top-N Pills
   ================================ */
.dashboard-filter { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.dashboard-filter label { font-size: 13px; color: var(--color-text-muted); font-weight: 500; }
.filter-pills { display: flex; gap: 4px; }
.filter-pills .pill {
  padding: 8px 14px; border-radius: 20px; border: 1px solid var(--color-border);
  background: transparent; color: var(--color-text-muted); font-size: 12px;
  font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: var(--font-body);
  min-height: 36px;
}
.filter-pills .pill:hover { border-color: var(--color-text-faint); color: var(--color-text); }
.filter-pills .pill.active { background: var(--color-accent); color: white; border-color: var(--color-accent); }

/* ================================
   MOVERS TABLE
   ================================ */
.movers-table-wrap {
  margin-bottom: 0;
  border: none;
  box-shadow: none;
}

.mover-up {
  color: var(--color-success);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mover-down {
  color: var(--color-danger, var(--color-warning));
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ================================
   EXITED SECTION
   ================================ */
.exited-section {
  margin-bottom: 36px;
}

.exited-section .chart-title {
  margin-bottom: 4px;
}

.exited-section .chart-subtitle {
  margin-bottom: 16px;
}

/* ================================
   DATA ATTRIBUTION
   ================================ */
.data-attribution {
  margin: 24px 0 36px;
  padding: 16px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.data-attribution a {
  color: var(--color-accent);
  font-weight: 600;
}

/* ================================
   SUNDAY PAPER TAB
   ================================ */
.paper-hero {
  text-align: center;
}

.paper-content {
  max-width: 600px;
  margin: 48px auto;
  text-align: center;
}

.paper-icon {
  color: var(--color-accent);
  margin-bottom: 24px;
  opacity: 0.7;
}

.paper-description {
  font-size: 15px;
  line-height: 1.8;
  color: var(--color-text-secondary);
  margin-bottom: 36px;
}

.paper-cta-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.cta-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 32px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--color-accent);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all 200ms ease;
  box-shadow: var(--shadow-sm);
  min-height: 44px;
}

.cta-button:hover {
  text-decoration: none;
  filter: brightness(1.1);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.cta-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 150ms ease;
}

.cta-secondary:hover {
  color: var(--color-accent);
  text-decoration: none;
}

/* ================================
   FOOTER
   ================================ */
.site-footer {
  padding: 36px 0 48px;
  border-top: 1px solid var(--color-border-light);
  margin-top: 8px;
}

[data-theme="dark"] .site-footer {
  background: var(--color-surface);
  border-top-color: var(--color-border-light);
}

.footer-data-source {
  font-size: 12px;
  color: var(--color-text-faint);
  line-height: 1.6;
  margin-bottom: 8px;
}

.ai-disclosure {
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  max-width: 55ch;
  line-height: 1.6;
  margin-bottom: 14px;
}

.footer-links {
  font-size: 13px;
  margin-bottom: 16px;
}

.footer-links a { color: var(--color-text-muted); }
.footer-links a:hover { color: var(--color-accent); }

.footer-sep {
  margin: 0 10px;
  color: var(--color-text-faint);
}

.footer-ip {
  font-size: 11px;
  color: var(--color-text-faint);
  line-height: 1.6;
  margin-bottom: 8px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.footer-sig {
  font-size: 12px;
  color: var(--color-text-faint);
}

/* ================================
   LR/CR BAND COLORS
   ================================ */
.lr-band-low {
  color: var(--color-success) !important;
  font-weight: 600;
}
.lr-band-mid {
  color: var(--color-text-secondary) !important;
  font-weight: 500;
}
.lr-band-high {
  color: var(--color-danger) !important;
  font-weight: 600;
}

/* Mobile card ratio badges */
.carrier-card-ratio {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ================================
   STATS ROW — 5 and 6 columns
   ================================ */
.stats-row-5 {
  grid-template-columns: repeat(5, 1fr);
}
.stats-row-6 {
  grid-template-columns: repeat(6, 1fr);
}

.stat-source {
  font-size: 10px;
  color: var(--color-text-faint);
  margin-top: 2px;
  font-style: italic;
}

/* ================================
   DEFINITIONS TAB
   ================================ */
.definitions-note {
  margin: 24px 0 20px;
  padding: 16px 20px;
  background: var(--color-accent-subtle);
  border: 1px solid var(--color-accent-border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.definitions-note strong {
  color: var(--color-accent);
}

.definitions-table-wrap {
  margin-bottom: 32px;
}

.definitions-table td {
  vertical-align: top;
  line-height: 1.7;
}

.def-metric {
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
}

.def-intel {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  font-style: italic;
  color: var(--color-accent);
  line-height: 1.5;
}

.definitions-table code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  font-size: 12px;
  padding: 2px 6px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text);
}

.definitions-footer {
  margin-bottom: 48px;
  padding: 20px 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.definitions-footer h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--color-text);
}

.definitions-footer ul {
  list-style: none;
  padding: 0;
}

.definitions-footer li {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.7;
  padding: 4px 0;
}

.definitions-footer li strong {
  color: var(--color-text);
}

/* ================================
   CARRIER SUMMARY CARD
   ================================ */
.summary-card-section {
  margin-bottom: 24px;
}

.summary-card-controls {
  margin: 16px 0;
}

.summary-card-controls select {
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  min-width: 280px;
  cursor: pointer;
  transition: border-color 150ms ease;
}

.summary-card-controls select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  max-width: 520px;
}

.summary-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border-light);
}

.summary-card-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--color-text);
}

.summary-card-rank {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

.summary-card-rank-change {
  font-size: 13px;
  font-weight: 600;
  margin-left: 6px;
}

.summary-card-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.summary-metric {
  text-align: center;
}

.summary-metric-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.summary-metric-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.2;
}

.summary-metric-sub {
  font-size: 11px;
  margin-top: 2px;
  margin-bottom: 8px;
  min-height: 16px;
}

.sparkline-canvas {
  display: block;
  margin: 0 auto;
}

.summary-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--color-border-light);
}

.summary-card-years {
  font-size: 11px;
  color: var(--color-text-faint);
}

/* ================================
   REDUCED MOTION
   ================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ================================
   RESPONSIVE — Tablet
   ================================ */
@media (max-width: 900px) {
  .charts-grid-2col {
    grid-template-columns: 1fr;
  }

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

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

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

  .app-header .header-nav {
    gap: 0;
  }

  .app-header .nav-tab {
    padding: 8px 10px;
    font-size: 12px;
  }

  .chart-canvas-tall {
    height: 450px;
  }

  .summary-card {
    max-width: 100%;
  }

  .definitions-table .def-metric {
    white-space: normal;
  }
}

/* ================================
   RESPONSIVE — Mobile
   ================================ */
@media (max-width: 640px) {
  .app-header .header-inner {
    padding: 10px 16px;
    flex-wrap: wrap;
  }

  .app-header .logo a span {
    font-size: 15px;
  }

  .app-header .header-nav {
    order: 3;
    width: 100%;
    justify-content: center;
    padding-top: 8px;
    border-top: 1px solid var(--color-border-light);
    margin-top: 8px;
  }

  .app-header .nav-tab {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 12px;
  }

  .container { padding: 0 16px; }
  .page-hero { padding: 16px 0 10px; }
  .search-wrap { max-width: 100%; }

  .filter-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .chip { flex-shrink: 0; }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stats-row-5 {
    grid-template-columns: 1fr;
  }

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

  .stat-card { padding: 16px; }
  .stat-value { font-size: 28px; }

  /* Ensure chart cards go full width on mobile */
  .chart-card,
  .chart-card-wide {
    width: 100%;
    max-width: 100%;
  }

  /* Force dashboard container to respect viewport */
  #tab-dashboard .container {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Movers table scroll on mobile */
  .chart-card .movers-table-wrap,
  .chart-card .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Canvas must not exceed card width */
  .chart-canvas-wrap canvas {
    max-width: 100% !important;
  }

  .summary-card-metrics {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .summary-card-controls select {
    width: 100%;
    min-width: unset;
  }

  .chart-canvas-wrap { height: 250px; }
  .chart-canvas-tall { height: 400px; }

  /* Hide table, show cards on mobile */
  #carrier-table-wrap {
    display: none;
  }

  .card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 24px;
  }

  .carrier-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-xs);
  }

  .carrier-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }

  .carrier-card-badges {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .carrier-card-rank {
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text-faint);
    background: var(--color-surface-2);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
  }

  .carrier-card-name {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 4px;
  }

  .carrier-card-name a {
    color: inherit;
    text-decoration: none;
  }

  .carrier-card-name a:hover {
    color: var(--color-accent);
  }

  .carrier-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
  }

  .carrier-card-type {
    font-size: 12px;
    color: var(--color-text-muted);
  }

  .carrier-card-mhg {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-accent);
  }

  .carrier-card-yoy {
    font-size: 11px;
    font-weight: 700;
  }

  .carrier-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .footer-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .dashboard-filter {
    flex-wrap: wrap;
  }

  .filter-pills {
    flex-wrap: wrap;
  }
}

@media (max-width: 380px) {
  .stats-row {
    grid-template-columns: 1fr;
  }
}

/* ================================
   APP BRAND (NK monogram + name)
   ================================ */
.app-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-height: 44px;
}
.app-brand svg { flex-shrink: 0; color: var(--color-text); }
.app-brand:hover { color: var(--color-accent); text-decoration: none; }
.app-brand:hover svg { color: var(--color-accent); }

/* ================================
   APP THEME TOGGLE
   ================================ */

.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  padding: 6px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.18s ease, border-color 0.18s ease;
  flex-shrink: 0;
}
.theme-toggle:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
  :root:not([data-theme]) .theme-toggle .icon-sun  { display: block; }
}


/* ================================
   FOCUS STYLES
   ================================ */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
