:root {
  /* Thème bleu nuit + accent cyan lisible sur fond sombre */
  --bg: #0a1020; --card: #111a30; --card2: #18223c; --line: #263352;
  --fg: #e8edf7; --muted: #8b9bc0; --accent: #38bdf8; --accent-ink: #06283d;
  --long: #34d17a; --short: #f26d6d;
  --radius: 10px; --shadow: 0 2px 12px rgba(0,0,0,.35);
  --t: .18s ease;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 620px at 72% -12%, #16264f 0%, var(--bg) 62%) fixed;
  color: var(--fg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; transition: color var(--t), opacity var(--t); }
a:hover { text-decoration: underline; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; gap: 1.2rem; align-items: center;
  padding: .7rem 1.2rem; background: rgba(15,23,44,.82); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 800; font-size: 1.1rem; color: var(--accent); letter-spacing: .3px; }
.topbar nav { display: flex; gap: .3rem; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: .35rem .7rem; border-radius: 8px;
  transition: color var(--t), background var(--t); }
.topbar nav a:hover { color: var(--fg); background: var(--card2); text-decoration: none; }
.topbar nav a.active { color: var(--fg); background: var(--card2);
  box-shadow: inset 0 -2px 0 var(--accent); }
.topbar .inline { margin-left: auto; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; transition: color var(--t); }
.link:hover { color: var(--fg); }
.live-badge { display: inline-flex; align-items: center; gap: .35rem; margin-left: auto;
  color: var(--muted); font-size: .78rem; }
.live-badge + .inline { margin-left: 1rem; }
#live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--long); display: inline-block; }
#live-dot.pulse { animation: pulse .9s ease; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(46,160,67,.6); } 100% { box-shadow: 0 0 0 8px rgba(46,160,67,0); } }

main { max-width: 1040px; margin: 1.5rem auto; padding: 0 1rem; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; }
.muted { color: var(--muted); } .error { color: var(--short); }
.warn { color: var(--accent); } .banner { background: #16264f; color: var(--fg);
  padding: .6rem 1rem; text-align: center; border-bottom: 1px solid var(--line); }

.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: .8rem 1rem; margin: 1rem 0; }
.filters label { margin: 0; display: flex; flex-direction: column; gap: .2rem;
  font-size: .8rem; color: var(--muted); }
.filters select { width: auto; min-width: 120px; }
.filters .btn { padding: .5rem .9rem; }

table.grid { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); }
table.grid th, table.grid td { padding: .55rem .7rem; border-bottom: 1px solid var(--line);
  text-align: left; }
table.grid tbody tr:last-child td { border-bottom: none; }
/* En-tête NON sticky : le sticky (top:52px, sous un topbar de 57px) recouvrait la
   1re ligne des tables autonomes (Stats, Historique, Positions) au défilement. */
table.grid thead th { background: var(--card2); }
table.grid th { color: var(--muted); font-weight: 600; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .3px; }
table.grid tbody tr { transition: background var(--t); }
table.grid tbody tr:hover { background: rgba(255,255,255,.03); }
.dir-long { color: var(--long); font-weight: 600; }
.dir-short { color: var(--short); font-weight: 600; }
td.live-price { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg); }
td.inzone { color: var(--accent); font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent); }

/* Jauge de progression entrée → TP3 */
td.gauge-cell { white-space: nowrap; }
.gauge { position: relative; display: inline-block; width: 120px; height: 9px;
  background: #0a1122; border: 1px solid var(--line); border-radius: 5px;
  overflow: hidden; vertical-align: middle; }
.gauge-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 5px;
  transition: width .4s ease; min-width: 2px; }
.dir-bg-long { background: linear-gradient(90deg, #1f7a35, var(--long)); }
.dir-bg-short { background: linear-gradient(90deg, #a83a34, var(--short)); }
.gauge-tick { position: absolute; top: 0; width: 2px; height: 100%;
  background: rgba(255,255,255,.35); }
.gauge-pct { margin-left: .5rem; font-size: .8rem; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.status-error { color: var(--short); } .status-open { color: var(--long); }

/* TP franchis + badge d'état actionnable */
.tp-list { white-space: nowrap; font-variant-numeric: tabular-nums; }
.tp-mark { color: var(--muted); }
.tp-mark.hit { color: var(--long); font-weight: 700; }
.state { display: inline-block; padding: .12rem .5rem; border-radius: 10px;
  font-size: .74rem; font-weight: 600; white-space: nowrap; border: 1px solid var(--line); }
.state-waiting { color: var(--muted); }
.state-fresh { color: #7ee08a; border-color: #2f6b39; background: rgba(46,120,60,.15); }
.state-progressing { color: var(--accent); border-color: #24506b; background: rgba(30,80,120,.15); }
.state-near_tp { color: #6fd07f; border-color: #2f6b39; background: rgba(46,120,60,.22); }
.state-exhausted { color: #e0b24a; border-color: #7a5a1f; background: rgba(140,100,30,.18); }
.state-invalidated { color: var(--short); border-color: #7a2f2f; background: rgba(140,50,50,.18); }
.state-new { color: #ffd466; border-color: #7a6320; background: rgba(160,130,30,.22); }
.row-new > td { box-shadow: inset 0 1px 0 rgba(255,212,102,.25); }
.gain-max { margin-left: .35rem; font-size: .78rem; color: var(--long); font-variant-numeric: tabular-nums; }
.risk-tag { margin-left: .4rem; font-size: .75rem; color: #e0b24a; font-variant-numeric: tabular-nums; }
.mkt-badge { display: inline-block; padding: .05rem .4rem; border-radius: 6px; font-size: .68rem;
  font-weight: 600; border: 1px solid var(--line); vertical-align: middle; margin: 0 .2rem; }
.mkt-futures { color: #7fb3ff; border-color: #2a4a6b; background: rgba(40,80,130,.18); }
.mkt-spot { color: #9be08a; border-color: #3a6b2f; background: rgba(60,120,46,.18); }

/* Groupes dépliables par paire (Historique) — natif <details>, sans JS */
.pair-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin: .6rem 0; box-shadow: var(--shadow); overflow: hidden; }
.pair-group > summary { cursor: pointer; padding: .7rem 1rem; list-style: none; display: flex;
  align-items: center; gap: .6rem; flex-wrap: wrap; user-select: none; transition: background var(--t); }
.pair-group > summary:hover { background: var(--card2); }
.pair-group > summary::-webkit-details-marker { display: none; }
.pair-group > summary::before { content: "\25B8"; color: var(--muted); transition: transform var(--t); }
.pair-group[open] > summary::before { transform: rotate(90deg); }
.pair-group > summary strong { font-size: 1.05rem; }
.grp-tags { display: inline-flex; gap: .3rem; flex-wrap: wrap; margin-left: auto; }
.grp-tags .state { font-size: .7rem; }
.pair-group table.grid { border: none; border-radius: 0; box-shadow: none; margin: 0; }

.pager { display: flex; align-items: center; gap: .8rem; margin: .8rem 0; }

/* Positions live (obj 1) : badge « live » + actions inline TP/SL/Close par ligne */
.live-tag { display: inline-block; font-size: .62rem; text-transform: uppercase; letter-spacing: .4px;
  color: #6ee7a8; border: 1px solid #2f6b46; background: rgba(46,120,70,.18);
  border-radius: 4px; padding: 0 .3rem; vertical-align: middle; margin-left: .25rem; }
.pos-actions { white-space: nowrap; }
.pos-actions .act-form { display: inline-flex; align-items: center; gap: .25rem; margin: .12rem .25rem .12rem 0; }
.pos-actions .act-form input[type=text] { width: 5.5rem; padding: .25rem .35rem; font-size: .8rem; }
.pos-actions .act-form .btn { padding: .25rem .5rem; font-size: .78rem; }

/* TP partiels : % de clôture par TP (formulaire de prise de position) */
.tp-splits { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  margin: .2rem 0 .4rem 1.6rem; }
.tp-splits .split-in { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; }
.tp-splits .split-in input { width: 4rem; }
.tp-splits .split-hint { width: 100%; font-size: .78rem; }

/* Menu d'actions par ligne (⋯) — natif <details>, sans JS. Expansion en flux
   (pas d'absolu) pour ne pas être rognée par l'overflow:hidden de la table. */
.row-menu { display: inline-block; }
.row-menu > summary { cursor: pointer; list-style: none; user-select: none;
  padding: .1rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card2); font-weight: 700; letter-spacing: 1px; line-height: 1.2; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu > summary::marker { content: ""; }
.row-menu > summary:hover { background: var(--line); }
.row-menu-items { display: flex; flex-direction: column; gap: .12rem; margin-top: .3rem;
  min-width: 108px; background: var(--card2); border: 1px solid var(--line);
  border-radius: 8px; padding: .25rem; box-shadow: var(--shadow); }
.row-menu-items a, .row-menu-items button { display: block; width: 100%; text-align: left;
  padding: .35rem .55rem; font-size: .85rem; border-radius: 6px; background: none;
  border: none; color: var(--fg); cursor: pointer; text-decoration: none; }
.row-menu-items a:hover, .row-menu-items button:hover { background: var(--line); }
.row-menu-items .menu-danger { color: var(--short); }

/* Watchlist : barre de seuil + case à cocher par paire */
.wl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem .9rem; margin: .6rem 0; box-shadow: var(--shadow); }
.wl-threshold { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 0; }
.wl-threshold label { display: inline-flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.wl-threshold input[type=number] { width: 4.5rem; }
.wl-note { font-size: .8rem; }
.wl-form { display: inline; margin: 0; }
.wl-toggle { background: none; border: none; cursor: pointer; font-size: 1.15rem;
  line-height: 1; padding: 0 .1rem; color: var(--muted); vertical-align: middle; }
.wl-toggle:hover { color: var(--fg); }
.wl-toggle.on { color: var(--accent, #5aa0ff); }

/* Action « + Journal » (enregistrer un signal) — mise en avant */
.btn-save { background: var(--accent-bg, rgba(90,160,255,.16)); color: var(--accent);
  border: 1px solid var(--accent, #5aa0ff); font-weight: 700; }
.btn-save:hover { background: var(--accent, #5aa0ff); color: #06101f; }

/* Journal : barre d'onglets (SSR, liens — fonctionne sans JS) */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin: .6rem 0 1rem;
  border-bottom: 1px solid var(--line); }
.tabs .tab { padding: .5rem .9rem; text-decoration: none; color: var(--muted);
  border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0;
  font-weight: 600; transition: background var(--t), color var(--t); margin-bottom: -1px; }
.tabs .tab:hover { color: var(--fg); background: var(--card2); }
.tabs .tab.active { color: var(--fg); background: var(--card); border-color: var(--line);
  border-bottom: 1px solid var(--card); }
.tabs .tab-count { display: inline-block; min-width: 1.2rem; text-align: center;
  font-size: .72rem; padding: 0 .35rem; margin-left: .2rem; border-radius: 10px;
  background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.tabs .tab.active .tab-count { background: var(--accent-bg, rgba(90,160,255,.15)); color: var(--accent); }

/* « Mes signaux » : 3 sections de cycle de vie (attente / activés / terminés) */
.lifecycle-section { margin: 1.4rem 0; }
.lifecycle-section .sec-head { margin: 0 0 .1rem; font-size: 1.15rem; }
.lifecycle-section .sec-hint { margin: 0 0 .5rem; font-size: .82rem; }
.lifecycle-section .sec-empty { margin: .3rem 0 0; font-size: .85rem; opacity: .8; }

/* Cartes récap PnL (/trades) */
.pnl-cards { display: flex; flex-wrap: wrap; gap: .8rem; margin: 1rem 0; }
.pnl-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: .7rem 1rem; min-width: 140px; display: flex; flex-direction: column; gap: .25rem; }
.pnl-card strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* Bandeau de commandement (page Signaux) : compte + soldes + résumé positions */
.acct-bar { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .8rem 1rem; margin: 1rem 0; }
.acct-form { display: flex; align-items: flex-end; gap: .8rem; flex-wrap: wrap; margin-bottom: .8rem;
  padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.acct-form label { margin: 0; display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.acct-form select { width: auto; min-width: 220px; }
.acct-metrics { display: flex; flex-wrap: wrap; gap: 1.6rem; }
.acct-metrics .metric { display: flex; flex-direction: column; gap: .15rem; }
.acct-metrics .metric strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.acct-note { font-size: .78rem; margin: .6rem 0 0; }

/* Compteur de complétude des signaux (bug 1) : reçus → retenus → base → affichés */
.signal-count { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .55rem;
  margin: .5rem 0 .2rem; font-size: .82rem; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.signal-count .sc-item strong { color: var(--fg); }
.signal-count .sc-sep { color: var(--line); font-weight: 700; }
.signal-count .sc-tf { font-size: .78rem; }
.signal-count .sc-drop { color: var(--short); border: 1px solid #7a2f2f;
  background: rgba(140,50,50,.15); border-radius: 8px; padding: 0 .45rem; font-weight: 600; }

/* Barre d'actualisation (bouton manuel + dernière maj) */
.refresh-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin: .2rem 0 1rem; }
.refresh-row form { margin: 0; }
.refresh-row .btn { padding: .4rem .8rem; font-size: .85rem; }

/* Sortie IA (markdown rendu en texte préformaté, lisible) */
.ai-out { white-space: pre-wrap; line-height: 1.5; font-size: .95rem; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 1.2rem; margin: 1rem 0; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
label { display: block; margin: .7rem 0; }
label.check { display: flex; gap: .4rem; align-items: center; }
input, select { width: 100%; padding: .5rem; margin-top: .2rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; color: var(--fg); }
label.check input { width: auto; }

button, .btn { display: inline-block; padding: .5rem .95rem; border-radius: 8px; border: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
  transition: transform var(--t), box-shadow var(--t), background var(--t), opacity var(--t); }
button:hover, .btn:hover { transform: translateY(-1px); box-shadow: var(--shadow);
  text-decoration: none; opacity: .95; }
button:active, .btn:active { transform: translateY(0); }
.btn.secondary { background: #233052; color: var(--fg); }
.btn.danger { background: var(--short); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
.actions { display: flex; gap: .8rem; margin-top: 1rem; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.row-actions .btn { padding: .35rem .7rem; font-size: .85rem; }
dl.recap { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; }
dl.recap dt { color: var(--muted); }
fieldset.accounts { border: 1px solid var(--line); border-radius: 8px; padding: .6rem 1rem 1rem; margin: 1rem 0; }
fieldset.accounts legend { color: var(--muted); font-size: .85rem; padding: 0 .4rem; }

/* ==== Formulaire d'ordre : segments/toggles (mapping 1:1 place-order), sans JS ==== */
fieldset.of { border: 1px solid var(--line); border-radius: 8px; padding: .7rem 1rem 1rem; margin: 1rem 0; }
fieldset.of legend { color: var(--muted); font-size: .8rem; padding: 0 .4rem;
  text-transform: uppercase; letter-spacing: .3px; }
.of-map { margin: .5rem 0 0; font-size: .8rem; color: var(--muted); }
.of-map code { color: var(--accent); background: rgba(56,189,248,.1); padding: 0 .3rem; border-radius: 4px; }
.of-grid { display: flex; flex-wrap: wrap; gap: .8rem; }
.of-grid label { flex: 1 1 200px; margin: 0; font-size: .85rem; color: var(--muted); }

/* Segment : radios rendus en boutons collés (natif, sans JS) */
.seg { position: relative; display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; background: var(--bg); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg label { display: inline-flex; flex-direction: column; align-items: flex-start; gap: .1rem;
  padding: .45rem .9rem; margin: 0; cursor: pointer; color: var(--muted); font-weight: 600;
  font-size: .9rem; user-select: none; border-right: 1px solid var(--line);
  transition: background var(--t), color var(--t); }
.seg label:last-of-type { border-right: none; }
.seg label:hover { color: var(--fg); background: var(--card2); }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg-sub { font-size: .68rem; font-weight: 500; opacity: .8; }

/* Sous-bloc TP (partiel + custom) — TOUJOURS visible (pas de contenu masqué sans JS) */
.of-sub { margin-top: .7rem; padding: .6rem .7rem; background: var(--bg);
  border: 1px dashed var(--line); border-radius: 8px; }
.of-sub-h { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
.of-custom { display: block; margin: .5rem 0 0; font-size: .85rem; color: var(--muted); }

/* Chips comptes (checkbox rendus en pastilles) */
.chips { position: relative; display: flex; flex-wrap: wrap; gap: .5rem; }
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .8rem; margin: 0;
  border: 1px solid var(--line); border-radius: 20px; cursor: pointer; font-size: .88rem;
  font-weight: 600; color: var(--muted); background: var(--bg);
  transition: background var(--t), color var(--t), border-color var(--t); }
.chip::before { content: "\25CB"; font-size: .9rem; }
.chip:hover { color: var(--fg); border-color: #33415a; }
.chips input:checked + .chip { color: var(--accent); border-color: var(--accent);
  background: rgba(56,189,248,.12); }
.chips input:checked + .chip::before { content: "\2713"; }
.chips input:focus-visible + .chip { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Indicateur discret « live » (point de couleur) — obj minimalisme : ne pas répéter « live » */
.live-dot-i { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--long); vertical-align: middle; margin-left: .3rem;
  box-shadow: 0 0 5px rgba(52,209,122,.7); }
.live-dot-i.estim { background: var(--muted); box-shadow: none; }

/* ---- Polish : ombres, cartes, overlay de chargement, responsive ---- */
.filters, .card { box-shadow: var(--shadow); }
.card { transition: border-color var(--t); }
.pnl-card { box-shadow: var(--shadow); transition: transform var(--t), border-color var(--t); }
.pnl-card:hover { transform: translateY(-2px); border-color: #33415a; }
.banner { animation: fadein .25s ease; }

/* Barre de progression de navigation fluide (en haut) */
#nav-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; opacity: 0;
  background: var(--accent); box-shadow: 0 0 8px var(--accent); z-index: 60;
  transition: width .4s ease, opacity .3s ease; }

/* Overlay de chargement (analyse IA) */
#loading-overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem; color: var(--fg);
  background: rgba(8,10,14,.72); backdrop-filter: blur(3px); }
#loading-overlay[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(56,189,248,.25); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Réduction des animations si l'utilisateur le demande (accessibilité) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}

/* Responsive : mobile / petits écrans */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  main { margin: 1rem auto; }
  .head-row { flex-direction: column; align-items: flex-start; gap: .3rem; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters select { min-width: 0; width: 100%; }
  /* tables défilables horizontalement sans casser la page */
  table.grid { display: block; overflow-x: auto; white-space: nowrap; }
  .pnl-cards { gap: .5rem; }
  .pnl-card { flex: 1 1 45%; min-width: 0; }
}
