/* Cairn — suivi de patrimoine. Thème clair par défaut, sombre choisi. */
:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --surface-3: #e9e7e1;
  --line: #e6e4dd;
  --line-strong: #d6d3ca;
  --ink: #16171c;
  --ink-2: #4f515a;
  --ink-3: #8a8c94;
  --accent: #5652d8;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfc;
  --up: #11845a;
  --up-soft: #e3f4ec;
  --down: #c9372f;
  --down-soft: #fbe9e7;
  --warn: #b26b00;
  --chart-1: #5652d8;
  --chart-2: #9a9ca5;
  --grid: #ecebe5;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 8px 24px -12px rgba(20, 20, 30, .10);
  --radius: 18px;
  --radius-sm: 11px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Inter Display", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Display", "Segoe UI", Roboto, sans-serif;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948; --c9: #a3a39d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0e11; --surface: #15161b; --surface-2: #1c1d23; --surface-3: #24252c;
    --line: #24262d; --line-strong: #33353e;
    --ink: #eceef3; --ink-2: #a9acb7; --ink-3: #6f727d;
    --accent: #8f8cf8; --accent-ink: #111; --accent-soft: #23234a;
    --up: #3ccf91; --up-soft: #12291f; --down: #ff6b61; --down-soft: #2f1716; --warn: #f0a440;
    --chart-1: #8f8cf8; --chart-2: #6f727d; --grid: #1f2026;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c9: #6f6f69;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e11; --surface: #15161b; --surface-2: #1c1d23; --surface-3: #24252c;
  --line: #24262d; --line-strong: #33353e;
  --ink: #eceef3; --ink-2: #a9acb7; --ink-3: #6f727d;
  --accent: #8f8cf8; --accent-ink: #111; --accent-soft: #23234a;
  --up: #3ccf91; --up-soft: #12291f; --down: #ff6b61; --down-soft: #2f1716; --warn: #f0a440;
  --chart-1: #8f8cf8; --chart-2: #6f727d; --grid: #1f2026;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c9: #6f6f69;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .amount, td.r, .kpi-value, .hero-value { font-variant-numeric: tabular-nums; }
::selection { background: var(--accent-soft); }

/* ---------- mise en page ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand svg { width: 28px; height: 28px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2);
  font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.side-foot { margin-top: auto; display: flex; gap: 6px; padding: 0 6px; }
.main { min-width: 0; padding: 30px clamp(16px, 4vw, 48px) 80px; max-width: 1240px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 26px; }
.topbar h1 { font: 650 24px/1.2 var(--display); letter-spacing: -.02em; margin: 0; }
.topbar .sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.mt { margin-top: 18px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; min-width: 0; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2, .card-title { font-size: 15px; font-weight: 620; margin: 0; letter-spacing: -.005em; }
.card-head .link { font-size: 13px; color: var(--ink-3); }
.card-head .link:hover { color: var(--ink); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }

/* ---------- héros ---------- */
.hero { padding: 26px 26px 12px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.hero-label { color: var(--ink-3); font-size: 13px; font-weight: 500; display: flex; gap: 8px; align-items: center; }
.hero-value { font: 640 clamp(34px, 5vw, 46px)/1.1 var(--display); letter-spacing: -.035em; margin: 6px 0 6px; }
.hero-value .cents { color: var(--ink-3); font-weight: 560; }
.hero-delta { display: flex; gap: 8px; align-items: center; font-weight: 560; font-size: 14px; min-height: 22px; }
.hero-date { color: var(--ink-3); font-weight: 450; }
.chart-wrap { position: relative; height: 290px; margin: 14px -8px 0; }
.chart-wrap.sm { height: 220px; }
.chart-wrap.xs { height: 170px; }

/* ---------- sélecteur de période ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); font-weight: 560; font-size: 12.5px; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- pastilles ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.pill.flat { background: var(--surface-2); color: var(--ink-2); }
.up { color: var(--up); } .down { color: var(--down); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; font-weight: 560; }
.tag.warn { color: var(--warn); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.kpi { padding: 18px 20px; }
.kpi-label { color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
.kpi-value { font: 620 21px/1.25 var(--display); letter-spacing: -.02em; margin-top: 6px; }
.kpi-foot { font-size: 12.5px; margin-top: 4px; color: var(--ink-3); }

/* ---------- listes ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 11px 8px; margin: 0 -8px; border-radius: 12px; transition: background .12s;
}
a.row:hover, .row.click:hover { background: var(--surface-2); cursor: pointer; }
.row + .row { border-top: 1px solid var(--line); }
a.row:hover + .row, .row:hover + .row { border-top-color: transparent; }
.avatar {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 650; font-size: 13px;
  background: var(--surface-2); color: var(--ink-2);
}
.avatar svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.row-title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; }
.row-end .amount { font-weight: 600; }
.group-title { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 18px 0 4px; }
.group-title:first-child { margin-top: 0; }

/* ---------- tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 560; color: var(--ink-3); padding: 0 10px 10px; white-space: nowrap; cursor: default; user-select: none; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--ink); }
th.r, td.r { text-align: right; }
td { padding: 12px 10px; border-top: 1px solid var(--line); white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr.click:hover { background: var(--surface-2); cursor: pointer; }
td .name { font-weight: 560; max-width: 260px; overflow: hidden; text-overflow: ellipsis; display: block; }
td .sub { color: var(--ink-3); font-size: 12px; }
.spark { width: 84px; height: 28px; display: block; margin-left: auto; }

/* ---------- répartition ---------- */
.alloc { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: center; }
.alloc:not(.big) .donut-box { width: min(210px, 100%); margin: 0 auto; }
.alloc.big { grid-template-columns: 300px minmax(0, 1fr); }
.donut-box { position: relative; aspect-ratio: 1; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; padding: 22%; }
.donut-center .v { font: 640 19px/1.2 var(--display); letter-spacing: -.02em; }
.donut-center .l { color: var(--ink-3); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; flex-direction: column; gap: 2px; min-width: 0; width: 100%; max-width: 560px; }
.legend-item { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 9px; font-size: 13.5px; cursor: default; transition: background .12s, opacity .2s; }
.legend-item:hover, .legend-item.hl { background: var(--surface-2); }
.legend.dim .legend-item:not(.hl) { opacity: .45; }
.legend-item .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item .pct { color: var(--ink-3); font-size: 12.5px; min-width: 44px; text-align: right; }
.legend-item .val { font-weight: 560; min-width: 90px; text-align: right; }
.bar-track { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .8s cubic-bezier(.2,.8,.2,1); }

/* ---------- graphiques ---------- */
.chart { position: absolute; inset: 0; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .cross { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2.5; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 10px; padding: 8px 11px; font-size: 12.5px; white-space: nowrap; opacity: 0; transform: translateY(4px);
  transition: opacity .12s, transform .12s; z-index: 5;
}
.tooltip.on { opacity: 1; transform: none; }
.tooltip .t-date { color: var(--ink-3); font-size: 11.5px; margin-bottom: 3px; }
.tooltip .t-row { display: flex; gap: 14px; justify-content: space-between; align-items: center; }
.tooltip .t-row .k { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .t-row .k i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tooltip .t-row b { font-weight: 600; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; color: var(--chart-2); }
.empty-chart { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: 13px; }

/* ---------- boutons & formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 0; cursor: pointer; padding: 9px 15px; border-radius: 11px;
  font-weight: 580; font-size: 13.5px; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--ink); color: var(--bg); box-shadow: none; }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--down); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.icon { padding: 8px; border-radius: 10px; }
.btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 560; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; min-height: 41px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.hint { font-size: 12.5px; color: var(--ink-3); }
.err { color: var(--down); font-size: 13px; min-height: 18px; }

/* ---------- modale ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 10, 15, .38); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .18s ease; }
.modal { background: var(--surface); border-radius: 20px; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); animation: pop .22s cubic-bezier(.2,.9,.3,1.2); }
.modal h3 { margin: 0 0 18px; font: 640 18px/1.3 var(--display); letter-spacing: -.01em; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- recherche ticker ---------- */
.search-results { border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; max-height: 240px; overflow: auto; }
.search-results:empty { display: none; }
.search-results button { display: flex; width: 100%; justify-content: space-between; gap: 10px; text-align: left; border: 0; background: none; padding: 9px 12px; cursor: pointer; }
.search-results button:hover { background: var(--surface-2); }
.search-results button + button { border-top: 1px solid var(--line); }

/* ---------- import ---------- */
.drop { border: 1.5px dashed var(--line-strong); border-radius: 16px; padding: 34px 20px; text-align: center; color: var(--ink-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--ink); }

/* ---------- connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 32px; }
.login .brand { padding: 0 0 6px; font-size: 20px; }
.login .brand svg { width: 34px; height: 34px; }

/* ---------- divers ---------- */
.progress { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 12px 0 8px; }
.progress > div { height: 100%; border-radius: 6px; background: var(--accent); width: 0; transition: width 1.1s cubic-bezier(.2,.8,.2,1); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 16px; }
.empty .btn { margin-top: 14px; }
.notice { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 13.5px; margin-bottom: 18px; }
.notice .btn { margin-left: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--ink-3); font-weight: 560; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-color: var(--ink); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); }
.stat-line { display: flex; justify-content: space-between; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.stat-line:first-child { border-top: 0; }
.stat-line span:first-child { color: var(--ink-2); }
.stat-line span:last-child { font-weight: 580; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; max-width: calc(100vw - 32px); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.fade-in { animation: rise .35s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* mode discret : masque les montants */
.private .amount, .private .hero-value, .private .kpi-value.amount, .private .tooltip b, .private .donut-center .v, .private .chart .axis.y text { filter: blur(7px); }

/* ---------- mobile ---------- */
.mobile-nav { display: none; }
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .alloc.big { grid-template-columns: 240px minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 20px 16px 110px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--ink-3); padding: 4px 6px; font-weight: 560; min-width: 54px; }
  .mobile-nav a svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .mobile-nav a.active { color: var(--ink); }
  .g-2, .alloc, .alloc.big { grid-template-columns: minmax(0, 1fr); }
  .alloc .donut-box { max-width: 240px; margin: 0 auto; width: 100%; }
  .kpis { gap: 12px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 18px; }
  .card { padding: 18px; border-radius: 16px; }
  .table-wrap { margin: 0 -18px; padding: 0 18px; }
  .hero { padding: 20px 18px 8px; }
  .chart-wrap { height: 230px; }
  .topbar h1 { font-size: 21px; }
  .form-row, .form-row.three { grid-template-columns: minmax(0, 1fr); }
  .hide-m { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
input[type="range"] { accent-color: var(--accent); width: 100%; }
