/* ==========================================================================
   Northfield IQ — AI Youth Soccer Analytics
   Design tokens
   ========================================================================== */

:root {
  /* -- surfaces & ink (light) -- */
  --bg: #F2F5EE;
  --surface: #FFFFFF;
  --surface-2: #E9EFE1;
  --surface-3: #DCE6D0;
  --border: #D7E0CE;
  --border-strong: #C3D0B6;
  --ink: #10231A;
  --ink-muted: #5B6B5A;
  --ink-faint: #8A9A86;

  /* -- brand accent (pitch lime) -- */
  --accent: #3F8F1C;
  --accent-ink: #2F6E15;
  --accent-soft: #E3F1D7;
  --on-accent: #FFFFFF;

  /* -- AI signal (floodlight amber) — reserved, never reused as categorical -- */
  --ai: #9C6508;
  --ai-soft: #FBEEDA;
  --on-ai: #FFFFFF;

  /* -- status (semantic, distinct hue family from accent) -- */
  --good: #0E8F7C;
  --good-soft: #DCF2EC;
  --warning: #B9790A;
  --warning-soft: #FBEEDA;
  --critical: #C23B33;
  --critical-soft: #FAE4E1;

  /* -- chart categorical, fixed order, validated CVD-safe -- */
  --cat-1: #3F8F1C; /* us / primary series */
  --cat-2: #1C7FB0; /* opponent / secondary series */
  --cat-3: #C23566; /* tertiary series */
  --cat-4: #6E3FCB; /* quaternary series */
  --chart-grid: #DCE6D0;
  --chart-axis-text: #5B6B5A;

  /* -- pitch surface tokens (for the SVG shot-map "material") -- */
  --pitch-fill: #E3EEDA;
  --pitch-line: #B9CBAC;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow-card: 0 1px 2px rgba(16,35,26,0.06), 0 1px 1px rgba(16,35,26,0.04);
  --shadow-pop: 0 12px 28px rgba(16,35,26,0.16), 0 2px 6px rgba(16,35,26,0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1310;
    --surface: #121C16;
    --surface-2: #182419;
    --surface-3: #1F2E20;
    --border: rgba(244,247,241,0.10);
    --border-strong: rgba(244,247,241,0.16);
    --ink: #F2F6EE;
    --ink-muted: #9FB0A3;
    --ink-faint: #637465;

    --accent: #5BC92E;
    --accent-ink: #7CDC4C;
    --accent-soft: rgba(91,201,46,0.14);
    --on-accent: #07140A;

    --ai: #FFB648;
    --ai-soft: rgba(255,182,72,0.14);
    --on-ai: #1A1206;

    --good: #35D6B8;
    --good-soft: rgba(53,214,184,0.14);
    --warning: #FFC24D;
    --warning-soft: rgba(255,194,77,0.14);
    --critical: #FF6B63;
    --critical-soft: rgba(255,107,99,0.14);

    --cat-1: #4FA61E;
    --cat-2: #2894C4;
    --cat-3: #E85C82;
    --cat-4: #9B6AE0;
    --chart-grid: rgba(244,247,241,0.10);
    --chart-axis-text: #9FB0A3;

    --pitch-fill: #16241A;
    --pitch-line: rgba(244,247,241,0.18);

    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 1px 1px rgba(0,0,0,0.2);
    --shadow-pop: 0 16px 32px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0A1310;
  --surface: #121C16;
  --surface-2: #182419;
  --surface-3: #1F2E20;
  --border: rgba(244,247,241,0.10);
  --border-strong: rgba(244,247,241,0.16);
  --ink: #F2F6EE;
  --ink-muted: #9FB0A3;
  --ink-faint: #637465;

  --accent: #5BC92E;
  --accent-ink: #7CDC4C;
  --accent-soft: rgba(91,201,46,0.14);
  --on-accent: #07140A;

  --ai: #FFB648;
  --ai-soft: rgba(255,182,72,0.14);
  --on-ai: #1A1206;

  --good: #35D6B8;
  --good-soft: rgba(53,214,184,0.14);
  --warning: #FFC24D;
  --warning-soft: rgba(255,194,77,0.14);
  --critical: #FF6B63;
  --critical-soft: rgba(255,107,99,0.14);

  --cat-1: #4FA61E;
  --cat-2: #2894C4;
  --cat-3: #E85C82;
  --cat-4: #9B6AE0;
  --chart-grid: rgba(244,247,241,0.10);
  --chart-axis-text: #9FB0A3;

  --pitch-fill: #16241A;
  --pitch-line: rgba(244,247,241,0.18);

  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 1px 1px rgba(0,0,0,0.2);
  --shadow-pop: 0 16px 32px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
}

/* ==========================================================================
   Reset & base
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-family: "Oswald", "Arial Narrow", sans-serif; font-weight: 600; letter-spacing: 0.01em; text-wrap: balance; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: "IBM Plex Mono", "SF Mono", monospace; }

::selection { background: var(--accent-soft); }

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* -- Sidebar -- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
}
.brand-crest {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-family: "Oswald", sans-serif;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: "Oswald", sans-serif; font-weight: 600; font-size: 15px; letter-spacing: 0.01em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--ink-muted); white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 8px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  color: var(--ink-muted);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: grid; place-items: center; }
.nav-item .nav-icon svg { width: 17px; height: 17px; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.season-pill {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.season-pill .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); font-weight: 600; }
.season-pill .value { font-size: 12.5px; color: var(--ink); font-weight: 500; }

.proto-badge {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-m);
  background: var(--ai-soft);
  border: 1px solid transparent;
}
.proto-badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ai);
  margin-top: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai) 20%, transparent);
}
.proto-badge .text { font-size: 11.5px; color: var(--ink-muted); line-height: 1.4; }
.proto-badge strong { color: var(--ink); font-weight: 600; }

/* -- Main -- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { display: flex; flex-direction: column; gap: 2px; }
.topbar-title h1 { font-size: 22px; }
.topbar-title .eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}
.chip.active { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
button.chip { transition: background .12s ease, color .12s ease, border-color .12s ease; }
button.chip:hover:not(.active) { background: var(--surface-2); color: var(--ink); }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  display: grid;
  place-items: center;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.view { padding: 24px 28px 48px; display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

/* ==========================================================================
   Grid & cards
   ========================================================================== */

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1.3fr 1fr; }
.grid-2-even { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-main-side { grid-template-columns: 2fr 1fr; }

@media (max-width: 1100px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2-even, .grid-main-side { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.card-flat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-head .meta { font-size: 11.5px; color: var(--ink-faint); font-weight: 500; }
.card-sub { font-size: 12px; color: var(--ink-muted); margin-top: -8px; }

/* -- KPI tile -- */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); font-weight: 600; }
.kpi .value-row { display: flex; align-items: baseline; gap: 8px; }
.kpi .value { font-family: "Oswald", sans-serif; font-size: 30px; font-weight: 600; line-height: 1; }
.kpi .unit { font-size: 13px; color: var(--ink-muted); font-weight: 500; }
.kpi .delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; }
.kpi .delta.up { color: var(--good); }
.kpi .delta.down { color: var(--critical); }
.kpi .spark { margin-top: 2px; }

/* -- AI insight callout -- */
.ai-callout {
  background: var(--ai-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-l);
  padding: 16px 18px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.ai-callout .ai-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ai);
  color: var(--on-ai);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.ai-callout .ai-icon svg { width: 16px; height: 16px; }
.ai-callout .ai-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ai-callout .ai-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; color: var(--ai); }
.ai-callout .ai-text { font-size: 13.5px; color: var(--ink); line-height: 1.5; }
.ai-callout .ai-text strong { font-weight: 600; }

/* -- Badges / pills -- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.critical { background: var(--critical-soft); color: var(--critical); }
.badge.neutral { background: var(--surface-2); color: var(--ink-muted); }

.result-chip {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.result-chip.W { background: var(--good-soft); color: var(--good); }
.result-chip.D { background: var(--surface-3); color: var(--ink-muted); }
.result-chip.L { background: var(--critical-soft); color: var(--critical); }

/* ==========================================================================
   Overview — fixture card
   ========================================================================== */

.fixture-card {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.fixture-teams { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 220px; }
.team-badge {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: "Oswald", sans-serif;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.team-badge.us { background: var(--accent-soft); color: var(--accent-ink); }
.team-badge.them { background: var(--surface-3); color: var(--ink-muted); }
.fixture-vs { font-size: 12px; color: var(--ink-faint); font-weight: 600; }
.fixture-meta { display: flex; flex-direction: column; gap: 2px; }
.fixture-meta .name { font-size: 14px; font-weight: 600; }
.fixture-meta .sub { font-size: 11.5px; color: var(--ink-muted); }
.fixture-info { display: flex; flex-direction: column; gap: 3px; text-align: right; }
.fixture-info .when { font-size: 13px; font-weight: 600; }
.fixture-info .where { font-size: 11.5px; color: var(--ink-muted); }
.predict-pill {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  border-radius: var(--radius-m);
  background: var(--accent-soft);
  text-align: center;
  min-width: 108px;
}
.predict-pill .pct { font-family: "Oswald", sans-serif; font-size: 20px; font-weight: 700; color: var(--accent-ink); line-height: 1; }
.predict-pill .pct-label { font-size: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

/* ==========================================================================
   Charts (generic SVG scaffolding)
   ========================================================================== */

.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis-label { fill: var(--chart-axis-text); font-size: 10px; font-family: "IBM Plex Mono", monospace; }
.grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-muted); font-weight: 500; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  font-size: 11.5px;
  padding: 7px 10px;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-pop);
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 20;
  line-height: 1.4;
}
.tooltip.show { opacity: 1; }
.tooltip .t-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .t-row { display: flex; gap: 8px; justify-content: space-between; }

.hover-dot { pointer-events: all; cursor: pointer; }

/* -- paired comparison bars (match center) -- */
.compare-row { display: flex; flex-direction: column; gap: 4px; }
.compare-labels { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
.compare-labels .l { color: var(--cat-1); }
.compare-labels .r { color: var(--cat-2); }
.compare-track { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; height: 14px; }
.compare-bar { height: 8px; border-radius: 4px; background: var(--surface-3); position: relative; overflow: hidden; }
.compare-bar.l { justify-self: end; }
.compare-fill { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.compare-bar.l .compare-fill { right: 0; background: var(--cat-1); }
.compare-bar.r .compare-fill { left: 0; background: var(--cat-2); }
.compare-stat { font-size: 11px; color: var(--ink-faint); font-weight: 600; text-align: center; min-width: 80px; }

/* -- table -- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table th.num, table.data-table td.num { text-align: right; }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr { cursor: pointer; transition: background 0.1s ease; }
table.data-table tbody tr:hover { background: var(--surface-2); }
table.data-table tbody tr:last-child td { border-bottom: none; }

.player-cell { display: flex; align-items: center; gap: 10px; }
.avatar-sm {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--surface-3);
  color: var(--ink-muted);
  display: grid;
  place-items: center;
  font-family: "Oswald", sans-serif;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}
.player-cell .pname { font-weight: 600; color: var(--ink); }
.player-cell .ppos { font-size: 11px; color: var(--ink-faint); }

.sparkbar-wrap { display: flex; align-items: center; gap: 8px; }
.sparkbar-track { width: 64px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.sparkbar-fill { height: 100%; border-radius: 3px; background: var(--accent); }

/* ==========================================================================
   Player profile
   ========================================================================== */

.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.avatar-lg {
  width: 72px; height: 72px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-family: "Oswald", sans-serif;
  font-weight: 700;
  font-size: 26px;
  flex-shrink: 0;
  position: relative;
}
.avatar-lg .num {
  position: absolute;
  bottom: -6px; right: -6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  border: 2px solid var(--surface);
}
.profile-id { display: flex; flex-direction: column; gap: 4px; }
.profile-id h2 { font-size: 24px; }
.profile-id .sub { font-size: 13px; color: var(--ink-muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.profile-id .dotsep { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-faint); }

.select-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
select.pill-select {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 32px 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%235B6B5A' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.rating-chip { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.rating-chip.good { background: var(--good-soft); color: var(--good); }
.rating-chip.ok { background: var(--surface-3); color: var(--ink-muted); }
.rating-chip.low { background: var(--critical-soft); color: var(--critical); }

footer.app-footer {
  padding: 16px 28px 28px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.scroll-x { overflow-x: auto; }

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
