/* =========================================================================
   Expense Manager — Design System & App Styles
   Palette/card language ported from the ProductivityVault reference:
   deep glass cards, gradient icon tiles, glow-on-hover, always-dark sidebar.
   Sections:
   1. Reset & base           7. Cards                     13. Toasts
   2. Design tokens          8. Buttons                    14. Skeletons
   3. Typography             9. Forms & fields              15. Charts
   4. App shell layout       10. Chips                     16. Transaction lists
   5. Sidebar (desktop)      11. Bottom sheets              17. History screen
   6. Topbar / Tabbar        12. Modals                    18. Reports / Settings
                                                             19. Empty states / a11y
                                                             20. Auth page
   ========================================================================= */

/* ---------------------------------------------------------------------- */
/* 1. Reset & base                                                        */
/* ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 15% 8%,  var(--bg-glow) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 82% 82%, var(--bg-glow-2) 0%, transparent 50%),
    radial-gradient(ellipse 50% 50% at 50% 45%, var(--bg-glow-3) 0%, transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}
ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

/* Gradient scrollbar, matching the reference's global scrollbar treatment */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--accent-500), var(--accent2)); border-radius: 4px; }

/* ---------------------------------------------------------------------- */
/* 2. Design tokens                                                        */
/* ---------------------------------------------------------------------- */
:root {
  /* Spacing scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px; --sp-9: 48px;

  /* Radii */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-full: 999px;

  /* Motion */
  --dur-fast: 150ms;  --dur-base: 220ms; --dur-slow: 320ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* Accent + semantic colours are constant across light/dark — only the
     "canvas" tokens below (surfaces, text, shadows) flip per theme. */
  --accent-50: #eef2ff;  --accent-100: #dde6fe; --accent-400: #8fa8fb;
  --accent-500: #6d8ff8; --accent-600: #5474e0; --accent-700: #435fc0;
  --accent2: #8b3cf0; /* gradient second stop */
  --purple-500: #b06aff;
  --teal-500: #00e5cc;

  --income-500: #0ee5a0; --income-600: #0bc488;
  --expense-500: #ff4d6d; --expense-600: #e0395a;
  --warn-500: #ffb830;

  /* Gradients (two-stop, 135deg) */
  --grad-primary: linear-gradient(135deg, #6d8ff8 0%, #8b3cf0 100%);
  --grad-income:  linear-gradient(135deg, #0ee5a0 0%, #00b4d8 100%);
  --grad-expense: linear-gradient(135deg, #ff4d6d 0%, #c2185b 100%);
  --grad-warn:    linear-gradient(135deg, #ffb830 0%, #f97316 100%);
  --grad-purple:  linear-gradient(135deg, #b06aff 0%, #6d8ff8 100%);
  --grad-teal:    linear-gradient(135deg, #00e5cc 0%, #00b4d8 100%);

  /* Sidebar is intentionally dark in BOTH themes; these tokens + the
     translucent overlay/border stay constant regardless of --bg/--text. */
  --sidebar-glass: rgba(255, 255, 255, 0.07);
  --sidebar-border: rgba(109, 143, 248, 0.22);
  --sidebar-text: #8b9dc9;
  --sidebar-text-hover: #e6ecff;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Light theme (default canvas — "system" falls back to this unless the OS
   prefers dark, handled by the media query below) */
:root, [data-theme="light"] {
  --bg: #eef2ff;
  --surface: #ffffff;
  --surface-alt: #f0f4ff;
  --surface-raised: #ffffff;
  --border: #d0d9f5;
  --border-2: #b0bce0;
  --text: #141930;
  --text-muted: #3f5080;
  --text-faint: #7888b0;
  --accent: var(--accent-500);
  --accent-contrast: #ffffff;

  --card: rgba(255, 255, 255, 0.98);
  --glass: rgba(0, 0, 0, 0.03);
  --glass2: rgba(0, 0, 0, 0.05);

  --shadow-sm: 0 2px 8px rgba(80, 100, 200, 0.09);
  --shadow-md: 0 4px 24px rgba(80, 100, 200, 0.12);
  --shadow-lg: 0 24px 64px rgba(80, 100, 200, 0.18);
  --shadow-glow: 0 0 24px rgba(109, 143, 248, 0.2);
  --backdrop: rgba(20, 18, 40, 0.28);

  --skeleton-base: #e8edfb;
  --skeleton-shine: #f5f8ff;

  --bg-glow: rgba(109, 143, 248, 0.1);
  --bg-glow-2: rgba(139, 60, 240, 0.08);
  --bg-glow-3: rgba(14, 229, 160, 0.05);

  /* Sidebar stays dark for punch even on the light theme — matches reference */
  --sidebar-t: #161b50;
  --sidebar-b: #05071a;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #07090f;
  --surface: #0c0f1d;
  --surface-alt: #111524;
  --surface-raised: #161b2e;
  --border: #1c2240;
  --border-2: #263059;
  --text: #e6ecff;
  --text-muted: #7b8db8;
  --text-faint: #4a5880;
  --accent: var(--accent-500);
  --accent-contrast: #ffffff;

  --card: rgba(13, 16, 32, 0.9);
  --glass: rgba(255, 255, 255, 0.04);
  --glass2: rgba(255, 255, 255, 0.07);

  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(109, 143, 248, 0.25);
  --backdrop: rgba(3, 4, 10, 0.7);

  --skeleton-base: #161b2e;
  --skeleton-shine: #212a48;

  --bg-glow: rgba(109, 143, 248, 0.09);
  --bg-glow-2: rgba(139, 60, 240, 0.08);
  --bg-glow-3: rgba(0, 229, 204, 0.04);

  --sidebar-t: #0b0f20;
  --sidebar-b: #080b17;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07090f;
    --surface: #0c0f1d;
    --surface-alt: #111524;
    --surface-raised: #161b2e;
    --border: #1c2240;
    --border-2: #263059;
    --text: #e6ecff;
    --text-muted: #7b8db8;
    --text-faint: #4a5880;
    --card: rgba(13, 16, 32, 0.9);
    --glass: rgba(255, 255, 255, 0.04);
    --glass2: rgba(255, 255, 255, 0.07);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 24px rgba(109, 143, 248, 0.25);
    --backdrop: rgba(3, 4, 10, 0.7);
    --skeleton-base: #161b2e;
    --skeleton-shine: #212a48;
    --bg-glow: rgba(109, 143, 248, 0.09);
    --bg-glow-2: rgba(139, 60, 240, 0.08);
    --bg-glow-3: rgba(0, 229, 204, 0.04);
    --sidebar-t: #0b0f20;
    --sidebar-b: #080b17;
  }
}

/* ---------------------------------------------------------------------- */
/* 3. Typography                                                          */
/* ---------------------------------------------------------------------- */
h1, h2, h3 { font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: 16px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.amt-expense { color: var(--expense-500); }
.amt-income { color: var(--income-500); }
.link-more { font-size: 13px; color: var(--accent); font-weight: 600; }

.gradient-text {
  background: var(--grad-primary); background-clip: text; -webkit-background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}

/* ---------------------------------------------------------------------- */
/* 4. App shell layout                                                     */
/* ---------------------------------------------------------------------- */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-9) + var(--safe-bottom) + 80px);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.screens { flex: 1; position: relative; }
.screen {
  display: none;
  position: relative;
  min-height: calc(100dvh - 56px);
  padding-top: calc(56px + var(--safe-top));
}
.screen.is-active { display: block; }
.screen.slide-in-right { animation: slideInRight var(--dur-slow) var(--ease); }
.screen.slide-in-left { animation: slideInLeft var(--dur-slow) var(--ease); }
@keyframes slideInRight { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideInLeft  { from { transform: translateX(-24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------------------------------------------------------------- */
/* 5. Sidebar (desktop / tablet) — always dark, in both themes            */
/* ---------------------------------------------------------------------- */
.sidebar { display: none; }

@media (min-width: 768px) {
  .app-shell { flex-direction: row; }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 76px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar-t) 0%, var(--sidebar-b) 100%);
    border-right: 1px solid var(--sidebar-border);
    padding: var(--sp-5) var(--sp-2);
    position: sticky;
    top: 0;
    height: 100dvh;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }
  .sidebar-brand { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); padding: var(--sp-2) 0 var(--sp-6); color: var(--accent-400); }
  .sidebar-title {
    display: none; font-weight: 700; font-size: 16px;
    background: var(--grad-primary); background-clip: text; -webkit-background-clip: text;
    color: transparent; -webkit-text-fill-color: transparent;
  }
  .sidebar-nav { display: flex; flex-direction: column; gap: var(--sp-1); flex: 1; }
  .sidebar-link {
    position: relative;
    display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
    padding: var(--sp-3); border-radius: var(--r-md); color: var(--sidebar-text);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  }
  .sidebar-link .nav-label { display: none; }
  .sidebar-link:hover { background: var(--sidebar-glass); color: var(--sidebar-text-hover); }
  .sidebar-link:active { transform: scale(0.96); }
  .sidebar-link.is-active {
    background: linear-gradient(135deg, rgba(109,143,248,0.2) 0%, rgba(139,60,240,0.14) 100%);
    color: var(--accent-400); font-weight: 620;
    box-shadow: inset 0 1px 0 rgba(109,143,248,0.15);
  }
  .sidebar-link.is-active::before {
    content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 20px; border-radius: var(--r-full); background: var(--grad-primary);
    box-shadow: 0 0 8px rgba(109,143,248,0.6);
  }
  .sidebar-footer { display: flex; flex-direction: column; gap: 2px; padding-top: var(--sp-3); border-top: 1px solid var(--sidebar-border); }
  .sidebar-logout { color: var(--sidebar-text); width: 100%; }
  .sidebar-logout:hover { background: var(--sidebar-glass); color: var(--sidebar-text-hover); }

  .screen { min-height: 100dvh; padding-top: var(--sp-6); }
  .container { padding: var(--sp-6) var(--sp-7) var(--sp-9); max-width: 1080px; }
}

@media (min-width: 1024px) {
  .sidebar { width: 240px; align-items: stretch; padding: var(--sp-5) var(--sp-4); }
  .sidebar-brand { justify-content: flex-start; padding-left: var(--sp-2); }
  .sidebar-title { display: inline; }
  .sidebar-link { justify-content: flex-start; }
  .sidebar-link .nav-label { display: inline; font-weight: 560; font-size: 14px; }
  .dash-charts-grid { grid-template-columns: 1.2fr 1fr; }
}

/* ---------------------------------------------------------------------- */
/* 6. Topbar / Tabbar (mobile)                                            */
/* ---------------------------------------------------------------------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; gap: var(--sp-2);
  padding-left: var(--sp-4); padding-right: var(--sp-4);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(109, 143, 248, 0.14);
  box-shadow: 0 1px 0 rgba(109,143,248,0.08), 0 4px 20px rgba(0,0,0,0.12);
}
.topbar-title {
  flex: 1; font-size: 17px; font-weight: 700;
  background: linear-gradient(90deg, var(--text) 55%, var(--accent-500) 100%);
  background-clip: text; -webkit-background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
.topbar-action {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-full); color: var(--text);
}
.topbar-action:active { background: var(--glass2); transform: scale(0.94); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-around;
  padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(109, 143, 248, 0.14);
}
.tabbar-link {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 56px; min-height: 48px; justify-content: center;
  color: var(--text-faint); border-radius: var(--r-md);
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.tabbar-link .tabbar-label { font-size: 11px; font-weight: 560; }
.tabbar-link.is-active { color: var(--accent-500); transform: scale(1.04); }
.tabbar-link:active { transform: scale(0.94); }

.tabbar-fab {
  width: 56px; height: 56px; border-radius: var(--r-full);
  background: var(--grad-primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(109,143,248,0.45), 0 2px 6px rgba(139,60,240,0.3);
  transform: translateY(-14px);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.tabbar-fab:active { transform: translateY(-14px) scale(0.92); }

@media (min-width: 768px) {
  .topbar { display: none; }
  .tabbar { display: none; }
  .app-shell > .toast-stack { bottom: var(--sp-6); }
}

/* ---------------------------------------------------------------------- */
/* 7. Cards — glass surface, blur, glow-on-hover (mirrors .stat-card)      */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; flex-direction: column; gap: var(--sp-3);
  position: relative; overflow: hidden;
  transition: box-shadow var(--dur-base) var(--ease), transform var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease);
}
.card::after {
  content: ""; position: absolute; inset: 0; opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
  background: radial-gradient(ellipse at center, var(--glass2) 0%, transparent 70%);
}
@media (hover: hover) and (min-width: 768px) {
  .card:hover { box-shadow: var(--shadow-md), var(--shadow-glow); border-color: var(--border-2); transform: translateY(-2px); }
  .card:hover::after { opacity: 1; }
}

/* Tinted "big" cards (dashboard/report panels) — colored top border always;
   the vivid gradient wash only in light theme, matching the reference. */
.card--tint-blue, .card--tint-green, .card--tint-amber, .card--tint-purple {
  border-top-width: 3px; border-top-style: solid;
}
.card--tint-blue   { border-top-color: rgba(109,143,248,0.6); }
.card--tint-green  { border-top-color: rgba(14,229,160,0.6); }
.card--tint-amber  { border-top-color: rgba(255,184,48,0.6); }
.card--tint-purple { border-top-color: rgba(176,106,255,0.6); }

[data-theme="light"] .card--tint-blue {
  background: linear-gradient(160deg, rgba(109,143,248,0.1) 0%, rgba(255,255,255,0.97) 55%, rgba(139,60,240,0.05) 100%);
}
[data-theme="light"] .card--tint-green {
  background: linear-gradient(160deg, rgba(14,229,160,0.12) 0%, rgba(255,255,255,0.97) 55%, rgba(0,180,216,0.05) 100%);
}
[data-theme="light"] .card--tint-amber {
  background: linear-gradient(160deg, rgba(255,184,48,0.12) 0%, rgba(255,255,255,0.97) 55%, rgba(249,115,22,0.05) 100%);
}
[data-theme="light"] .card--tint-purple {
  background: linear-gradient(160deg, rgba(176,106,255,0.1) 0%, rgba(255,255,255,0.97) 55%, rgba(109,143,248,0.05) 100%);
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); position: relative; }

.dash-greeting { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-1) 0; }
.dash-hello { font-size: 20px; font-weight: 700; }
.dash-date { color: var(--text-muted); font-size: 13px; }

.dash-summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
.dash-summary-grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 640px) { .dash-summary-grid:not(.dash-summary-grid--3) { grid-template-columns: repeat(4, 1fr); } }
/* Below ~380px, two/three columns leave too little room for currency values
   to fit without truncating — drop to one column so nothing gets cut off. */
@media (max-width: 380px) {
  .dash-summary-grid, .dash-summary-grid--3 { grid-template-columns: 1fr; }
}

/* Icon left, value+label stacked right — compact single row like a stat tile */
.summary-card {
  flex-direction: row; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4);
  min-height: 68px;
}
.summary-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }

.summary-icon {
  width: 40px; height: 40px; border-radius: var(--r-md); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
  position: relative;
}
.summary-icon--balance  { background: var(--grad-primary); box-shadow: 0 4px 14px rgba(109,143,248,0.35); }
.summary-icon--expense  { background: var(--grad-expense); box-shadow: 0 4px 14px rgba(255,77,109,0.3); }
.summary-icon--income   { background: var(--grad-income);  box-shadow: 0 4px 14px rgba(14,229,160,0.3); }
.summary-icon--category { background: var(--grad-warn);    box-shadow: 0 4px 14px rgba(255,184,48,0.3); }

.summary-label {
  font-size: 11.5px; color: var(--text-muted); font-weight: 600; position: relative;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.summary-value {
  font-size: 17px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
  line-height: 1.2; position: relative;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.summary-value--sm { font-size: 14px; }
@media (min-width: 480px) { .summary-value { font-size: 19px; } }
@media (min-width: 1024px) { .summary-value { font-size: 21px; } }

/* Light theme: pastel tint per card, matching each icon's colour */
[data-theme="light"] .summary-card:has(.summary-icon--balance) {
  background: linear-gradient(135deg, rgba(109,143,248,0.15) 0%, rgba(235,240,255,0.9) 100%);
  border-color: rgba(109,143,248,0.25);
}
[data-theme="light"] .summary-card:has(.summary-icon--expense) {
  background: linear-gradient(135deg, rgba(255,77,109,0.12) 0%, rgba(255,235,240,0.92) 100%);
  border-color: rgba(255,77,109,0.22);
}
[data-theme="light"] .summary-card:has(.summary-icon--income) {
  background: linear-gradient(135deg, rgba(14,229,160,0.15) 0%, rgba(230,255,248,0.92) 100%);
  border-color: rgba(14,229,160,0.25);
}
[data-theme="light"] .summary-card:has(.summary-icon--category) {
  background: linear-gradient(135deg, rgba(255,184,48,0.15) 0%, rgba(255,252,235,0.92) 100%);
  border-color: rgba(255,184,48,0.28);
}

.dash-charts-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
.chart-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.chart-wrap canvas { max-width: 100%; }

.progress-track { height: 10px; border-radius: var(--r-full); background: var(--surface-alt); overflow: hidden; margin-top: var(--sp-2); }
.progress-fill { height: 100%; border-radius: var(--r-full); background: var(--grad-primary); transition: width var(--dur-slow) var(--ease); }
.progress-fill.is-over { background: var(--grad-expense); }

.budget-summary-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.budget-spent { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.budget-spent .muted { font-size: 14px; font-weight: 600; margin: 0 2px; }
.budget-percent-badge {
  flex-shrink: 0; font-size: 12.5px; font-weight: 700; padding: 4px 11px; border-radius: var(--r-full);
  background: rgba(14,229,160,0.16); color: var(--income-500); white-space: nowrap;
}
.budget-percent-badge.is-over { background: rgba(255,77,109,0.16); color: var(--expense-500); }

/* ---------------------------------------------------------------------- */
/* 8. Buttons                                                              */
/* ---------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-5);
  border-radius: var(--r-md); font-weight: 600; font-size: 14px;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--grad-primary); color: #fff; box-shadow: 0 2px 12px rgba(109,143,248,0.35); }
@media (hover: hover) {
  .btn-primary:hover { box-shadow: 0 6px 20px rgba(109,143,248,0.5); transform: translateY(-2px); filter: brightness(1.08); }
  .btn-primary:active { transform: translateY(0) scale(0.97); }
}
.btn-secondary { background: var(--glass2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-2); }
.btn-danger { background: var(--grad-expense); color: #fff; box-shadow: 0 2px 12px rgba(255,77,109,0.32); }
.btn-danger-outline { background: rgba(255,77,109,0.1); color: var(--expense-500); border: 1.5px solid rgba(255,77,109,0.35); }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 15.5px; }
.btn-sm { min-height: 36px; padding: 0 var(--sp-3); font-size: 13px; }
.btn-icon-text { gap: var(--sp-2); position: relative; }
.btn-chip { min-height: 36px; padding: 0 var(--sp-3); border-radius: var(--r-full); background: var(--glass2); border: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.icon-btn {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-full); color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--glass2); color: var(--accent-500); }
.icon-btn:active { transform: scale(0.92); }

/* ---------------------------------------------------------------------- */
/* 9. Forms & fields                                                       */
/* ---------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field-inline { flex-direction: row; align-items: center; gap: var(--sp-2); }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field-block { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-row { display: flex; gap: var(--sp-3); }
.field-row > * { flex: 1; }
.field-error { color: var(--expense-500); font-size: 13px; font-weight: 560; margin: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="date"], input[type="month"], select {
  height: 46px; padding: 0 var(--sp-4); border-radius: var(--r-md);
  border: 1.5px solid var(--border); background: var(--surface-alt); color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  width: 100%;
}
input::placeholder { color: var(--text-faint); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent-500); outline-offset: 2px;
}
input:focus, select:focus { border-color: var(--accent-500); box-shadow: 0 0 0 3px rgba(109,143,248,0.15); }
.form-grid { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ---------------------------------------------------------------------- */
/* 10. Chips                                                               */
/* ---------------------------------------------------------------------- */
.chip-row { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; touch-action: pan-x; }
.chip-row::-webkit-scrollbar { display: none; }
@media (hover: hover) and (min-width: 768px) {
  .chip-row { cursor: grab; }
  .chip-row.is-dragging { cursor: grabbing; user-select: none; }
  .chip-row.is-dragging .chip { pointer-events: none; }
}
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: 40px; padding: 0 var(--sp-4);
  border-radius: var(--r-full); background: var(--glass2); border: 1.5px solid var(--border);
  font-size: 13.5px; font-weight: 600; color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease);
}
.chip:active { transform: scale(0.96); }
.chip.is-active {
  background: linear-gradient(135deg, rgba(109,143,248,0.22) 0%, rgba(139,60,240,0.14) 100%);
  border-color: rgba(109,143,248,0.4); color: var(--accent-400);
}
.chip-swatch { width: 18px; height: 18px; border-radius: var(--r-full); flex-shrink: 0; }

.type-toggle { display: flex; background: var(--glass2); border-radius: var(--r-full); padding: 4px; gap: 4px; }
.type-toggle-btn { flex: 1; min-height: 40px; border-radius: var(--r-full); font-weight: 650; color: var(--text-muted); transition: all var(--dur-fast) var(--ease); }
.type-toggle-btn.is-active[data-type="expense"] { background: var(--grad-expense); color: #fff; box-shadow: 0 3px 10px rgba(255,77,109,0.35); }
.type-toggle-btn.is-active[data-type="income"] { background: var(--grad-income); color: #fff; box-shadow: 0 3px 10px rgba(14,229,160,0.35); }

.filter-badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: var(--r-full); background: var(--grad-expense); color: #fff;
  font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}

/* ---------------------------------------------------------------------- */
/* 11. Bottom sheets (mobile) / centered modal (desktop)                   */
/* ---------------------------------------------------------------------- */
.overlay-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: var(--backdrop);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity var(--dur-base) var(--ease);
}
.overlay-backdrop.is-visible { opacity: 1; }

.txn-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 90dvh; overflow-y: auto;
  padding: var(--sp-2) var(--sp-5) calc(var(--sp-6) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease);
  touch-action: pan-y;
}
.txn-sheet.is-open { transform: translateY(0); }
.txn-sheet-handle { display: flex; justify-content: center; padding: var(--sp-2) 0; cursor: grab; }
.txn-sheet-handle span { width: 36px; height: 4px; border-radius: var(--r-full); background: var(--border-2); }
.txn-sheet-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: var(--sp-3); }
.txn-form { display: flex; flex-direction: column; gap: var(--sp-4); }

.amount-field {
  display: flex; align-items: center; gap: var(--sp-2);
  border-bottom: 2px solid var(--border); padding: var(--sp-3) var(--sp-1);
}
.amount-currency { font-size: 28px; font-weight: 700; color: var(--text-muted); }
.amount-field input {
  border: none; background: transparent; height: auto; padding: 0;
  font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.amount-field input:focus { outline: none; }
.date-row { display: flex; gap: var(--sp-2); align-items: center; }
.date-row input { flex: 1; }

@media (min-width: 768px) {
  .txn-sheet, #filterSheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: min(480px, 92vw);
    border-radius: var(--r-xl); border-bottom: 1px solid var(--border);
    transform: translate(-50%, -46%) scale(0.96); opacity: 0;
    transition: transform var(--dur-base) var(--ease), opacity var(--dur-base) var(--ease);
    pointer-events: none;
  }
  .txn-sheet.is-open, #filterSheet.is-open {
    transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto;
  }
  .txn-sheet-handle { display: none; }
}

/* ---------------------------------------------------------------------- */
/* 12. Modals                                                              */
/* ---------------------------------------------------------------------- */
.confirm-modal, .entity-modal {
  position: fixed; left: 50%; top: 50%; z-index: 61;
  width: min(420px, 90vw);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg), 0 0 0 1px rgba(109,143,248,0.08);
  padding: var(--sp-6);
  transform: translate(-50%, -50%) scale(0.94); opacity: 0;
  transition: transform var(--dur-base) var(--ease), opacity var(--dur-base) var(--ease);
  pointer-events: none;
  max-height: 88dvh; overflow-y: auto;
}
.confirm-modal.is-open, .entity-modal.is-open { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
.confirm-modal h2 { margin-bottom: var(--sp-2); }
.confirm-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }
.confirm-actions .btn { flex: 1; }
.entity-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }

.icon-picker, .color-picker { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.icon-swatch, .color-swatch {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--border); background: var(--glass2); color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease);
}
.icon-swatch.is-selected { border-color: var(--accent-500); background: rgba(109,143,248,0.16); color: var(--accent-400); }
.color-swatch { border-radius: var(--r-full); border-width: 3px; border-color: transparent; }
.color-swatch.is-selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

/* ---------------------------------------------------------------------- */
/* 13. Toasts                                                              */
/* ---------------------------------------------------------------------- */
.toast-stack {
  position: fixed; left: 0; right: 0; bottom: calc(72px + var(--safe-bottom) + var(--sp-3)); z-index: 80;
  display: flex; flex-direction: column-reverse; align-items: center; gap: var(--sp-2);
  pointer-events: none; padding: 0 var(--sp-4);
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--sp-2);
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-alt) 100%); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(109,143,248,0.08); font-size: 13.5px; font-weight: 560;
  max-width: 420px; width: 100%;
  animation: toastIn var(--dur-base) var(--ease);
}
.toast.is-leaving { animation: toastOut var(--dur-base) var(--ease) forwards; }
.toast--success { border-left: 3px solid var(--income-500); }
.toast--error { border-left: 3px solid var(--expense-500); }
.toast--info { border-left: 3px solid var(--accent-500); }
@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateY(16px); opacity: 0; } }

@media (min-width: 768px) { .toast-stack { bottom: var(--sp-6); left: auto; right: var(--sp-6); align-items: flex-end; } }

/* ---------------------------------------------------------------------- */
/* 14. Skeletons                                                           */
/* ---------------------------------------------------------------------- */
.skeleton {
  position: relative; overflow: hidden; background: var(--skeleton-base); border-radius: var(--r-sm);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skel-line { height: 14px; border-radius: 4px; margin: 4px 0; }
.skel-card { height: 92px; border-radius: var(--r-xl); }
.skel-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; }
.skel-circle { width: 40px; height: 40px; border-radius: var(--r-full); flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* 15. Charts                                                              */
/* ---------------------------------------------------------------------- */
.donut-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); justify-content: center; }
.donut-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.donut-legend-dot { width: 9px; height: 9px; border-radius: var(--r-full); }

/* ---------------------------------------------------------------------- */
/* 16. Transaction lists                                                   */
/* ---------------------------------------------------------------------- */
.txn-list { display: flex; flex-direction: column; }
.txn-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--border);
  position: relative; background: transparent;
}
.txn-row:last-child { border-bottom: none; }
.txn-icon {
  width: 42px; height: 42px; border-radius: var(--r-md); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.txn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.txn-title { font-weight: 620; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-sub { font-size: 12.5px; color: var(--text-muted); }
.txn-amount { font-weight: 700; font-size: 15px; flex-shrink: 0; }

.txn-row-wrap { position: relative; overflow: hidden; }
.txn-swipe-actions {
  position: absolute; top: 0; right: 0; bottom: 0; display: flex; transform: translateX(100%);
  transition: transform var(--dur-fast) var(--ease);
}
.txn-row-wrap.is-swiped .txn-swipe-actions { transform: translateX(0); }
.txn-row-wrap.is-swiped .txn-row { transform: translateX(-136px); }
.txn-row { transition: transform var(--dur-fast) var(--ease); }
.swipe-btn { width: 68px; display: flex; align-items: center; justify-content: center; color: #fff; }
.swipe-btn--edit { background: var(--grad-primary); }
.swipe-btn--delete { background: var(--grad-expense); }

.day-group { display: flex; flex-direction: column; gap: 0; margin-bottom: var(--sp-3); }
.day-group-head { display: flex; align-items: baseline; justify-content: space-between; padding: var(--sp-2) 0; }
.day-group-date { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.day-group-total { font-size: 13px; font-weight: 700; }
.day-group-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 0 var(--sp-4); box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

/* ---------------------------------------------------------------------- */
/* 17. History screen                                                      */
/* ---------------------------------------------------------------------- */
.history-toolbar { display: flex; gap: var(--sp-3); align-items: center; }
.search-field {
  flex: 1; display: flex; align-items: center; gap: var(--sp-2);
  height: 44px; padding: 0 var(--sp-4); border-radius: var(--r-md);
  background: var(--surface-alt); border: 1.5px solid var(--border); color: var(--text-muted);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.search-field:focus-within { border-color: var(--accent-500); box-shadow: 0 0 0 3px rgba(109,143,248,0.15); }
.search-field input { border: none; background: transparent; height: auto; padding: 0; color: var(--text); }
.search-field input:focus { outline: none; }
.load-more-wrap { display: flex; justify-content: center; padding: var(--sp-2) 0; }

.pull-refresh {
  position: absolute; top: calc(-48px + var(--safe-top)); left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; height: 48px;
  color: var(--accent-500); opacity: 0; transition: opacity var(--dur-fast) var(--ease);
}
.pull-refresh.is-visible { opacity: 1; }
.pull-spinner {
  width: 22px; height: 22px; border-radius: var(--r-full);
  border: 2.5px solid var(--accent-100); border-top-color: var(--accent-500);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------- */
/* 18. Reports / Settings                                                  */
/* ---------------------------------------------------------------------- */
.reports-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

.table-scroll { display: none; overflow-x: auto; }
.data-table th, .data-table td { text-align: left; padding: var(--sp-3); font-size: 13.5px; border-bottom: 1px solid var(--border); }
.data-table th {
  color: var(--text-muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  background: linear-gradient(90deg, var(--glass2) 0%, transparent 100%);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--glass); }
.txn-list--report { display: flex; }
@media (min-width: 1024px) {
  .table-scroll { display: block; }
  .txn-list--report { display: none; }
}

.settings-tabs { display: flex; gap: var(--sp-2); background: var(--glass2); padding: 4px; border-radius: var(--r-full); }
.settings-tab { flex: 1; min-height: 40px; border-radius: var(--r-full); font-weight: 620; font-size: 13.5px; color: var(--text-muted); }
.settings-tab.is-active { background: var(--surface); color: var(--accent-500); box-shadow: var(--shadow-sm); }
.settings-panel { display: none; flex-direction: column; gap: var(--sp-4); margin-top: var(--sp-4); }
.settings-panel.is-active { display: flex; }
.settings-panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

.admin-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.admin-row {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-3); box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.admin-row:hover { border-color: var(--border-2); }
.admin-row.is-inactive { opacity: 0.55; }
.admin-row-handle { color: var(--text-faint); cursor: grab; touch-action: none; }
.admin-row-icon {
  width: 38px; height: 38px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0; font-weight: 700; font-size: 13px;
}
.role-badge {
  flex-shrink: 0; padding: 3px 10px; border-radius: var(--r-full); font-size: 11px; font-weight: 700; white-space: nowrap;
}
.role-badge--admin { background: rgba(176,106,255,0.18); color: var(--purple-500); }
.role-badge--user { background: var(--glass2); color: var(--text-muted); }
.admin-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.admin-row-name { font-weight: 620; font-size: 14.5px; }
.admin-row-meta { font-size: 12px; color: var(--text-muted); }
.admin-row-actions { display: flex; align-items: center; gap: var(--sp-1); }
.admin-row.dragging { opacity: 0.5; }

.switch { position: relative; width: 40px; height: 24px; border-radius: var(--r-full); background: var(--border); flex-shrink: 0; transition: background var(--dur-fast) var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: var(--r-full); background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-fast) var(--ease); }
.switch.is-on { background: var(--grad-income); }
.switch.is-on::after { transform: translateX(16px); }

/* ---------------------------------------------------------------------- */
/* 19. Empty states / accessibility                                        */
/* ---------------------------------------------------------------------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-8) var(--sp-4); color: var(--text-muted); }
.empty-state svg { width: 96px; height: 96px; color: var(--text-faint); }
.empty-state h3 { color: var(--text); font-size: 16px; }
.empty-state p { font-size: 13.5px; max-width: 280px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------------- */
/* 20. Auth page (login.php)                                               */
/* ---------------------------------------------------------------------- */
.auth-shell {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--sp-5);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 60% at 20% 40%, var(--bg-glow) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 80% 20%, var(--bg-glow-2) 0%, transparent 50%),
    radial-gradient(ellipse 50% 50% at 50% 80%, var(--bg-glow-3) 0%, transparent 55%);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(109,143,248,0.1);
  padding: var(--sp-7) var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); text-align: center; }
.auth-logo {
  width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--grad-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(109,143,248,0.4);
}
.auth-brand h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.auth-sub { color: var(--text-muted); font-size: 13.5px; }
.auth-tabs { display: flex; gap: var(--sp-2); background: var(--glass2); padding: 4px; border-radius: var(--r-full); }
.auth-tab { flex: 1; min-height: 40px; border-radius: var(--r-full); font-weight: 620; font-size: 13.5px; color: var(--text-muted); }
.auth-tab.is-active { background: var(--surface); color: var(--accent-500); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-4); }
.auth-hint { text-align: center; font-size: 12px; color: var(--text-faint); }
.auth-hint code { background: var(--glass2); padding: 2px 6px; border-radius: 4px; }

/* Number count-up target uses tabular nums already via body rule */
