:root {
  --bg: #f5f7fb;
  --bg-elevated: #ffffff;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(14, 20, 32, 0.06);
  --text: #111827;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --brand-color: #0C3927;
}

body.dark {
  --bg: #09111f;
  --bg-elevated: #111c2d;
  --panel: rgba(17, 28, 45, 0.96);
  --panel-border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #a0aec0;
  --primary: #60a5fa;
  --primary-soft: rgba(96, 165, 250, 0.15);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow: 0 22px 50px rgba(2, 6, 23, 0.42);
  --brand-color: #F8F5EC;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 28%), var(--bg);
  color: var(--text);
}
body { transition: background 0.25s ease, color 0.25s ease; }
button, input, select { font: inherit; }

.app-shell, .login-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}

.topbar-branding { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  text-decoration: none;
  cursor: pointer;
}
.brand-mark:hover .brand-name { opacity: 0.85; }
.brand-icon { width: 38px; height: 38px; border-radius: 9px; flex: none; display: block; }
.brand-name {
  font-family: 'Segoe UI Rounded', 'SF Pro Rounded', 'Nunito', ui-rounded, 'Segoe UI', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--brand-color);
  line-height: 1;
}
.admin-subtitle { margin: 0; }

.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
  color: var(--muted);
}
.icon-button:hover { background: var(--primary-soft); color: var(--text); }

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

h1, h2 { margin: 0; }

h1 { font-size: clamp(2rem, 4vw, 2.8rem); }

.topbar-actions, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.user-chip { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.logout-button { white-space: nowrap; }

.nav-dropdown { position: relative; }
.nav-dropdown-toggle { white-space: nowrap; }
.nav-dropdown-panel {
  display: none;
  flex-direction: column;
  gap: 2px;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}
.nav-dropdown-open .nav-dropdown-panel { display: flex; }
.nav-dropdown-panel .nav-link { display: block; }

.primary-button, .ghost-button {
  border-radius: 12px;
  padding: 10px 14px;
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  border: none;
  box-shadow: var(--shadow);
}

.ghost-button {
  background: var(--bg-elevated);
  color: var(--text);
}

.primary-button:hover, .ghost-button:hover { transform: translateY(-1px); }

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.summary-budget-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
  align-items: stretch;
}

.summary-panel { display: flex; flex-direction: column; justify-content: center; }

.summary-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -4px 0 12px;
}

.metric-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
}

.metric-card .label {
  display: block;
  color: var(--muted);
  margin-bottom: 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.metric-card strong { font-size: clamp(1.05rem, 1.6vw, 1.5rem); }
.metric-card.income { background: linear-gradient(180deg, var(--success-soft), transparent); }
.metric-card.expense { background: linear-gradient(180deg, var(--danger-soft), transparent); }
.metric-card.balance { background: linear-gradient(180deg, var(--primary-soft), transparent); }

.content-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.8fr;
  gap: 18px;
}

.lower-grid {
  margin-top: 6px;
}

.panel {
  position: relative;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.28));
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  /* Forces its own GPU compositor layer so the backdrop-filter snapshot never
     falls back to a flat opaque paint during scroll/refresh re-tiling (the
     "gros carré blanc" flicker documented in repo memory) instead of silently
     reintroducing that bug across every panel in the app. */
  will-change: backdrop-filter;
  transform: translateZ(0);
}
body.dark .panel {
  background: linear-gradient(165deg, rgba(30, 41, 59, 0.55), rgba(15, 23, 42, 0.28));
  border-color: rgba(148, 163, 184, 0.18);
}
/* High contrast trades the frosted look for a fully opaque, high-legibility panel. */
body.high-contrast .panel {
  background: var(--panel);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Allow tooltips to render outside the filters panel, and above the panels
   below it — backdrop-filter on .panel creates a stacking context, so the
   tooltip's own z-index can't escape it; only a higher z-index on this panel
   itself lets it paint over later sibling panels. */
#dash-filters {
  overflow: visible;
  padding: 12px 16px;
  position: relative;
  z-index: 5;
}
#dash-filters .stack-form { gap: 6px; }
#dash-filters .filter-group-label { margin: 0 0 2px; }
#dash-filters .chip { padding: 5px 10px; font-size: 0.78rem; }
#dash-filters .period-month-button { padding: 4px 8px; }
#dash-filters .period-summary { margin-top: 2px; font-size: 0.78rem; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

#dash-budget-types { padding: 12px 16px; }
#dash-budget-types .panel-header { margin-bottom: 8px; }
#dash-budget-types .panel-header h2 { font-size: 1rem; }
#dash-budget-types .stack-form { gap: 4px; }
#dash-budget-types .filter-row {
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.05);
}
#dash-budget-types .dot { width: 9px; height: 9px; }
#dash-budget-types .category-name { font-size: 0.86rem; }
#dash-budget-types .transaction-sub { font-size: 0.72rem; }
#dash-budget-types .chip { padding: 3px 8px; font-size: 0.7rem; }

.panel-separator {
  margin-top: 18px;
}

.warning-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-weight: 600;
}

.info-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-soft, rgba(59, 130, 246, 0.12));
  color: var(--primary, #2563eb);
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.period-shortcuts-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.period-cashflow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-cashflow select {
  min-width: 220px;
}

.topbar-eye-toggle {
  padding: 8px 10px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-eye-toggle .eye-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.topbar-eye-toggle .eye-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.topbar-eye-toggle.amounts-hidden {
  background: var(--primary-soft);
  color: var(--primary);
}

.period-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Period shortcuts, prev/next navigation and (optionally) the budget-month info
   icon all share one compact row instead of stacking on separate lines. */
.period-row-combined {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Prev-pill(s)-next grouped into one visually cohesive control (shared border/
   background) instead of two loose arrow buttons floating around the month
   pill(s) — reads as "one navigator" rather than three unrelated controls. */
.period-nav-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  background: rgba(148, 163, 184, 0.04);
}

.period-months {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.period-month-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}

.period-month-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Muted text dash between a range's two month pills — deliberately NOT
   arrow-shaped so it never reads as another navigation control next to the
   real prev/next chevrons. */
.period-range-sep {
  color: var(--muted);
  font-size: 0.85rem;
}

.nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
.nav-arrow:hover {
  background: rgba(148, 163, 184, 0.14);
}

.period-summary {
  margin-top: 6px;
}

.tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-icon {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(148, 163, 184, 0.04);
  color: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.tooltip-content {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  min-width: 260px;
  max-width: 360px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.3;
  z-index: 10;
  display: none;
}

.tooltip:hover .tooltip-content,
.tooltip:focus-within .tooltip-content {
  display: block;
}

.tooltip.open .tooltip-content {
  display: block;
}

.sankey-detail-level-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Monthly-average control: label + ON/OFF switch + its own info icon, kept as
   one inline unit so it wraps as a whole on narrow screens. */
.monthly-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.monthly-toggle-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* Same on/off language as .chip/.chip-active: primary blue = selected,
   neutral/muted = not selected — plus a ✓/✕ glyph on the knob so the state
   never relies on color alone. */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  width: 44px;
  height: 24px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  cursor: pointer;
  flex: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle-switch-on {
  background: var(--primary);
  border-color: transparent;
}

.toggle-switch-knob {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  transform: translateX(0);
  transition: transform 0.15s ease, color 0.15s ease;
}

.toggle-switch-on .toggle-switch-knob {
  transform: translateX(20px);
  background: white;
  color: var(--primary);
}

/* Small vertical divider between independent chip groups sharing one row
   (e.g. detail-level chips vs. cashflow chips). */
.row-divider {
  width: 1px;
  height: 20px;
  background: var(--border, rgba(255, 255, 255, 0.14));
  margin: 0 2px;
}

.category-list, .transaction-list { display: flex; flex-direction: column; gap: 12px; }

.category-row, .transaction-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.04);
  border: 1px solid transparent;
}

.category-row { gap: 10px; }
.category-meta { display: flex; align-items: center; gap: 10px; }
.field-mini { display: flex; flex-direction: column; gap: 2px; }
.field-mini-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.field-mini-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.field-mini-checkbox input { width: auto; }
.field-mini-checkbox .field-mini-label { text-transform: none; font-size: 0.8rem; }
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}
.category-name { font-weight: 600; }
.category-value, .transaction-amount { font-weight: 700; }
.category-subtle {
  color: var(--muted);
  font-size: 0.8rem;
}

.transaction-row { align-items: center; flex-wrap: wrap; gap: 8px; }
.transaction-row.cashflow-excluded { opacity: 0.6; }
.transaction-main { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; min-width: 0; }
.transaction-label {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.transaction-sub-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-display-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.txn-display-controls select { width: auto; padding: 5px 8px; font-size: 0.8rem; }
.txn-display-toggle { flex-direction: row; margin: 0; }
.transaction-row .field-mini select,
.transaction-row .field-mini input {
  width: auto;
  min-width: 96px;
  max-width: 140px;
  padding: 6px 8px;
  font-size: 0.78rem;
  border-radius: 8px;
}
.transaction-comment-input {
  min-width: 120px;
  max-width: 160px;
}
.transaction-sub, .empty-state {
  color: var(--muted);
  font-size: 0.83rem;
}
.transaction-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mini-donut {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mini-donut::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--panel-border);
}
.mini-donut-label {
  position: relative;
  z-index: 1;
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--text);
}
.amount-income { color: var(--success); }
.amount-expense { color: var(--danger); }

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

input, select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  padding: 11px 12px;
  background: rgba(255,255,255,0.24);
  color: var(--text);
}

/* The native <option> popup ignores the translucent <select> background and
   falls back to the browser's default (opaque white) — without this, dark
   theme's light `color: var(--text)` renders as near-invisible light text on
   that default white popup. */
select option {
  background: var(--bg-elevated);
  color: var(--text);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(100%, 420px);
  background: var(--bg-elevated);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.logo-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: block;
  object-fit: contain;
}

.empty-state { margin: 0; }

@media (max-width: 760px) {
  .content-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 20px; }
  /* flex-basis from the desktop row layout applies to height once column, not width */
  .topbar-branding, .topbar-right { flex-basis: auto; }
  .topbar-right { justify-content: flex-start; }

  /* Merge the "Revenus/Dépenses/Restant" summary and "Répartition par type de
     budget" panels into a single visual block instead of two stacked frosted
     cards — the wrapper becomes the only panel (same frosted-glass look as
     every other .panel); its children lose their own
     background/border/shadow/padding and are separated by a thin divider. */
  .summary-budget-grid {
    grid-template-columns: 1fr;
    gap: 0;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.28));
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 14px 16px;
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    will-change: backdrop-filter;
    transform: translateZ(0);
  }
  body.dark .summary-budget-grid {
    background: linear-gradient(165deg, rgba(30, 41, 59, 0.55), rgba(15, 23, 42, 0.28));
    border-color: rgba(148, 163, 184, 0.18);
  }
  body.high-contrast .summary-budget-grid {
    background: var(--panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .summary-budget-grid .panel {
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0;
    border-radius: 0;
  }
  .summary-budget-grid #dash-budget-types {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--panel-border);
  }
  .summary-budget-grid .metric-card { padding: 8px 12px; }
  .summary-budget-grid .summary-stack { gap: 6px; }
}

/* ---- High contrast theme ---- */
body.high-contrast {
  --bg: #000000;
  --bg-elevated: #0a0a0a;
  --panel: #0a0a0a;
  --panel-border: #ffffff;
  --text: #ffffff;
  --muted: #d4d4d8;
  --primary: #ffd600;
  --primary-soft: rgba(255, 214, 0, 0.25);
  --success: #22ff88;
  --success-soft: rgba(34, 255, 136, 0.2);
  --danger: #ff4d4d;
  --danger-soft: rgba(255, 77, 77, 0.2);
  --shadow: none;
  --brand-color: #ffd600;
}
body.high-contrast .primary-button { background: var(--primary); color: #000; font-weight: 700; }
body.high-contrast .panel, body.high-contrast .metric-card { border-width: 2px; }

/* ---- Navigation ---- */
.nav-link {
  padding: 8px 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: var(--primary-soft); color: var(--text); }
.nav-link-active { background: var(--primary-soft); color: var(--primary); }

/* ---- Chips / filters ---- */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.filter-row input, .filter-row select { width: auto; min-width: 120px; flex: 1 1 auto; }
.filter-row label { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.filter-group-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.period-inline-label {
  display: inline-flex;
  align-items: center;
  margin-top: 0;
  padding-right: 4px;
}
.nav-row { justify-content: center; gap: 14px; }
.nav-row-label { min-width: 110px; text-align: center; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip-active { background: var(--primary); color: white; border-color: transparent; }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warning { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

/* ---- Breadcrumb ---- */
.breadcrumb { display: flex; gap: 4px; font-size: 0.85rem; }
.breadcrumb-link { color: var(--primary); cursor: pointer; }
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb-current { color: var(--muted); font-weight: 600; }
.breadcrumb-sep { color: var(--muted); }

/* ---- Sankey ---- */
/* No fixed height: the container grows to the SVG's own height (computed from
   the data in sankey.js), so there's never a vertical scrollbar to fight. */
.sankey-panel {
  min-height: 220px;
  overflow: hidden;
}
/* Soft, blurred color blobs behind the chart — decorative only (never intercepts
   clicks), the classic glassmorphism "light through frosted glass" cue. Clipped
   by the panel's own overflow:hidden so they never bleed into neighboring panels.
   The frosted gradient/blur itself now lives on the shared .panel base class. */
.sankey-panel::before,
.sankey-panel::after {
  content: '';
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}
.sankey-panel::before { top: -80px; left: -60px; background: var(--success); }
.sankey-panel::after { bottom: -100px; right: -60px; background: var(--primary); }
.sankey-panel > * { position: relative; z-index: 1; }

body.high-contrast .sankey-panel::before,
body.high-contrast .sankey-panel::after { display: none; }

.sankey-panel-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
}
.sankey-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.sankey-title-row h2 { margin: 0; }

.sankey-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Round icon-only buttons (expand / export) — same visual family as .nav-arrow
   and .info-icon so every small circular control in the app reads consistently. */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-button:hover {
  transform: translateY(-1px);
  background: var(--primary-soft);
}

.sankey-container { width: 100%; overflow-x: auto; overflow-y: visible; }
.sankey-container svg { display: block; }
.sankey-label { font-size: 12px; fill: var(--text); font-weight: 600; }

/* Ribbon hover highlight — brought forward from the (transparent) wider hit-path
   so a thin flow is easy to trace even though its own visible stroke is thin. */
.sankey-link { transition: stroke-opacity 0.15s ease; }
.sankey-link.sankey-link-active {
  stroke-opacity: 0.85;
  filter: drop-shadow(0 0 4px rgba(15, 23, 42, 0.25));
}
.sankey-node-rect { transition: filter 0.15s ease; }
.sankey-node-rect:hover { filter: url(#sankeyNodeShadow) brightness(1.1); }

/* ---- Modal / popin (shared by the Sankey "view large" popin and other dialogs) ---- */
dialog.modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}
.modal { max-width: min(92vw, 640px); }
dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}
dialog.modal .panel-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}
.modal-header h3 { margin: 0; }

.sankey-modal {
  max-width: min(96vw, 1500px);
  width: min(96vw, 1500px);
  height: min(92vh, 1000px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.sankey-modal .modal-header { flex: none; }
.sankey-modal .sankey-container {
  flex: 1;
  min-height: 0;
  padding: 20px;
  overflow: auto;
}

@media (max-width: 640px) {
  .sankey-modal { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
  .sankey-modal .sankey-container { padding: 12px; }
  .sankey-title-row { flex-wrap: wrap; }
}

/* ---- Import mapping ---- */
.mapping-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 160px;
}

/* ---- Toasts ---- */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 340px;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--success); color: var(--success); }

@media (max-width: 640px) {
  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row input, .filter-row select { width: 100%; }

  /* Keep the month shortcut chips flowing/wrapping instead of stacking one-per-line. */
  .filter-row-chips { flex-direction: row; flex-wrap: wrap; }
  .filter-row-chips .chip { flex: 0 1 auto; }

  /* Keep prev/current/next as one visually grouped horizontal row. */
  .nav-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; }
  .nav-row .nav-arrow { flex: 0 0 auto; padding: 10px 16px; font-size: 1.1rem; }
  .nav-row .nav-row-label { flex: 1 1 auto; text-align: center; color: var(--muted); font-size: 0.85rem; }

  /* Combined period row: wrap onto multiple lines rather than stacking every
     single chip/arrow on its own line; the whole prev/pill(s)/next navigator
     gets its own centered line since it's the widest single unit. */
  .period-row-combined { flex-direction: row; flex-wrap: wrap; }
  .sankey-detail-level-row { flex-direction: row; flex-wrap: wrap; }
  .row-divider { display: none; }
  .period-nav-group { justify-content: center; width: 100%; order: 1; }
  .monthly-toggle-group { width: 100%; justify-content: center; order: 2; }
}

@media (max-width: 640px) {
  .panel-header { flex-wrap: wrap; row-gap: 8px; }
  .panel { padding: 14px 14px; }
  .metric-card { padding: 10px 14px; }
  .sankey-panel { min-height: 200px; }
  .sankey-label { font-size: 13px; }
  .transaction-right { flex-wrap: wrap; justify-content: flex-end; }
}


