/* Sports Edge — système visuel. Grille de 8 pt, échelle typographique ×1,25, contrastes WCAG AA. */
:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e6e9ee;
  --border: #e1e4ea;
  --border-strong: #c9ced8;
  --text: #121620;
  --text-2: #4a5263;
  --text-3: #6b7385;
  --accent: #3d4fd8;
  --accent-strong: #2f3fbf;
  --accent-soft: #eceefd;
  --on-accent: #ffffff;
  --focus: #3d4fd8;

  /* Catégories de décision */
  --value: #0f7a45;   --value-soft: #e3f4ea;
  --study: #a15c00;   --study-soft: #fdf1dc;
  --watch: #2459c9;   --watch-soft: #e5edfc;
  --none: #5d6577;    --none-soft: #eceef2;
  --danger: #b42318;  --danger-soft: #fdecea;
  --demo: #8a2fb8;    --demo-soft: #f5e8fb;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 15px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --nav-w: 232px;
  --tabbar-h: 60px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1016; --surface: #151922; --surface-2: #1b202b; --surface-3: #242a37;
    --border: #262c39; --border-strong: #353d4e;
    --text: #eef1f6; --text-2: #b4bccb; --text-3: #8d96a8;
    --accent: #8b97ff; --accent-strong: #a3adff; --accent-soft: #23284a; --on-accent: #0d1016; --focus: #a3adff;
    --value: #4ccb88; --value-soft: #12301f; --study: #f0b14d; --study-soft: #33260f;
    --watch: #7aa5ff; --watch-soft: #172644; --none: #9aa2b3; --none-soft: #222733;
    --danger: #ff8a7a; --danger-soft: #3a1714; --demo: #d593f5; --demo-soft: #2f1a3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1016; --surface: #151922; --surface-2: #1b202b; --surface-3: #242a37;
  --border: #262c39; --border-strong: #353d4e;
  --text: #eef1f6; --text-2: #b4bccb; --text-3: #8d96a8;
  --accent: #8b97ff; --accent-strong: #a3adff; --accent-soft: #23284a; --on-accent: #0d1016; --focus: #a3adff;
  --value: #4ccb88; --value-soft: #12301f; --study: #f0b14d; --study-soft: #33260f;
  --watch: #7aa5ff; --watch-soft: #172644; --none: #9aa2b3; --none-soft: #222733;
  --danger: #ff8a7a; --danger-soft: #3a1714; --demo: #d593f5; --demo-soft: #2f1a3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs)/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs); }
p { margin: 0; }
small, .small { font-size: var(--fs-sm); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Structure ---------- */
.app { min-height: 100dvh; display: flex; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; width: var(--nav-w); flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: var(--s5) var(--s3);
}
.brand { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s2) var(--s5); font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.02em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 14px; font-weight: 800; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--s3); min-height: 40px; padding: 0 var(--s3);
  border-radius: var(--r); color: var(--text-2); font-weight: 520;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav-foot { margin-top: auto; padding: var(--s3); font-size: var(--fs-xs); color: var(--text-3); }

.main { flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s5); padding-top: max(var(--s3), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: var(--fs-lg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 520px) {
  .topbar .btn-label { display: none; }
  .topbar .btn { width: 44px; padding: 0; }
}
.topbar .spacer { flex: 1; }
.content { padding: var(--s5); max-width: 1180px; margin: 0 auto; padding-bottom: calc(var(--s7) + env(safe-area-inset-bottom)); }

.tabbar { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { padding-left: var(--s4); padding-right: var(--s4); }
  .content { padding: var(--s4); padding-bottom: calc(var(--tabbar-h) + var(--s6) + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px); border-top: 1px solid var(--border);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: 500 11px/1.2 var(--font); color: var(--text-3); background: none; border: 0; min-height: 44px;
  }
  .tabbar a[aria-current="page"], .tabbar button[aria-expanded="true"] { color: var(--accent); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a:hover { text-decoration: none; }
}

/* ---------- Composants ---------- */
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.section { margin-top: var(--s6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow); min-width: 0; }
.card-tight { padding: var(--s3); }
.card h3 { margin-bottom: var(--s2); }
.card-link { display: block; color: inherit; transition: border-color .15s var(--ease), transform .15s var(--ease); }
.card-link:hover { text-decoration: none; border-color: var(--border-strong); }
.card-link:active { transform: scale(.995); }

.kpi .label { font-size: var(--fs-sm); color: var(--text-2); }
.kpi .value { font-size: var(--fs-2xl); font-weight: 680; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; }
.kpi .hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4); border-radius: var(--r); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: 560 var(--fs-sm)/1 var(--font); cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-lg { min-height: 48px; padding: 0 var(--s5); font-size: var(--fs); border-radius: var(--r-lg); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-sm { min-height: 32px; padding: 0 var(--s3); font-size: var(--fs-xs); }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn-sm { min-height: 36px; } }
.btn svg { width: 16px; height: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 620; line-height: 1.5; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.badge-value { background: var(--value-soft); color: var(--value); }
.badge-study { background: var(--study-soft); color: var(--study); }
.badge-watch { background: var(--watch-soft); color: var(--watch); }
.badge-none { background: var(--none-soft); color: var(--none); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-demo { background: var(--demo-soft); color: var(--demo); letter-spacing: .04em; }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-ok { background: var(--value); } .dot-warn { background: var(--study); } .dot-bad { background: var(--danger); } .dot-off { background: var(--border-strong); }

.cat-bar { border-left: 4px solid var(--none); }
.cat-bar.value { border-left-color: var(--value); }
.cat-bar.study { border-left-color: var(--study); }
.cat-bar.watch { border-left-color: var(--watch); }

.banner { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-sm); }
.banner-demo { background: var(--demo-soft); border-color: color-mix(in srgb, var(--demo) 35%, transparent); color: var(--text); }
.banner-warn { background: var(--study-soft); border-color: color-mix(in srgb, var(--study) 35%, transparent); }
.banner-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.banner strong { display: block; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { text-align: left; padding: 10px var(--s3); border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label-sm { font-size: var(--fs-sm); font-weight: 560; color: var(--text-2); }
.field .help { font-size: var(--fs-xs); color: var(--text-3); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r); min-height: 40px; padding: 8px 12px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); min-height: 32px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s3); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: 560 var(--fs-sm)/1.2 var(--font); color: var(--text-2); cursor: pointer; min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Barre de probabilité : modèle vs marché */
.probbar { position: relative; height: 8px; background: var(--surface-3); border-radius: var(--r-pill); overflow: visible; margin: 6px 0 4px; }
.probbar .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: var(--r-pill); }
.probbar .range { position: absolute; top: -3px; bottom: -3px; background: color-mix(in srgb, var(--accent) 22%, transparent); border-radius: var(--r-pill); }
.probbar .mark { position: absolute; top: -5px; width: 2px; height: 18px; background: var(--text); border-radius: 1px; }
.legend { display: flex; gap: var(--s3); font-size: var(--fs-xs); color: var(--text-3); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

.match-card { display: grid; gap: var(--s2); }
.match-card .teams { font-weight: 620; font-size: var(--fs); }
.match-card .meta { font-size: var(--fs-xs); color: var(--text-3); display: flex; gap: var(--s2); flex-wrap: wrap; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.metrics > div { background: var(--surface-2); border-radius: var(--r-sm); padding: 6px 8px; min-width: 0; }
.metrics .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.metrics .v { font-weight: 640; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.reasons { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: var(--fs-sm); }
.reasons li { display: flex; gap: var(--s2); align-items: flex-start; }
.reasons li::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; margin-top: 7px; background: var(--text-3); }
.reasons li.pour::before { background: var(--value); }
.reasons li.contre::before { background: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); background: var(--surface-2); font-size: var(--fs-xs); color: var(--text-2); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: var(--fs-sm); }
.steps li { display: flex; gap: var(--s2); align-items: center; }
.steps .st { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--surface-3); color: var(--text-3); flex: none; }
.steps .running .st { background: var(--accent); color: var(--on-accent); animation: pulse 1s infinite; }
.steps .done .st { background: var(--value); color: #fff; }
.steps .warn .st { background: var(--study); color: #fff; }
.steps .error .st { background: var(--danger); color: #fff; }
@keyframes pulse { 50% { opacity: .55; } }

.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--text-2); }
.empty h3 { color: var(--text); margin-bottom: var(--s2); }

.news-item { display: grid; gap: 6px; padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: 0; }
.news-item .title { font-weight: 600; }

details { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
details > summary { cursor: pointer; padding: var(--s3) var(--s4); font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: var(--s2); }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; color: var(--text-3); font-weight: 400; }
details[open] > summary::after { content: "–"; }
details > .details-body { padding: 0 var(--s4) var(--s4); }

/* Modale et notifications */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 18, .45); z-index: 60; display: grid; place-items: center; padding: var(--s4); animation: fade .15s var(--ease); }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: var(--s5); }
.modal h2 { margin-bottom: var(--s3); font-size: var(--fs-lg); }
.modal .actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom)); animation: up .2s var(--ease); }
}
.toasts { position: fixed; z-index: 70; right: var(--s4); bottom: calc(var(--s4) + env(safe-area-inset-bottom)); display: grid; gap: var(--s2); max-width: min(380px, calc(100vw - 32px)); }
@media (max-width: 860px) { .toasts { bottom: calc(var(--tabbar-h) + var(--s3) + env(safe-area-inset-bottom)); left: var(--s4); right: var(--s4); max-width: none; } }
.toast { background: var(--text); color: var(--bg); border-radius: var(--r); padding: var(--s3) var(--s4); font-size: var(--fs-sm); box-shadow: var(--shadow-lg); animation: up .2s var(--ease); }
.toast.error { background: var(--danger); color: #fff; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.sheet-menu { display: grid; gap: 4px; }
.sheet-menu a { display: flex; align-items: center; gap: var(--s3); min-height: 48px; padding: 0 var(--s3); border-radius: var(--r); color: var(--text); font-weight: 560; }
.sheet-menu a:hover { background: var(--surface-2); text-decoration: none; }
.sheet-menu svg { width: 20px; height: 20px; color: var(--text-2); }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ref { stroke: var(--text-3); stroke-dasharray: 4 4; stroke-width: 1; }
.chart .pt { fill: var(--accent); }
.chart .zero { stroke: var(--text-3); stroke-width: 1; }

.hero-analyze { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.hero-analyze .when { font-size: var(--fs-sm); color: var(--text-2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--s4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 520; }
.compare { width: 100%; font-size: var(--fs-sm); }
.compare td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.compare td:nth-child(2) { text-align: center; color: var(--text-3); font-size: var(--fs-xs); }
.compare td:first-child { text-align: right; font-weight: 600; }
.compare td:last-child { text-align: left; font-weight: 600; }
.hidden { display: none !important; }
