:root {
  color-scheme: light;
  --page: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --grid: #e7e6e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --series-1: #2a78d6;   /* BUY / gains / solde */
  --series-2: #eb6834;   /* SELL */
  --neg: #e34948;        /* pertes (pôle du divergent) */
  --neutral: #b9b8b3;    /* BE */
  --good: #0ca30c;
  --warning: #c98500;
  --critical: #d03b3b;
  --accent-soft: #e6effb;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2c;
    --grid: #2c2c2a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --series-1: #3987e5;
    --series-2: #d95926;
    --neg: #e66767;
    --neutral: #5c5b57;
    --warning: #fab219;
    --critical: #e66767;
    --accent-soft: #1c2c42;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2c;
  --grid: #2c2c2a;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --series-1: #3987e5;
  --series-2: #d95926;
  --neg: #e66767;
  --neutral: #5c5b57;
  --warning: #fab219;
  --critical: #e66767;
  --accent-soft: #1c2c42;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
button, input, select { font: inherit; color: inherit; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--series-1);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M6 22l6-7 5 4 9-11' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
.sub { margin: 0; font-size: 12px; color: var(--text-3); }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 7px;
  color: var(--text-2); cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.ghost {
  border: 1px solid var(--border); background: transparent; border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; color: var(--text-2);
}

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- filtres ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
  margin-bottom: 8px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-3); }
.filters .check { flex-direction: row; align-items: center; gap: 6px; height: 34px; color: var(--text-2); font-size: 13px; }
.filters.inline { margin: 0; gap: 8px; flex-wrap: nowrap; }
.filters.inline select { min-width: 0; height: 30px; font-size: 13px; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-title h2 { font-size: 18px; }
.tab-sep { width: 1px; margin: 6px 4px; background: var(--border); }
.logout { display: inline-flex; align-items: center; width: auto; padding: 0 12px; text-decoration: none; font-size: 13px; }
.primary {
  height: 36px; padding: 0 18px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--series-1); color: #fff; font-weight: 600;
}
.primary:disabled { opacity: .45; cursor: default; }
.ghost-btn {
  height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 600;
}

/* ---------- connexion ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; }
.login .logo { margin: 0 auto; }
.login input { height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.login .primary { height: 40px; }
.login p { margin: 0; }

/* ---------- niveaux ---------- */
.levels-grid { align-items: start; }
.lv-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.lv-row:last-child { border-bottom: 0; }
.lv-row .lv-price { font-size: 16px; font-weight: 600; }
.lv-row .lv-zone { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 8px; }
.lv-row select { min-width: 0; height: 32px; font-size: 13px; }
.lv-del { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: transparent; cursor: pointer; color: var(--critical); font-size: 16px; }
.lv-add { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.lv-add input { flex: 1 1 160px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.lv-add select { min-width: 0; }
.lv-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; }
.ladder { position: relative; }
.ladder-row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; align-items: center; height: 30px; font-size: 13px; }
.ladder-row .bar { height: 8px; border-radius: 4px; background: var(--surface-2); }
.ladder-row.price { color: var(--series-1); font-weight: 700; }
.ladder-row.price .bar { background: var(--series-1); height: 2px; }
.ladder-row .dist { color: var(--text-3); font-size: 12px; }

/* ---------- pause ---------- */
.pause-box { display: inline-flex; align-items: center; gap: 6px; }
.pause-box select { min-width: 0; height: 32px; font-size: 13px; }
.pause-box .ghost-btn { height: 32px; }

/* ---------- journal ---------- */
.journal-card { margin-top: 8px; }
.journal { max-height: 340px; overflow-y: auto; }
.jrow { display: grid; grid-template-columns: 96px auto 1fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.jrow:last-child { border-bottom: 0; }
.jtime { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.jmsg { min-width: 0; }

/* ---------- notes & export ---------- */
td.note { cursor: text; min-width: 160px; max-width: 280px; white-space: normal; color: var(--text-2); }
td.note:hover { background: var(--surface-2); }
.note-input { width: 100%; height: 28px; padding: 0 8px; border: 1px solid var(--series-1); border-radius: 6px; background: var(--surface); }
.export-btn { margin-left: auto; }

/* ---------- calendrier ---------- */
.card > header select { min-width: 0; height: 30px; font-size: 13px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head { font-size: 11px; color: var(--text-3); text-align: center; padding-bottom: 2px; }
.cal-day { min-height: 54px; border-radius: 6px; padding: 5px 6px; display: flex; flex-direction: column; justify-content: space-between; cursor: default; }
.cal-day.empty-day { background: var(--surface-2); opacity: .55; }
.cal-n { font-size: 11px; color: var(--text-2); }
.cal-v { font-size: 13px; font-weight: 600; text-align: right; color: var(--text); }

.empty-block { text-align: center; padding: 48px 24px; color: var(--text-2); }
.empty-block h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
select, input[type=number] {
  height: 34px; padding: 0 10px; min-width: 120px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input[type=number] { width: 110px; min-width: 0; }
.suffix { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.suffix input { width: 72px; }
.note { margin: 4px 0 20px; color: var(--text-3); font-size: 12px; min-height: 1em; }

/* ---------- cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--text-3); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.wide { grid-column: 1 / -1; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--text-3); }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.kpi .detail { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ---------- graphiques ---------- */
.chart { position: relative; width: 100%; height: 280px; }
.chart.small { height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis text { fill: var(--text-3); font-size: 11px; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--text-3); stroke-width: 1; }
.refline { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 4; }
.reflabel { fill: var(--text-2); font-size: 11px; }
.crosshair { stroke: var(--text-3); stroke-width: 1; }
.empty { display: grid; place-items: center; height: 100%; color: var(--text-3); font-size: 13px; text-align: center; padding: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.dirrow { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; margin-bottom: 14px; }
.dirrow .name { font-weight: 600; }
.stack { display: flex; gap: 2px; height: 22px; }
.stack > div { border-radius: 4px; min-width: 2px; cursor: default; }
.dirmeta { grid-column: 2; font-size: 12px; color: var(--text-2); margin-top: -6px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  max-width: 260px;
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .muted { color: var(--text-3); }

/* ---------- tableaux ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.pos { color: var(--good); }
.negtxt { color: var(--critical); }

/* ---------- en direct ---------- */
.bot { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.bot-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bot-head h2 { font-size: 20px; }
.status {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: 13px;
}
.status .ico { font-size: 14px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); letter-spacing: .04em; }
.updated { margin-left: auto; font-size: 12px; color: var(--text-3); }
.big { font-size: 28px; font-weight: 600; }
.rows { display: grid; gap: 8px; }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.row span:first-child { color: var(--text-3); }
.progress { position: relative; height: 10px; background: var(--surface-2); border-radius: 999px; margin: 12px 0 6px; overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--series-1); }
.zones { display: flex; flex-wrap: wrap; gap: 6px; }
.zone { padding: 4px 10px; border-radius: 8px; font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.zone i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.empty-live { text-align: center; padding: 56px 24px; }
.empty-live h2 { font-size: 18px; margin-bottom: 8px; }
.empty-live p { color: var(--text-2); max-width: 520px; margin: 6px auto; }
.empty-live ol { text-align: left; display: inline-block; color: var(--text-2); margin-top: 12px; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .bot { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .tabs { margin-left: 0; order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tab { flex: 1 0 auto; white-space: nowrap; padding: 6px 10px; }
  .tab-sep { display: none; }
  .lv-row .lv-zone { display: block; margin-left: 0; }
  .jrow { grid-template-columns: 80px 1fr; }
  .jrow .badge { display: none; }
  .cal-day { min-height: 44px; padding: 3px 4px; }
  .cal-v { font-size: 11px; }
  .export-btn { margin-left: 0; }
  #themeBtn { margin-left: auto; }
  main { padding: 16px; }
}
