:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-track: #cde2fb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b42f2f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: rgba(255, 255, 255, 0.10);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-track: #184f95;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-track: #184f95;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
small, .muted { color: var(--muted); }
.secondary { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

/* --- barre du haut ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 700;
}
.brand small { display: block; font-weight: 400; font-size: 12px; line-height: 1.2; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--text-2); padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.sync { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.sync form { margin: 0; }

/* --- structure ------------------------------------------------------------------ */
main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-tiles { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .grid-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 520px) { .grid-tiles { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 13px; }

/* --- chiffres ------------------------------------------------------------------- */
.hero { display: grid; gap: 4px; }
.hero-label { color: var(--text-2); font-size: 14px; font-weight: 500; }
.hero-value { font-size: clamp(40px, 7vw, 56px); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.hero-note { color: var(--muted); font-size: 13px; }
.tile { display: grid; gap: 2px; align-content: start; }
.tile-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.tile-value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.tile-note { color: var(--muted); font-size: 12.5px; }
.negative { color: var(--critical-text); }

/* --- graphiques ----------------------------------------------------------------- */
.chart { position: relative; height: 280px; }
.chart.tall { height: 340px; }
.chart.short { height: 240px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.line-key { width: 18px; height: 0; border-top: 2px solid var(--series-1); display: inline-block; }
.line-key.dashed { border-top-style: dashed; }

/* --- tableaux ------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.scroll { max-height: 560px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px;
  padding: 8px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td .sub { display: block; color: var(--muted); font-size: 12.5px; }
tfoot td { font-weight: 600; border-top: 1px solid var(--baseline); }
details.table-view { margin-top: 12px; }
details.table-view summary { cursor: pointer; color: var(--text-2); font-size: 13px; }

/* --- statuts (icône + libellé, jamais la couleur seule) ------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.good::before { background: var(--good); }
.badge.warning::before { background: var(--warning); }
.badge.serious::before { background: var(--serious); }
.badge.critical::before { background: var(--critical); }
.badge.accent::before { background: var(--accent); }

.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--muted);
}
.alert .icon { font-size: 16px; line-height: 1.4; }
.alert.warning { border-left-color: var(--warning); }
.alert.critical { border-left-color: var(--critical); }
.alert.success { border-left-color: var(--good); }
.alert.info { border-left-color: var(--accent); }
.flashes { display: grid; gap: 8px; }

/* --- formulaires ---------------------------------------------------------------- */
button, .button {
  font: inherit; font-size: 14px; font-weight: 500; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 7px 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.small { padding: 3px 10px; font-size: 13px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
input, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--baseline); border-radius: 10px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--surface); }
.segmented a { padding: 4px 14px; border-radius: 999px; color: var(--text-2); font-size: 14px; }
.segmented a.active { background: var(--surface-2); color: var(--text); }
.segmented a:hover { text-decoration: none; }

/* --- jauges budget -------------------------------------------------------------- */
.meter { height: 8px; border-radius: 999px; background: var(--accent-track); overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter.warning > span { background: var(--warning); }
.meter.critical > span { background: var(--critical); }

/* --- journal -------------------------------------------------------------------- */
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); align-items: start; }
.feed li:last-child { border-bottom: none; }
.feed .kind { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; }
.feed .title { font-weight: 500; }
.feed .detail { color: var(--muted); font-size: 12.5px; }
.feed .amounts { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.feed .amounts strong { display: block; }

/* --- connexion ------------------------------------------------------------------ */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); display: grid; gap: 16px; }

.empty { text-align: center; padding: 48px 20px; display: grid; gap: 12px; justify-items: center; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
