/* Palette dalla skill dataviz (references/palette.md) — validata per
   contrasto e daltonismo, non modificare i valori senza ri-validare. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.12);
  --series-2: #eb6834;
  --series-2-soft: rgba(235, 104, 52, 0.14);
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --border: rgba(11, 11, 11, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.16);
    --series-2: #d95926;
    --series-2-soft: rgba(217, 89, 38, 0.18);
    --border: rgba(255, 255, 255, 0.10);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --series-1: #3987e5;
  --series-1-soft: rgba(57, 135, 229, 0.16);
  --series-2: #d95926;
  --series-2-soft: rgba(217, 89, 38, 0.18);
  --border: rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  font-weight: 700;
  font-size: 17px;
}
.sidebar-brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--series-1);
}
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
}
.nav-item:hover:not(.disabled) {
  background: var(--page-plane);
}
.nav-item.active {
  color: var(--series-1);
  background: var(--series-1-soft);
  font-weight: 600;
  border-right: 3px solid var(--series-1);
}
.nav-item.disabled {
  opacity: 0.5;
}
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* --- Main --- */
.main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 48px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.topbar h1 {
  font-size: 20px;
  margin: 0;
}
.topbar .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* --- KPI row (stat tiles) --- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* --- Chart card --- */
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}
.chart-card h2 {
  font-size: 15px;
  margin: 0 0 4px;
}
.chart-card .chart-caption {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 12px;
}
.chart-svg { width: 100%; height: auto; display: block; }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1; }
.chart-area { fill: var(--series-1-soft); }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-point { fill: var(--series-1); }
.chart-label { fill: var(--text-muted); font-size: 10px; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.chart-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 0;
}

/* --- Tables --- */
.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  min-width: 0;
}
.table-card-wide { overflow-x: auto; }
.table-card h2 {
  font-size: 15px;
  margin: 0 0 14px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gridline);
}
td {
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--page-plane); }
.match-teams { font-weight: 600; color: var(--text-primary); }
.match-link { color: inherit; text-decoration: none; }
.match-link:hover { text-decoration: underline; }
.match-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.probs { color: var(--text-secondary); white-space: nowrap; }
.pick-badge {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--status-good);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}
.value-hit {
  color: var(--status-good);
  font-weight: 700;
}
.prob-strong {
  color: var(--series-1);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.col-divider { border-left: 1px solid var(--gridline); padding-left: 12px; }

/* --- League tabs (pagina Partite) --- */
.league-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.league-tab {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
}
.league-tab.active {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
  font-weight: 600;
}

/* --- Filtro data (pagina Pronostici) --- */
.date-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.date-filter input[type="date"] {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
}
.date-filter button {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--series-1);
  background: var(--series-1);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* --- View tabs (Tutte / Per giornata / Per data) --- */
.view-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
}
.view-tab {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.view-tab.active {
  color: var(--series-1);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

.match-group { margin-bottom: 16px; }
.group-header {
  font-size: 14px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--page-plane);
  color: var(--text-secondary);
}

/* --- Status badge (pagina Partite) --- */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--gridline);
  color: var(--text-secondary);
}
.status-FINISHED { background: var(--status-good); color: #fff; }
.status-POSTPONED, .status-CANCELLED { background: var(--status-critical); color: #fff; }

.table-link {
  color: var(--series-1);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.table-link:hover { text-decoration: underline; }
.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
}

/* --- Confronto statistiche (pagina dettaglio partita) --- */
.match-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
}
.match-header-team {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  text-align: center;
}
.match-header-team.home { color: var(--series-1); }
.match-header-team.away { color: var(--series-2); }
.match-header-score {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.stat-legend span { display: inline-flex; align-items: center; gap: 6px; }
.stat-legend .swatch { width: 10px; height: 10px; border-radius: 2px; }
.stat-legend .home .swatch { background: var(--series-1); }
.stat-legend .away .swatch { background: var(--series-2); }

.stat-row { margin-bottom: 18px; }
.stat-row-labels {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-row-labels .value { font-weight: 700; color: var(--text-primary); width: 48px; }
.stat-row-labels .value.away { text-align: right; }
.stat-row-labels .name { color: var(--text-secondary); }

/* Barra singola continua (possesso: le due quote sommano già a 100) */
.stat-bar-single {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--gridline);
}
.stat-bar-single .home { background: var(--series-1); }
.stat-bar-single .away { background: var(--series-2); }

/* Barre appaiate dal centro verso l'esterno (tutte le altre statistiche) */
.stat-bar-split {
  display: flex;
  align-items: center;
  height: 8px;
}
.stat-bar-split .half { flex: 1; display: flex; height: 100%; }
.stat-bar-split .half.home { justify-content: flex-end; }
.stat-bar-split .fill { height: 100%; border-radius: 4px; }
.stat-bar-split .home .fill { background: var(--series-1); border-radius: 4px 0 0 4px; }
.stat-bar-split .away .fill { background: var(--series-2); border-radius: 0 4px 4px 0; }
.stat-bar-split .gap { width: 3px; flex-shrink: 0; background: var(--surface-1); }

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .table-row { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
}
