/* Layout : barre fixe fine, une colonne de cartes larges, grille 2 colonnes pour les ventilations. */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #e1e5eb;
  --text: #0d1218;
  --text-2: #4a5462;
  --muted: #7d8794;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --save: #0b7a43;
  --save-soft: #e2f4ea;
  --up: #b4382f;
  --grid: #e9ecf1;
  --other: #b9c0ca;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --shadow: 0 1px 2px rgb(13 18 24 / 4%), 0 4px 16px rgb(13 18 24 / 4%);
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0d11; --surface: #13161b; --surface-2: #1a1e25; --border: #252a32;
    --text: #edf0f4; --text-2: #a7b0bb; --muted: #6d7682;
    --accent: #3987e5; --accent-soft: #16263b; --save: #3ccf7f; --save-soft: #12291d; --up: #f07b72;
    --grid: #1f242b; --other: #4b525c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d11; --surface: #13161b; --surface-2: #1a1e25; --border: #252a32;
  --text: #edf0f4; --text-2: #a7b0bb; --muted: #6d7682;
  --accent: #3987e5; --accent-soft: #16263b; --save: #3ccf7f; --save-soft: #12291d; --up: #f07b72;
  --grid: #1f242b; --other: #4b525c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
.wrap {
  max-width: 1240px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; min-width: 0; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); flex: none; }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.select select, .search {
  appearance: none;
  font: 500 13px/1 var(--font);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 30px 8px 14px;
}
.select { position: relative; }
.select::after {
  content: ""; position: absolute; right: 13px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); cursor: pointer; color: var(--text-2);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover, .select select:hover { border-color: var(--muted); }

/* En-tête */
.hero { padding-block: 40px 20px; max-width: 62rem; }
.hero h1 {
  margin: 0; font-weight: 600; font-size: clamp(26px, 3.6vw, 40px); line-height: 1.12;
  letter-spacing: -0.03em; text-wrap: balance;
}
.hero h1 em { font-style: normal; color: var(--save); }
.lede { margin: 12px 0 0; color: var(--text-2); font-size: 16px; max-width: 65ch; text-wrap: pretty; }

/* Tuiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.tile-label { font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tile-value { font: 500 30px/1.1 var(--mono); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.tile-foot { font-size: 13px; color: var(--text-2); }
.tile-save .tile-value { color: var(--save); }

/* Cartes */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 20px; margin-bottom: 14px; }
.card-head > div:first-child { min-width: 0; flex: 1 1 28rem; }
.card h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.note { margin: 4px 0 0; color: var(--text-2); font-size: 13.5px; max-width: 75ch; }
.note.small { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-2 .card { margin-bottom: 0; }

/* Contrôles segmentés et puces */
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 999px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 13px; border-radius: 999px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text-2);
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 12%); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text-2);
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { font-family: var(--mono); opacity: 0.7; margin-left: 4px; }

/* Légende */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* Graphique */
.chart { position: relative; width: 100%; min-height: 340px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis text { fill: var(--muted); font: 400 11.5px var(--mono); }
.axis line, .axis path { stroke: var(--grid); }
.gridline { stroke: var(--grid); stroke-width: 1; }
.seg-rect { stroke: var(--surface); stroke-width: 2; }
.hover-band { fill: var(--text); opacity: 0; }
.hover-band.on { opacity: 0.045; }
.bar-total { fill: var(--text-2); font: 500 11px var(--mono); }
.partial-label { fill: var(--muted); font: 400 11px var(--font); }
.src-strip { font: 400 11px var(--font); fill: var(--muted); }

/* Barres horizontales */
.hbars { display: grid; gap: 4px; }
.hbar {
  display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 5.2rem 4.6rem; align-items: center; gap: 12px;
  padding: 6px 8px; border-radius: 8px; font-size: 13.5px;
}
.hbar:hover { background: var(--surface-2); }
.hbar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.hbar-val { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.delta { text-align: right; font: 400 12.5px var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.delta.up { color: var(--up); }
.delta.down { color: var(--save); }

/* Recommandations */
.recs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rec {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 24px;
  border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; background: var(--surface);
}
.rec:hover { border-color: color-mix(in srgb, var(--muted) 60%, var(--border)); }
.rec-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rec h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.tag {
  font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.tag.cat { background: var(--accent-soft); color: var(--accent); }
.tag.ip-ok { background: var(--surface-2); color: var(--text-2); }
.tag.ip-warn { background: color-mix(in srgb, #fab219 22%, transparent); color: var(--text); }
.tag.ip-bad { background: color-mix(in srgb, var(--up) 16%, transparent); color: var(--up); }
.tag.status { background: var(--save-soft); color: var(--save); }
.rec.done { background: var(--surface-2); }
.rec.done .rec-save { color: var(--text-2); }
.rec-sub { font-size: 12.5px; color: var(--muted); }
.rec-body { grid-column: 1; font-size: 13.5px; color: var(--text-2); display: grid; gap: 4px; }
.rec-body b { color: var(--text); font-weight: 500; }
.rec-money { grid-column: 2; grid-row: 1 / span 2; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 9rem; }
.rec-save { font: 500 22px/1 var(--mono); color: var(--save); letter-spacing: -0.02em; }
.rec-save small { font-size: 12px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.rec-from { font: 400 12.5px var(--mono); color: var(--muted); }
.rec-meter { width: 9rem; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.rec-meter i { display: block; height: 100%; }
.rec-meter .keep { background: var(--other); }
.rec-meter .cut { background: var(--save); }
.rec-total { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 4px 0; font-size: 14px; color: var(--text-2); }
.rec-total b { font: 500 18px var(--mono); color: var(--save); }

/* Tables */
.table-box { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 500;
  font-size: 12px; color: var(--text-2); padding: 0; white-space: nowrap; z-index: 1;
}
.tbl th:not(:has(button)) { padding: 9px 12px; }
.tbl th button { all: unset; display: block; padding: 9px 12px; cursor: pointer; }
.tbl th button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tbl th[aria-sort="descending"] button::after { content: " ↓"; }
.tbl th[aria-sort="ascending"] button::after { content: " ↑"; }
.tbl td { padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tbody tr:hover { background: var(--surface-2); }
.res-name { font-weight: 500; word-break: break-all; }
.res-type { display: block; font-size: 12px; color: var(--muted); word-break: break-all; }
.cell-bar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.cell-bar i { display: block; height: 6px; border-radius: 999px; background: var(--accent); opacity: 0.85; }
.badge { font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.badge.cm { background: var(--accent-soft); color: var(--accent); }
.badge.inv { background: var(--surface-2); color: var(--text-2); }
.badge.none { background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up); }
.search { padding: 8px 14px; min-width: 0; width: min(100%, 260px); }

/* Infobulle */
.tip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 300px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 18%); padding: 10px 12px; font-size: 12.5px;
}
.tip-h { color: var(--text-2); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 16px; }
.tip-h b { color: var(--text); font-family: var(--mono); font-weight: 500; }
.tip-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 8px; align-items: center; line-height: 1.6; }
.tip-row i { width: 10px; height: 10px; border-radius: 3px; }
.tip-row span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.tip-row span:last-child { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.foot { color: var(--muted); font-size: 12.5px; padding-block: 8px 48px; }

@media (max-width: 720px) {
  .hide-sm { display: none; }
  .card { padding: 18px 16px; }
  .hbar { grid-template-columns: minmax(0, 8rem) minmax(0, 1fr) 4.6rem; }
  .hbar .delta { display: none; }
  .rec { grid-template-columns: 1fr; }
  .rec-money { grid-column: 1; grid-row: auto; align-items: flex-start; text-align: left; }
  .brand-sub { display: none; }
}
@media (max-width: 420px) { .hide-xs { display: none; } }
@media (prefers-reduced-motion: no-preference) {
  .hbar-fill, .cell-bar i { transition: width 400ms cubic-bezier(.2, .8, .2, 1); }
}
