:root {
  color-scheme: light;
  --surface-0: #f6f6f4;
  --surface-1: #fcfcfb;
  --surface-2: #efefec;
  --border: #e0e0da;
  --border-strong: #cbcbc3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85847e;
  --accent: #1c5cab;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  --good: #12734a;
  --bad: #b8322f;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 12px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border: #33332f;
    --border-strong: #4a4a45;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #94938a;
    --accent: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good: #3da97b;
    --bad: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --border: #33332f;
  --border-strong: #4a4a45;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #94938a;
  --accent: #6da7ec;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --good: #3da97b;
  --bad: #e66767;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

/* Un selecteur de classe (.login-wrap { display: grid }) l'emporte sur la regle
   navigateur [hidden] { display: none }. Sans ce !important, l'ecran de connexion
   restait affiche apres login et poussait le dashboard sous le pli. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.01em; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: var(--accent); }

/* ---------------------------------------------------------------- login -- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 6px; }
.login-card p { color: var(--text-secondary); margin: 0 0 22px; font-size: 14px; }

input, select {
  width: 100%; padding: 10px 12px; font-size: 15px; font-family: inherit;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: 8px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button {
  font: inherit; font-weight: 560; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-primary);
  padding: 9px 14px;
}
button:hover { border-color: var(--text-muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }

.error { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 20px; }

/* --------------------------------------------------------------- layout -- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
header.top .brand { display: flex; flex-direction: column; }
header.top .brand small { color: var(--text-muted); font-size: 12px; }
header.top .spacer { flex: 1; }

nav.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 0 20px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 61px; z-index: 19;
}
nav.tabs button {
  border: none; background: none; border-radius: 0; padding: 11px 12px;
  color: var(--text-secondary); border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); }

main { padding: 20px; max-width: 1320px; margin: 0 auto; }
section[hidden] { display: none; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar label { font-size: 13px; color: var(--text-secondary); }
.toolbar select { width: auto; min-width: 150px; padding: 7px 10px; font-size: 14px; }

/* ---------------------------------------------------------------- cards -- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card > header .hint { color: var(--text-muted); font-size: 12.5px; margin-left: auto; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.tile .value { font-size: 25px; font-weight: 640; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile.hero .value { font-size: 32px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* --------------------------------------------------------------- charts -- */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; padding: 0; list-style: none; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
thead th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border-strong);
}
tbody tr:hover td { background: var(--surface-2); }
tbody tr:hover td:first-child { background: var(--surface-2); }
td.num, th.num { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
tfoot td { font-weight: 640; border-top: 1px solid var(--border-strong); border-bottom: none; }
tfoot td:first-child { background: var(--surface-1); }

.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 20px;
  border: 1px solid var(--border-strong); color: var(--text-secondary); vertical-align: middle;
}
.badge.warn { color: var(--series-4); border-color: var(--series-4); }

/* ------------------------------------------------------------ waterfall -- */
.waterfall { display: flex; flex-direction: column; gap: 2px; }
.wf-row { display: grid; grid-template-columns: 190px 1fr 110px; gap: 12px; align-items: center; font-size: 13.5px; }
.wf-row .bar-track { background: var(--surface-2); border-radius: 4px; height: 22px; position: relative; overflow: hidden; }
.wf-row .bar { height: 100%; border-radius: 4px; }
.wf-row .amount { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
.wf-row.total { font-weight: 640; padding-top: 6px; border-top: 1px solid var(--border-strong); margin-top: 6px; }

/* --------------------------------------------------------------- forms --- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 5px; }
.field .suffix { font-size: 12px; color: var(--text-muted); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
legend { font-weight: 620; font-size: 14px; padding: 0 6px; }

.note {
  background: var(--surface-2); border-left: 3px solid var(--series-4);
  padding: 12px 14px; border-radius: 6px; font-size: 13.5px; color: var(--text-secondary); margin-bottom: 16px;
}
.note strong { color: var(--text-primary); }
.note.banner-error { border-left-color: var(--bad); }
#banner[hidden] { display: none; }

/* ----------------------------------------------------------- simulateur -- */
.sim-row {
  display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 12px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border);
}
.sim-row:last-of-type { border-bottom: none; }
.sim-row label { font-size: 13.5px; color: var(--text-secondary); }
.sim-row output {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  min-width: 76px; text-align: right; font-variant-numeric: tabular-nums;
}
input[type="range"] { width: 100%; accent-color: var(--accent); padding: 0; border: none; background: none; }
input[type="range"]:focus { outline: 2px solid var(--accent); outline-offset: 4px; }

.verdict { padding: 12px 14px; border-radius: 8px; font-weight: 620; margin-bottom: 12px; }
.verdict.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.verdict.ko { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

/* ------------------------------------------------------ plan d'action -- */
.plan-list { display: flex; flex-direction: column; }
.plan-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--border); align-items: start;
}
.plan-item:last-child { border-bottom: none; }
.plan-item input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--good); }
.plan-item.done .plan-main label { text-decoration: line-through; opacity: .55; }
.plan-item.done { opacity: .7; }
.plan-item.dropped { opacity: .4; }
.plan-item.doing { border-left: 3px solid var(--series-4); padding-left: 10px; margin-left: -13px; }
.plan-main label { cursor: pointer; display: block; margin-bottom: 3px; }
.plan-main .muted { font-size: 13px; line-height: 1.45; }
.plan-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.plan-meta select, .plan-meta input {
  width: auto; padding: 4px 8px; font-size: 12.5px; border-radius: 6px;
}
.plan-meta input { min-width: 130px; }
.plan-gain {
  font-family: var(--mono); font-size: 13.5px; font-weight: 600;
  color: var(--good); white-space: nowrap; padding-top: 2px;
}
@media (max-width: 640px) {
  .plan-item { grid-template-columns: auto 1fr; }
  .plan-gain { grid-column: 2; }
}

.muted { color: var(--text-muted); font-size: 13px; }
.right { text-align: right; }
.spinner { color: var(--text-muted); padding: 40px; text-align: center; }

@media (max-width: 640px) {
  main { padding: 14px; }
  nav.tabs { top: 57px; padding: 0 10px; }
  .wf-row { grid-template-columns: 130px 1fr 92px; font-size: 12.5px; }
  .tile .value { font-size: 22px; }
}
