:root {
  --bg: #F2F5F3;
  --surface: #FFFFFF;
  --surface-2: #E8EDEA;
  --ink: #16211D;
  --ink-2: #4A5752;
  --ink-3: #7B8884;
  --line: #D5DDD9;
  --green: #1F8A5B;
  --green-soft: #DDF0E6;
  --gold: #B8903A;
  --gold-soft: #F4EBD6;
  --red: #C6413A;
  --red-soft: #F6DEDC;
  --blue: #3B6E9E;
  --radius: 10px;
  --font: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1A17;
    --surface: #16231F;
    --surface-2: #1E2D28;
    --ink: #E6EDE9;
    --ink-2: #A9B7B1;
    --ink-3: #74837D;
    --line: #27362F;
    --green: #2EB67D;
    --green-soft: #173A2B;
    --gold: #D4AB54;
    --gold-soft: #3A3017;
    --red: #E06A62;
    --red-soft: #3E1F1D;
    --blue: #6FA3D8;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
body { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green); }
.num { font-variant-numeric: tabular-nums; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }
.loading { padding: 40px 16px; color: var(--ink-3); text-align: center; }

/* ---------- en-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.brand span { color: var(--green); }
.topbar .grow { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.running { background: var(--green-soft); color: var(--green); }
.pill.paused { background: var(--gold-soft); color: var(--gold); }
.pill.halted, .pill.offline { background: var(--red-soft); color: var(--red); }
.pill.stopped { background: var(--surface-2); color: var(--ink-3); }
.select-bot { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 4px 8px; font-size: 13px; }

/* ---------- contenu ---------- */
main { flex: 1; padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
h2 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 22px 0 8px; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.notice { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; display: flex; gap: 12px; align-items: flex-start; }
.notice.red { background: var(--red-soft); color: var(--red); }
.notice.gold { background: var(--gold-soft); color: var(--gold); }
.notice.grey { background: var(--surface-2); color: var(--ink-2); }
.notice .body { flex: 1; }
.notice strong { display: block; margin-bottom: 2px; }
.notice p { margin: 0; font-size: 14px; }

/* bandeau d'équité */
.equity { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: end; margin-bottom: 6px; }
.equity .value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.equity .unit { font-size: 15px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }
.equity .delta { font-size: 17px; font-weight: 700; text-align: right; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.equity .delta .lbl { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.equity .sub { grid-column: 1 / -1; font-size: 13px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.sparkline { width: 100%; height: 64px; display: block; margin: 6px 0 2px; }
.sparkline path.line { fill: none; stroke: var(--green); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.sparkline path.area { fill: var(--green); opacity: 0.08; }
.sparkline line.base { stroke: var(--line); stroke-dasharray: 3 4; }
.range-switch { display: inline-flex; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.range-switch button { border: 0; background: transparent; padding: 3px 10px; border-radius: 6px; font-size: 13px; color: var(--ink-2); }
.range-switch button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* échelles de grille */
.ladders { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .ladders { gap: 6px; } }
.ladder { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 8px 8px; min-width: 0; }
.ladder .head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.ladder .sym { font-weight: 700; font-size: 15px; }
.ladder .px { font-size: 13px; color: var(--ink-2); }
.ladder .regime { font-size: 12px; margin: 2px 0 0; min-height: 2.6em; line-height: 1.3; font-weight: 600; }
.ladder .vol { font-size: 11px; color: var(--ink-3); margin-bottom: 2px; min-height: 1.3em; }
.ladder .regime.down { color: var(--red); }
.ladder .regime.up { color: var(--green); }
.ladder .regime.range { color: var(--ink-3); }
.ladder svg { width: 100%; height: 160px; display: block; }
.ladder svg .axis { stroke: var(--line); }
.ladder svg .rung { stroke-width: 2.5; stroke-linecap: round; }
.ladder svg .rung.empty { stroke: var(--line); }
.ladder svg .rung.buy_open { stroke: var(--blue); }
.ladder svg .rung.holding { stroke: var(--gold); }
.ladder svg .rung.sell_open { stroke: var(--green); }
.ladder svg .price { stroke: var(--ink); stroke-width: 1.2; }
.ladder svg .price-dot { fill: var(--ink); }
.ladder svg text { font-size: 8.5px; fill: var(--ink-3); font-family: var(--font); }
.ladder .foot { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.ladder .foot .fl { display: flex; justify-content: space-between; gap: 4px; padding: 1px 0; }
.ladder .foot b { color: var(--ink); font-weight: 600; }
.ladder .foot b.pos { color: var(--green); }
.ladder .foot b.neg { color: var(--red); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-3); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legend .buy_open i { background: var(--blue); }
.legend .holding i { background: var(--gold); }
.legend .sell_open i { background: var(--green); }
.legend .empty i { background: var(--line); }

/* listes */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.stat .k { font-size: 12px; color: var(--ink-3); }
.stat .v { font-size: 17px; font-weight: 700; }
.stat .s { font-size: 12px; color: var(--ink-3); }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 12px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .t { font-size: 14px; }
.row .m { font-size: 12px; color: var(--ink-3); grid-column: 1 / -1; }
.row .r { font-weight: 600; font-size: 14px; text-align: right; }
.row.alert .t { color: var(--red); }
.row.warn .t { color: var(--gold); }
.row.trade .t { color: var(--ink); }
.row.info .t { color: var(--ink-2); }
.row.error .t { color: var(--red); }
.empty { padding: 24px 12px; color: var(--ink-3); text-align: center; font-size: 14px; }

/* formulaires */
.form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px; }
.field { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; }
.field label { font-size: 14px; }
.field .hint { display: block; font-size: 12px; color: var(--ink-3); }
.field input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; text-align: right; font-size: 15px; }
.field input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: transparent; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.quiet { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

.proposal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.proposal.pending { border-color: var(--gold); }
.proposal .when { font-size: 12px; color: var(--ink-3); }
.proposal .compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; font-size: 13px; }
.proposal .compare > div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.proposal .compare .h { font-weight: 600; margin-bottom: 4px; }
.proposal .reason { font-size: 13px; color: var(--ink-2); margin: 4px 0 8px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.tag.applied { background: var(--green-soft); color: var(--green); }
.tag.pending { background: var(--gold-soft); color: var(--gold); }

/* connexion */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login h1 span { color: var(--green); }
.login p { color: var(--ink-3); margin: 0 0 20px; }
.login input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px; margin-bottom: 10px; font-size: 16px; }
.login input:focus { outline: 2px solid var(--green); border-color: transparent; }
.login .err { color: var(--red); font-size: 14px; margin: 4px 0 10px; }

/* onglets bas */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { border: 0; background: transparent; padding: 10px 4px 8px; font-size: 12px; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tabs button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--green); font-weight: 600; }
.tabs button .badge { position: absolute; margin-left: 26px; margin-top: -2px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--gold); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; padding: 0 4px; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast .2s ease-out; }
  @keyframes toast { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
}
