:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --gold: #c98500;
  --gold-2: #eda100;
  --s1: #3987e5;
  --s2: #d95926;
  --pos: #19b07c;
  --neg: #e66767;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--text); overscroll-behavior: none; }
body { font-size: 14px; line-height: 1.35; }
button, input, select { font: inherit; color: inherit; }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
small { color: var(--muted); }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px; background: var(--page); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; }
.brand small { font-weight: 500; margin-left: 4px; }
.last { margin-left: auto; text-align: right; display: flex; flex-direction: column; line-height: 1.1; }
.last b { font-variant-numeric: tabular-nums; color: var(--gold-2); }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--text-2); cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: var(--surface-2); }
.banner { background: #3a2a05; color: #f6d48a; padding: 6px 12px; font-size: 12px; border-bottom: 1px solid #5a4210; }

main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 10px calc(90px + var(--safe-b)); display: none; }
.view.scroll.active { display: block; }

.tabbar { display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
.tabbar button { flex: 1; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; height: var(--tab-h); justify-content: center; cursor: pointer; }
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--gold-2); }
.tabbar button .dot { position: absolute; }

/* ---------- chips / contrôles ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--gold); border-color: var(--gold); color: #0b0b0b; font-weight: 600; }
.chip.ghost { background: none; }
.chip:disabled { opacity: .4; }
.btn { border: 0; border-radius: 10px; padding: 10px 14px; background: var(--surface-3); color: var(--text); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--gold); color: #0b0b0b; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:active { filter: brightness(1.15); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- graphique ---------- */
.chart-tools { padding: 8px 10px 4px; display: flex; flex-direction: column; gap: 6px; background: var(--page); }
.chart-wrap { flex: 1; position: relative; min-height: 200px; }
#chartEl { position: absolute; inset: 0; }
.chart-legend { position: absolute; left: 8px; top: 6px; z-index: 3; pointer-events: none; font-size: 12px; font-variant-numeric: tabular-nums; background: rgba(26, 26, 25, .78); padding: 4px 7px; border-radius: 6px; max-width: calc(100% - 70px); }
.chart-legend .ohlc span { margin-right: 6px; }
.chart-legend .ohlc b { font-weight: 600; }
.chart-legend .ma { display: flex; gap: 8px; }
.chart-legend .ma i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 3px; }
.measure-box { position: absolute; left: 50%; transform: translateX(-50%); bottom: 40px; white-space: nowrap; z-index: 3; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-loading { position: absolute; right: 70px; bottom: 34px; z-index: 3; font-size: 12px; color: var(--muted); }
.tool-row { display: flex; gap: 6px; align-items: center; }
.float-tools { position: absolute; right: 66px; top: 50%; transform: translateY(-50%); z-index: 4; display: flex; flex-direction: column; gap: 6px; }
.float-tools .tbtn { background: rgba(35, 35, 33, .9); width: 36px; height: 34px; padding: 0; }
.tool-row .chips { flex: 1; }
.tbtn { flex: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); border-radius: 8px; height: 30px; min-width: 34px; padding: 0 8px; display: grid; place-items: center; cursor: pointer; font-size: 13px; }
.tbtn.on { border-color: var(--gold); color: var(--gold-2); }
.tbtn input[type=date] { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }

/* ---------- cartes / formulaires ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.card h3 { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.card h3 .spacer { flex: 1; }
.card p.help, .help { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
details.card > summary { list-style: none; cursor: pointer; font-weight: 700; font-size: 15px; display: flex; align-items: center; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .2s; }
details.card:not([open]) > summary::after { transform: rotate(-90deg); }
details.card > summary small { margin-left: 8px; font-weight: 400; }
details.card[open] > summary { margin-bottom: 10px; }
.field { display: grid; grid-template-columns: 1fr minmax(120px, 46%); align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.field:first-of-type { border-top: 0; }
.field > label { color: var(--text-2); }
.field > label small { display: block; font-size: 11px; }
.field.full { grid-template-columns: 1fr; }
.inp { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 9px; color: var(--text); font-variant-numeric: tabular-nums; min-height: 38px; }
.inp:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
.unit { position: relative; }
.unit .inp { padding-right: 34px; }
.unit > span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.days { display: flex; gap: 4px; }
.days button { flex: 1; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-weight: 600; cursor: pointer; padding: 0; }
.days button.on { background: var(--gold); border-color: var(--gold); color: #0b0b0b; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 7px; color: var(--text-2); cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--surface-3); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.sticky-run { position: sticky; bottom: -80px; padding: 10px 0 0; background: linear-gradient(transparent, var(--page) 30%); }
.lat-chips { margin-top: 6px; }
.desc { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 9px 10px; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 19px; font-weight: 700; margin-top: 2px; }
.kpi .s { font-size: 11px; color: var(--muted); margin-top: 1px; }
.kpi.wide { grid-column: span 2; }
.lat-impact { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; text-align: center; }
.lat-impact .v { font-size: 20px; font-weight: 700; }
.lat-impact .arrow { color: var(--muted); font-size: 20px; }
.callout { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.callout.bad { border-left: 3px solid var(--neg); }
.callout.good { border-left: 3px solid var(--pos); }

/* ---------- mini graphiques ---------- */
.mini-box { position: relative; width: 100%; }
svg.mini { display: block; touch-action: pan-y; }
svg.mini text.axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: #0b0b0b; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); margin: 2px 0 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.lw-box { position: relative; height: 240px; }
.hm { display: grid; gap: 2px; font-size: 10px; user-select: none; }
.hm-col { color: var(--muted); text-align: center; font-size: 9px; overflow: visible; white-space: nowrap; }
.hm-row { color: var(--muted); display: flex; align-items: center; font-size: 11px; }
.hm-cell { border-radius: 3px; min-height: 22px; cursor: pointer; }
.hm-text .hm-cell { display: grid; place-items: center; font-size: 10px; color: #fff; font-variant-numeric: tabular-nums; min-height: 26px; }
.hm-cell.sel { outline: 2px solid var(--text); outline-offset: -1px; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.scale .grad { flex: 1; height: 8px; border-radius: 4px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; color: var(--muted); font-weight: 500; padding: 5px 4px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.tbl td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:active td { background: var(--surface-2); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 11px; background: var(--surface-3); color: var(--text-2); }
.tag.TP { background: rgba(25, 176, 124, .18); color: var(--pos); }
.tag.SL { background: rgba(230, 103, 103, .18); color: var(--neg); }
.tag.TS { background: rgba(57, 135, 229, .2); color: #8bb8f0; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { color: var(--text); display: block; font-size: 16px; margin-bottom: 6px; }
.warn { color: #f6d48a; font-size: 12px; }

/* ---------- sheet / overlays ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--surface); width: 100%; max-width: 640px; max-height: 88dvh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; padding-bottom: var(--safe-b); }
.sheet-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.sheet-title { font-size: 16px; flex: 1; }
.sheet-body { overflow-y: auto; padding: 12px 14px 20px; }
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .6); display: grid; place-items: center; }
.busy-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; width: min(320px, 86vw); }
.busy-card .ttl { font-weight: 700; margin-bottom: 10px; }
.busy-card .bar { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.busy-card .bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .15s; }
.busy-card .lab { color: var(--muted); font-size: 12px; margin-top: 8px; min-height: 16px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + var(--safe-b)); transform: translate(-50%, 10px); background: #0b0b0b; border: 1px solid var(--border); color: var(--text); padding: 9px 14px; border-radius: 10px; z-index: 70; opacity: 0; transition: .25s; font-size: 13px; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.boot { position: fixed; inset: 0; z-index: 100; background: var(--page); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text-2); padding: 20px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--surface-3); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi.wide { grid-column: span 2; }
}
