/* Neve 26/27 — stile mobile-first, tema chiaro/scuro automatico */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #13202f;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --accent: #0b5cad;
  --top: #0f1b2d;
  --top-text: #ffffff;
  --live: #d92d20;
  --ok: #1a7f37;
  --warn-bg: #fff4d6;
  --ita-bg: #e7f5ea;
  --ita-line: #2e9e4f;
  --c-biathlon: #7b2cbf;
  --c-alpine: #d62839;
  --c-crosscountry: #2b9348;
  --c-jumping: #1f6fd1;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1420; --surface: #152132; --surface-2: #1c2b40; --text: #e8eef6; --muted: #9aabbf;
    --line: #26364d; --accent: #6fb0ff; --top: #08101a; --warn-bg: #3d3214; --ita-bg: #143322; --ita-line: #3fbf6a;
    --c-biathlon: #b07cf0; --c-alpine: #ff6b78; --c-crosscountry: #52c47a; --c-jumping: #5fa4ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1420; --surface: #152132; --surface-2: #1c2b40; --text: #e8eef6; --muted: #9aabbf;
  --line: #26364d; --accent: #6fb0ff; --top: #08101a; --warn-bg: #3d3214; --ita-bg: #143322; --ita-line: #3fbf6a;
  --c-biathlon: #b07cf0; --c-alpine: #ff6b78; --c-crosscountry: #52c47a; --c-jumping: #5fa4ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.sport-biathlon { --c: var(--c-biathlon); }
.sport-alpine { --c: var(--c-alpine); }
.sport-crosscountry { --c: var(--c-crosscountry); }
.sport-jumping { --c: var(--c-jumping); }

/* Barra in alto */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--top); color: var(--top-text);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.brand { margin: 0; font-size: 1.15rem; letter-spacing: .2px; }
.brand span { opacity: .7; font-weight: 500; }
.sync { font-size: .75rem; opacity: .75; white-space: nowrap; }
.sync.offline { color: #ffcf5c; opacity: 1; }

.view { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }

/* Barra in basso */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .75rem; color: var(--muted); gap: 2px; }
.tabbar a .ico { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.active .ico { filter: none; opacity: 1; }

/* Filtri */
.filters { display: grid; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: .85rem; color: var(--muted);
}
.chip.on { color: var(--text); border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--surface)); font-weight: 600; }

/* Oggi in gara */
.today {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px;
}
.today h2 { margin: 0 0 8px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.today .count { background: var(--accent); color: #fff; border-radius: 999px; font-size: .75rem; padding: 1px 8px; }
.empty-today p { margin: 0; color: var(--muted); font-size: .9rem; }

/* Selettore a segmenti */
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 12px; gap: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segmented.sports button.on { box-shadow: inset 0 -3px 0 var(--c), 0 1px 3px rgb(0 0 0 / .12); }
.segmented.sports button { font-size: .82rem; }

/* Gare */
h3.day { font-size: .85rem; font-weight: 500; color: var(--muted); margin: 16px 2px 6px; text-transform: none; }
h3.day b { color: var(--text); }
.list { display: grid; gap: 6px; }
.race {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: 12px; padding: 10px 10px 10px 8px; min-height: 58px;
}
.race:active { transform: scale(.99); }
.race.cancelled { opacity: .55; }
.race.cancelled .race-title { text-decoration: line-through; }
.race-time { font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; font-size: 1.02rem; }
.race-title { font-weight: 600; font-size: .95rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.race-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.g { font-size: .68rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; background: var(--surface-2); color: var(--muted); }
.g-F { background: #fde4ef; color: #a3195b; }
.g-M { background: #e0ecff; color: #1d4f9c; }
.g-X { background: #efe6ff; color: #5b2a9e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .g-F { background: #4a1630; color: #ffb3d4; }
  :root:not([data-theme="light"]) .g-M { background: #142f55; color: #a9cbff; }
  :root:not([data-theme="light"]) .g-X { background: #2f1d4f; color: #d4bcff; }
}
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.st-live { background: var(--live); color: #fff; }
.badge.st-finished { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok); }
.badge.st-cancelled, .badge.st-postponed { background: #6b7280; color: #fff; }
.badge.comp { background: #f4c542; color: #3a2c00; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.pager { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; font-weight: 600; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; }
.btn.icon { width: 40px; height: 40px; padding: 0; font-size: 1.4rem; line-height: 1; }
.btn.wide { width: 100%; margin-top: 12px; }
.week-day.is-today h3.day b, .week-day.is-today h3.day { color: var(--accent); }

/* Mese */
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.dow span { text-align: center; font-size: .72rem; color: var(--muted); padding: 2px 0 6px; }
.cell { border: 0; background: transparent; border-radius: 9px; aspect-ratio: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0; }
.cell:disabled { cursor: default; color: var(--muted); opacity: .6; }
.cell:not(:disabled) { background: var(--surface-2); font-weight: 600; }
.cell.out { opacity: .3; }
.cell.is-today { outline: 2px solid var(--accent); }
.cell.sel { background: var(--accent); color: #fff; }
.dots { display: flex; gap: 2px; height: 6px; }
.dots i, .legend i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot-biathlon { background: var(--c-biathlon); } .dot-alpine { background: var(--c-alpine); }
.dot-crosscountry { background: var(--c-crosscountry); } .dot-jumping { background: var(--c-jumping); }
.legend { display: flex; gap: 12px; justify-content: center; font-size: .75rem; color: var(--muted); margin: 8px 0; }
.legend i { margin-right: 4px; }

/* Risultati */
.result-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.rc-head { border-left: 5px solid var(--c); padding: 10px 12px; display: grid; gap: 2px; }
.rc-head .g { margin-left: 4px; }
.rc-head .badge { justify-self: start; margin-top: 4px; }
.rc-body { padding: 4px 12px 12px; }
.podium { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.podium li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 10px; background: var(--surface-2); }
.podium .medal { font-size: 1.2rem; }
.podium .who { font-weight: 600; font-size: .92rem; }
.podium .res { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); }
.ita { background: var(--ita-bg) !important; box-shadow: inset 3px 0 0 var(--ita-line); }
.ita-txt { color: var(--ita-line); font-weight: 600; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table.results { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.results th { text-align: left; color: var(--muted); font-weight: 500; font-size: .75rem; padding: 4px; border-bottom: 1px solid var(--line); }
table.results td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.pos { width: 32px; font-weight: 700; text-align: right; padding-right: 8px; }
td.tm, td.pts, td.sh { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.pts { color: var(--muted); }
.nat { color: var(--muted); }
.members { display: grid; gap: 1px; margin-top: 3px; font-size: .78rem; color: var(--muted); }
.members small { white-space: nowrap; }
.runs { font-size: .76rem; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
tr.divider td { background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 600; padding: 4px 8px; }
.note { font-size: .78rem; color: var(--muted); margin: 8px 0 0; }
.note a { color: var(--accent); }
.back { display: inline-block; margin: 0 0 10px; color: var(--accent); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty.small { padding: 6px 0; font-size: .85rem; text-align: left; }
.loading { color: var(--muted); text-align: center; }
.loading.small { text-align: left; font-size: .85rem; }
.warn { background: var(--warn-bg); border-radius: 10px; padding: 8px 10px; font-size: .85rem; margin: 0 0 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  background: #1d2735; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .88rem; z-index: 20; box-shadow: 0 4px 16px rgb(0 0 0 / .25);
  max-width: calc(100% - 32px);
}
