/* LSF Cycling — stile condiviso (sito + pannello) */
:root {
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #1B2430;
  --muted: #5D6A79;
  --line: #D3DAE2;
  --line-soft: #E4E9EE;
  --accent: #D3150D;        /* rosso LSF */
  --accent-deep: #7E1511;   /* rosso scuro LSF */
  --accent-soft: #FBE7E5;
  --accent-ink: #FFFFFF;
  --ok: #1F8A5B;
  --danger: #C62B2B;
  --bib: #FFFFFF;
  --bib-ink: #12161C;
  --radius: 10px;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161C; --surface: #1A2129; --ink: #E7ECF1; --muted: #93A0AE;
    --line: #2C3642; --line-soft: #232B35; --accent: #FF4A3D; --accent-deep: #C2241B; --accent-soft: #3A1A19; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161C; --surface: #1A2129; --ink: #E7ECF1; --muted: #93A0AE;
  --line: #2C3642; --line-soft: #232B35; --accent: #FF4A3D; --accent-deep: #C2241B; --accent-soft: #3A1A19; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.05; margin: 0; letter-spacing: .005em; }
h1 { font-size: clamp(40px, 7vw, 72px); }
h2 { font-size: 28px; }
h3 { font-size: 20px; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- Barra superiore ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 3px 0 var(--accent);
}
.topbar-in {
  max-width: 1160px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 18px; height: 58px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand img { width: 36px; height: 36px; flex: none; }
.brand b { font-family: var(--display); font-size: 24px; font-weight: 800; color: var(--accent-deep); }
:root[data-theme="dark"] .brand b { color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand b { color: var(--ink); } }
.brand span { font-family: var(--display); font-size: 16px; color: var(--muted); font-weight: 600; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap;
  font-weight: 500; color: var(--muted);
}
.nav a[aria-current="page"] { color: var(--accent-deep); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; height: 34px; min-width: 34px; cursor: pointer; font-size: 15px;
}

/* ---------- Layout ---------- */
main { max-width: 1160px; margin: 0 auto; padding: 28px 16px 80px; }
.section { margin-top: 44px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head p { color: var(--muted); }
.cols { display: grid; gap: 32px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols { grid-template-columns: 1.35fr 1fr; } .cols.even { grid-template-columns: 1fr 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel.flush { padding: 0; overflow: hidden; }

/* ---------- Hero stagione ---------- */
.hero { display: grid; gap: 6px; padding-top: 8px; }
.hero-kicker { color: var(--muted); font-size: 15px; }
.hero h1 .yr { color: var(--accent); }
.hero-stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 14px; }
.hero-stats div { display: grid; }
.hero-stats .num { font-size: 32px; line-height: 1; }
.hero-stats span:last-child { color: var(--muted); font-size: 13px; }

/* ---------- Dorsale (numero di gara) ---------- */
.bib {
  position: relative; display: inline-grid; place-items: center;
  width: 44px; height: 36px; flex: none;
  background: var(--bib); color: var(--bib-ink);
  border: 1px solid #C9CFD6; border-radius: 4px;
  font: 800 22px/1 var(--display);
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.bib::before, .bib::after {
  content: ""; position: absolute; top: 4px; width: 4px; height: 4px; border-radius: 50%;
  background: #9AA4AF;
}
.bib::before { left: 4px; } .bib::after { right: 4px; }
.bib.sm { width: 34px; height: 28px; font-size: 17px; }
.bib.lead { background: var(--accent); color: #fff; border-color: var(--accent); }
.bib.lead::before, .bib.lead::after { background: rgba(255,255,255,.6); }

/* ---------- Classifica a nastri ---------- */
.ribbons { display: grid; gap: 8px; }
.ribbon {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  text-decoration: none; color: inherit;
}
.ribbon-track { position: relative; height: 40px; border-radius: 6px; background: var(--line-soft); overflow: hidden; }
.ribbon-fill {
  position: absolute; inset: 0 auto 0 0; border-radius: 6px;
  background: var(--team);
  transform-origin: left; animation: grow .9s cubic-bezier(.2,.7,.2,1) both;
}
.ribbon-fill::after { /* banda secondaria della maglia */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--team2, transparent);
}
.ribbon-name {
  position: absolute; left: 12px; top: 0; bottom: 0; display: flex; align-items: center; gap: 8px;
  font-weight: 600; white-space: nowrap; color: var(--on-team, #fff);
}
.ribbon-name { overflow: hidden; }
.ribbon-name > span { overflow: hidden; text-overflow: ellipsis; }
.ribbon-name small { font-weight: 400; opacity: .8; }
.ribbon-name.outside { color: var(--ink); }
.ribbon .count { font: 700 26px/1 var(--display); min-width: 2ch; text-align: right; }
.ribbon:hover .ribbon-track { outline: 2px solid var(--line); }
@keyframes grow { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .ribbon-fill { animation: none; } }

/* ---------- Elementi squadra/categoria ---------- */
.team {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; text-decoration: none;
  font-weight: 500;
}
.team i { width: 12px; height: 12px; border-radius: 3px; background: var(--team); flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.team.empty { color: var(--muted); font-weight: 400; }
.cat {
  display: inline-grid; place-items: center; min-width: 34px; height: 22px; padding: 0 6px;
  border-radius: 5px; font: 700 14px/1 var(--display);
  background: var(--cat, #ddd); color: var(--cat-ink, #111);
}
.cat.none { background: transparent; color: var(--muted); }

/* ---------- Tabelle ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table-scroll.tall { max-height: 72vh; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 13px; background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 2; }
th.sticky-col { z-index: 3; }
.race-link { font-weight: 500; text-decoration: none; }
.race-link:hover { text-decoration: underline; }

/* ---------- Controlli ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=url], input[type=date], select, textarea {
  height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  min-width: 0;
}
textarea { height: auto; padding: 10px 12px; }
input[type=search] { flex: 1 1 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px;
  cursor: pointer; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--accent); color: var(--accent-deep); }
.chip[aria-pressed="true"], .chip[aria-current="page"] { background: var(--accent-deep); color: #fff; border-color: var(--accent-deep); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--accent-deep);
  background: var(--accent-deep); color: #fff; cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn.ghost { background: var(--surface); color: var(--accent-deep); border-color: color-mix(in srgb, var(--accent-deep) 30%, var(--line)); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent-deep); }
.btn:not(.ghost):not(.danger):hover { filter: brightness(1.1); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 22px 0 22px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--accent-deep); border-color: var(--accent); }

/* ---------- Feed risultati ---------- */
.feed { display: grid; }
.feed-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); align-items: center; }
.feed-row:last-child { border-bottom: 0; }
.feed-row .what { min-width: 0; }
.feed-row .what a { font-weight: 600; text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-row .what small { color: var(--muted); }

/* ---------- Griglie squadre / corse ---------- */
.team-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.team-card {
  display: grid; text-decoration: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.jersey { height: 64px; background: var(--team); position: relative; }
.jersey::after { content: ""; position: absolute; left: 0; right: 0; top: 40px; height: 10px; background: var(--team2, transparent); }
.team-card .body { padding: 14px 16px 16px; display: grid; gap: 10px; }
.team-card h3 { font-size: 22px; }
.kv-row { display: flex; gap: 18px; }
.kv-row div { display: grid; }
.kv-row .num { font-size: 26px; line-height: 1; }
.kv-row span:last-child { font-size: 12px; color: var(--muted); }

.page-head { display: grid; gap: 10px; }
.page-head .crumbs { color: var(--muted); font-size: 14px; }
.page-head .crumbs a { text-decoration: none; color: var(--accent-deep); }
.team-banner { border-radius: var(--radius); background: var(--team); color: var(--on-team, #fff); padding: 26px 22px; position: relative; overflow: hidden; }
.team-banner::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: var(--team2, transparent); }
.team-banner h1 { font-size: clamp(36px, 6vw, 60px); }

/* ---------- Grafici ---------- */
.chart-box { position: relative; height: 340px; }
.chart-box.short { height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 13px; }

/* ---------- Matrice albo d'oro ---------- */
.matrix td.cell { min-width: 150px; }
.matrix .cell-in { display: flex; align-items: center; gap: 6px; }

/* ---------- Stati ---------- */
.empty-state { padding: 34px 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.error-box { padding: 16px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.toast { border-left: 4px solid var(--accent);
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.err { background: var(--danger); color: #fff; }
footer.site { max-width: 1160px; margin: 0 auto; padding: 0 16px 40px; color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
footer.site a { text-decoration: none; }

@media (max-width: 760px) {
  .topbar-in { flex-wrap: wrap; height: auto; padding-top: 8px; gap: 4px 12px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 1 1 100%; margin: 0 -16px; padding: 0 12px 6px; }
  .nav a { padding: 7px 10px; }
}
@media (max-width: 640px) {
  main { padding-top: 18px; }
  .ribbon-name small { display: none; }
  .section { margin-top: 34px; }
  th, td { padding: 8px 10px; }
  .ribbon-track { height: 36px; }
  .brand span { display: none; }
}

/* Dark mode: i colori scuri del brand diventano più luminosi per restare leggibili */
:root[data-theme="dark"] .nav a[aria-current="page"], :root[data-theme="dark"] .tabs button[aria-selected="true"],
:root[data-theme="dark"] .btn.ghost, :root[data-theme="dark"] .page-head .crumbs a { color: var(--accent); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .nav a[aria-current="page"], :root:not([data-theme="light"]) .tabs button[aria-selected="true"],
  :root:not([data-theme="light"]) .btn.ghost, :root:not([data-theme="light"]) .page-head .crumbs a { color: var(--accent); }
}
.footer-brand { display: inline-flex; align-items: center; gap: 8px; }
.footer-brand img { width: 22px; height: 22px; }
