:root {
  --bg: #0B0D10;
  --card: #16191E;
  --card-top: #1B1F25;
  --card-raised: #20242B;
  --line: rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.11);
  --text: #F2F4F7;
  --muted: #8C949F;
  --faint: #5A616B;
  --up: #A9C9B5;
  --down: #D4A9A9;
  --green: #22B567;
  --yellow: #F2C233;
  --red: #E0352F;
  --on-state: #0B0D10;
  --radius: 20px;
  --radius-sm: 12px;
  --gutter: 16px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: linear-gradient(var(--bg) 70%, rgba(11, 13, 16, 0));
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px; flex: none;
  background:
    linear-gradient(135deg, transparent 46%, var(--bg) 46% 54%, transparent 54%),
    var(--text);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.freshness {
  display: flex; align-items: center; gap: 6px;
  font: 12px var(--mono); color: var(--muted); white-space: nowrap;
}
.freshness .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.freshness.is-stale { color: var(--yellow); }
.freshness.is-stale .dot { background: var(--yellow); }

/* ---------- Vue ---------- */
.view {
  display: flex; flex-direction: column; gap: 12px;
  padding: 4px var(--gutter) calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto; outline: none;
}
.view.has-composer { padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }
.screen-title {
  margin: 6px 2px 2px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
}

/* ---------- Cartes ---------- */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--card-top), var(--card) 60%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.card-head.dark { background: #0F1114; border-bottom: 0; }
.label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text);
}
.meta { font: 12px var(--mono); color: var(--muted); }
.card-body { padding: 16px 18px 18px; }
.sub { color: var(--muted); font-size: 13px; }

/* ---------- Bandeau d'état ---------- */
.status-body {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 18px 18px; color: var(--on-state);
}
.status-title { font-size: 27px; line-height: 1.05; font-weight: 900; letter-spacing: -0.015em; text-transform: uppercase; }
.status-detail { margin-top: 5px; font-size: 13.5px; font-weight: 600; opacity: 0.82; }
.status-icon { width: 38px; height: 38px; flex: none; }
.status-icon * { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.state-signal .status-body { background: var(--green); }
.state-closed .status-body { background: var(--yellow); }
.state-fault  .status-body { background: var(--red); color: #fff; }
.state-idle   .status-body { background: var(--card-raised); color: var(--text); }
.state-idle .status-detail { color: var(--muted); opacity: 1; }

/* ---------- Portefeuille ---------- */
.hero-value { font: 700 40px/1 var(--mono); letter-spacing: -0.04em; }
.hero-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 8px; }
.pnl { font: 600 15px var(--mono); }
.pos { color: var(--up); }
.neg { color: var(--down); }
.rank { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.rank li {
  display: grid; grid-template-columns: 22px 1fr auto auto; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.rank li:last-child { border-bottom: 0; padding-bottom: 0; }
.rank .pos-n { font: 13px var(--mono); color: var(--faint); }
.rank .tick { font-weight: 800; letter-spacing: 0.02em; }
.rank .tick small { display: block; font: 12px var(--mono); color: var(--muted); font-weight: 400; letter-spacing: 0; }
.rank .r { text-align: right; font: 14px var(--mono); }
.rank .r small { display: block; font-size: 12px; color: var(--muted); }

/* ---------- Comptes a rebours ---------- */
.countdowns { display: grid; grid-template-columns: 1fr 1fr; }
.countdown { padding: 15px 18px 17px; }
.countdown + .countdown { border-left: 1px solid var(--line); }
.countdown .sub { font-size: 12px; }
.clock { margin-top: 6px; font: 700 22px/1.1 var(--mono); letter-spacing: -0.03em; }
.clock .u { font-size: 13px; color: var(--muted); font-weight: 500; margin: 0 3px 0 1px; }
.countdown .when { margin-top: 4px; font: 12px var(--mono); color: var(--muted); }

/* ---------- Filet du 25 ---------- */
.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; margin: 2px 0 14px; }
.split span { display: block; }
.sw-0 { background: #E9ECEF; } .sw-1 { background: #9AA2AC; } .sw-2 { background: #5A616B; }
.alloc { list-style: none; margin: 0; padding: 0; }
.alloc li { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 0; }
.alloc .sw { width: 10px; height: 10px; border-radius: 3px; }
.alloc .tick { font-weight: 800; }
.alloc .tick small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.alloc .share { font: 14px var(--mono); color: var(--muted); }
.alloc .amt { font: 600 14px var(--mono); min-width: 74px; text-align: right; }

/* ---------- Reel vs paper ---------- */
.versus { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; padding: 18px 18px 20px; }
.versus .side .label { color: var(--muted); }
.versus .side .num { display: block; margin-top: 4px; font-size: 17px; font-weight: 600; white-space: nowrap; }
.versus .side.right { text-align: right; }
.versus .center { text-align: center; }
.versus .center .sub { font-size: 12px; }
.versus .gap { display: block; font: 800 30px/1 var(--mono); letter-spacing: -0.04em; margin-top: 4px; white-space: nowrap; }

/* ---------- Moteur ---------- */
.gauge { position: relative; height: 8px; margin: 16px 0 6px; border-radius: 4px;
  background: linear-gradient(90deg, #3A4048, #2A2F36 55%, #22262C 55%, #22262C); }
.gauge .ceiling { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--muted); }
.gauge .needle { position: absolute; top: -6px; width: 4px; height: 20px; margin-left: -2px; border-radius: 2px; background: var(--text); }
.gauge-scale { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--faint); }
.big-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.big-num { font: 800 44px/1 var(--mono); letter-spacing: -0.04em; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}
.chip.yellow { background: var(--yellow); color: var(--on-state); }
.chip.green { background: var(--green); color: var(--on-state); }
.chip.red { background: var(--red); color: #fff; }
.chip.quiet { background: var(--card-raised); color: var(--muted); }
.kv { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv li:last-child { border-bottom: 0; padding-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); text-align: right; white-space: nowrap; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scan { padding: 14px 16px 16px; }
.scan .clock { font-size: 24px; }
.scan .state { margin-top: 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.scan .state i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.scan.failed .state { color: var(--text); }
.scan.failed .state i { background: var(--red); }

.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 12px 6px 8px; text-align: right; vertical-align: bottom;
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.table th small { display: block; margin-top: 2px; font: 500 10.5px var(--mono); letter-spacing: 0; text-transform: none; color: var(--faint); }
.table th:first-child, .table td:first-child { text-align: left; padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table td { padding: 11px 6px; border-top: 1px solid var(--line); text-align: right; font: 14px var(--mono); white-space: nowrap; }
.table td.asset { font-family: var(--sans); font-weight: 800; letter-spacing: 0.02em; }
.table td.asset small { display: block; font-weight: 500; font-size: 11px; color: var(--faint); letter-spacing: 0; }
.mark { display: inline-block; width: 8px; height: 8px; margin-left: 7px; border-radius: 50%; vertical-align: 1px; }
.mark.ok { background: var(--text); }
.mark.no { border: 1.5px solid var(--faint); }
.table td.na { color: var(--faint); }
.table tr.is-signal td { background: rgba(34, 181, 103, 0.08); }
.table tr.is-signal td:first-child { box-shadow: inset 4px 0 0 var(--green); }
.missing { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 16px; padding: 12px 18px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.legend .mark { margin: 0 6px 0 0; }

/* ---------- News ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter) 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.filter {
  flex: none; padding: 8px 15px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: transparent; font-size: 13px; font-weight: 700; letter-spacing: 0.02em; color: var(--muted); cursor: pointer;
}
.filter[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--on-state); }
.filter:focus-visible, .tabbar a:focus-visible, .send:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.news { list-style: none; margin: 0; padding: 0; }
.news li { display: grid; grid-template-columns: 26px 1fr; gap: 6px 10px; padding: 15px 18px; border-top: 1px solid var(--line); }
.news li:first-child { border-top: 0; }
.news .n { font: 13px var(--mono); color: var(--faint); padding-top: 2px; }
.news .tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 11px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.news .tone { display: inline-flex; align-items: center; gap: 5px; }
.news .tone svg { width: 9px; height: 9px; }
.news .tone.up { color: var(--up); } .news .tone.down { color: var(--down); } .news .tone.neutral { color: var(--muted); }
.news .weight { color: var(--text); }
.news .assets { color: var(--muted); font-family: var(--mono); letter-spacing: 0; text-transform: none; font-weight: 600; }
.news .headline { grid-column: 2; font-size: 15px; line-height: 1.38; font-weight: 600; }
.news .foot { grid-column: 2; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font: 12px var(--mono); color: var(--muted); }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Chat ---------- */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 11px 14px 9px; border-radius: 18px; font-size: 15px; line-height: 1.42; white-space: pre-line; }
.msg time { display: block; margin-top: 4px; font: 11px var(--mono); color: var(--faint); }
.msg.user { align-self: flex-end; background: var(--text); color: var(--on-state); border-bottom-right-radius: 6px; }
.msg.user time { color: #5E656F; text-align: right; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.pending { color: var(--muted); font-style: italic; }
.chat-note { text-align: center; font-size: 12px; color: var(--faint); margin: 4px 0 0; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 6;
  padding: 10px var(--gutter);
  background: linear-gradient(rgba(11, 13, 16, 0), var(--bg) 30%);
}
.composer form { display: flex; align-items: flex-end; gap: 8px; max-width: 520px; margin: 0 auto; }
.composer textarea {
  flex: 1; min-height: 46px; max-height: 120px; resize: none;
  padding: 12px 16px; border-radius: 23px; border: 1px solid var(--line-strong);
  background: var(--card); outline: none;
}
.composer textarea:focus { border-color: var(--muted); }
.send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--text); color: var(--on-state); display: grid; place-items: center; cursor: pointer;
}
.send:disabled { background: var(--card-raised); color: var(--faint); cursor: default; }
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(11, 13, 16, 0.96); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-decoration: none; color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--text); }

/* ---------- Etats de chargement / erreur ---------- */
.skeleton { height: 120px; border-radius: var(--radius); background: var(--card); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.error-card .card-body { color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
@media (max-width: 350px) {
  .hero-value { font-size: 34px; }
  .status-title { font-size: 23px; }
  .countdowns { grid-template-columns: 1fr; }
  .countdown + .countdown { border-left: 0; border-top: 1px solid var(--line); }
}

.pnl-col { min-width: 58px; }
.gate-text { margin: 12px 0 0; }
.status-title.phase { font-size: 24px; }
.news li.empty { display: block; }
.net-mode { margin: 0 0 12px; }
.net-target { margin: 10px 0 0; font-size: 12px; }
