:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --up: #006300;
  --down: #d03b3b;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --up: #0ca30c; --down: #e66767; --accent: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --up: #0ca30c; --down: #e66767; --accent: #3987e5;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: .95rem; margin: 0 0 8px; font-weight: 600; }
p { margin: 0 0 10px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }
.hidden { display: none !important; }
.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 10px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 5px; right: 5px; bottom: 6px; height: 9px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: skewY(-25deg); }
.nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--text-2); padding: 7px 10px; border-radius: 8px; font-size: .9rem; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.menu-toggle { display: none; }

/* ---------- boutons & formulaires ---------- */
.btn {
  font: inherit; font-size: .9rem; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--down); }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn.icon { padding: 6px 10px; font-size: 1rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, svg:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; border: 0; background: var(--surface); color: var(--text-2); padding: 6px 11px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.hint { font-size: .8rem; color: var(--muted); }

/* ---------- mise en page ---------- */
.view { max-width: 1320px; margin: 0 auto; padding: 22px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-width: 160px; padding: 6px 10px; font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }
.view > .card ~ .card, .view > .grid ~ .card, .view > .card ~ .grid, .view > .grid ~ .grid { margin-top: 16px; }
.mt { margin-top: 16px; }
.m0 { margin: 0 !important; }
.center { justify-content: center; }
.row-flex { display: flex; gap: 8px; }
.row-flex select { flex: 1; min-width: 0; }
.section-title { margin: 24px 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

/* tuiles chiffres */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: .8rem; color: var(--text-2); margin-bottom: 4px; }
.tile .v { font-size: 1.45rem; font-weight: 650; letter-spacing: -.01em; }
.tile .s { font-size: .85rem; margin-top: 2px; color: var(--text-2); }
.tile.hero .v { font-size: 1.9rem; }

/* tableaux */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: .8rem; padding: 8px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td { padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--axis); }
.t-name { font-weight: 600; }
.t-sub { font-size: .78rem; color: var(--muted); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.pea { color: var(--series-1); }
.badge.cto { color: var(--series-2); }
.actions { white-space: nowrap; text-align: right; }

/* avis */
.verdict { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: .85rem; padding: 3px 10px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.verdict.buy { color: var(--up); }
.verdict.sell { color: var(--down); }
.verdict.hold { color: var(--text-2); }
.signals { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.signal-card h3 { margin: 0; font-size: 1rem; }
.signal-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.reasons { list-style: none; padding: 0; margin: 10px 0 0; font-size: .87rem; }
.reasons li { display: grid; grid-template-columns: 36px 1fr; gap: 8px; padding: 5px 0; border-top: 1px solid var(--grid); }
.reasons .pts { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px 14px; font-size: .85rem; }
.kv div span { display: block; color: var(--muted); font-size: .75rem; }
.kv div b { font-weight: 600; font-variant-numeric: tabular-nums; }
.gauge { margin: 6px 0 2px; }
.disclaimer { font-size: .82rem; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; border: 1px solid var(--border); }

/* graphiques */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.thin { stroke-width: 1.5; }
.chart .area { stroke: none; opacity: .10; }
.s1 { stroke: var(--series-1); }
.s2 { stroke: var(--series-2); }
.s3 { stroke: var(--series-3); }
.fill-s1 { fill: var(--series-1); }
.fill-s2 { fill: var(--series-2); }
.fill-s3 { fill: var(--series-3); }
.chart .xh { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .mk { stroke: var(--surface); stroke-width: 2; }
.chart .mk.buy { fill: var(--up); }
.chart .mk.sell { fill: var(--down); }
.chart .mk-label { font-size: 9px; font-weight: 700; fill: #fff; pointer-events: none; }
.chart .bar { fill: var(--series-1); }
.chart .bar-label { fill: var(--text); font-size: 12px; }
.chart .bar-value { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .neutral { fill: var(--grid); }
.chart .gauge-pos { fill: var(--up); }
.chart .gauge-neg { fill: var(--down); }
.chart .gauge-tick { stroke: var(--text-2); stroke-width: 2; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.legend i.s1 { border-color: var(--series-1); }
.legend i.s2 { border-color: var(--series-2); }
.legend i.s3 { border-color: var(--series-3); }
.legend i.dot-buy, .legend i.dot-sell { width: 9px; height: 9px; border: 0; border-radius: 50%; }
.legend i.dot-buy { background: var(--up); }
.legend i.dot-sell { background: var(--down); }
.tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  white-space: nowrap; transform: translate(-50%, -100%); margin-top: -10px;
}
.tip b { display: block; margin-bottom: 3px; font-weight: 600; }
.tip .row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.tip .row i { width: 10px; border-top: 2px solid; display: inline-block; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty h2 { color: var(--text); }
.loading { opacity: .55; transition: opacity .2s; }
.skeleton { color: var(--muted); padding: 30px; text-align: center; }

/* progression (plafond PEA) */
.meter { height: 8px; background: var(--grid); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.meter > div { height: 100%; background: var(--series-1); border-radius: 99px; }

/* fenêtre modale */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#modal-body { padding: 20px 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.results { list-style: none; margin: 10px 0 0; padding: 0; max-height: 340px; overflow: auto; }
.results li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--grid); }
.preview { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: .9rem; margin-top: 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; }
#toast div { background: var(--text); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: .9rem; margin-top: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--down); color: #fff; }

/* connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 18px; }
.login-card h1 { margin-bottom: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card form + form { margin-top: 8px; }
.alert { background: var(--surface-2); border-left: 3px solid var(--down); padding: 9px 12px; border-radius: 6px; font-size: .9rem; }

@media (max-width: 1100px) {
  .grid.side, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .menu-toggle { display: inline-block; margin-left: auto; }
  .nav { display: none; order: 3; width: 100%; flex-direction: column; }
  .nav.open { display: flex; }
  .top-actions { order: 2; }
  .top-actions form, #btn-theme { display: none; }
  .nav.open ~ .top-actions form { display: inline; }
  .grid.two { grid-template-columns: 1fr; }
  .view { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .signals { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media print {
  .topbar, .filters, .btn { display: none !important; }
  .card, .tile { box-shadow: none; }
}
