:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #1b2436;
  --muted: #6b7688;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --expense: #e5484d;
  --income: #16a34a;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
  --radius: 14px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e1320;
  --surface: #161d2c;
  --surface-2: #1f2838;
  --border: #2c3648;
  --text: #e7eaf1;
  --muted: #98a2b6;
  --accent: #818cf8;
  --accent-soft: #262a44;
  --expense: #f87171;
  --income: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* Ajustements de contraste en mode sombre (puces colorées claires -> teintes sombres) */
:root[data-theme="dark"] .pill-ok,
:root[data-theme="dark"] .bg-in-tag { background: rgba(22, 163, 74, .18); color: #4ade80; }
:root[data-theme="dark"] .pill-warn,
:root[data-theme="dark"] .flag-warn { background: rgba(245, 158, 11, .18); color: #fbbf24; }
:root[data-theme="dark"] .flag-up { background: rgba(220, 38, 38, .2); color: #f87171; }
:root[data-theme="dark"] .pill-off { background: rgba(148, 163, 184, .15); color: #94a3b8; }

* { box-sizing: border-box; }

/* Barres de défilement fines et cohérentes avec le thème (au lieu du rendu par défaut du navigateur) */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: 20px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--muted); background-clip: padding-box; }

/* L'attribut `hidden` doit toujours l'emporter, même sur un display d'auteur. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2 { margin: 0; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c74f0);
  color: #fff; font-weight: 700; font-size: 22px;
  border-radius: 12px;
}
.brand h1 { font-size: 18px; letter-spacing: -.2px; }
.tagline { margin: 0; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
  font-weight: 500;
}
.btn:hover { border-color: #c7cede; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 16px; height: 16px; flex: 0 0 auto; display: block; }
.saved-views .icon-btn svg { width: 14px; height: 14px; }

/* Summary cards */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  padding: 20px 24px 4px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat .value.expense { color: var(--expense); }
.stat .value.income { color: var(--income); }

/* Alertes de budget (projection de fin de mois basée sur le rythme actuel) */
.budget-alerts { display: flex; flex-direction: column; gap: 8px; padding: 0 24px 4px; }
.budget-alert { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.4; border: 1px solid; }
.budget-alert.warn { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .35); }
.budget-alert.over { background: rgba(220, 38, 38, .1); border-color: rgba(220, 38, 38, .35); }
.ba-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; margin-top: 5px; }
.budget-alert.warn .ba-dot { background: #f59e0b; }
.budget-alert.over .ba-dot { background: var(--expense); }
.ba-text strong { font-weight: 600; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  padding: 16px 24px 40px;
  align-items: start;
}

/* Filters */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 128px;
  max-height: calc(100vh - 144px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.filters-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.filters-head h2 { font-size: 15px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1 1 0; min-width: 0; }
input, select {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.filter-group { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.filter-group-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 11px; padding: 0; }
.checklist { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; overscroll-behavior: contain; }
.check {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.check:hover { background: var(--surface-2); }
.check input { width: auto; }
.check .cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check .camt { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* Content */
.content { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-head h2 { font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 600; }

/* Segmented control */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.segmented button { border: none; background: none; padding: 4px 10px; font-size: 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

/* Breakdown bars */
.breakdown { display: flex; flex-direction: column; gap: 10px; }
.bd-row { cursor: pointer; display: flex; align-items: flex-start; gap: 8px; }
.bd-row:hover .bd-label { color: var(--accent); }
.bd-check { flex: 0 0 auto; padding-top: 2px; cursor: pointer; }
.bd-check input { cursor: pointer; }
.bd-body { flex: 1 1 auto; min-width: 0; }
.bd-row.bd-disabled .bd-body { opacity: .4; }
.bd-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; gap: 8px; }
.bd-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bd-track { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bd-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #8b83f2); border-radius: 6px; transition: width .3s ease; }
.bd-row.active .bd-fill { background: linear-gradient(90deg, #db2777, #f472b6); }

/* Simulateur : recalcul dépenses/solde/taux d'épargne en décochant des postes */
.breakdown-sim { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.bs-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.bs-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.bs-card { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.bs-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.bs-val { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bs-val.income { color: var(--income); }
.bs-val.expense { color: var(--expense); }
.bs-delta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Monthly chart */
.monthly { display: flex; align-items: flex-end; gap: 4px; height: 200px; overflow-x: auto; padding-bottom: 24px; }
.mo-bar { flex: 0 0 26px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.mo-fill { width: 18px; background: linear-gradient(180deg, #8b83f2, var(--accent)); border-radius: 5px 5px 0 0; min-height: 2px; transition: height .3s ease; }
.mo-bar:hover .mo-fill { background: linear-gradient(180deg, #f472b6, #db2777); }
.mo-label { position: absolute; bottom: -22px; font-size: 9px; color: var(--muted); transform: rotate(-45deg); transform-origin: center; white-space: nowrap; }
.mo-bar .mo-tip {
  position: absolute; bottom: 100%; margin-bottom: 4px;
  background: var(--text); color: var(--bg); font-size: 11px; padding: 3px 7px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 5;
}
.mo-bar:hover .mo-tip { opacity: 1; }

/* Donut (camembert) */
.donut-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.donut-svg { width: 170px; height: 170px; flex: 0 0 auto; }
.donut-seg { transition: opacity .15s; }
.donut-seg:hover { opacity: .82; }
.donut-center-1 { font-size: 17px; font-weight: 700; fill: var(--text); }
.donut-center-2 { font-size: 9px; fill: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.donut-legend { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 3px; }
.lg-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.lg-item:hover { background: var(--surface-2); }
.lg-item.active { background: var(--accent-soft); }
.lg-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.lg-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg-val { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }

/* Dépenses par année */
.yearly { display: flex; align-items: flex-end; gap: 16px; height: 200px; padding-bottom: 22px; justify-content: space-around; }
.yr-bar { flex: 1; max-width: 90px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.yr-fill { width: 100%; max-width: 58px; background: linear-gradient(180deg, #8b83f2, var(--accent)); border-radius: 7px 7px 0 0; min-height: 2px; transition: height .3s ease; }
.yr-val { font-size: 11px; font-weight: 600; color: var(--text); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.yr-label { position: absolute; bottom: -20px; font-size: 12px; color: var(--muted); }

/* Cumul des dépenses */
.cumulative { width: 100%; }
.cum-svg { width: 100%; height: auto; display: block; }
.cum-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); }
.cum-labels span:nth-child(2) { font-weight: 600; color: var(--text); }

/* Survol interactif des courbes */
.chart-hover { position: relative; }
.chart-hover svg { cursor: crosshair; }
.chart-tip {
  position: absolute; transform: translate(-50%, -132%);
  background: var(--text); color: var(--bg); font-size: 11px; padding: 5px 9px; border-radius: 7px;
  white-space: nowrap; pointer-events: none; z-index: 6; text-align: center; line-height: 1.4;
  box-shadow: var(--shadow);
}

/* Abonnements récurrents */
.subs-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.subs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.subs-table th, .subs-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.subs-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.subs-table th.num, .subs-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.subs-table tbody tr { cursor: pointer; }
.subs-table tbody tr:hover { background: var(--surface-2); }
.sub-merchant { font-weight: 600; }
.sub-mini { color: var(--muted); font-weight: 400; font-size: 11px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.pill-ok { background: #dcfce7; color: #15803d; }
.pill-warn { background: #fef3c7; color: #b45309; }
.pill-off { background: #f1f5f9; color: #64748b; }
.flag { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 10px; font-weight: 600; margin-left: 4px; vertical-align: middle; }
.flag-warn { background: #fef3c7; color: #b45309; }
.flag-up { background: #fee2e2; color: #b91c1c; }

/* Revenus vs Dépenses */
.rvd { display: flex; align-items: flex-end; gap: 8px; height: 210px; overflow-x: auto; padding-bottom: 24px; }
.rvd-col { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.rvd-bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.rvd-bar { width: 13px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s ease; }
.rvd-bar.rev { background: linear-gradient(180deg, #4ade80, #16a34a); }
.rvd-bar.dep { background: linear-gradient(180deg, #f87171, #dc2626); }
.rvd-label { position: absolute; bottom: -22px; font-size: 9px; color: var(--muted); transform: rotate(-45deg); white-space: nowrap; }
.rvd-tip { position: absolute; bottom: 100%; margin-bottom: 4px; background: var(--text); color: var(--bg); font-size: 11px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 5; }
.rvd-col:hover .rvd-tip { opacity: 1; }
.rvd-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; margin-right: 3px; }
.rvd-key.rvd-rev { background: #16a34a; }
.rvd-key.rvd-dep { background: #dc2626; }

/* Presets de dates + vues sauvegardées */
.saved-views { display: flex; gap: 6px; margin-bottom: 12px; }
.saved-views select { flex: 1; min-width: 0; }
.saved-views .btn-sm { padding: 6px 9px; }
.date-presets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.date-presets button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 11px; padding: 4px 9px; border-radius: 20px; cursor: pointer; }
.date-presets button:hover { border-color: var(--accent); color: var(--accent); }

/* Fiche détail */
.detail-body { display: flex; flex-direction: column; margin-bottom: 16px; }
.dt-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.dt-row:last-child { border-bottom: none; }
.dt-k { color: var(--muted); flex: 0 0 auto; }
.dt-v { text-align: right; word-break: break-word; }
.tx-table tbody tr { cursor: pointer; }

/* Solde initial */
.balance-start-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.balance-start-label input { width: 92px; padding: 5px 8px; }

/* Objectifs d'épargne */
#goals-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.goal-top { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.goal-name { font-weight: 600; font-size: 14px; }
.goal-val { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-left: auto; }
.goal-del { border: none; background: var(--surface-2); color: var(--muted); cursor: pointer; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; flex: 0 0 auto; }
.goal-del:hover { background: var(--expense); color: #fff; }
.goal-track { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.goal-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), #8b83f2); transition: width .3s ease; }
.goal-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.goal-fill.ok { background: linear-gradient(90deg, #16a34a, #4ade80); }
.goal-meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.goal-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border-top: 1px solid var(--border); padding-top: 14px; }
.goal-add input { width: auto; flex: 1 1 120px; min-width: 0; }
.goal-add input#goal-name { flex: 2 1 160px; }

/* Simulateur d'épargne */
.goal-sim { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.sim-title { font-size: 14px; margin: 0 0 12px; }
.sim-inputs { display: flex; flex-wrap: wrap; gap: 8px; }
.sim-inputs input { width: auto; flex: 1 1 140px; min-width: 0; }
.sim-auto { font-size: 12px; color: var(--muted); margin-top: 10px; }
.sim-detail { opacity: .8; font-size: 11px; }
.sim-use { border: 1px solid var(--border); background: var(--surface); color: var(--accent); font-size: 11px; padding: 2px 8px; border-radius: 20px; cursor: pointer; margin-left: 4px; }
.sim-use:hover { border-color: var(--accent); background: var(--accent-soft); }
.sim-result { font-size: 14px; margin: 12px 0 6px; line-height: 1.5; }
.sim-placeholder { color: var(--muted); font-size: 13px; }

/* Menus rétractables */
.collapse-btn {
  border: none; background: none; cursor: pointer; padding: 0;
  width: 18px; height: 18px; flex: 0 0 auto; font-size: 11px;
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center; border-radius: 5px;
}
.collapse-btn::before { content: '▾'; }
.card.collapsed .collapse-btn::before, .filter-group.collapsed .collapse-btn::before { content: '▸'; }
.collapse-btn:hover { color: var(--text); background: var(--surface-2); }
.collapsible-title { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 7px; }
.card.collapsed > *:not(.card-head) { display: none !important; }
.card.collapsed .card-head { margin-bottom: 0; }
.filter-group.collapsed .checklist { display: none; }
.filter-group.collapsed .filter-group-head { margin-bottom: 0; }

/* Budgets */
.budget-controls { display: flex; align-items: center; gap: 12px; }
.budget-period { width: auto; padding: 6px 10px; font-size: 13px; }
.budget-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.budget-table th, .budget-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.budget-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.budget-table th.num, .budget-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bg-cat { font-weight: 600; }
.bg-input { white-space: nowrap; }
.bg-field { width: 82px; padding: 5px 8px; font-size: 13px; text-align: right; display: inline-block; }
.bg-unit { color: var(--muted); font-size: 12px; margin-left: 4px; }
.bg-track { height: 9px; background: var(--surface-2); border-radius: 6px; overflow: hidden; min-width: 120px; }
.bg-fill { height: 100%; border-radius: 6px; transition: width .3s ease, background .2s; width: 0; }
.bg-fill.ok { background: linear-gradient(90deg, #16a34a, #4ade80); }
.bg-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.bg-fill.over { background: linear-gradient(90deg, #dc2626, #f87171); }
.bg-fill.none { background: var(--border); }
.bg-note { font-size: 12px; font-weight: 500; white-space: nowrap; }
.bg-note.ok { color: var(--income); }
.bg-note.warn { color: #b45309; }
.bg-note.over { color: var(--expense); font-weight: 600; }
.bg-note.none { color: var(--muted); font-weight: 400; }
.bg-total td { border-top: 2px solid var(--border); border-bottom: none; font-weight: 600; }
.bg-income td { background: rgba(22, 163, 74, .05); }
.bg-in-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; background: var(--income); margin-right: 7px; vertical-align: middle; }
.bg-in-tag { font-size: 10px; color: #15803d; background: #dcfce7; border-radius: 20px; padding: 1px 7px; margin-left: 8px; font-weight: 600; }
.bg-in-amt { color: var(--income); font-weight: 600; }
.bg-muted { color: var(--muted); }

/* Table */
.table-wrap { overflow-x: auto; }
.tx-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tx-table th, .tx-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.tx-table th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
.tx-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.tx-table th.sortable:hover { color: var(--accent); }
.tx-table th.num, .tx-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tx-table tbody tr:hover { background: var(--surface-2); }
.tx-table td.amount { font-weight: 600; }
.tx-table td.amount.neg { color: var(--expense); }
.tx-table td.amount.pos { color: var(--income); }
.tx-label { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  display: inline-block; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 9px; font-size: 11px; color: var(--muted); cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.sort-arrow { font-size: 10px; margin-left: 3px; }

/* Choix des sections affichées */
.section-hidden { display: none !important; }
.layout.no-filters { grid-template-columns: 1fr; }
.sections-dropdown { position: relative; }
.sections-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 8px; min-width: 250px; z-index: 40;
  display: flex; flex-direction: column; gap: 2px; max-height: 72vh; overflow-y: auto;
}
.sections-menu-head { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 4px 8px 6px; font-weight: 600; }
.sections-menu-actions { display: flex; gap: 14px; padding: 0 8px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.sec-item { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px; font-size: 13px; cursor: pointer; }
.sec-item:hover { background: var(--surface-2); }
.sec-item input { width: auto; }

/* Navigation entre vues */
.viewnav { display: flex; gap: 4px; padding: 8px 24px 0; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 74px; z-index: 15; }
.nav-btn { border: none; background: none; padding: 10px 16px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0; display: inline-flex; align-items: center; gap: 8px; }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Page Exclusions */
.excl-page { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 20px; }
.excl-head h2 { font-size: 20px; }
.excl-intro { color: var(--muted); font-size: 13px; margin: 6px 0 4px; max-width: 780px; line-height: 1.5; }
.excl-add { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.excl-add select { width: auto; min-width: 190px; }
.excl-sep { width: 1px; height: 26px; background: var(--border); margin: 0 6px; }
.excl-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.excl-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 5px 6px 5px 12px; font-size: 13px; }
.ec-name { font-weight: 500; }
.ec-amt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ec-remove { border: none; background: var(--surface); color: var(--muted); cursor: pointer; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.ec-remove:hover { background: var(--expense); color: #fff; }
.tx-locked { border: none; background: none; cursor: pointer; font-size: 12px; padding: 2px 5px; border-radius: 5px; opacity: .55; }
.tx-locked:hover { opacity: 1; background: var(--surface-2); }

/* Page Comparaison de périodes */
.cmp-presets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.cmp-presets button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 11px; padding: 4px 9px; border-radius: 20px; cursor: pointer; }
.cmp-presets button:hover { border-color: var(--accent); color: var(--accent); }
.cmp-periods { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cmp-period-picker { flex: 1 1 260px; min-width: 220px; }
.cmp-period-label { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; margin-bottom: 8px; }
.cmp-period-label.cmp-a { background: var(--accent-soft); color: var(--accent); }
.cmp-period-label.cmp-b { background: var(--surface-2); color: var(--muted); }
.cmp-vs { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; padding-top: 20px; }
.cmp-stat .cmp-stat-vals { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.cmp-val { font-size: 20px; font-weight: 700; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.cmp-val-b { font-size: 14px; font-weight: 500; color: var(--muted); }
.cmp-vs-sep { color: var(--muted); font-size: 11px; }
.cmp-pct { color: var(--muted); }
.cmp-delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.cmp-delta.good { color: var(--income); }
.cmp-delta.bad { color: var(--expense); }
.cmp-tag { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 20px; }
.cmp-tag-new { background: rgba(220, 38, 38, .12); color: var(--expense); }
.cmp-tag-gone { background: rgba(22, 163, 74, .12); color: var(--income); }
.cmp-table tr.cmp-total-row { font-weight: 700; border-top: 2px solid var(--border); }
.cmp-table tr.cmp-total-row td { padding-top: 10px; }

/* Transactions ignorées + action */
.tx-show-ignored { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tx-show-ignored input { width: auto; }
.tx-actions, .tx-actions-h { white-space: nowrap; text-align: right; }
.tx-ignore, .tx-del { border: none; background: none; cursor: pointer; font-size: 13px; padding: 2px 5px; border-radius: 5px; opacity: 0; transition: opacity .12s, background .12s; line-height: 1; }
.tx-table tbody tr:hover .tx-ignore, .tx-table tbody tr:hover .tx-del { opacity: 1; }
.tx-ignored .tx-ignore { opacity: 1; }
.tx-ignore:hover, .tx-del:hover { background: var(--surface-2); }

/* Fenêtre de saisie manuelle */
#tx-modal .modal-box label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
#tx-modal .modal-box label input:not([type=radio]) { margin-top: 5px; }
#tx-modal .txm-type { display: flex; gap: 18px; margin-bottom: 14px; }
#tx-modal .txm-type label { display: inline-flex; align-items: center; gap: 7px; margin: 0; color: var(--text); font-size: 14px; cursor: pointer; }
#tx-modal .txm-type input { width: auto; margin: 0; }
#tx-modal .txm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#tx-modal .txm-grid label { margin-bottom: 12px; }
.tx-ignored { color: var(--muted); }
.tx-ignored .tx-label, .tx-ignored .amount { text-decoration: line-through; }

/* Cellule catégorie éditable */
.cat-cell { white-space: nowrap; }
.cat-edit { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 12px; padding: 2px 5px; border-radius: 5px; margin-left: 4px; opacity: 0; transition: opacity .12s, background .12s; }
.tx-table tbody tr:hover .cat-edit { opacity: 1; }
.cat-edit:hover { background: var(--surface-2); color: var(--accent); }

/* Fenêtre modale */
.modal { position: fixed; inset: 0; background: rgba(20, 30, 60, .42); backdrop-filter: blur(2px); z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal-box { background: var(--surface); border-radius: 16px; padding: 22px; width: 100%; max-width: 460px; box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 12px; font-size: 17px; }
.modal-tx { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; margin: 0 0 16px; line-height: 1.55; word-break: break-word; }
.modal-box > label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.modal-box select, #cat-modal-new { margin-top: 5px; }
#cat-modal-new { margin: 8px 0 4px; }
.modal-scope { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 20px; }
.modal-scope label { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-size: 13px; margin: 0; cursor: pointer; line-height: 1.4; }
.modal-scope input { width: auto; margin-top: 2px; flex: 0 0 auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
#cat-modal-reset { margin-right: auto; }

/* Drop overlay */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(79, 70, 229, .12);
  backdrop-filter: blur(2px); z-index: 50; display: grid; place-items: center;
}
.drop-inner {
  border: 3px dashed var(--accent); border-radius: 20px; padding: 40px 60px;
  background: var(--surface); font-size: 18px; font-weight: 600; color: var(--accent);
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 60; box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; }
  .panels { grid-template-columns: 1fr; }
}

/* ===========================================================================
   Authentification (écran de connexion) & compte utilisateur
   =========================================================================== */

/* Masquage de l'app tant que l'utilisateur n'est pas connecté (mode auth actif) */
html.auth-gate:not(.authed) body > header,
html.auth-gate:not(.authed) body > .viewnav,
html.auth-gate:not(.authed) body > #dashboard-view,
html.auth-gate:not(.authed) body > #exclusions-page {
  display: none !important;
}

/* L'écran d'auth n'apparaît que si l'auth est configurée ET non connecté */
.auth-screen { display: none; }
html.auth-gate:not(.authed) .auth-screen {
  display: flex;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  z-index: 50;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.auth-brand .logo {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.auth-name { letter-spacing: .2px; }

.auth-tagline {
  margin: 10px 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  border: 0;
  background: transparent;
  padding: 9px 8px;
  border-radius: 7px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 30, 60, .08);
}

.auth-field {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.auth-field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-sizing: border-box;
}
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 15px;
}
.auth-submit.is-busy { opacity: .65; cursor: progress; }

.auth-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}
.auth-link:hover { text-decoration: underline; }

.auth-message {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
}
.auth-message-error {
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--expense) 30%, transparent);
}
.auth-message-ok {
  color: var(--income);
  background: color-mix(in srgb, var(--income) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--income) 30%, transparent);
}

/* Puce utilisateur dans l'en-tête */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.user-email {
  font-size: 13px;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
  transition: background-color .2s ease;
}
.sync-dot.sync-saved   { background: var(--income); }
.sync-dot.sync-pending { background: #eab308; }
.sync-dot.sync-saving  { background: #eab308; animation: sync-pulse 1s ease-in-out infinite; }
.sync-dot.sync-error   { background: var(--expense); }
@keyframes sync-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

@media (max-width: 640px) {
  .user-email { display: none; }
}
