:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-2: #EAEEF4;
  --ink: #14213D;
  --ink-2: #4A5878;
  --ink-3: #8592AD;
  --line: #DCE2EC;
  --brand: #2347D6;
  --brand-ink: #FFFFFF;
  --brand-soft: #E3E9FD;
  --up: #0B8A63;
  --up-soft: #DDF3EB;
  --down: #D2433A;
  --down-soft: #FBE4E2;
  --paper: #B7791F;
  --paper-soft: #FBEFD9;
  --radius-l: 18px;
  --radius-m: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 24px -12px rgba(20, 33, 61, .12);
  --sans: 'Schibsted Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  --nav-w: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1729; --surface: #16203A; --surface-2: #1D2946; --ink: #E8EDF8; --ink-2: #A8B4CF; --ink-3: #6E7C9C;
    --line: #26334F; --brand: #6E8CFF; --brand-ink: #0F1729; --brand-soft: #22305A;
    --up: #3CCB98; --up-soft: #133A33; --down: #FF7A6E; --down-soft: #46242A; --paper: #F0B95A; --paper-soft: #3A2E1A;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 28px -16px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .7em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
.up { color: var(--up); } .down { color: var(--down); }
.hidden { display: none !important; }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 17px; }
.brand svg { flex: none; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav .badge { margin-left: auto; background: var(--brand); color: var(--brand-ink); border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav-foot { margin-top: auto; padding: 12px; font-size: 13px; color: var(--ink-3); }
.nav-foot button { margin-top: 6px; }
main { padding: 26px clamp(16px, 3vw, 40px) 80px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); gap: 0;
  }
  .brand, .nav-foot, .nav .label-long { display: none; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav .badge { position: absolute; margin: -4px 0 0 18px; }
  main { padding-bottom: 100px; }
  h1 { font-size: 22px; }
}

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-hero { grid-template-columns: minmax(280px, 5fr) 7fr; }
@media (max-width: 1050px) { .g-2, .g-hero { grid-template-columns: 1fr; } }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border-radius: 10px; padding: 9px 15px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 35%, var(--line)); }
.btn.danger:hover { background: var(--down-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }
.spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.pill.paper { background: var(--paper-soft); color: var(--paper); }
.pill.live { background: var(--down-soft); color: var(--down); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; border: 0; background: transparent; color: var(--ink-2); padding: 5px 11px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12.5px; padding: 0 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -10px; }
.sym { font-weight: 650; }
.sym small { color: var(--ink-3); font-weight: 500; margin-left: 4px; }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-size: 15px; }

/* ---------- Bandeau d'état ---------- */
.statusbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px 12px 18px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
}
.statusbar .grow { flex: 1; min-width: 180px; color: var(--ink-2); font-size: 14px; }
.statusbar .grow b { color: var(--ink); font-weight: 600; }
.banner { border-radius: var(--radius-m); padding: 12px 16px; margin-bottom: 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: var(--paper-soft); color: var(--ink); }
.banner.bad { background: var(--down-soft); color: var(--ink); }
.banner.info { background: var(--brand-soft); color: var(--ink); }
.banner a { font-weight: 600; }

/* ---------- Héros : valeur + voix du bot ---------- */
.value-card { display: flex; flex-direction: column; gap: 18px; }
.value-big { font-size: clamp(34px, 5vw, 46px); font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.value-big .cur { font-size: .42em; font-weight: 600; color: var(--ink-3); margin-left: 6px; letter-spacing: 0; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.kpi .k { font-size: 13px; color: var(--ink-3); }
.kpi .v { font-size: 17px; font-weight: 650; }
.alloc { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; }
.alloc span { display: block; height: 100%; }

.voice { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 24px 26px 20px; display: flex; flex-direction: column; }
.voice-label { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-2); margin-bottom: 12px; }
.voice-avatar { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; flex: none; }
.voice blockquote {
  margin: 0; font-family: var(--serif); font-size: clamp(18px, 1.8vw, 21px); line-height: 1.5; color: var(--ink);
  font-weight: 400; max-width: 68ch; display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden;
}
.voice.open blockquote { -webkit-line-clamp: unset; }
.voice-foot { margin-top: auto; padding-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.order-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); }
.order-chip b { font-weight: 650; }
.order-chip.ok.buy b { color: var(--up); }
.order-chip.ok.sell b { color: var(--down); }
.order-chip.ko { opacity: .7; text-decoration: line-through; }

/* ---------- Graphique ---------- */
.chart { position: relative; height: 260px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -120%); }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--ink-3); text-align: center; font-size: 14px; }

/* ---------- Comptes rendus + chat ---------- */
.reports { display: grid; grid-template-columns: 230px 1fr; gap: 18px; align-items: start; }
@media (max-width: 1050px) { .reports { grid-template-columns: 1fr; } }
.day-list { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow: auto; }
@media (max-width: 1050px) { .day-list { flex-direction: row; overflow-x: auto; max-height: none; padding-bottom: 4px; } }
.day-item { text-align: left; font: inherit; cursor: pointer; border: 1px solid transparent; background: transparent; border-radius: 10px; padding: 9px 12px; display: flex; justify-content: space-between; gap: 12px; color: var(--ink); white-space: nowrap; }
.day-item:hover { background: var(--surface-2); }
.day-item.on { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.report-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
@media (max-width: 1250px) { .report-layout { grid-template-columns: 1fr; } }
.prose { font-family: var(--serif); font-size: 17px; line-height: 1.6; max-width: 70ch; }
.prose h2 { font-family: var(--sans); font-size: 16px; margin: 1.5em 0 .5em; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-family: var(--sans); font-size: 15px; margin: 1.2em 0 .4em; }
.prose ul, .prose ol { padding-left: 1.2em; margin: 0 0 .8em; }
.prose li { margin-bottom: .3em; }
.prose code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, monospace; }
.prose strong { font-weight: 600; }
.chat { display: flex; flex-direction: column; height: min(78vh, 760px); position: sticky; top: 20px; padding: 0; overflow: hidden; }
.chat-head { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.assistant ul { padding-left: 1.1em; margin: .3em 0; }
.msg p:last-child { margin-bottom: 0; }
.msg code { font-size: .85em; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chat-suggest button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 5px 11px; cursor: pointer; }
.chat-suggest button:hover { color: var(--ink); border-color: var(--ink-3); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; min-height: 42px; max-height: 140px; }
.proposal { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.proposal + .proposal { margin-top: 8px; }

/* ---------- Formulaires ---------- */
input, select, textarea {
  font: inherit; font-size: 14.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 90px; line-height: 1.45; }
label.field { display: flex; flex-direction: column; gap: 6px; }
label.field > span:first-child { font-weight: 600; font-size: 14px; }
.help { font-size: 13px; color: var(--ink-3); line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px 20px; }
.input-unit { position: relative; }
.input-unit input { padding-right: 52px; }
.input-unit em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--ink-3); font-size: 13px; }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.switch input { appearance: none; width: 40px; height: 24px; flex: none; border-radius: 99px; background: var(--line); position: relative; padding: 0; border: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(16px); }
.switch b { display: block; font-weight: 600; font-size: 14px; }
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 7px 12px; border-radius: 8px; color: var(--ink-2); font-size: 14px; }
.settings-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
@media (max-width: 900px) { .settings-layout { grid-template-columns: 1fr; } .settings-nav { display: none; } }
.section { scroll-margin-top: 20px; }
.section + .section { margin-top: 18px; }
.section > p.muted { margin: -6px 0 18px; max-width: 70ch; }
.section-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; align-items: center; }
.times { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.time-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--brand-soft); color: var(--brand); border-radius: 9px; padding: 4px 4px 4px 11px; font-weight: 650; }
.time-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.time-chip button:hover { background: color-mix(in srgb, var(--brand) 15%, transparent); }
.times input[type=time] { width: auto; padding: 5px 8px; }
.source-row { display: grid; grid-template-columns: auto 1fr 120px auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.source-row .src-url { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .source-row { grid-template-columns: auto 1fr auto; } .source-row select, .source-row .src-test { display: none; } }
.lesson { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lesson p { flex: 1; margin: 0; }

/* ---------- Dialogues ---------- */
dialog { border: 0; border-radius: var(--radius-l); padding: 0; background: var(--surface); color: var(--ink); width: min(480px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); }
dialog::backdrop { background: rgba(15, 23, 41, .45); backdrop-filter: blur(3px); }
.dlg-body { padding: 22px 24px 8px; }
.dlg-body p { color: var(--ink-2); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px 20px; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.login .brand { padding: 0 0 8px; justify-content: center; font-size: 20px; }

/* ---------- Divers ---------- */
#toasts { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 900px) { #toasts { bottom: 86px; left: 12px; right: 12px; } }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); max-width: 420px; animation: tin .2s ease-out; }
.toast.bad { background: var(--down); color: #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.meter { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.meter.warn span { background: var(--paper); } .meter.bad span { background: var(--down); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div:hover { opacity: 1; }
.news-item { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; }
.news-item:last-child { border-bottom: 0; }
.news-item a { color: var(--ink); font-weight: 550; }
.news-item .when { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.cycle { padding: 16px 0; border-bottom: 1px solid var(--line); }
.cycle:last-child { border-bottom: 0; }
.cycle-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.cycle .view { font-family: var(--serif); font-size: 16.5px; line-height: 1.55; max-width: 75ch; }
.details-toggle { font: inherit; font-size: 13px; color: var(--brand); background: none; border: 0; padding: 0; cursor: pointer; font-weight: 600; }
.log-line { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.log-line.warn { color: var(--paper); } .log-line.error { color: var(--down); }
.stack > * + * { margin-top: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
