/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #7d8590;
  --accent:      #388bfd;
  --accent-dim:  #1f6feb;
  --gold:        #e3b341;
  --green:       #3fb950;
  --red:         #f85149;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);

  /* Chart colours — assigned by JS index */
  --c0: #388bfd; --c1: #e3b341; --c2: #3fb950;
  --c3: #f85149; --c4: #a371f7; --c5: #39c5cf;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

header .logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

header .logo span { color: var(--accent); }

main {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: calc(100vh - 57px);
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Form controls ────────────────────────────────────────────────────────── */
/* Compare team label */
.sidebar-section h3 .optional {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
  font-size: 10px;
}

/* Dashed legend line indicator for compare team */
.metric-swatch.dashed {
  background: none !important;
  border: 2px dashed currentColor;
  border-radius: 0;
  width: 14px;
  height: 0;
  margin-top: 5px;
}

select, input[type="number"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
select:focus, input:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

/* Segmented control (home/away/both) */
.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg button {
  flex: 1;
  padding: 7px 0;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface2);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button:not(:last-child) { border-right: 1px solid var(--border); }
.seg button.active {
  background: var(--accent-dim);
  color: #fff;
}

/* Metric checkboxes */
.metric-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 2px;
}
.metric-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}
.metric-item:hover { background: var(--surface2); }
.metric-item input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.metric-item label {
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  flex: 1;
}
.metric-swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Apply button */
.btn-primary {
  width: 100%;
  padding: 9px;
  background: var(--accent-dim);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary:hover   { background: var(--accent); }
.btn-primary:active  { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; cursor: default; }

/* ── Content area ─────────────────────────────────────────────────────────── */
.content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Summary bar */
.summary-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  min-height: 56px;
  flex-shrink: 0;
}

.summary-bar .summary-divider {
  color: var(--border);
  font-size: 20px;
  padding: 0 8px;
  align-self: stretch;
  display: flex;
  align-items: center;
}

.summary-bar .team-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  min-width: 60px;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.stat-pill .val {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.stat-pill .lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.stat-pill .val.good  { color: var(--green); }
.stat-pill .val.warn  { color: var(--gold);  }
.stat-pill .val.grade-A { color: var(--green); }
.stat-pill .val.grade-B { color: var(--accent); }
.stat-pill .val.grade-C { color: var(--gold);   }
.stat-pill .val.grade-D, .stat-pill .val.grade-F { color: var(--red); }

.summary-bar .no-data {
  color: var(--text-muted);
  font-size: 13px;
}

/* Chart area */
.chart-wrap {
  flex: 1;
  position: relative;
  padding: 20px 24px 16px;
  overflow: hidden;
}

canvas#chart {
  width: 100% !important;
  height: 100% !important;
}

/* State overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}
.overlay.hidden { display: none; }
.overlay .icon { font-size: 40px; }
.overlay p     { color: var(--text-muted); font-size: 14px; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #3d1a1a;
  border: 1px solid var(--red);
  color: #f85149;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: var(--shadow);
  transform: translateY(80px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  z-index: 999;
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 380px; border-right: none; border-bottom: 1px solid var(--border); }
  .chart-wrap { padding: 12px; }
  .summary-bar { gap: 16px; flex-wrap: wrap; }
}