:root {
  --bg: #0e0f0c;
  --surface: #161712;
  --surface-2: #1d1e19;
  --line: #2a2b24;
  --line-2: #3a3b33;
  --text: #ecebe4;
  --muted: #8f8d81;
  --faint: #5f5e55;
  --gold: #d9a441;
  --gold-ink: #1a1405;
  --gold-soft: rgba(217, 164, 65, .12);
  --up: #63b57d;
  --up-soft: rgba(99, 181, 125, .13);
  --down: #e0675b;
  --down-soft: rgba(224, 103, 91, .13);
  --warn: #e3b450;
  --radius: 14px;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
.num, .mono { font-family: var(--mono); font-feature-settings: "tnum"; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.up { color: var(--up); }
.down { color: var(--down); }
.gold { color: var(--gold); }
.err { color: var(--down); font-size: 14px; margin: 0; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Écran de connexion ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: 100%; max-width: 380px; display: grid; gap: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
}
.gate-card h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.gate-card p { margin: 0; font-size: 14px; }
.gate-mark {
  width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--gold); color: var(--gold);
  display: grid; place-items: center; font: 700 20px Georgia, serif;
}

/* ---------- Structure ---------- */
.shell { max-width: 1080px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 88px); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(14, 15, 12, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
}
.topbar-in { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; border: 0; background: none; padding: 0; cursor: pointer; text-align: left; min-width: 0; }
.brand small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; border: 1.5px solid var(--gold); color: var(--gold);
  display: grid; place-items: center; font: 700 13px Georgia, serif;
}
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; line-height: 1.1; }
.topbar .spacer { flex: 1; }
.tabs-top { display: none; gap: 4px; }
.tab-btn {
  border: 0; background: none; padding: 8px 12px; border-radius: 10px; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-weight: 500;
}
.tab-btn[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.tab-btn svg { width: 20px; height: 20px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(14, 15, 12, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b));
}
.bottomnav .tab-btn { flex-direction: column; gap: 3px; font-size: 11px; justify-content: center; border-radius: 0; }
.bottomnav .tab-btn[aria-current="page"] { background: none; color: var(--gold); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 31;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--gold); color: var(--gold-ink); display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.fab svg { width: 26px; height: 26px; }

@media (min-width: 820px) {
  .tabs-top { display: flex; }
  .bottomnav { display: none; }
  .fab { bottom: 28px; right: max(28px, calc((100vw - 1080px) / 2 - 80px)); }
  .shell { padding-bottom: 120px; }
}

/* ---------- Titres & sections ---------- */
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 22px 0 14px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; font-weight: 600; }
.view-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 26px 0 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: center;
}

/* ---------- Cartes & métriques ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: 1fr; }
.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.metric .lbl { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.metric .val { font: 600 24px/1.15 var(--mono); margin-top: 6px; letter-spacing: -.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.metric.hero { grid-column: 1 / -1; padding: 18px; }
.metric.hero .val { font-size: 34px; }
.metric.alert { border-color: rgba(224, 103, 91, .5); background: linear-gradient(0deg, var(--down-soft), var(--down-soft)), var(--surface); }
.metric.warn { border-color: rgba(227, 180, 80, .45); }

.pips { display: flex; gap: 5px; margin-top: 10px; }
.pip { height: 6px; flex: 1; border-radius: 3px; background: var(--line-2); }
.pip.on { background: var(--gold); }
.pip.loss { background: var(--down); }
.pip.win { background: var(--up); }

.bar { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; margin-top: 10px; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--gold); border-radius: 3px; }
.bar > i.neg { background: var(--down); }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.compare > div { padding: 2px 14px; }
.compare > div + div { border-left: 1px solid var(--line); }
.compare h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 3px 0; }
.kv span:last-child { font-family: var(--mono); }

.chart { width: 100%; height: 180px; display: block; }
.chart text { font: 10.5px var(--mono); fill: var(--faint); }

.callout {
  border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 18px; color: var(--muted);
  text-align: center; font-size: 14px;
}

/* ---------- Liste de trades ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.list { display: grid; gap: 8px; }
.trade {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; text-align: left; width: 100%;
}
.trade:hover { border-color: var(--line-2); }
.dir {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font: 600 11px var(--mono); letter-spacing: .02em;
}
.dir.long { background: var(--up-soft); color: var(--up); }
.dir.short { background: var(--down-soft); color: var(--down); }
.trade .t1 { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trade .t2 { font-size: 13px; color: var(--muted); margin-top: 2px; }
.trade .res { text-align: right; }
.trade .res .r { font: 600 16px var(--mono); }
.trade .res .e { font: 12.5px var(--mono); color: var(--muted); }
.badge {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line-2);
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.badge.pending { color: var(--warn); border-color: rgba(227, 180, 80, .4); }
.badge.open { color: var(--gold); border-color: rgba(217, 164, 65, .45); background: var(--gold-soft); }
.badge.cancelled { color: var(--faint); }
.badge.ok { color: var(--up); border-color: rgba(99, 181, 125, .4); }
.badge.ko { color: var(--down); border-color: rgba(224, 103, 91, .4); }
.trade-actions { grid-column: 1 / -1; display: flex; gap: 8px; }

/* ---------- Notes ---------- */
.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.note-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note .thumbs { margin-top: 10px; }
.composer { display: grid; gap: 10px; }

/* ---------- Formulaires ---------- */
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; color: var(--text); outline: none; min-width: 0;
}
input[type=number], .num-in { font-family: var(--mono); }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
input[type=datetime-local] { min-height: 46px; }
.row { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row3 { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 380px) { .row3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field-note { font-size: 12.5px; color: var(--muted); }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 9px 6px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 40%; }
.seg.dirseg button[data-v="long"][aria-pressed="true"] { background: var(--up-soft); color: var(--up); box-shadow: inset 0 0 0 1px rgba(99,181,125,.4); }
.seg.dirseg button[data-v="short"][aria-pressed="true"] { background: var(--down-soft); color: var(--down); box-shadow: inset 0 0 0 1px rgba(224,103,91,.4); }

.scale { display: flex; gap: 6px; }
.scale button {
  flex: 1; height: 40px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg);
  color: var(--muted); font: 600 15px var(--mono); cursor: pointer;
}
.scale button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-ink); background: var(--gold); }
.scale-legend { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--faint); margin-top: 4px; }

.checks { display: grid; gap: 6px; }
.check {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--bg); cursor: pointer; color: var(--text); font-weight: 500; font-size: 14.5px;
  text-align: left; width: 100%;
}
.check .box {
  width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--line-2); flex: none;
  display: grid; place-items: center;
}
.check[aria-pressed="true"] { border-color: rgba(99,181,125,.45); }
.check[aria-pressed="true"] .box { background: var(--up); border-color: var(--up); color: var(--bg); }
.check .box svg { width: 14px; height: 14px; opacity: 0; }
.check[aria-pressed="true"] .box svg { opacity: 1; }

.calc-strip {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; background: var(--bg);
}
.calc-strip > div { padding: 10px 12px; }
.calc-strip > div + div { border-left: 1px solid var(--line); }
.calc-strip .lbl { font-size: 11.5px; color: var(--muted); }
.calc-strip .val { font: 600 15px var(--mono); margin-top: 2px; white-space: nowrap; }

.ta-wrap { position: relative; }
.mic {
  position: absolute; right: 8px; bottom: 8px; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.mic svg { width: 18px; height: 18px; }
.mic.rec { background: var(--down); border-color: var(--down); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--down-soft); } }
.ta-wrap textarea { padding-right: 52px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 92px; height: 66px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line-2); cursor: zoom-in; background: var(--bg); padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 6px; border: 0;
  background: rgba(0,0,0,.7); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 14px; line-height: 1;
}
.add-shot {
  width: 92px; height: 66px; border-radius: 9px; border: 1px dashed var(--line-2); background: none;
  color: var(--muted); display: grid; place-items: center; cursor: pointer; font-size: 12px; text-align: center; padding: 4px;
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--surface-2);
  cursor: pointer; font-weight: 600; font-size: 14.5px; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.ghost { background: none; }
.btn.danger { color: var(--down); background: none; border-color: rgba(224,103,91,.35); }
.btn.small { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn.wide { width: 100%; }
.btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--line); background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 19px; height: 19px; }

.quick-exit { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.quick-exit button { padding: 9px 4px; font-size: 13px; }
.quick-exit button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }

/* ---------- Feuille modale ---------- */
.sheet-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 94dvh; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column; animation: up .2s ease-out;
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 17px; flex: 1; }
.sheet-body { overflow-y: auto; padding: 16px; display: grid; gap: 16px; overscroll-behavior: contain; }
.sheet-foot {
  display: flex; gap: 8px; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line);
  background: var(--surface);
}
.sheet-foot .btn.primary { flex: 1; }
.sheet.small { max-width: 420px; }
.block { display: grid; gap: 10px; }
.block-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.divider { height: 1px; background: var(--line); margin: 2px 0; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; list-style: none; padding: 4px 0; }
details.more > summary::before { content: "+ "; color: var(--gold); }
details.more[open] > summary::before { content: "− "; }
details.more > .block { margin-top: 12px; }
@media (min-width: 680px) {
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88dvh; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

.menu { display: grid; gap: 8px; }
.menu button {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--bg); cursor: pointer;
}
.menu button svg { width: 22px; height: 22px; color: var(--gold); flex: none; }
.menu button b { display: block; font-size: 15px; }
.menu button span { font-size: 13px; color: var(--muted); }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 70;
  bottom: calc(var(--nav-h) + var(--safe-b) + 90px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: up .2s ease-out; max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--down); color: #fff; }

.rule-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.settings-grid { display: grid; gap: 12px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
