/* =============================================================
   Bachat — Personal Expense Tracker · style.css
   Design language: warm "spatial glass" — frosted panels over a
   soft neutral backdrop, Manrope type, green = income,
   coral = expenses.
   -------------------------------------------------------------
   1.  Design tokens (light + dark)
   2.  Base & utilities
   3.  Backdrop & glass surfaces
   4.  App shell: top bar, sidebar, stage, footer
   5.  Shared components
   6.  Dashboard
   7.  Transactions
   8.  Add transaction form
   9.  Budgets
   10. Reports
   11. Settings
   12. Dialogs & toasts
   13. Responsive layouts
   14. Motion & accessibility preferences
   ============================================================= */

@property --pct {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* ---------- 1. Design tokens ---------- */
:root {
  color-scheme: light;
  --bg: #efe7dd;
  --ink: #231c19;
  --muted: #65564d;
  --line: rgb(74 49 33 / 11%);
  --line-strong: rgb(74 49 33 / 17%);
  --rim: rgb(255 255 255 / 30%);
  --rim-hi: rgb(255 255 255 / 100%);
  --rim-lo: rgb(255 255 255 / 25%);
  --edge-light: rgb(255 255 255 / 95%);
  --edge-shade: rgb(57 40 28 / 8%);
  --gloss: rgb(255 255 255 / 58%);
  --inner-glow: rgb(255 255 255 / 24%);
  --glow: rgb(255 255 255 / 60%);
  --glass: rgb(255 255 255 / 28%);
  --glass-strong: rgb(255 253 250 / 76%);
  --tray: rgb(255 255 255 / 24%);
  --card: rgb(255 255 255 / 50%);
  --card-2: rgb(255 255 255 / 26%);
  --inner: rgb(110 78 56 / 6%);
  --inner-strong: rgb(110 78 56 / 11%);
  --raised: rgb(255 255 255 / 66%);
  --glass-blur: 26px;
  --surface: #fbf8f4;
  --track: rgb(81 49 32 / 10%);
  --primary: #231c19;
  --primary-ink: #fffaf5;
  --income: #0b7a55;
  --expense: #b9401f;
  --warn: #a06100;
  --danger-ink: #ffffff;
  --focus: #17695c;
  --chart-grid: rgba(74, 49, 33, 0.1);
  --shadow-rgb: 70 45 28;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.22, .9, .26, 1);
  /* Fine grain that makes glass look frosted rather than flat plastic */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 .5'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1d1613;
  --ink: #fbf1e7;
  --muted: #cbb9aa;
  --line: rgb(243 221 198 / 11%);
  --line-strong: rgb(243 221 198 / 20%);
  --rim: rgb(255 236 212 / 10%);
  --rim-hi: rgb(255 236 212 / 45%);
  --rim-lo: rgb(255 236 212 / 6%);
  --edge-light: rgb(255 242 225 / 22%);
  --edge-shade: rgb(0 0 0 / 30%);
  --gloss: rgb(255 237 213 / 8%);
  --inner-glow: rgb(255 228 205 / 4%);
  --glow: rgb(255 214 180 / 13%);
  --glass: rgb(30 22 19 / 40%);
  --glass-strong: rgb(40 30 27 / 82%);
  --tray: rgb(255 240 225 / 3%);
  --card: rgb(52 40 36 / 50%);
  --card-2: rgb(40 30 27 / 30%);
  --inner: rgb(255 240 225 / 5%);
  --inner-strong: rgb(255 240 225 / 10%);
  --raised: rgb(255 240 225 / 8%);
  --surface: #2b221f;
  --track: rgb(245 226 212 / 13%);
  --primary: #f3ddca;
  --primary-ink: #231a16;
  --income: #5fd3a6;
  --expense: #ff8c6e;
  --warn: #f0bb55;
  --danger-ink: #2a120c;
  --focus: #f9bf9b;
  --chart-grid: rgba(243, 221, 198, 0.1);
  --shadow-rgb: 0 0 0;
}

/* ---------- 2. Base & utilities ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 100px; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.i { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon { width: 18px; height: 18px; flex: none; }

.skip-link {
  position: fixed; left: 16px; top: -60px; z-index: 200;
  padding: 10px 16px; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink); font-weight: 800;
  transition: top .2s;
}
.skip-link:focus { top: 16px; }

/* ---------- 3. Backdrop & glass ---------- */
/* The backdrop is fixed. As cards scroll over the coloured shapes, the frosted glass
   blurs and tints them — that moving refraction is what makes surfaces read as glass. */
.backdrop {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(120% 80% at 0% 0%, #fbf4ec 0%, transparent 55%),
    linear-gradient(160deg, #f3e8dd, #eadbcc 60%, #e4d4c4);
}
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .85; }
.blob-1 { width: 46vw; height: 46vw; left: -12vw; top: -14vw; background: #ffb894; }
.blob-2 { width: 38vw; height: 38vw; right: -8vw; top: 4vh; background: #9fe3c4; }
.blob-3 { width: 42vw; height: 42vw; left: 28vw; bottom: -20vw; background: #ffd27f; }
.blob-4 { width: 28vw; height: 28vw; right: 14vw; bottom: 6vh; background: #d9b8f0; }

/* Crisp "glass marbles" and a ring: sharp shapes make the blur behind each card visible */
.bg-orb {
  position: absolute; aspect-ratio: 1; border-radius: 50%; opacity: .92;
  box-shadow: inset -12px -16px 40px rgb(0 0 0 / 18%), inset 10px 12px 30px rgb(255 255 255 / 45%);
}
.bg-orb-1 { width: clamp(180px, 21vw, 320px); right: 7vw; top: 16vh; background: radial-gradient(circle at 32% 28%, #ffffff 0 5%, #a6f3d6 20%, #2bb38a 56%, #0c6650 100%); }
.bg-orb-2 { width: clamp(220px, 25vw, 380px); left: 20vw; bottom: -9vh; background: radial-gradient(circle at 32% 28%, #fff8f2 0 5%, #ffbb98 22%, #f0643d 62%, #a3321a 100%); }
.bg-orb-3 { width: clamp(110px, 11vw, 170px); left: 3vw; top: 52vh; background: radial-gradient(circle at 32% 28%, #ffffff 0 6%, #ddd0ff 22%, #8a6be0 64%, #4a2ea3 100%); }
.bg-orb-4 { width: clamp(90px, 9vw, 140px); right: 32vw; top: 58vh; background: radial-gradient(circle at 32% 28%, #fffbe8 0 6%, #ffe08a 25%, #f0a92a 64%, #ad6800 100%); }
.bg-ring {
  position: absolute; width: clamp(260px, 30vw, 460px); aspect-ratio: 1; right: -7vw; bottom: -12vh;
  border-radius: 50%; border: clamp(16px, 2vw, 26px) solid rgb(255 255 255 / 60%);
  box-shadow: 0 0 0 1px rgb(255 255 255 / 40%), inset 0 0 0 1px rgb(255 255 255 / 40%);
}

:root[data-theme="dark"] .backdrop { background: linear-gradient(160deg, #261c18, #1c1512 60%, #181210); }
:root[data-theme="dark"] .blob { opacity: .3; }
:root[data-theme="dark"] .bg-orb { opacity: .55; }
:root[data-theme="dark"] .bg-ring { border-color: rgb(255 236 212 / 12%); box-shadow: none; }

/* ---------- Background motion ----------
   Ambient, never distracting. Long loops with different lengths (34–52s) so the pattern
   never visibly repeats, soft in-out easing, and depth: far shapes move least.
   script.js adds mouse parallax, scroll depth and a slow "camera" pan between views by
   setting --mx / --my on .backdrop; each shape multiplies them by its own --depth.
   Settings › Background motion (or the system's reduced-motion setting) turns it all off. */
:root { --spring: cubic-bezier(.34, 1.56, .64, 1); }

.blob, .bg-orb, .bg-ring, .sheen { will-change: transform, translate; }
.blob, .bg-orb, .bg-ring {
  translate: calc(var(--mx, 0px) * var(--depth, 1)) calc(var(--my, 0px) * var(--depth, 1));
}

/* Far layer: colour fields drift, turn and breathe. Uneven corners make a turn read as a change of shape. */
.blob { --depth: .35; border-radius: 42% 58% 61% 39% / 47% 41% 59% 53%; }
.blob-1 { animation: drift-a 38s ease-in-out infinite, bloom-in 1.8s var(--ease) both; }
.blob-2 { animation: drift-b 44s ease-in-out -12s infinite, bloom-in 1.8s var(--ease) .15s both; }
.blob-3 { animation: drift-c 52s ease-in-out -20s infinite, bloom-in 1.8s var(--ease) .3s both; }
.blob-4 { animation: drift-b 34s ease-in-out -6s infinite reverse, bloom-in 1.8s var(--ease) .45s both; }

@keyframes drift-a {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  33%      { transform: translate3d(6vw, 5vh, 0) rotate(28deg) scale(1.08); }
  66%      { transform: translate3d(-3vw, 8vh, 0) rotate(-12deg) scale(.94); }
}
@keyframes drift-b {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  40%      { transform: translate3d(-7vw, 6vh, 0) rotate(-24deg) scale(1.1); }
  70%      { transform: translate3d(-2vw, -5vh, 0) rotate(14deg) scale(.96); }
}
@keyframes drift-c {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  30%      { transform: translate3d(5vw, -6vh, 0) rotate(18deg) scale(1.05); }
  65%      { transform: translate3d(-6vw, -2vh, 0) rotate(-20deg) scale(1.12); }
}
@keyframes bloom-in { from { opacity: 0; scale: .7; } }

/* Mid and near layer: glass balls float like they're suspended in water.
   They never rotate, so their highlight always faces the same light. */
.bg-orb-1 { --depth: 1;   animation: float-a 13s ease-in-out -4s infinite alternate, pop-in 1.3s var(--spring) .35s both; }
.bg-orb-2 { --depth: .85; animation: float-b 17s ease-in-out -9s infinite alternate, pop-in 1.3s var(--spring) .5s both; }
.bg-orb-3 { --depth: .6;  animation: float-a 11s ease-in-out -2s infinite alternate-reverse, pop-in 1.3s var(--spring) .65s both; }
.bg-orb-4 { --depth: .5;  animation: float-b 15s ease-in-out -7s infinite alternate-reverse, pop-in 1.3s var(--spring) .8s both; }
@keyframes float-a { from { transform: translate3d(-12px, 18px, 0) scale(.985); } to { transform: translate3d(14px, -30px, 0) scale(1.02); } }
@keyframes float-b { from { transform: translate3d(16px, 14px, 0) scale(1.015); } to { transform: translate3d(-14px, -26px, 0) scale(.98); } }
@keyframes pop-in { from { opacity: 0; scale: .55; } }

/* The ring spins slowly; a bright glint on its rim makes the rotation visible */
.bg-ring {
  --depth: .8;
  --ring-w: clamp(16px, 2vw, 26px);
  border: 0;
  box-shadow: none;
  background: conic-gradient(from 0deg, rgb(255 255 255 / 22%), rgb(255 255 255 / 95%) 16%, rgb(255 255 255 / 30%) 38%, rgb(255 255 255 / 75%) 64%, rgb(255 255 255 / 22%) 86%, rgb(255 255 255 / 22%));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring-w) - 1px), #000 calc(100% - var(--ring-w)));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring-w) - 1px), #000 calc(100% - var(--ring-w)));
  animation: ring-spin 60s linear infinite, ring-in 2s var(--ease) .6s both;
}
:root[data-theme="dark"] .bg-ring {
  background: conic-gradient(from 0deg, rgb(255 236 212 / 5%), rgb(255 236 212 / 32%) 16%, rgb(255 236 212 / 8%) 38%, rgb(255 236 212 / 22%) 64%, rgb(255 236 212 / 5%) 86%, rgb(255 236 212 / 5%));
}
@keyframes ring-spin { to { transform: rotate(360deg); } }
@keyframes ring-in { from { opacity: 0; scale: .8; rotate: -50deg; } }

/* A soft band of light passes behind the glass every 26s, so the cards shimmer as it crosses */
.sheen {
  position: absolute; top: -50%; left: 0;
  width: 38vw; height: 200%;
  rotate: 18deg;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 38%) 50%, transparent);
  animation: sheen-pass 26s cubic-bezier(.45, 0, .25, 1) 4s infinite both;
  pointer-events: none;
}
:root[data-theme="dark"] .sheen { background: linear-gradient(90deg, transparent, rgb(255 236 212 / 7%) 50%, transparent); }
@keyframes sheen-pass {
  0%       { transform: translateX(-60vw); }
  45%, 100% { transform: translateX(170vw); }
}

/* Motion switched off (Settings) */
.motion-off .backdrop * { animation: none !important; translate: none !important; }
.motion-off .sheen { display: none; }
@media (prefers-reduced-transparency: reduce) { .sheen { display: none; } }

/* Shared glass recipe: translucent tint + strong blur + grain + inner glow */
.glass {
  border: 1px solid var(--rim);
  background:
    var(--noise),
    linear-gradient(160deg, var(--gloss), transparent 38% 68%, var(--gloss)),
    var(--glass);
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    inset 0 -1px 0 var(--edge-shade),
    inset 0 0 30px var(--inner-glow),
    0 16px 44px rgb(var(--shadow-rgb) / 14%);
  backdrop-filter: blur(30px) saturate(1.9);
  -webkit-backdrop-filter: blur(30px) saturate(1.9);
}

/* Gradient rim: bright on the top-left and bottom-right edges, like light catching glass */
.glass::before, .panel::before, .metric::before {
  content: "";
  position: absolute; inset: -1px; z-index: 2;
  padding: 1px; border-radius: inherit;
  background: linear-gradient(150deg, var(--rim-hi), var(--rim-lo) 30%, transparent 50%, var(--rim-lo) 72%, var(--rim-hi));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
}

/* ---------- 4. App shell ---------- */
.shell {
  width: min(100% - 48px, 1440px);
  margin-inline: auto;
  padding: 18px 0 20px;
}

/* Top bar */
.topbar {
  position: sticky; top: 12px; z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 460px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 10px 8px 12px;
  border-radius: 999px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo { width: 38px; height: 38px; border-radius: 13px; box-shadow: 0 3px 10px rgb(var(--shadow-rgb) / 18%); }
.brand-text strong { display: block; font-size: 12.5px; letter-spacing: .18em; font-weight: 800; line-height: 1.1; }
.brand-text { min-width: 0; }
.brand-text small { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ask {
  display: flex; align-items: center; gap: 10px;
  min-height: 46px; min-width: 0;
  padding: 4px 14px 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gloss), transparent 85%), var(--inner);
  box-shadow: inset 0 1px 0 var(--edge-light), inset 0 -1px 0 var(--edge-shade);
  text-align: start;
  transition: background .2s;
}
.ask:hover { background: var(--raised); }
.orb {
  flex: none; width: 27px; height: 27px; border-radius: 50%;
  background:
    radial-gradient(ellipse at 32% 24%, #f8fffb 5%, #8ff0c9 26%, transparent 58%),
    radial-gradient(ellipse at 67% 54%, #9be7c6, #1d8f69 55%, #0b4a3a 80%);
  box-shadow: inset 0 0 0 .75px rgb(240 255 248 / 75%), inset 0 -2px 5px #0e5f48, 0 0 0 3px rgb(20 110 80 / 12%), 0 2px 8px rgb(10 70 50 / 30%);
}
.ask-prompt {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: 12.5px; font-weight: 750;
}
.ask-prompt.typing { animation: type-in .8s steps(32, end) both; }
@keyframes type-in { from { clip-path: inset(0 100% 0 0); } }
.ask-kbd {
  margin-inline-start: auto;
  padding: 2px 7px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--raised);
  font: 700 10.5px/1.5 var(--font); color: var(--muted); white-space: nowrap;
}
.ask-search { color: var(--muted); }
.ask-search .icon { width: 16px; height: 16px; }

.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.notify-dot {
  position: absolute; top: 9px; right: 10px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--expense);
  box-shadow: 0 0 0 2px var(--surface);
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--expense) 15%, transparent); } }

/* Workspace grid */
.workspace {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

/* Sidebar */
.sidebar {
  position: sticky; top: 96px;
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 10px;
  border-radius: 26px;
}
.nav-heading {
  padding: 0 14px 6px;
  font-size: 10.5px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted);
}
.nav-link {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 12px;
  min-height: 46px; padding: 0 14px;
  border-radius: 15px;
  font-weight: 720; color: var(--muted);
  transition: color .2s, background .2s;
}
.nav-link:not([aria-current="page"]):hover { color: var(--ink); background: var(--inner); }
.nav-link[aria-current="page"] { color: var(--ink); }
.nav-link[aria-current="page"] .icon { color: var(--income); }
.nav-short { display: none; }

.nav-indicator {
  position: absolute; top: 0; left: 0; z-index: 0;
  border-radius: 15px;
  border: 1px solid var(--rim-hi);
  background: linear-gradient(160deg, var(--gloss), transparent 70%), var(--raised);
  box-shadow: inset 0 1px 0 var(--edge-light), inset 0 -1px 0 var(--edge-shade), 0 4px 14px rgb(var(--shadow-rgb) / 14%);
  visibility: hidden;
  pointer-events: none;
}
.nav-indicator.ready {
  visibility: visible;
  transition: transform .42s var(--ease), width .42s var(--ease), height .42s var(--ease);
}

.nav-budget {
  display: grid; gap: 8px;
  margin-top: 16px; padding: 14px;
  border-radius: 18px;
  background: var(--inner);
  border: 1px solid var(--line);
  transition: background .2s;
}
.nav-budget:hover { background: var(--inner-strong); }
.nav-budget-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 750; color: var(--muted); }
.nav-budget-head strong { color: var(--ink); }
.nav-budget-text { font-size: 11.5px; color: var(--muted); }

/* Stage */
.stage {
  position: relative;
  min-width: 0;
  min-height: calc(100svh - 150px);
  padding: clamp(20px, 2.4vw, 36px);
  border-radius: 32px;
  outline: none;
}
/* The stage is a clear glass tray with no blur of its own. A blurred parent would stop
   the cards inside it from blurring the backdrop (browsers don't nest backdrop blur). */
.stage.glass {
  background: var(--noise), linear-gradient(160deg, var(--tray), transparent 70%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: inset 0 1px 0 var(--edge-light), inset 0 0 40px var(--inner-glow), 0 20px 60px rgb(var(--shadow-rgb) / 10%);
}

.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 14px 24px;
  margin-bottom: 22px;
}
.eyebrow { margin-bottom: 6px; font-size: 12px; font-weight: 750; color: var(--muted); }
.view-head h1 {
  font-size: clamp(30px, 3.4vw, 46px);
  line-height: 1.04; letter-spacing: -.05em; font-weight: 800;
  outline: none;
}
.view-desc { margin-top: 8px; color: var(--muted); }
.view-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Entrance animation when a view opens. Only the cards themselves animate: fading a
   wrapper would briefly switch off the frosted blur of every card inside it. */
.view.is-entering > :is(.view-head, .banner, .alert-strip, .panel),
.view.is-entering .metric-grid > *,
.view.is-entering :is(.dash-grid, .report-grid, .settings-grid, .budget-grid) > *,
.view.is-entering .add-grid > .panel,
.view.is-entering .add-side > * {
  animation: enter .6s var(--ease) both;
}
.view.is-entering .metric-grid > :nth-child(2) { animation-delay: .04s; }
.view.is-entering .metric-grid > :nth-child(3) { animation-delay: .08s; }
.view.is-entering .metric-grid > :nth-child(4) { animation-delay: .12s; }
.view.is-entering :is(.dash-grid, .report-grid, .settings-grid, .budget-grid, .add-side) > :nth-child(2) { animation-delay: .08s; }
.view.is-entering :is(.dash-grid, .report-grid, .settings-grid, .budget-grid) > :nth-child(3) { animation-delay: .14s; }
.view.is-entering :is(.dash-grid, .report-grid, .settings-grid, .budget-grid) > :nth-child(n+4) { animation-delay: .2s; }
@keyframes enter { from { opacity: 0; transform: translateY(16px) scale(.985); } }

/* Footer */
.footer {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 16px 6px 0;
  font-size: 11.5px; font-weight: 700; color: var(--muted);
}
.footer > span { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--inner); }
.footer .icon { width: 13px; height: 13px; }

/* ---------- 5. Shared components ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 999px;
  font-size: 13px; font-weight: 780; line-height: 1.2; white-space: nowrap;
  transition: transform .15s, filter .2s, background .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn .icon { width: 16px; height: 16px; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 12px; }
.btn-lg { min-height: 48px; padding: 0 22px; }
/* Glossy buttons: a soft white highlight on the top half, like a glass bead */
.btn-primary {
  background: linear-gradient(180deg, rgb(255 255 255 / 16%), transparent 55%), var(--primary);
  color: var(--primary-ink);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 24%), 0 6px 16px rgb(var(--shadow-rgb) / 20%);
}
.btn-primary:hover { filter: brightness(1.2); }
:root[data-theme="dark"] .btn-primary:hover { filter: brightness(1.06); }
.btn-secondary {
  background: linear-gradient(180deg, var(--gloss), transparent 75%), var(--raised);
  border-color: var(--line-strong);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--edge-light), 0 3px 10px rgb(var(--shadow-rgb) / 8%);
}
.btn-secondary:hover { background: linear-gradient(180deg, var(--gloss), transparent 75%), var(--surface); border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--inner-strong); }
.btn-danger { background: var(--expense); color: var(--danger-ink); }
.btn-danger:hover { filter: brightness(1.1); }
.btn-danger-outline { background: transparent; color: var(--expense); border-color: color-mix(in srgb, var(--expense) 45%, transparent); }
.btn-danger-outline:hover { background: color-mix(in srgb, var(--expense) 9%, transparent); }

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--inner);
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: var(--raised); }
.icon-btn:active { transform: scale(.94); }
.icon-btn-sm { width: 34px; height: 34px; }
.icon-btn-sm .icon { width: 15px; height: 15px; }
.icon-btn.danger:hover { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, transparent); }

.segmented {
  display: inline-flex; gap: 2px; padding: 4px;
  border: 1px solid var(--rim); border-radius: 999px;
  background: var(--inner);
  box-shadow: inset 0 1px 0 var(--gloss);
}
.segmented button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 0; border-radius: 999px;
  background: transparent;
  font-size: 12.5px; font-weight: 750; color: var(--muted); white-space: nowrap;
  transition: background .2s, color .2s;
}
.segmented button .icon { width: 15px; height: 15px; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] {
  background: linear-gradient(180deg, rgb(255 255 255 / 16%), transparent 55%), var(--primary);
  color: var(--primary-ink);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 24%), 0 3px 10px rgb(var(--shadow-rgb) / 18%);
}
.segmented-sm button { min-height: 32px; padding: 0 12px; font-size: 12px; }

/* Panels & metric cards: each one is its own frosted-glass pane */
.panel, .metric {
  position: relative;
  isolation: isolate;
  min-width: 0;
  border: 1px solid var(--rim);
  background:
    var(--noise),
    linear-gradient(150deg, var(--gloss), transparent 42%),
    linear-gradient(160deg, var(--card), var(--card-2));
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    inset 0 -1px 0 var(--edge-shade),
    inset 0 0 24px var(--inner-glow),
    0 10px 30px rgb(var(--shadow-rgb) / 9%);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
}
/* Soft light that follows the mouse across a card (position comes from script.js) */
.panel::after, .metric::after {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  border-radius: inherit;
  background: radial-gradient(380px circle at var(--mx, 50%) var(--my, 0%), var(--glow), transparent 45%);
  opacity: 0;
  transition: opacity .35s;
  pointer-events: none;
}
.panel:hover::after, .metric:hover::after { opacity: 1; }

/* Inner wells get a thin top highlight so they read as layers of the same glass */
:is(.budget-row, .budget-facts div, .data-stats div, .nav-budget, .budget-impact, .notice, .preview-card, .month-stepper) {
  box-shadow: inset 0 1px 0 var(--gloss);
}
/* Elements sitting directly on the stage tray can frost the backdrop themselves */
.banner, .alert-pill {
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  box-shadow: inset 0 1px 0 var(--gloss);
}
.panel { padding: 18px 20px; border-radius: 24px; }
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap;
  gap: 8px 14px; margin-bottom: 14px;
}
.panel-head h2 { font-size: 15.5px; font-weight: 800; letter-spacing: -.02em; }
.panel-head p { margin-top: 2px; font-size: 12px; color: var(--muted); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric {
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  min-height: 140px; padding: 16px 18px;
  border-radius: 22px;
  transition: transform .25s var(--ease), box-shadow .25s;
}
.metric:hover { transform: translateY(-3px); box-shadow: inset 0 1px 0 var(--edge-light), inset 0 0 24px var(--inner-glow), 0 18px 38px rgb(var(--shadow-rgb) / 15%); }
.metric-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 750; color: var(--muted); }
.metric-icon {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 12px;
  background: var(--inner-strong); color: var(--ink);
}
.metric-icon .icon { width: 16px; height: 16px; }
.metric[data-tone="income"] .metric-icon { color: var(--income); background: color-mix(in srgb, var(--income) 13%, transparent); }
.metric[data-tone="expense"] .metric-icon { color: var(--expense); background: color-mix(in srgb, var(--expense) 12%, transparent); }
.metric[data-tone="savings"] .metric-icon { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }
.metric-value {
  display: block;
  font-size: clamp(23px, 2.2vw, 33px); line-height: 1.05;
  font-weight: 800; letter-spacing: -.045em;
  overflow-wrap: anywhere;
}
.metric[data-tone="income"] .metric-value { color: var(--income); }
.metric[data-tone="expense"] .metric-value { color: var(--expense); }
.metric-value[data-sign="negative"] { color: var(--expense); }
.metric-caption { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 650; color: var(--muted); }

/* Tinted green glass with a diagonal reflection band */
.metric-feature {
  --rim-hi: rgb(210 255 238 / 90%);
  --rim-lo: rgb(210 255 238 / 20%);
  --glow: rgb(210 255 238 / 22%);
  color: #fff;
  border-color: rgb(196 248 231 / 30%);
  background:
    var(--noise),
    linear-gradient(118deg, rgb(255 255 255 / 16%) 0%, rgb(255 255 255 / 5%) 36%, transparent 36.4%),
    radial-gradient(ellipse at 0% -20%, rgb(84 214 170 / 75%), transparent 65%),
    linear-gradient(145deg, rgb(26 130 98 / 82%), rgb(6 66 54 / 90%));
  box-shadow:
    inset 0 1px 1px rgb(220 255 244 / 75%),
    inset 0 -12px 30px rgb(0 40 30 / 28%),
    0 14px 34px rgb(14 80 62 / 30%);
}
.metric-feature .metric-head, .metric-feature .metric-caption { color: #d9f2e9; }
.metric-feature .metric-icon { background: rgb(255 255 255 / 15%); color: #fff; }
.metric-feature .metric-value { color: #fff; }

.delta {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 800;
}
.delta .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.delta[data-good="true"] { color: var(--income); background: color-mix(in srgb, var(--income) 13%, transparent); }
.delta[data-good="false"] { color: var(--expense); background: color-mix(in srgb, var(--expense) 12%, transparent); }
.delta[data-good="neutral"] { color: var(--muted); background: var(--inner-strong); }
.metric-feature .delta { color: #fff; background: rgb(255 255 255 / 16%); }

/* Inputs */
.field { display: grid; gap: 7px; min-width: 0; margin: 0 0 16px; padding: 0; border: 0; }
.label { font-size: 12.5px; font-weight: 780; padding: 0; }
.optional { margin-left: 4px; font-weight: 650; color: var(--muted); }
.input {
  width: 100%; min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--raised);
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: var(--muted); opacity: .75; }
.input:hover { border-color: color-mix(in srgb, var(--ink) 28%, transparent); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--expense); box-shadow: 0 0 0 3px color-mix(in srgb, var(--expense) 14%, transparent); }
.input-sm { min-height: 36px; padding: 6px 10px; border-radius: 11px; font-size: 13px; }
select.input { appearance: auto; }
textarea.input { min-height: 92px; resize: vertical; }
select option, select optgroup { background: var(--surface); color: var(--ink); }
.field-error { font-size: 12px; font-weight: 700; color: var(--expense); }
.field-error:empty { display: none; }
.field-error::before { content: "⚠ "; }
.field-foot { display: flex; justify-content: space-between; gap: 10px; }
.counter { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.counter[data-near="true"] { color: var(--warn); font-weight: 800; }
.hint { font-size: 12px; color: var(--muted); }
.hint:empty { display: none; }

.input-affix { position: relative; }
.input-affix .affix {
  position: absolute; left: 14px; top: 50%; translate: 0 -50%;
  font-weight: 800; color: var(--muted); pointer-events: none;
}
.input-affix .input { padding-left: 36px; }

.search-field {
  display: flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 13px;
  background: var(--raised);
}
.search-field .icon { width: 16px; height: 16px; color: var(--muted); }
.search-field input { flex: 1; min-width: 0; min-height: 40px; border: 0; background: transparent; outline: none; }
.search-field:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

.select-field {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 42px; padding: 0 6px 0 11px;
  border: 1px solid var(--line-strong); border-radius: 13px;
  background: var(--raised);
}
.select-field .icon { width: 15px; height: 15px; color: var(--muted); }
.select-field select { min-height: 40px; max-width: 190px; border: 0; background: transparent; outline: none; font-size: 13px; font-weight: 680; cursor: pointer; }
.select-field:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

/* Meters & progress */
.meter { display: block; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter-fill {
  display: block; width: 0; height: 100%;
  border-radius: inherit; background: var(--income);
  transition: width .8s var(--ease), background .3s;
}
.meter-fill[data-level="warn"] { background: var(--warn); }
.meter-fill[data-level="over"] { background: var(--expense); }

.status-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 800; white-space: nowrap;
  color: var(--muted); background: var(--inner-strong);
}
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip[data-level="ok"] { color: var(--income); background: color-mix(in srgb, var(--income) 12%, transparent); }
.status-chip[data-level="warn"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.status-chip[data-level="over"] { color: var(--expense); background: color-mix(in srgb, var(--expense) 12%, transparent); }

.cat-icon {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 12px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 15%, transparent);
}
.cat-icon .icon { width: 17px; height: 17px; }
.cat-icon-lg { width: 52px; height: 52px; border-radius: 16px; }
.cat-icon-lg .icon { width: 24px; height: 24px; }
:root[data-theme="dark"] .cat-icon { color: color-mix(in srgb, var(--c) 60%, white); background: color-mix(in srgb, var(--c) 26%, transparent); }

.amount { font-weight: 800; white-space: nowrap; }
.amount[data-type="income"] { color: var(--income); }
.amount[data-type="expense"] { color: var(--expense); }

.legend { display: inline-flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; font-weight: 720; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }

.chart-box { position: relative; min-width: 0; height: 250px; }
.chart-box canvas { display: block; }
.chart-note {
  position: absolute; inset: 0;
  display: grid; place-items: center; padding: 20px;
  text-align: center; font-size: 12.5px; font-weight: 700; color: var(--muted);
}

.banner {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding: 12px 12px 12px 16px;
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--income) 28%, transparent);
  background: color-mix(in srgb, var(--income) 9%, var(--card));
}
.banner p { flex: 1; font-size: 13px; }
.banner-icon { color: var(--income); }
.banner-actions { display: flex; align-items: center; gap: 6px; }

.empty-state { display: grid; justify-items: center; gap: 6px; padding: 34px 16px; text-align: center; }
.empty-icon {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 6px;
  border-radius: 18px; background: var(--inner-strong); color: var(--muted);
}
.empty-icon .icon { width: 26px; height: 26px; }
.empty-state h3 { font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
.empty-state p { max-width: 360px; font-size: 13px; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
.muted-note { padding: 8px; font-size: 12px; color: var(--muted); }

/* Tables */
.table-wrap { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th {
  padding: 10px 12px;
  background: var(--inner);
  font-size: 11.5px; font-weight: 800; text-align: left; color: var(--muted); white-space: nowrap;
}
.data-table th:first-child { border-radius: 10px 0 0 10px; }
.data-table th:last-child { border-radius: 0 10px 10px 0; }
.data-table td { padding: 12px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.data-table tbody tr:first-child td { border-top: 0; }
.data-table tbody tr { transition: background .15s; }
.data-table tbody tr:hover { background: var(--inner); }
.data-table .num { text-align: right; }

/* ---------- 6. Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 14px; }
/* Panels stretch to the row height; line/bar charts grow to fill that space. */
.dash-grid > .panel { display: flex; flex-direction: column; }
.chart-flow, .chart-monthly { flex: 1 1 0; height: auto; min-height: 250px; }
.chart-flow canvas, .chart-monthly canvas { position: absolute; inset: 0; }
.chart-donut { height: 190px; max-width: 210px; margin-inline: auto; }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
  pointer-events: none;
}
.donut-center strong { font-size: 19px; font-weight: 800; letter-spacing: -.04em; }
.donut-center span { font-size: 11.5px; color: var(--muted); }

.cat-legend { display: grid; gap: 2px; margin-top: 14px; }
.cat-legend-row {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 40px; align-items: center; gap: 10px;
  width: 100%; min-height: 34px; padding: 4px 8px;
  border: 0; border-radius: 10px; background: transparent; text-align: left;
  transition: background .15s, opacity .2s;
}
.cat-legend-row:hover { background: var(--inner); }
.cat-legend-row[aria-pressed="false"] { opacity: .4; }
.cat-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12.5px; font-weight: 720; }
.cat-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.bar-track { height: 5px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: inherit; background: var(--c); }
.cat-legend-row strong { font-size: 12px; text-align: right; }

.recent-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.tx-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 9px 8px; border-radius: 14px;
  transition: background .15s;
}
.tx-row:hover { background: var(--inner); }
.tx-main { min-width: 0; }
.tx-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 760; }
.tx-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }

/* ---------- 7. Transactions ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar .search-field { flex: 1 1 260px; }
.toolbar-second { margin-top: 10px; }
.custom-range { display: flex; flex-wrap: wrap; gap: 8px; }
.custom-range label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 750; color: var(--muted); }
.custom-range .input { width: auto; }

.tx-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 16px 0 10px;
  font-size: 12.5px; color: var(--muted);
}
.tx-summary strong { color: var(--ink); }
.sum-pill { padding: 3px 10px; border-radius: 999px; background: var(--inner-strong); font-weight: 750; color: var(--ink); }
.sum-pill[data-type="income"] { color: var(--income); background: color-mix(in srgb, var(--income) 11%, transparent); }
.sum-pill[data-type="expense"] { color: var(--expense); background: color-mix(in srgb, var(--expense) 10%, transparent); }
.range-note { color: var(--warn); font-weight: 750; }

.tx-table .c-date { white-space: nowrap; color: var(--muted); font-weight: 650; }
.tx-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; max-width: 360px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--inner-strong); font-size: 12px; font-weight: 720; white-space: nowrap;
}
.type-pill {
  display: inline-flex; padding: 3px 9px; border-radius: 7px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
}
.type-pill[data-type="income"] { color: var(--income); background: color-mix(in srgb, var(--income) 12%, transparent); }
.type-pill[data-type="expense"] { color: var(--expense); background: color-mix(in srgb, var(--expense) 11%, transparent); }
.tx-table .c-amount { font-size: 14px; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.more-wrap { display: flex; justify-content: center; margin-top: 14px; }
.more-wrap:has(> [hidden]:only-child) { display: none; }

/* ---------- 8. Add transaction ---------- */
.add-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.form-panel { padding: 22px 24px; }
.add-side { display: grid; gap: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-option {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px;
  border: 1px solid var(--line-strong); border-radius: 15px;
  background: var(--raised);
  font-weight: 800; color: var(--muted);
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s, transform .15s;
}
.type-option:active { transform: scale(.98); }
.type-option input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.type-option:has(input:checked)[data-type="expense"] { color: var(--expense); border-color: var(--expense); background: color-mix(in srgb, var(--expense) 9%, var(--raised)); }
.type-option:has(input:checked)[data-type="income"] { color: var(--income); border-color: var(--income); background: color-mix(in srgb, var(--income) 10%, var(--raised)); }
.type-option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.form-success {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 18px; padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--income) 32%, transparent); border-radius: 15px;
  background: color-mix(in srgb, var(--income) 11%, var(--raised));
  color: var(--income); font-weight: 750;
  animation: pop .45s var(--ease);
}
.form-success .icon { width: 20px; height: 20px; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(-6px); } }

.preview-card { padding: 6px; border: 1px dashed var(--line-strong); border-radius: 18px; background: var(--inner); }
.preview-note { padding: 2px 10px 8px 58px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.budget-impact { display: grid; gap: 8px; margin-top: 14px; padding: 12px 14px; border-radius: 16px; background: var(--inner); }
.budget-impact-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 750; }
.budget-impact p { font-size: 12px; color: var(--muted); }

.mini-stats { display: grid; gap: 2px; }
.mini-stat { display: flex; justify-content: space-between; align-items: center; padding: 9px 4px; border-top: 1px solid var(--line); font-size: 13px; }
.mini-stat:first-child { border-top: 0; }
.mini-stat span { color: var(--muted); font-weight: 650; }

/* ---------- 9. Budgets ---------- */
.alert-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.alert-strip:empty { display: none; }
.alert-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  font-size: 12.5px; font-weight: 750;
  border: 1px solid transparent;
}
.alert-pill .icon { width: 15px; height: 15px; }
.alert-pill[data-level="over"] { color: var(--expense); background: color-mix(in srgb, var(--expense) 10%, var(--card)); border-color: color-mix(in srgb, var(--expense) 30%, transparent); }
.alert-pill[data-level="warn"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 11%, var(--card)); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert-pill[data-level="ok"] { color: var(--income); background: color-mix(in srgb, var(--income) 10%, var(--card)); border-color: color-mix(in srgb, var(--income) 28%, transparent); }

.budget-grid { display: grid; grid-template-columns: minmax(280px, .85fr) minmax(0, 1.6fr); gap: 14px; align-items: start; }
.budget-overview { position: sticky; top: 100px; }

.ring {
  --pct: 0;
  --ring-color: var(--income);
  display: grid; place-items: center;
  width: min(190px, 70%); aspect-ratio: 1;
  margin: 4px auto 20px;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--pct) * 1%), var(--track) 0);
  transition: --pct 1s var(--ease);
}
.ring[data-level="warn"] { --ring-color: var(--warn); }
.ring[data-level="over"] { --ring-color: var(--expense); }
.ring-inner {
  display: grid; place-content: center; text-align: center;
  width: calc(100% - 30px); aspect-ratio: 1; border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 2px 8px rgb(var(--shadow-rgb) / 10%);
}
.ring-inner strong { font-size: 32px; font-weight: 800; letter-spacing: -.05em; line-height: 1.1; }
.ring-inner span { font-size: 12px; color: var(--muted); }

.budget-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.budget-facts div { padding: 10px; border-radius: 14px; background: var(--inner); }
.budget-facts dt { font-size: 11px; font-weight: 750; color: var(--muted); }
.budget-facts dd { margin-top: 2px; font-size: 14px; font-weight: 800; overflow-wrap: anywhere; }

.unsaved {
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 800;
  color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent);
}

.budget-list { display: grid; gap: 8px; margin-bottom: 16px; }
.budget-row {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.5fr) 160px; align-items: center; gap: 16px;
  padding: 12px 14px;
  border: 1px solid transparent; border-radius: 17px;
  background: var(--inner);
  transition: border-color .3s, background .3s;
}
.budget-row[data-level="warn"] { border-color: color-mix(in srgb, var(--warn) 38%, transparent); }
.budget-row[data-level="over"] { border-color: color-mix(in srgb, var(--expense) 40%, transparent); background: color-mix(in srgb, var(--expense) 6%, var(--inner)); }
.budget-name { display: flex; align-items: center; gap: 11px; min-width: 0; }
.budget-name strong { display: block; font-size: 13.5px; font-weight: 780; }
.budget-name small { display: block; font-size: 12px; color: var(--muted); }
.budget-progress-text { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 7px; font-size: 11.5px; color: var(--muted); }
.budget-input .input { min-height: 40px; }
.budget-input .field-error { margin-top: 4px; }

/* ---------- 10. Reports ---------- */
.report-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.9fr); gap: 14px; }
.report-grid .span-full { grid-column: 1 / -1; }
.chart-daily { height: 260px; }
.chart-breakdown { height: 300px; }
.chart-year { height: 300px; }

.top-cat { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.top-cat strong { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.03em; }
.top-cat span { font-size: 12.5px; color: var(--muted); }
.top-cat + .meter .meter-fill { background: var(--c); }
.fact-list { display: grid; margin-top: 16px; }
.fact-list div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); font-size: 12.5px; }
.fact-list dt { color: var(--muted); font-weight: 650; }
.fact-list dd { font-weight: 800; text-align: right; overflow-wrap: anywhere; }

.summary-table tr[data-selected="true"] td { background: color-mix(in srgb, var(--income) 8%, transparent); }
.summary-table tr[data-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--income); }
.summary-table tfoot td { border-top: 2px solid var(--line-strong); font-weight: 800; }
.rate { font-weight: 800; }
.rate[data-good="true"] { color: var(--income); }
.rate[data-good="false"] { color: var(--expense); }

.month-stepper { display: inline-flex; align-items: center; gap: 6px; padding: 4px; border-radius: 999px; border: 1px solid var(--rim); background: var(--inner); }
.month-input { width: 170px; text-align: center; border-radius: 999px; }

/* ---------- 11. Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.setting-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.panel-head + .setting-row, .data-stats + .setting-row { border-top: 0; padding-top: 4px; }
.setting-row strong { font-size: 13.5px; font-weight: 780; }
.setting-row p { max-width: 340px; font-size: 12px; color: var(--muted); }
.setting-select { width: auto; min-width: 190px; }
.danger-zone { border-color: color-mix(in srgb, var(--expense) 28%, var(--rim)); }
.danger-zone .panel-head h2 { color: var(--expense); }

.data-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.data-stats div { padding: 10px 12px; border-radius: 14px; background: var(--inner); }
.data-stats span { display: block; font-size: 11px; font-weight: 750; color: var(--muted); }
.data-stats strong { font-size: 16px; font-weight: 800; }

.switch {
  position: relative; flex: none;
  width: 50px; height: 30px; padding: 0;
  border: 0; border-radius: 999px;
  background: var(--track);
  transition: background .25s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 22%);
  transition: transform .3s var(--ease);
}
.switch[aria-checked="true"] { background: var(--income); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ---------- 12. Dialogs & toasts ---------- */
.dialog {
  width: min(100% - 32px, 440px);
  padding: 0;
  border: 1px solid var(--rim-hi); border-radius: 26px;
  background: var(--noise), linear-gradient(160deg, var(--gloss), transparent 50%), var(--glass-strong);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--edge-light), inset 0 0 30px var(--inner-glow), 0 30px 90px rgb(var(--shadow-rgb) / 35%);
  backdrop-filter: blur(36px) saturate(1.8);
  -webkit-backdrop-filter: blur(36px) saturate(1.8);
}
.dialog[open] { animation: dialog-in .32s var(--ease); }
.dialog::backdrop { background: rgb(30 21 17 / 30%); backdrop-filter: blur(3px) saturate(1.2); -webkit-backdrop-filter: blur(3px) saturate(1.2); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.dialog-inner { padding: 22px; }
.dialog-icon {
  display: grid; place-items: center;
  width: 50px; height: 50px; margin-bottom: 14px;
  border-radius: 16px;
  color: var(--expense); background: color-mix(in srgb, var(--expense) 13%, transparent);
}
.dialog-icon .icon { width: 22px; height: 22px; }
.dialog h2 { font-size: 21px; font-weight: 800; letter-spacing: -.03em; }
.dialog-inner > p { margin-top: 6px; color: var(--muted); overflow-wrap: anywhere; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }

.dialog-search { width: min(100% - 32px, 580px); margin-top: 11vh; }
.search-head { display: flex; gap: 8px; }
.search-head .search-field { flex: 1; }
.search-field-lg { min-height: 50px; }
.search-field-lg input { font-size: 15px; }
.search-results { display: grid; gap: 4px; max-height: 56vh; margin-top: 14px; overflow-y: auto; }
.search-group { padding: 8px 6px 4px; font-size: 10.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.search-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--inner); text-align: left;
  transition: background .15s;
}
.search-item:hover, .search-item:focus-visible { background: var(--raised); }
.search-item .view-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--inner-strong); }
.search-item > .icon { color: var(--muted); }

.notice {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 8px;
  border-radius: 16px; background: var(--inner);
  border: 1px solid transparent;
}
.notice[data-level="over"] { border-color: color-mix(in srgb, var(--expense) 35%, transparent); }
.notice[data-level="warn"] { border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.notice strong { display: block; font-size: 13.5px; }
.notice small { display: block; margin-bottom: 7px; font-size: 12px; color: var(--muted); }
.notice-pct { font-weight: 800; }
.notice[data-level="over"] .notice-pct { color: var(--expense); }
.notice[data-level="warn"] .notice-pct { color: var(--warn); }
.notice-off { margin-bottom: 12px; padding: 10px 12px; border-radius: 12px; background: var(--inner); font-size: 12.5px; color: var(--muted); }

.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: grid; gap: 8px;
  width: min(380px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 10px 11px 14px;
  border: 1px solid var(--rim); border-radius: 17px;
  background: var(--glass-strong);
  box-shadow: 0 14px 40px rgb(var(--shadow-rgb) / 20%);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  animation: toast-in .4s var(--ease);
}
.toast.leaving { animation: toast-out .28s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.96); } }
.toast p { flex: 1; font-size: 13px; font-weight: 650; }
.toast-icon { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 10px; }
.toast-icon .icon { width: 16px; height: 16px; }
.toast[data-tone="success"] .toast-icon { color: var(--income); background: color-mix(in srgb, var(--income) 14%, transparent); }
.toast[data-tone="danger"] .toast-icon { color: var(--expense); background: color-mix(in srgb, var(--expense) 13%, transparent); }
.toast[data-tone="warn"] .toast-icon { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.toast[data-tone="info"] .toast-icon { color: var(--ink); background: var(--inner-strong); }
.toast-action {
  padding: 6px 12px; border: 0; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink);
  font-size: 12px; font-weight: 800;
}
.toast-close { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.toast-close:hover { background: var(--inner-strong); }
.toast-close .icon { width: 15px; height: 15px; }

/* ---------- 13. Responsive layouts ---------- */
@media (max-width: 1240px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .budget-row { grid-template-columns: minmax(0, 1fr) 150px; }
  .budget-progress { grid-column: 1 / -1; grid-row: 2; }
}

/* Tablet: sidebar collapses to icons */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding: 10px 8px; }
  .nav-heading, .nav-budget { display: none; }
  .nav-link { justify-content: center; padding: 0; }
  .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .nav-link::after {
    content: attr(data-tip);
    position: absolute; left: calc(100% + 12px); top: 50%; translate: 0 -50%;
    padding: 6px 10px; border-radius: 9px;
    border: 1px solid var(--rim); background: var(--surface);
    box-shadow: 0 6px 18px rgb(var(--shadow-rgb) / 16%);
    font-size: 12px; font-weight: 750; color: var(--ink); white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .15s;
  }
  .nav-link:hover::after, .nav-link:focus-visible::after { opacity: 1; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
}

@media (max-width: 920px) {
  .dash-grid, .add-grid, .budget-grid, .report-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .budget-overview { position: relative; }
  .brand-text { display: none; }
}

/* Phone: sidebar becomes a bottom dock */
@media (max-width: 760px) {
  .shell { width: calc(100% - 20px); padding-top: 10px; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; top: 8px; border-radius: 24px; }
  .brand-text { display: block; }
  .ask { grid-column: 1 / -1; grid-row: 2; }
  .ask-kbd, .top-add { display: none; }
  .workspace { display: block; margin-top: 12px; }

  .sidebar {
    position: fixed; top: auto; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 30;
    flex-direction: row; justify-content: space-between; gap: 2px;
    padding: 6px; border-radius: 999px;
  }
  /* Six equal buttons. min-width: 0 lets them shrink below their label width, and the
     label size scales with the screen (10px from 375px wide, down to 8.5px on tiny phones). */
  .nav-link { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; min-height: 54px; padding: 4px 1px; border-radius: 999px; font-size: clamp(8.5px, 2.75vw, 10px); }
  .nav-link::after { display: none; }
  /* Last resort on the very smallest screens: end the label with "…" instead of spilling out */
  .nav-short { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.1; }
  .nav-indicator { border-radius: 999px; }
  .nav-add .i { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); }
  .nav-add[aria-current="page"] .icon { color: var(--primary-ink); }

  .stage { min-height: 0; padding: 18px 14px; border-radius: 24px; }
  .view-head { align-items: flex-start; flex-direction: column; margin-bottom: 16px; }
  .view-actions { width: 100%; }
  .segmented { max-width: 100%; overflow-x: auto; }
  .metric-grid { gap: 10px; }
  .metric { min-height: 118px; padding: 14px; border-radius: 18px; }
  .panel { padding: 16px; border-radius: 20px; }
  .form-panel { padding: 18px 16px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .banner { flex-wrap: wrap; }
  .toolbar .select-field { flex: 1 1 45%; }
  .select-field select { max-width: none; width: 100%; }

  /* Transaction table turns into stacked cards */
  .tx-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tx-table, .tx-table tbody { display: block; }
  .tx-table tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    padding: 12px; margin-bottom: 8px;
    border: 1px solid var(--line); border-radius: 16px; background: var(--inner);
  }
  .tx-table td { display: block; padding: 0; border: 0; }
  .tx-table .c-tx { order: 1; flex: 1 1 60%; min-width: 0; }
  .tx-table .c-amount { order: 2; margin-left: auto; }
  .tx-table .c-cat { order: 3; }
  .tx-table .c-type { order: 4; }
  .tx-table .c-date { order: 5; font-size: 12px; }
  .tx-table .c-actions { order: 6; margin-left: auto; }
  .tx-cell { min-width: 0; }

  .budget-facts { grid-template-columns: 1fr 1fr 1fr; }
  .data-stats { grid-template-columns: 1fr 1fr 1fr; }
  .month-stepper { width: 100%; justify-content: space-between; }
  .month-input { flex: 1; width: auto; }
  .toasts { left: 12px; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); width: auto; }
  .dialog-search { margin-top: 6vh; }
}

@media (max-width: 420px) {
  .metric-value { font-size: 21px; }
  .metric-head { font-size: 11.5px; }
  .metric-icon { width: 28px; height: 28px; border-radius: 10px; }
  .segmented button { padding: 0 10px; font-size: 12px; }
  .budget-row { grid-template-columns: 1fr; }
  .budget-progress { grid-row: auto; }
  .budget-facts dd { font-size: 12.5px; }
  .form-actions .btn { flex: 1; }
}

/* Very narrow phones (360px and below, e.g. the original iPhone SE): give the bottom menu every pixel */
@media (max-width: 360px) {
  .sidebar { left: 6px; right: 6px; padding: 5px; gap: 0; }
  .nav-add .i { width: 27px; height: 27px; }
}

/* Phones: keep the backdrop shapes at the edges so they never sit behind headings */
@media (max-width: 760px) {
  .bg-orb-1 { width: 170px; right: -60px; top: 1vh; }
  .bg-orb-2 { width: 220px; left: -70px; bottom: 8vh; }
  .bg-orb-3 { width: 90px; left: auto; right: -20px; top: 60vh; }
  .bg-orb-4 { display: none; }
  .bg-ring { width: 240px; right: -120px; bottom: 26vh; }
}

/* ---------- 14. Motion & accessibility preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .glass, .panel, .metric:not(.metric-feature), .toast, .dialog { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .bg-orb, .bg-ring { display: none; }
}
/* Browsers without backdrop blur get solid cards so text stays readable */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .panel, .metric:not(.metric-feature), .dialog, .toast { background: var(--surface); }
}
@media (forced-colors: active) {
  .panel, .metric, .glass, .btn, .icon-btn, .segmented button { border: 1px solid CanvasText; }
  .segmented button[aria-pressed="true"], .nav-link[aria-current="page"] { outline: 2px solid Highlight; }
}
