:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #14171c;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --up: #12805c;
  --down: #c8312b;
  --up-bg: #e3f5ed;
  --down-bg: #fbe9e8;
  --bench: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #2a313c;
    --accent: #4c8dff;
    --accent-text: #ffffff;
    --up: #3fb984;
    --down: #ff6b61;
    --up-bg: rgba(63, 185, 132, 0.14);
    --down-bg: rgba(255, 107, 97, 0.14);
    --bench: #f0a03c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- Structure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .updated { font-size: 12px; color: var(--muted); }
.icon-btn {
  border: 0; background: transparent; padding: 8px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

html, body { overflow-x: hidden; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(88px + var(--safe-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar a {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; color: var(--muted); font-size: 11px; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.hero .label { color: var(--muted); font-size: 13px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 6px; }
.hero .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.up { color: var(--up); }
.down { color: var(--down); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.pill.up { background: var(--up-bg); }
.pill.down { background: var(--down-bg); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Sélecteurs ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; font-size: 13px; font-weight: 500;
  color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.chart-box { position: relative; height: 170px; }
.chart-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 16px; }
.chart-box.small { height: 160px; }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; color: var(--text); width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer;
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; flex-shrink: 0; }
.row .right .title { font-weight: 600; }
.avatar {
  width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--muted);
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.alloc { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; align-items: center; }
.alloc .chart-box { height: 140px; }
@media (max-width: 380px) { .alloc { grid-template-columns: 1fr; } }

/* ---------- Formulaires ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
  min-height: 44px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.search-input { font-size: 17px; padding: 12px 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); width: 100%; min-height: 46px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--down-bg); color: var(--down); }
.btn.sm { width: auto; min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.estimate { background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: 14px; margin-bottom: 12px; }
.estimate .line { display: flex; justify-content: space-between; gap: 8px; }
.estimate .line + .line { margin-top: 4px; }
.estimate .total { font-weight: 700; font-size: 16px; }
.error { color: var(--down); font-size: 14px; margin: 8px 0; }

.lot { padding: 12px 0; }
.lot + .lot { border-top: 1px solid var(--border); }
.lot .top { display: flex; justify-content: space-between; gap: 8px; }
.lot .actions { display: flex; gap: 8px; margin-top: 10px; }

.empty { text-align: center; padding: 32px 12px; }
.empty p { color: var(--muted); }
.banner { background: var(--down-bg); color: var(--down); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }

.price-head .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- Feuille modale ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  background: var(--surface); color: var(--text); border-radius: 18px 18px 0 0;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.sheet .inner { padding: 18px 16px calc(18px + var(--safe-bottom)); }
dialog.sheet h3 { margin: 0 0 14px; font-size: 18px; }
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 18px; } }

.toast {
  position: fixed; left: 50%; bottom: calc(140px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

.skeleton { background: var(--surface-2); border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- Connexion ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.login-card h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 20px; }

/* ---------- Méthode ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 6px; }
.toc a {
  padding: 6px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text);
  font-size: 13px; font-weight: 500;
}
.toc a.on { background: var(--accent); color: var(--accent-text); }
.doc { scroll-margin-top: 70px; }
.doc h2 { font-size: 18px; }
.doc h3 { font-size: 15px; margin: 18px 0 8px; }
.doc p, .doc li { font-size: 15px; line-height: 1.5; }
.doc p { margin: 8px 0; }
.doc ul { padding-left: 20px; margin: 8px 0; }
.doc li + li { margin-top: 6px; }
.doc code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.formula {
  font-size: 14.5px; line-height: 1.6; font-weight: 500;
  background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 10px 12px; margin: 8px 0; overflow-x: auto;
}
.params { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 4px 0 12px; font-size: 14px; }
.params dt { color: var(--muted); }
.params dd { margin: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.num td + td, .tbl.num th + th { text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 12.5px; background: var(--surface-2); border-radius: 7px; padding: 4px 8px; }
.estimate a { text-decoration: none; }

/* ---------- Découvrir ---------- */
.spark { flex-shrink: 0; display: block; }
.row.top { align-items: flex-start; }
.row .why { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.row.top .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* ---------- Comparaison avec un indice ---------- */
.bench-select { min-height: 40px; padding: 8px 32px 8px 12px; font-weight: 600;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.bench-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.verdict { margin: 12px 0; font-size: 15px; }

/* ---------- Fiche action ---------- */
.stock-id { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.stock-id h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.avatar.lg { width: 46px; height: 46px; border-radius: 12px; font-size: 14px; }
.stock-head .big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.change-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.minmax { margin-top: 10px; }
.sub-h { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 16px 0 0; }
.btn.ghost { background: transparent; color: var(--muted); }
main.has-action { padding-bottom: calc(150px + var(--safe-bottom)); }
.action-bar {
  position: fixed; left: 0; right: 0; z-index: 9; bottom: calc(57px + var(--safe-bottom));
  padding: 10px 16px; display: flex; justify-content: center;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.action-bar .btn { max-width: 688px; box-shadow: 0 4px 14px rgba(31, 111, 235, .3); }

/* ---------- Feuille d'achat guidée ---------- */
dialog.sheet { max-height: 92vh; overflow-y: auto; }
.step { margin-bottom: 16px; }
.step-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.step-n {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
}
.step .seg { margin-bottom: 8px; }
.big-input { font-size: 22px; font-weight: 600; padding: 12px 14px; }
.chips.quick { margin-top: 8px; }
.chips.quick .chip { border: 0; cursor: pointer; font-size: 14px; font-weight: 600; padding: 7px 12px; color: var(--text); }
.chips.quick .chip:active { background: var(--accent); color: var(--accent-text); }
.step input[type="date"] { margin-top: 2px; }
.seg-full .seg { display: grid; grid-template-columns: repeat(6, 1fr); width: 100%; }
.seg-full .seg button { padding: 6px 2px; }

/* ---------- Raccourcis du tableau de bord ---------- */
.shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.shortcut {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 14px; line-height: 1.3;
}
.shortcut .ico { font-size: 22px; color: var(--accent); width: 28px; text-align: center; flex-shrink: 0; }

/* ---------- Comparer ---------- */
.ref-list .ref { padding: 10px 8px; margin: 0 -8px; width: calc(100% + 16px); border-radius: 10px; }
.ref-list .ref.on { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ref-list .ref .right { text-align: right; white-space: nowrap; }

/* ---------- Remonter le temps ---------- */
.wb-line { padding: 12px 0; border-top: 1px solid var(--border); }
.wb-line .title { font-weight: 600; }
.wb-top { display: flex; gap: 10px; align-items: center; }
.wb-top .main { flex: 1; min-width: 0; }
.wb-amount { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.wb-amount input { width: 96px; text-align: right; font-weight: 600; }
.wb-preview { margin-top: 4px; }
.wb-preview:empty { display: none; }

/* ---------- Sélecteur de portefeuille ---------- */
.pf-switch {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  border: 0; background: var(--surface-2); color: var(--text); border-radius: 10px;
  padding: 6px 10px; font: inherit; font-weight: 700; font-size: 16px; cursor: pointer;
}
.pf-switch .pf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-switch svg { flex-shrink: 0; color: var(--muted); }
.pf-list .row { padding: 12px 0; }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; }
.radio.on { border: 6px solid var(--accent); }
.pf-actions { display: flex; gap: 8px; margin-top: 10px; }
.chips.quick .chip.on { background: var(--accent); color: var(--accent-text); }

/* ---------- Bilan du tableau de bord ---------- */
.hero .big.up, .hero .big.down { font-size: 32px; }
.ledger { margin-top: 14px; background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: 14px; }
.ledger .line { display: flex; justify-content: space-between; gap: 8px; }
.ledger .line + .line { margin-top: 5px; }
.ledger .total { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); padding-top: 6px; margin-top: 6px; }

/* ---------- Méthode : bibliothèque ---------- */
.lib { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.lib-h { margin: 18px 2px 8px; }
.lib-card {
  display: flex; flex-direction: column; gap: 4px; padding: 14px; min-height: 108px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); box-shadow: var(--shadow); font-size: 15px; line-height: 1.3;
}
.lib-card:active { background: var(--surface-2); }
.lib-ico { font-size: 24px; line-height: 1; margin-bottom: 4px; }
.art-ico { font-size: 34px; margin-bottom: 8px; }
.doc h3 { margin-top: 16px; }

/* ---------- Historique (frise) ---------- */
.ev-month { margin: 14px 0 6px; }
.ev-month:first-child { margin-top: 4px; }
.frise { list-style: none; margin: 0; padding: 0 0 0 18px; position: relative; }
.frise::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.ev { position: relative; padding: 6px 0 10px; }
.ev-dot {
  position: absolute; left: -18px; top: 11px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px var(--surface);
}
.ev-sell .ev-dot { background: var(--up); }
.ev-sell.down .ev-dot { background: var(--down); }
.ev-start .ev-dot { background: var(--muted); }
.ev-body { display: block; color: var(--text); padding: 6px 10px; border-radius: 10px; }
a.ev-body:active { background: var(--surface-2); }
.ev-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ev-head > span:first-child { min-width: 0; }
.ev-head > .muted { white-space: nowrap; flex-shrink: 0; }
.ev-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.ev-sell .ev-tag { color: var(--up); }
.ev-sell.down .ev-tag { color: var(--down); }
.ev-start .ev-body { padding-top: 4px; }

/* ---------- Recherche : doublons de cotation ---------- */
.list li.group-note { border-top: 0; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin: 8px 0 2px; line-height: 1.4; }
.list li.group-note + li { border-top: 0; }
.listing-line { font-size: 12.5px; margin-top: 3px; line-height: 1.35; }
.tag-primary { display: inline-block; font-size: 11px; font-weight: 700; color: var(--up); background: var(--up-bg); border-radius: 5px; padding: 1px 6px; margin-right: 4px; }
.row.listing-secondary .title { font-weight: 500; }

/* ---------- Liquidité ---------- */
.pill.warn { background: color-mix(in srgb, #d97706 16%, transparent); color: #b45309; }
@media (prefers-color-scheme: dark) { .pill.warn { color: #f0a03c; } }
.liq-warn { margin-top: 10px; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.4;
  background: color-mix(in srgb, #d97706 14%, transparent); }
