/* RevX Bot: same family as RevX Radar (src/ui/dashboard.html of the radar):
   its colour tokens for the dark and light themes, system font at a dense
   size, monospace figures, pill chips, bordered cards, uppercase section
   titles with an accent bar, underlined tabs. The theme follows the system.
   Phone: bottom navigation; 480 px and wider (the Windows window): tabs on
   top, like the radar. The mode is never ambiguous: « RÉEL » in red,
   « ESSAI » in amber, in the header and on every order dialog. */

/* Light tokens by default; dark when the system asks for it, unless the ◐
   button chose light (data-theme on <html>, kept on the device). */
:root {
  color-scheme: light;
  --bg: #f8fafc; --surface: #ffffff; --surface-2: #f1f5f9; --surface-hover: #e2e8f0; --border: #cbd5e1;
  --grid: rgba(37, 99, 235, 0.04);
  --text: #0f172a; --text-2: #334155; --text-3: #64748b;
  --accent: #2563eb; --accent-soft: rgba(37, 99, 235, 0.1); --glow: rgba(37, 99, 235, 0.25);
  --good: #059669; --good-text: #047857; --good-soft: rgba(5, 150, 105, 0.09);
  --warning: #d97706; --warning-text: #b45309; --warning-soft: rgba(217, 119, 6, 0.11);
  --critical: #dc2626; --neg-text: #b91c1c; --neg-soft: rgba(220, 38, 38, 0.09);
  --real: #dc2626; --real-soft: rgba(220, 38, 38, 0.09);
  --essai: #d97706; --essai-ink: #ffffff; --essai-text: #92400e; --essai-soft: rgba(217, 119, 6, 0.11);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --tab-bg: rgba(248, 250, 252, 0.96);
  --mono: ui-monospace, "Cascadia Code", "Cascadia Mono", Consolas, "SF Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Inter", sans-serif;
  --gutter: 12px;
  --tabs-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #090d16; --surface: #111726; --surface-2: #161f33; --surface-hover: #1c2740; --border: #202d44;
    --grid: rgba(59, 130, 246, 0.035);
    --text: #f8fafc; --text-2: #cbd5e1; --text-3: #94a3b8;
    --accent: #3b82f6; --accent-soft: rgba(59, 130, 246, 0.14); --glow: rgba(59, 130, 246, 0.35);
    --good: #10b981; --good-text: #34d399; --good-soft: rgba(16, 185, 129, 0.14);
    --warning: #f59e0b; --warning-text: #fbbf24; --warning-soft: rgba(245, 158, 11, 0.14);
    --critical: #ef4444; --neg-text: #f87171; --neg-soft: rgba(239, 68, 68, 0.14);
    --real: #ef4444; --real-soft: rgba(239, 68, 68, 0.15);
    --essai: #f59e0b; --essai-ink: #090d16; --essai-text: #fbbf24; --essai-soft: rgba(245, 158, 11, 0.14);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
    --tab-bg: rgba(9, 13, 22, 0.96);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d16; --surface: #111726; --surface-2: #161f33; --surface-hover: #1c2740; --border: #202d44;
  --grid: rgba(59, 130, 246, 0.035);
  --text: #f8fafc; --text-2: #cbd5e1; --text-3: #94a3b8;
  --accent: #3b82f6; --accent-soft: rgba(59, 130, 246, 0.14); --glow: rgba(59, 130, 246, 0.35);
  --good: #10b981; --good-text: #34d399; --good-soft: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b; --warning-text: #fbbf24; --warning-soft: rgba(245, 158, 11, 0.14);
  --critical: #ef4444; --neg-text: #f87171; --neg-soft: rgba(239, 68, 68, 0.14);
  --real: #ef4444; --real-soft: rgba(239, 68, 68, 0.15);
  --essai: #f59e0b; --essai-ink: #090d16; --essai-text: #fbbf24; --essai-soft: rgba(245, 158, 11, 0.14);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
  --tab-bg: rgba(9, 13, 22, 0.96);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
}

.app {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}

h1, h2 { margin: 0; font-size: 14px; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.95em; }
.faint { color: var(--text-3); font-weight: 400; }
.mono { font-family: var(--mono); letter-spacing: -0.02em; }
.up { color: var(--good-text); }
.down { color: var(--neg-text); }
.warn { color: var(--warning-text); }
.error { color: var(--neg-text); }
.small { color: var(--text-3); margin: 8px 0; font-size: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- top bar: brand + mode, connection, theme ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  height: 36px; box-sizing: border-box;
  display: flex; align-items: center; gap: 8px 10px;
  padding: 0 var(--gutter); margin: 0 calc(-1 * var(--gutter)) 8px;
  background: var(--bg); border-bottom: 2px solid var(--essai);
  backdrop-filter: blur(12px);
}
body[data-mode="real"] .top { border-bottom-color: var(--real); }
.brand {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 13px; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase;
}
.brand img { border-radius: 4px; flex: none; width: 18px; height: 18px; }
.brand .ver { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: none; margin-left: -2px; }
.mode {
  padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 750; letter-spacing: 0.05em;
  background: var(--essai); color: var(--essai-ink); box-shadow: 0 1px 4px var(--essai-soft);
}
.mode[data-tone="real"] { background: var(--real); color: #fff; box-shadow: 0 1px 4px var(--real-soft); }
.spacer { flex: 1; }
.surv-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 750; letter-spacing: 0.05em; font-family: var(--mono);
  background: var(--good-soft); color: var(--good-text); border: 1px solid var(--good);
  cursor: default; user-select: none; white-space: nowrap; transition: all 150ms ease;
}
.surv-badge[data-state="warn"] {
  background: var(--neg-soft); color: var(--neg-text); border-color: var(--critical);
}
.surv-badge[data-state="off"] {
  background: var(--surface-2); color: var(--text-3); border-color: var(--border);
}
.surv-pulse {
  width: 6px; height: 6px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 6px var(--good); animation: surv-pulse-anim 2s infinite ease-in-out;
}
.surv-badge[data-state="warn"] .surv-pulse {
  background: var(--critical); box-shadow: 0 0 6px var(--critical);
}
.surv-badge[data-state="off"] .surv-pulse {
  background: var(--text-3); box-shadow: none; animation: none;
}
@keyframes surv-pulse-anim {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}
@media (max-width: 500px) {
  #surv-label { display: none; }
  .surv-badge { padding: 4px 6px; }
}
.status {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 12px; color: var(--text-2); white-space: nowrap; font-weight: 500;
}
#status-label { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-3); }
.status[data-code="ok"] .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status[data-code="warn"] .dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status[data-code="bad"] { color: var(--neg-text); font-weight: 650; }
.status[data-code="bad"] .dot { background: var(--critical); box-shadow: 0 0 8px var(--critical); }
.status[data-code="off"] .dot { background: transparent; border: 1.5px solid var(--text-3); }
.icon-btn {
  flex: none; width: 26px; height: 26px; padding: 0; border-radius: 5px; cursor: pointer;
  font: 12px/1 var(--sans); color: var(--text-2); background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; transition: all 120ms ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--accent); color: var(--text); }
.icon-btn svg { display: block; width: 14px; height: 14px; margin: auto; }
.icon-btn circle { fill: none; stroke: currentColor; stroke-width: 1.5; }
.icon-btn path { fill: currentColor; }
@media (max-width: 379px) {
  .brand-name { display: none; }
}

.offline, .status-text, .alert {
  margin: 0 0 8px; padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warning);
  color: var(--warning-text); box-shadow: var(--shadow);
}
.alert { border-left-color: var(--critical); color: var(--neg-text); }

/* ---- surfaces ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 14px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 8px; }
.auto-rules { color: var(--text-2); line-height: 1.6; }
.auto-live { border-left: 3px solid var(--border); }
.auto-live[data-tone="real"] { border-left-color: var(--real); }
.auto-live[data-tone="warn"] { border-left-color: var(--warning); }
.auto-live-state { font-weight: 700; font-size: 13.5px; margin: 0 0 4px; color: var(--text); }
.auto-live p { margin: 4px 0; }
.section-title {
  display: flex; align-items: center; gap: 8px; margin: 14px 0 6px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2);
}
.section-title::before { content: ""; flex: none; width: 3px; height: 12px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 8px var(--glow); }
.section-title .count { color: var(--text-3); font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 12.5px; }
.lede { color: var(--text-2); margin-bottom: 6px; line-height: 1.5; }

/* Folded sections: the summary is a section title. */
.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; min-height: 38px; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary .section-title { margin: 0; }
.fold > summary::after { content: "+"; margin-left: auto; color: var(--text-3); font-size: 16px; font-weight: 700; }
.fold[open] > summary::after { content: "−"; }

/* ---- header context strip ---- */
.mk-strip {
  margin: 0 0 8px; padding: 6px 10px; border-radius: 6px;
  font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--surface-2); border: 1px solid var(--border); font-variant-numeric: tabular-nums;
}

/* ---- "Compte" ---- */
.setup { border-left: 3px solid var(--essai); }
.setup h1 { font-size: 15px; font-weight: 800; margin-bottom: 6px; }
.setup ol { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.setup code { overflow-wrap: anywhere; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.setup .small { margin-bottom: 0; }
.ac-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 8px; }
.ac-head .section-title { margin: 0; }
.ac-usd { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.ac-usd p { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; }
.ac-usd p:first-child { border-right: 1px solid var(--border); padding-right: 12px; }
.ac-usd span { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.ac-usd b { font-size: 21px; font-weight: 750; color: var(--text); letter-spacing: -0.01em; }
.acts { display: inline-flex; align-items: center; gap: 6px; }
.btn-mini.btn-buy { color: var(--good-text); border-color: var(--good); background: var(--good-soft); }
.btn-mini.btn-buy:hover { background: var(--good); color: #fff; }
.chip.app-tag { margin-left: 5px; padding: 1px 6px; font-size: 10px; line-height: 15px; vertical-align: 1px; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); border-radius: 3px; font-weight: 700; }

/* ---- compact tables: positions, orders, journal ---- */
.scroll { overflow-x: auto; }
.card.scroll, .card > .grid { padding-top: 4px; padding-bottom: 4px; }
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th, .grid td { padding: 7px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.grid tr:last-child > * { border-bottom: 0; }
.grid th + th, .grid td + td, .grid td + th, .grid th + td { padding-left: 10px; }
.grid th:first-child, .grid td:first-child { text-align: left; }
.grid td { font-family: var(--mono); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.grid thead th { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); border-bottom: 1px solid var(--border); }
.grid tbody th { font-weight: 700; font-family: var(--sans); }
.grid .empty { text-align: left; color: var(--text-3); white-space: normal; font-family: var(--sans); letter-spacing: 0; padding: 12px 6px; }
.grid tr.sub td {
  padding: 6px 8px 8px; font-family: var(--sans); letter-spacing: 0; color: var(--text-2); font-size: 12px; white-space: normal;
  background: var(--surface-2); border-bottom: 1px solid var(--border); border-radius: 4px;
}
.grid tr:has(+ tr.sub) > * { border-bottom: 0; }
.sub .levels { font-family: var(--mono); letter-spacing: -0.02em; font-weight: 550; font-size: 11.5px; }
.sub .acts { margin-left: 10px; }
.journal td { vertical-align: top; text-align: left; white-space: normal; overflow-wrap: anywhere; font-family: var(--sans); letter-spacing: 0; font-size: 12.5px; padding: 8px 6px; }
.journal td:first-child { white-space: nowrap; color: var(--text-3); width: 1%; position: relative; padding-left: 10px; font-family: var(--mono); font-size: 12px; }
.journal td:first-child::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--border); }
.journal tr[data-tone="buy"] td:first-child::before { background: var(--accent); }
.journal tr[data-tone="gain"] td:first-child::before { background: var(--good); }
.journal tr[data-tone="loss"] td:first-child::before { background: var(--critical); }
.journal tr[data-tone="alert"] td:first-child::before { background: var(--warning); }

/* ---- buttons ---- */
.controls { display: grid; gap: 8px; margin: 14px 0 6px; }
.btn {
  min-height: 40px; padding: 8px 16px; border-radius: 6px; cursor: pointer;
  font: 700 13px/1.2 var(--sans); color: #fff; background: var(--accent); border: 1px solid var(--accent);
  box-shadow: 0 0 14px var(--glow); transition: all 120ms ease;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 0 18px var(--glow); }
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: var(--surface); color: var(--neg-text); border-color: var(--critical); box-shadow: none; }
.btn-danger:hover:not(:disabled) { background: var(--neg-soft); color: var(--neg-text); }
.btn-quiet { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: none; }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
/* the button that sends (or, in Essai, signs) an order: the mode's colour */
.btn-order { background: var(--essai); border-color: var(--essai); color: var(--essai-ink); box-shadow: none; font-weight: 750; }
body[data-mode="real"] .btn-order { background: var(--real); border-color: var(--real); color: #fff; }
.btn-mini {
  min-height: 30px; padding: 3px 12px; border-radius: 5px; cursor: pointer;
  font: 650 12px/1.2 var(--sans); color: var(--neg-text); background: var(--surface); border: 1px solid var(--critical);
  transition: all 120ms ease;
}
.btn-mini:hover:not(:disabled) { background: var(--neg-soft); }
.btn-mini:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-quiet-mini { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.btn-quiet-mini:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--text-3); }
.link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 650; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---- "Réglages" ---- */
.st-mode { border-left: 4px solid var(--essai); background: var(--essai-soft); display: grid; gap: 6px; padding: 12px 14px; border-radius: 6px; }
.st-mode[data-tone="real"] { border-left-color: var(--real); background: var(--real-soft); }
.st-mode-name { font-size: 16px; font-weight: 750; }
.st-mode p:not(.st-mode-name) { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.st-mode p.error { color: var(--neg-text); font-weight: 650; }

/* ---- forms ---- */
form { display: grid; gap: 10px; margin-top: 10px; }
label { font-weight: 650; color: var(--text-2); font-size: 12.5px; }
input {
  min-height: 40px; padding: 8px 12px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; width: 100%;
  font-variant-numeric: tabular-nums;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); outline: none; }
.ticket { display: grid; gap: 10px; margin-top: 8px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: grid; gap: 4px; align-content: start; min-width: 0; margin: 0; font-weight: 400; }
.field.full { grid-column: 1 / -1; }
.field > span:first-child, .field > label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3);
}
.field small { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--text-3); }
.field input {
  min-height: 38px; padding: 7px 10px; font: 13.5px var(--mono); letter-spacing: -0.01em;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; width: 100%;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); outline: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.seg button {
  min-height: 36px; padding: 0 12px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  background: transparent; border: 0; cursor: pointer; flex: 1; transition: all 120ms ease;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 1px 4px var(--glow); }
.field > .seg { display: flex; }
.figures { list-style: none; margin: 0; padding: 9px 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); display: grid; gap: 3px; font-size: 13px; font-variant-numeric: tabular-nums; }
.figures .faint { font-size: 12px; color: var(--text-3); }
.figures li.faint { font-style: italic; }
.basis { font-size: 12px; color: var(--text-3); line-height: 1.4; }

/* pair search of the buy form */
.pair-field { position: relative; }
.pair-field input { text-transform: uppercase; font-family: var(--sans); letter-spacing: 0.02em; font-weight: 600; }
.pair-list {
  position: absolute; z-index: 15; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 6px 0; list-style: none;
  max-height: 19rem; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.pair-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.pair-list li[aria-selected="true"], .pair-list li:hover { background: var(--surface-2); }
.pair-list .none { cursor: default; }
.pair-list .po-base { min-width: 3.5rem; font-weight: 700; }
.pair-list .po-figs { display: flex; gap: 8px; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pair-list .po-figs > :nth-child(2) { min-width: 3.4rem; text-align: right; }
.pair-list .empty-book { opacity: 0.6; }

/* ---- navigation: bottom bar on a phone ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tab-bg); border-top: 1px solid var(--border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.tabs a {
  flex: 1; max-width: 8rem; min-height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; color: var(--text-2); text-decoration: none; border-top: 2px solid transparent;
  transition: all 120ms ease;
}
.tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs a[aria-current="page"] { color: var(--text); font-weight: 700; border-top-color: var(--accent); }
.tabs a[aria-current="page"] svg { stroke: var(--accent); stroke-width: 2.2; filter: drop-shadow(0 0 6px var(--glow)); }
body.no-token .tabs { display: none; }

/* 480 px and wider (the Windows window): tabs on top, like the radar. */
@media (min-width: 480px) {
  .app { padding-bottom: 20px; }
  .tabs {
    position: static; justify-content: flex-start; gap: 4px; margin: 0 0 8px;
    padding: 0; background: none; border-top: 0; border-bottom: 1px solid var(--border); backdrop-filter: none;
    height: 32px;
  }
  .tabs a {
    flex: none; max-width: none; min-height: 0; height: 32px; flex-direction: row; gap: 6px; align-items: center;
    padding: 0 12px; font-size: 12.5px; border-top: 0; border-bottom: 2px solid transparent; border-radius: 5px 5px 0 0;
  }
  .tabs svg { width: 15px; height: 15px; }
  .tabs a:hover { background: var(--surface-2); color: var(--text); }
  .tabs a[aria-current="page"] { border-bottom-color: var(--accent); background: var(--surface); box-shadow: 0 2px 8px var(--glow); }
  .top { margin-bottom: 0; }
  body .toast { bottom: 20px; }
}

/* ---- dialogs and toast ---- */
dialog {
  width: min(28rem, calc(100vw - 2 * var(--gutter))); padding: 16px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 10px; font-size: 16px; font-weight: 750; }
dialog p { margin-bottom: 8px; color: var(--text-2); line-height: 1.5; }
dialog form { margin-top: 0; }
dialog .fields { margin-bottom: 8px; }
dialog .figures { margin: 8px 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.dialog-actions .btn-danger { background: var(--critical); color: #fff; }
.order-dialog { border: 2px solid var(--essai); }
body[data-mode="real"] .order-dialog { border-color: var(--real); }
.order-flag {
  margin: -16px -16px 12px !important; padding: 7px 16px; border-radius: 6px 6px 0 0;
  background: var(--essai); color: var(--essai-ink) !important; font-size: 12px; font-weight: 800; letter-spacing: 0.08em;
}
.order-flag[data-tone="real"] { background: var(--real); color: #fff !important; }
.order-dialog .seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.toast {
  position: fixed; left: var(--gutter); right: var(--gutter); z-index: 20;
  bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  max-width: 34rem; margin: 0 auto; padding: 10px 14px; border-radius: 6px;
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: rise 180ms ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } }
}

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; border-radius: 3px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  font-size: 11px; font-family: var(--mono); white-space: nowrap; letter-spacing: -0.01em;
}

/* ---- "Mouvements": direction toggle and one compact block per move ---- */
.filter { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.filter button {
  height: 32px; min-height: 32px; padding: 0 10px; font: inherit; font-size: 12px; font-weight: 600; color: var(--text-2);
  background: transparent; border: 0; cursor: pointer; transition: all 120ms ease;
}
.filter button + button { border-left: 1px solid var(--border); }
.filter button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 1px 4px var(--glow); }
.empty-card { color: var(--text-3); padding: 16px 12px; text-align: center; }

/* The controls of "Mouvements" stay under the app's header while the list
   scrolls (--top-h: the header's height, set by app.js). */
:root { --top-h: 36px; }
.mv-sentinel { display: block; height: 1px; margin-bottom: -1px; }
.mv-sticky {
  position: sticky; top: var(--top-h); z-index: 4;
  height: 44px; min-height: 44px; box-sizing: border-box;
  margin: 0 calc(-1 * var(--gutter)) 8px; padding: 6px var(--gutter);
  background: var(--bg); border-bottom: 1px solid transparent;
  display: flex; flex-direction: column; justify-content: center;
  transition: box-shadow 120ms ease-out, border-color 120ms ease-out;
  backdrop-filter: blur(12px);
}
.mv-sticky.stuck { border-bottom-color: var(--border); box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.4); }
@media (min-width: 480px) { .mv-sticky { top: var(--top-h); } }
.mv-bar-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.mv-bar-top .section-title { margin: 0; flex: 1 0 auto; }
.mv-q {
  flex: 1 1 90px; min-width: 80px; max-width: 170px; height: 32px; min-height: 32px; padding: 0 10px;
  font: inherit; font-size: 12.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
}
.mv-q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); outline: none; }
.mv-going {
  height: 32px; min-height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: all 120ms ease;
}
.mv-going:hover { background: var(--surface-hover); color: var(--text); }
.mv-going[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 1px 4px var(--glow); }
.mv-done-line { margin: 3px 0 0; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.mv-banner {
  margin: 4px 0 0; font-size: 12px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4;
}
/* phone: title and "Terminés" on the first row, direction and search on the second */
@media (max-width: 479px) {
  .mv-sticky { height: auto; min-height: 44px; padding: 6px var(--gutter); }
  .mv-bar-top .section-title { order: 0; flex: 1 1 auto; }
  .mv-going { order: 1; }
  .mv-bar-top .filter { order: 2; flex: none; }
  .mv-q { order: 3; max-width: none; }
}

/* ---- "Nouvelle stratégie": strategies, observations, "à éviter" ---- */
.sg { margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.sg > summary { cursor: pointer; list-style: none; display: flex; align-items: center; min-height: 36px; }
.sg > summary::-webkit-details-marker { display: none; }
.sg > summary .section-title { margin: 0; }
.sg > summary::after { content: "−"; margin-left: auto; color: var(--text-3); font-size: 16px; font-weight: 700; }
.sg:not([open]) > summary::after { content: "+"; }
.sg-note { margin: 0 0 6px; font-size: 12px; color: var(--text-3); line-height: 1.45; }
.sg-strats { list-style: none; margin: 0; padding: 0; }
.sg-strats > li { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.sg-strats > li:last-child { border-bottom: 0; }
.sg-strat-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-size: 13.5px; }
.sg-status { padding: 1px 8px; font-size: 11px; line-height: 18px; font-weight: 700; background: transparent; border-radius: 3px; }
.sg-stats { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sg-text { font-size: 11.5px; color: var(--text-3); }
.sg-list { margin-top: 8px; }
.sg-list > li.mv { contain-intrinsic-size: auto 120px; }
.chip.sg-chip { padding: 1px 8px; font-size: 11px; line-height: 18px; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: 1px; border-radius: 4px; font-weight: 700; }
.sg-card .mv-title { white-space: normal; }
.sg-card .mv-px { margin-top: 2px; }
.sg-reasons { margin: 3px 0 0; font-size: 12.5px; color: var(--text-2); }
.sg-exits { margin: 2px 0 0; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.mv-state[data-state="watch"] { color: var(--text-2); border-color: var(--border); background: var(--surface-2); }
.sg-avoid { margin: 8px 0 0; font-size: 12.5px; line-height: 1.6; }
.sg-avoid .chip { padding: 1px 8px; font-size: 11px; line-height: 18px; font-weight: 700; }
.sg-closed { margin-top: 8px; }
.sg-closed > summary { cursor: pointer; width: max-content; font-size: 13px; font-weight: 650; color: var(--accent); }
.sg-closed[open] > summary { margin-bottom: 6px; }
.sg-results { list-style: none; margin: 0; padding: 6px 12px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sg-results li { padding: 3px 0; }
.mv-state[data-state="rank"], .mv-state[data-state="horizon"] { color: var(--text-2); }

.moves { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.moves > li { padding: 8px 10px; border-bottom: 1px solid var(--border); transition: background 100ms ease; }
.moves > li:hover { background: var(--surface-hover); }
/* rows out of the screen are neither laid out nor painted (300 rows) */
.moves > li.mv {
  position: relative;
  content-visibility: auto;
  contain-intrinsic-size: auto 54px;
  min-height: 54px;
  box-sizing: border-box;
}
.moves > li:last-child { border-bottom: 0; }
.mv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; flex-wrap: wrap; }
.mv-title { font-size: 13px; min-width: 0; line-height: 1.35; display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; flex: 1 1 auto; }
.mv-title > * { white-space: nowrap; }
.mv-title b { font-weight: 750; font-size: 13.5px; color: var(--text); }
.mv-now { margin: 0; flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.mv-relaunch { font-size: 11px; font-weight: 750; padding: 2px 7px; border-radius: 4px; letter-spacing: -0.01em; }
.mv-relaunch[data-tone="up"] { color: var(--good-text); border-color: var(--good); background: var(--good-soft); }
.mv-relaunch[data-tone="down"] { color: var(--neg-text); border-color: var(--critical); background: var(--neg-soft); }
.chip.chip-reversal {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 750; padding: 1px 7px; border-radius: 4px;
  color: var(--warning-text); border-color: var(--warning); background: var(--warning-soft);
  box-shadow: 0 1px 4px var(--warning-soft);
}
.mv-more { margin-top: 4px; }
.mv-more > summary.mv-sum { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; min-height: 24px; padding: 2px 0; }
.mv-more > summary.mv-sum::-webkit-details-marker { display: none; }
.mv-sum .mv-read { flex: none; margin: 0; white-space: nowrap; font-size: 11.5px; font-weight: 550; }
.mv-sum .mv-track { flex: 1; min-width: 0; margin: 0; min-height: 22px; }
.mv-sum::after { content: "›"; color: var(--text-3); font-size: 15px; font-weight: 700; transition: transform 0.15s; margin-left: 4px; }
.mv-more[open] > .mv-sum::after { transform: rotate(90deg); }
.mv-more dl { margin: 6px 0 0; padding: 6px 10px; border-radius: 5px; background: var(--surface-2); font-size: 12px; border: 1px solid var(--border); }
.mv-more dl div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.mv-more dt { color: var(--text-3); flex: none; }
.mv-more dd { margin: 0; text-align: right; font-family: var(--mono); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
/* follow-up since detection: price, change, highs and lows, SL <-> TP bar, mini chart, state */
.mv-px { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.mv-entry { font-family: var(--mono); letter-spacing: -0.02em; color: var(--text-3); }
.mv-last { font-size: 13.5px; font-weight: 700; color: var(--text); }
.chip.mv-state { margin-left: auto; padding: 1px 6px; font-size: 10.5px; line-height: 16px; font-weight: 700; border-radius: 3px; }
.mv-state[data-state="open"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.mv-state[data-state="tp"] { color: #fff; background: var(--good); border-color: var(--good); box-shadow: 0 1px 4px var(--good-soft); }
.mv-state[data-state="sl"] { color: #fff; background: var(--critical); border-color: var(--critical); box-shadow: 0 1px 4px var(--neg-soft); }
.mv-ex { font-size: 11.5px; letter-spacing: -0.01em; }
.mv-track { display: flex; align-items: center; gap: 10px; margin-top: 0; }
.mv-bar { flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 6px; font-size: 10px; }
.mv-sl { color: var(--neg-text); white-space: nowrap; font-weight: 700; letter-spacing: -0.02em; }
.mv-tp { color: var(--good-text); white-space: nowrap; font-weight: 700; letter-spacing: -0.02em; }
.mv-bar .bar {
  position: relative; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--critical) 40%, var(--surface-2)), var(--surface-2) 50%, color-mix(in srgb, var(--good) 40%, var(--surface-2)));
  border: 1px solid var(--border);
}
.mv-bar .cursor { position: absolute; top: -4px; width: 4px; height: 14px; margin-left: -2px; border-radius: 2px; background: #fff; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }
.mv-spark { flex: none; width: 80px; height: 20px; overflow: visible; }
.mv-spark .s-line { fill: none; stroke: var(--text-2); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.mv-spark[data-tone="up"] .s-line, .mv-spark[data-tone="up"] .s-end { stroke: var(--good-text); fill: var(--good-text); }
.mv-spark[data-tone="down"] .s-line, .mv-spark[data-tone="down"] .s-end { stroke: var(--neg-text); fill: var(--neg-text); }
.mv-spark[data-tone] .s-line { fill: none; }
.mv-spark .s-end { fill: var(--text-2); stroke: none; }
.mv-spark .s-tp { stroke: var(--good); stroke-width: 1.2; stroke-dasharray: 3 2; }
.mv-spark .s-sl { stroke: var(--critical); stroke-width: 1.2; stroke-dasharray: 3 2; }
.mv-spark .s-zero { stroke: var(--text-3); stroke-width: 0.8; stroke-dasharray: 1 2; }
.mv-caveat { margin: 6px 0 0; font-size: 11.5px; color: var(--warning-text); line-height: 1.4; }

/* a row that moved: a short highlight */
@media (prefers-reduced-motion: no-preference) {
  .mv[data-flash]::after { content: ""; position: absolute; inset: 0; background: var(--glow); opacity: 0; pointer-events: none; border-radius: 4px; }
  .mv[data-flash="a"]::after { animation: mv-flash-a 700ms ease-out; }
  .mv[data-flash="b"]::after { animation: mv-flash-b 700ms ease-out; }
  @keyframes mv-flash-a { from { opacity: 1; } to { opacity: 0; } }
  @keyframes mv-flash-b { from { opacity: 1; } to { opacity: 0; } }
}

/* ---- Réglages ---- */
.st-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.st-row .st-mode-name { margin: 0; }
.st-form { margin-top: 0; gap: 0; }
.st-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.st-actions .btn { width: auto; padding-left: 16px; padding-right: 16px; }
.st-more { margin-top: 4px; }
.st-main .st-sub { margin: 0 0 4px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }
.st-main .fields + .st-sub { margin-top: 10px; }
.st-main #st-limits { margin: 8px 0 0; }
@media (max-width: 479px) { .mv-sum .mv-bar { display: none; } .mv-sum .mv-track { justify-content: flex-end; } }
.st-main { margin-top: 8px; }
.st-bot { margin-top: 8px; }
.st-more > .card + .card { margin-top: 8px; }
.st-save-bar.dirty {
  position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  padding: 8px 10px; border: 1px solid var(--accent); border-radius: 10px; background: var(--surface);
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.35);
}
@media (min-width: 480px) { .st-save-bar.dirty { bottom: 8px; } }
.st-bot .st-actions { margin-top: 0; }
.st-bot p { margin: 8px 0 0; }
.field .hint { font-size: 11px; color: var(--text-3); }
.field input.changed { border-color: var(--accent); }

/* ---- Mouvements : decision lines ---- */
.mv-read { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }
.mv-read .chip { font-weight: 700; }
.chip.read-good { color: var(--good-text); border-color: var(--good); }
.chip.read-neutral { color: var(--text); border-color: var(--border); }
.chip.read-warn { color: var(--warning-text); border-color: var(--warning); }
.chip.read-bad { color: var(--neg-text); border-color: var(--critical); }
.chip.read-faint { color: var(--text-3); border-color: var(--border); }
.mv-plan { margin: 3px 0 0; font-size: 12.5px; }
.mv-buy { margin: 6px 0 0; }
.mv .btn-mini.btn-buy.btn-quiet-mini { color: var(--text-2); border-color: var(--border); }
.mv-odds { margin: 2px 0 0; font-size: 12px; color: var(--text-2); }
.mv[data-read="loser"] .mv-title b, .mv[data-read="untradable"] .mv-title b { opacity: 0.8; }

/* ---- buy popup ---- */
.buy-dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; }
.buy-dialog .ticket { margin-top: 6px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dialog-head h2 { margin: 0; }
.close-x { font-size: 18px; line-height: 1; padding: 4px 8px; text-decoration: none; color: var(--text-2); }

/* ---- Auto Strategy selector & metrics ---- */
.auto-strategy {
  border-left: 3px solid var(--accent);
  margin-bottom: 10px;
}
.auto-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.auto-mode-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.auto-mode-sub {
  font-size: 11.5px;
  color: var(--text-2);
}
.auto-strat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.auto-strat-label-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge-auto-applied {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-auto-applied.auto {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.badge-auto-applied.manual {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.auto-strat-select {
  min-height: 34px;
  padding: 5px 12px;
  font: 700 13px var(--sans);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 120ms ease;
}
.auto-strat-select:hover { border-color: var(--accent); }
.auto-strat-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); outline: none; }
.auto-strat-desc {
  margin: 6px 0 10px !important;
  color: var(--text-2);
  line-height: 1.5;
  font-size: 12.5px;
}
.auto-strat-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.auto-strat-badges .pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.auto-strat-badges .pill.good {
  border-color: var(--good);
  color: var(--good-text);
  background: var(--good-soft);
  box-shadow: 0 1px 4px var(--good-soft);
}
.auto-strat-badges .pill.neutral {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---- Auto Market Context Box ---- */
.auto-market-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.auto-market-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.auto-market-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.pill.pill-market {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 750;
  font-family: var(--sans);
  border: 1px solid var(--border);
}
.pill.pill-market.good {
  background: var(--good-soft);
  color: var(--good-text);
  border-color: var(--good);
}
.pill.pill-market.warn {
  background: var(--warning-soft);
  color: var(--warning-text);
  border-color: var(--warning);
}
.pill.pill-market.down {
  background: var(--neg-soft);
  color: var(--neg-text);
  border-color: var(--critical);
}
.pill.pill-market.neutral {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border);
}
.auto-market-desc {
  margin: 0 !important;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.45;
}

.field select {
  min-height: 38px;
  padding: 7px 10px;
  font: 13px var(--sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}
.field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); outline: none; }
