/* ── Google Fonts ────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
  --bg:            #f8fafc;
  --surface:       #ffffff;
  --surface2:      #f9fafb;
  --surface3:      #f1f5f9;
  --border:        #e5e7eb;
  --border-light:  #f3f4f6;
  --text:          #111827;
  --text-muted:    #6b7280;
  --text-label:    #4b5563;
  --sidebar-from:  #1e3a5f;
  --sidebar-to:    #0f172a;
  --sidebar-text:  rgba(255,255,255,.88);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.1);
  --sidebar-active:#3b82f6;
  --primary:       #3b82f6;
  --primary-light: #eff6ff;
  --primary-dark:  #2563eb;
  --success:       #10b981;
  --success-light: #ecfdf5;
  --success-dark:  #059669;
  --danger:        #ef4444;
  --danger-light:  #fef2f2;
  --warning:       #f59e0b;
  --warning-light: #fffbeb;
  --purple:        #8b5cf6;
  --purple-light:  #f5f3ff;
  --teal:          #14b8a6;
  --teal-light:    #f0fdfa;
  --pink:          #ec4899;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.03);
  --shadow:        0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg:     0 10px 20px -5px rgba(0,0,0,.07), 0 6px 8px -4px rgba(0,0,0,.03);
  --shadow-xl:     0 20px 40px -10px rgba(0,0,0,.08);
  --radius:        14px;
  --radius-sm:     10px;
  --radius-xs:     6px;
  --th-bg:         #f9fafb;
  --th-color:      #6b7280;
  --progress-bg:   #e5e7eb;
  --input-bg:      #ffffff;
  --input-border:  #e5e7eb;
  --card-glow:     rgba(59,130,246,.05);
  --gradient-1:    linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-2:    linear-gradient(135deg, #10b981, #14b8a6);
  --gradient-3:    linear-gradient(135deg, #f59e0b, #ef4444);
  /* Density custom properties (overridden by JS) */
  --page-padding:  2.25rem 2.5rem;
  --card-padding:  1.35rem 1.4rem;
  --panel-padding: 1.75rem;
  --cell-padding:  .85rem 1.1rem;
  --grid-gap:      1.1rem;
}

[data-theme="dark"] {
  --bg:            #0a0f1e;
  --surface:       #111827;
  --surface2:      #1a2234;
  --surface3:      #0f1629;
  --border:        #1e2d45;
  --border-light:  #1a2234;
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --text-label:    #cbd5e1;
  --sidebar-from:  #0a0f1e;
  --sidebar-to:    #050810;
  --sidebar-text:  rgba(255,255,255,.85);
  --sidebar-muted: rgba(255,255,255,.3);
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active:#3b82f6;
  --primary:       #60a5fa;
  --primary-light: rgba(96,165,250,.15);
  --primary-dark:  #3b82f6;
  --success:       #34d399;
  --success-light: rgba(52,211,153,.15);
  --success-dark:  #10b981;
  --danger:        #f87171;
  --danger-light:  rgba(248,113,113,.15);
  --warning:       #fbbf24;
  --warning-light: rgba(251,191,36,.15);
  --purple:        #a78bfa;
  --purple-light:  rgba(167,139,250,.15);
  --teal:          #2dd4bf;
  --teal-light:    rgba(45,212,191,.15);
  --shadow-sm:     0 1px 3px rgba(0,0,0,.4);
  --shadow:        0 4px 6px -1px rgba(0,0,0,.5);
  --shadow-lg:     0 10px 25px -5px rgba(0,0,0,.6);
  --shadow-xl:     0 20px 40px -10px rgba(0,0,0,.7);
  --th-bg:         #1a2234;
  --th-color:      #94a3b8;
  --progress-bg:   #1e2d45;
  --input-bg:      #1a2234;
  --input-border:  #1e2d45;
  --card-glow:     rgba(96,165,250,.06);
  --gradient-1:    linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-2:    linear-gradient(135deg, #10b981, #14b8a6);
  --gradient-3:    linear-gradient(135deg, #f59e0b, #ef4444);
}

[data-theme="ocean"] {
  --bg:            #e8f4fc;
  --surface:       #ffffff;
  --surface2:      #f0f9ff;
  --surface3:      #e0f2fe;
  --border:        #bae6fd;
  --border-light:  #e0f2fe;
  --text:          #0c4a6e;
  --text-muted:    #0369a1;
  --text-label:    #075985;
  --sidebar-from:  #0369a1;
  --sidebar-to:    #0c4a6e;
  --sidebar-text:  rgba(255,255,255,.9);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.12);
  --sidebar-active:#38bdf8;
  --primary:       #0284c7;
  --primary-light: #e0f2fe;
  --primary-dark:  #0369a1;
  --success:       #059669;
  --success-light: #d1fae5;
  --success-dark:  #047857;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --purple:        #7c3aed;
  --purple-light:  #ede9fe;
  --teal:          #0891b2;
  --teal-light:    #cffafe;
  --shadow-sm:     0 1px 3px rgba(3,105,161,.08);
  --shadow:        0 4px 6px -1px rgba(3,105,161,.1);
  --shadow-lg:     0 10px 25px -5px rgba(3,105,161,.12);
  --shadow-xl:     0 20px 40px -10px rgba(3,105,161,.15);
  --th-bg:         #e0f2fe;
  --th-color:      #0369a1;
  --progress-bg:   #bae6fd;
  --input-bg:      #ffffff;
  --input-border:  #bae6fd;
  --card-glow:     rgba(2,132,199,.06);
}

[data-theme="forest"] {
  --bg:            #ecfdf5;
  --surface:       #ffffff;
  --surface2:      #f0fdf4;
  --surface3:      #dcfce7;
  --border:        #bbf7d0;
  --border-light:  #dcfce7;
  --text:          #14532d;
  --text-muted:    #166534;
  --text-label:    #15803d;
  --sidebar-from:  #166534;
  --sidebar-to:    #14532d;
  --sidebar-text:  rgba(255,255,255,.9);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.12);
  --sidebar-active:#4ade80;
  --primary:       #16a34a;
  --primary-light: #dcfce7;
  --primary-dark:  #15803d;
  --success:       #15803d;
  --success-light: #d1fae5;
  --success-dark:  #166534;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --purple:        #7c3aed;
  --purple-light:  #ede9fe;
  --teal:          #0d9488;
  --teal-light:    #ccfbf1;
  --shadow-sm:     0 1px 3px rgba(22,101,52,.06);
  --shadow:        0 4px 6px -1px rgba(22,101,52,.08);
  --shadow-lg:     0 10px 25px -5px rgba(22,101,52,.1);
  --shadow-xl:     0 20px 40px -10px rgba(22,101,52,.12);
  --th-bg:         #dcfce7;
  --th-color:      #166534;
  --progress-bg:   #bbf7d0;
  --input-bg:      #ffffff;
  --input-border:  #bbf7d0;
  --card-glow:     rgba(22,163,74,.06);
}

[data-theme="sunset"] {
  --bg:            #fff7ed;
  --surface:       #ffffff;
  --surface2:      #fffbf5;
  --surface3:      #ffedd5;
  --border:        #fed7aa;
  --border-light:  #ffedd5;
  --text:          #431407;
  --text-muted:    #9a3412;
  --text-label:    #c2410c;
  --sidebar-from:  #c2410c;
  --sidebar-to:    #7c2d12;
  --sidebar-text:  rgba(255,255,255,.9);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.12);
  --sidebar-active:#fb923c;
  --primary:       #ea580c;
  --primary-light: #ffedd5;
  --primary-dark:  #c2410c;
  --success:       #16a34a;
  --success-light: #d1fae5;
  --success-dark:  #15803d;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --purple:        #7c3aed;
  --purple-light:  #ede9fe;
  --teal:          #0d9488;
  --teal-light:    #ccfbf1;
  --shadow-sm:     0 1px 3px rgba(194,65,12,.06);
  --shadow:        0 4px 6px -1px rgba(194,65,12,.08);
  --shadow-lg:     0 10px 25px -5px rgba(194,65,12,.1);
  --shadow-xl:     0 20px 40px -10px rgba(194,65,12,.12);
  --th-bg:         #ffedd5;
  --th-color:      #9a3412;
  --progress-bg:   #fed7aa;
  --input-bg:      #ffffff;
  --input-border:  #fed7aa;
  --card-glow:     rgba(234,88,12,.06);
}

/* ── NEW THEMES ──────────────────────────────────────────────────────────── */

[data-theme="midnight"] {
  --bg:            #0f0f23;
  --surface:       #1a1a3e;
  --surface2:      #22224a;
  --surface3:      #151535;
  --border:        #2a2a5a;
  --border-light:  #22224a;
  --text:          #e8e8f0;
  --text-muted:    #9898c8;
  --text-label:    #b8b8d8;
  --sidebar-from:  #1a1a3e;
  --sidebar-to:    #0a0a20;
  --sidebar-text:  rgba(255,255,255,.85);
  --sidebar-muted: rgba(255,255,255,.3);
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active:#818cf8;
  --primary:       #818cf8;
  --primary-light: rgba(129,140,248,.15);
  --primary-dark:  #6366f1;
  --success:       #34d399;
  --success-light: rgba(52,211,153,.15);
  --success-dark:  #10b981;
  --danger:        #fb7185;
  --danger-light:  rgba(251,113,133,.15);
  --warning:       #fbbf24;
  --warning-light: rgba(251,191,36,.15);
  --purple:        #c084fc;
  --purple-light:  rgba(192,132,252,.15);
  --teal:          #2dd4bf;
  --teal-light:    rgba(45,212,191,.15);
  --pink:          #f472b6;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.5);
  --shadow:        0 4px 8px rgba(0,0,0,.5);
  --shadow-lg:     0 10px 25px rgba(0,0,0,.6);
  --shadow-xl:     0 20px 40px rgba(0,0,0,.7);
  --th-bg:         #22224a;
  --th-color:      #9898c8;
  --progress-bg:   #2a2a5a;
  --input-bg:      #22224a;
  --input-border:  #2a2a5a;
  --card-glow:     rgba(129,140,248,.08);
  --gradient-1:    linear-gradient(135deg, #818cf8, #c084fc);
  --gradient-2:    linear-gradient(135deg, #34d399, #2dd4bf);
  --gradient-3:    linear-gradient(135deg, #fbbf24, #fb7185);
}

[data-theme="rose"] {
  --bg:            #fff1f2;
  --surface:       #ffffff;
  --surface2:      #fff5f6;
  --surface3:      #ffe4e6;
  --border:        #fecdd3;
  --border-light:  #ffe4e6;
  --text:          #4c0519;
  --text-muted:    #be123c;
  --text-label:    #9f1239;
  --sidebar-from:  #be123c;
  --sidebar-to:    #881337;
  --sidebar-text:  rgba(255,255,255,.9);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.12);
  --sidebar-active:#fb7185;
  --primary:       #e11d48;
  --primary-light: #ffe4e6;
  --primary-dark:  #be123c;
  --success:       #16a34a;
  --success-light: #d1fae5;
  --success-dark:  #15803d;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --purple:        #7c3aed;
  --purple-light:  #ede9fe;
  --teal:          #0d9488;
  --teal-light:    #ccfbf1;
  --pink:          #ec4899;
  --shadow-sm:     0 1px 3px rgba(190,18,60,.06);
  --shadow:        0 4px 6px rgba(190,18,60,.08);
  --shadow-lg:     0 10px 25px rgba(190,18,60,.1);
  --shadow-xl:     0 20px 40px rgba(190,18,60,.12);
  --th-bg:         #ffe4e6;
  --th-color:      #be123c;
  --progress-bg:   #fecdd3;
  --input-bg:      #ffffff;
  --input-border:  #fecdd3;
  --card-glow:     rgba(225,29,72,.06);
}

[data-theme="lavender"] {
  --bg:            #f5f3ff;
  --surface:       #ffffff;
  --surface2:      #faf8ff;
  --surface3:      #ede9fe;
  --border:        #ddd6fe;
  --border-light:  #ede9fe;
  --text:          #2e1065;
  --text-muted:    #6d28d9;
  --text-label:    #7c3aed;
  --sidebar-from:  #6d28d9;
  --sidebar-to:    #4c1d95;
  --sidebar-text:  rgba(255,255,255,.9);
  --sidebar-muted: rgba(255,255,255,.4);
  --sidebar-hover: rgba(255,255,255,.12);
  --sidebar-active:#a78bfa;
  --primary:       #7c3aed;
  --primary-light: #ede9fe;
  --primary-dark:  #6d28d9;
  --success:       #16a34a;
  --success-light: #d1fae5;
  --success-dark:  #15803d;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --purple:        #7c3aed;
  --purple-light:  #ede9fe;
  --teal:          #0d9488;
  --teal-light:    #ccfbf1;
  --pink:          #ec4899;
  --shadow-sm:     0 1px 3px rgba(109,40,217,.06);
  --shadow:        0 4px 6px rgba(109,40,217,.08);
  --shadow-lg:     0 10px 25px rgba(109,40,217,.1);
  --shadow-xl:     0 20px 40px rgba(109,40,217,.12);
  --th-bg:         #ede9fe;
  --th-color:      #6d28d9;
  --progress-bg:   #ddd6fe;
  --input-bg:      #ffffff;
  --input-border:  #ddd6fe;
  --card-glow:     rgba(124,58,237,.06);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14.5px;
  line-height: 1.65;
  transition: background .3s ease, color .3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: linear-gradient(180deg, var(--sidebar-from) 0%, var(--sidebar-to) 100%);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
  box-shadow: 4px 0 24px rgba(0,0,0,.08);
}

.sidebar-header {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo {
  font-size: 1.15rem;
  font-weight: 800;
  color: white;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
  letter-spacing: -.01em;
}

.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 4px 15px rgba(59,130,246,.4);
}

.theme-switcher {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
}

.theme-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.2);
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
}
.theme-btn:hover { transform: scale(1.3); border-color: white; box-shadow: 0 0 12px rgba(255,255,255,.3); }
.theme-btn[data-theme="light"]    { background: linear-gradient(135deg,#f1f5f9,#e2e8f0); }
.theme-btn[data-theme="dark"]     { background: linear-gradient(135deg,#1e293b,#0f172a); }
.theme-btn[data-theme="ocean"]    { background: linear-gradient(135deg,#0284c7,#0c4a6e); }
.theme-btn[data-theme="forest"]   { background: linear-gradient(135deg,#16a34a,#14532d); }
.theme-btn[data-theme="sunset"]   { background: linear-gradient(135deg,#ea580c,#7c2d12); }
.theme-btn[data-theme="midnight"] { background: linear-gradient(135deg,#818cf8,#1a1a3e); }
.theme-btn[data-theme="rose"]     { background: linear-gradient(135deg,#fb7185,#881337); }
.theme-btn[data-theme="lavender"] { background: linear-gradient(135deg,#a78bfa,#4c1d95); }

.sidebar-nav { padding: .75rem 0 1rem; flex: 1; }
.nav-group { margin-bottom: .15rem; }

.nav-group-label {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--sidebar-muted);
  padding: 1rem 1.25rem .4rem;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: calc(100% - .75rem);
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: .65rem 1.25rem;
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 0 10px 10px 0;
  transition: all .2s ease;
  position: relative;
  margin-right: .75rem;
}
.nav-btn .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: .95rem;
  flex-shrink: 0;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  text-align: center;
  line-height: 1;
}
.nav-btn:hover { background: var(--sidebar-hover); color: white; }
.nav-btn.active {
  background: linear-gradient(90deg, rgba(255,255,255,.15), rgba(255,255,255,.05));
  color: white;
  font-weight: 600;
}
.nav-btn.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--sidebar-active);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--sidebar-active);
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; min-width: 0; width: 100%; }

.page { display: none; padding: 2.25rem 2.5rem; animation: pageIn .3s ease; }
.page.active { display: block; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.03em;
}
.page-subtitle {
  font-size: .88rem;
  color: var(--text-muted);
  margin-top: .3rem;
  line-height: 1.5;
}

h2 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.15rem;
  letter-spacing: -.01em;
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.1rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: all .25s ease;
  position: relative;
  overflow: hidden;
}
.card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  border-color: transparent;
}

.card .lbl {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .45rem;
}
.card .val {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* Card colour accents — gradient top border */
.card-green  { border-top: 3px solid var(--success) !important; }
.card-blue   { border-top: 3px solid var(--primary) !important; }
.card-orange { border-top: 3px solid var(--warning) !important; }
.card-red    { border-top: 3px solid var(--danger)  !important; }
.card-purple { border-top: 3px solid var(--purple)  !important; }
.card-teal   { border-top: 3px solid var(--teal)    !important; }

/* Colour helpers */
.green  { color: var(--success); }
.blue   { color: var(--primary); }
.orange { color: var(--warning); }
.purple { color: var(--purple); }
.red    { color: var(--danger); }
.teal   { color: var(--teal); }
.pink   { color: var(--pink); }
.pl-pos { color: var(--success); font-weight: 600; }
.pl-neg { color: var(--danger);  font-weight: 600; }

/* ── Panel ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.75rem;
  border: 1px solid var(--border);
  transition: box-shadow .2s ease;
  overflow-x: auto;
}
.panel:hover { box-shadow: var(--shadow); }

.panel > h2:first-child {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  padding-bottom: .85rem;
  border-bottom: 1.5px solid var(--border-light);
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  min-width: 130px;
}

.field label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.field input, .field select {
  padding: .6rem .9rem;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  transition: all .2s ease;
  outline: none;
}
.field input:hover, .field select:hover {
  border-color: var(--text-muted);
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--card-glow), 0 0 0 1px var(--primary);
}
.field input::placeholder { color: var(--text-muted); opacity: .55; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: .6rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
  letter-spacing: .01em;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.12);
  opacity: 0;
  transition: opacity .15s;
}
.btn:active::after { opacity: 1; }

.btn-blue {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 2px 8px rgba(59,130,246,.3);
}
.btn-blue:hover { box-shadow: 0 4px 16px rgba(59,130,246,.4); transform: translateY(-1px); }

.btn-green {
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  color: white;
  box-shadow: 0 2px 8px rgba(16,185,129,.3);
}
.btn-green:hover { box-shadow: 0 4px 16px rgba(16,185,129,.4); transform: translateY(-1px); }

.btn-gray { background: var(--text-muted); color: white; }
.btn-gray:hover { opacity: .85; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--card-glow); }

.btn-red { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: .25rem .45rem; border-radius: var(--radius-xs); transition: all .15s; }
.btn-red:hover { background: var(--danger-light); }

.btn-sm { padding: .3rem .7rem; font-size: .78rem; }
.btn-return { background: var(--primary); color: white; border: none; border-radius: var(--radius-xs); padding: .25rem .65rem; font-size: .75rem; cursor: pointer; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }

thead tr { border-bottom: none; }

th {
  background: var(--th-bg);
  color: var(--th-color);
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: .85rem 1.1rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1.5px solid var(--border);
}
th:first-child { border-radius: var(--radius-sm) 0 0 0; }
th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

td {
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background .15s ease;
}
td:hover { white-space: normal; overflow: visible; }

tbody tr { transition: all .15s ease; }
tbody tr:hover td { background: var(--card-glow); }
tbody tr:last-child td { border-bottom: none; }

/* Zebra stripe — very subtle */
tbody tr:nth-child(even) td { background: var(--surface2); }
tbody tr:nth-child(even):hover td { background: var(--card-glow); }

/* Amount cells */
td.amount { font-variant-numeric: tabular-nums; font-weight: 600; font-family: 'JetBrains Mono', 'Inter', monospace; font-size: .82rem; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: .02em;
}

/* Expense badges */
.badge-food, .badge-dining        { background: #fef3c7; color: #92400e; }
.badge-groceries                  { background: #d1fae5; color: #065f46; }
.badge-transport, .badge-fuel     { background: #dbeafe; color: #1e40af; }
.badge-vehicle                    { background: #fef9c3; color: #713f12; }
.badge-travel                     { background: #e0e7ff; color: #3730a3; }
.badge-utilities, .badge-internet { background: #ede9fe; color: #5b21b6; }
.badge-rent                       { background: #fce7f3; color: #9d174d; }
.badge-health, .badge-medicines   { background: #fee2e2; color: #991b1b; }
.badge-fitness                    { background: #ccfbf1; color: #134e4a; }
.badge-entertainment              { background: #fae8ff; color: #701a75; }
.badge-shopping, .badge-clothing  { background: #fce7f3; color: #9d174d; }
.badge-subscriptions              { background: #dbeafe; color: #1e40af; }
.badge-education, .badge-books    { background: #d1fae5; color: #065f46; }
.badge-family                     { background: #fef3c7; color: #92400e; }
.badge-gifts, .badge-festivals    { background: #fce7f3; color: #9d174d; }
.badge-charity                    { background: #d1fae5; color: #065f46; }
.badge-household                  { background: #f1f5f9; color: #475569; }
.badge-emi                        { background: #fee2e2; color: #991b1b; }
.badge-taxes                      { background: #fee2e2; color: #991b1b; }
.badge-general, .badge-other      { background: #f1f5f9; color: #475569; }

/* Income badges */
.badge-inc-salary                 { background: #d1fae5; color: #065f46; }
.badge-inc-bonus, .badge-inc-arrears, .badge-inc-gratuity { background: #fef3c7; color: #92400e; }
.badge-inc-freelance, .badge-inc-consulting { background: #dbeafe; color: #1e40af; }
.badge-inc-business               { background: #ede9fe; color: #5b21b6; }
.badge-inc-dividend, .badge-inc-interest, .badge-inc-capital_gains { background: #ccfbf1; color: #134e4a; }
.badge-inc-rental                 { background: #fce7f3; color: #9d174d; }
.badge-inc-mf_redemption          { background: #dbeafe; color: #1e40af; }
.badge-inc-pension                { background: #f1f5f9; color: #475569; }
.badge-inc-gift, .badge-inc-cashback, .badge-inc-refund { background: #fef3c7; color: #92400e; }
.badge-inc-other                  { background: #f1f5f9; color: #475569; }

/* Savings/gold/other badges */
.badge-ppf  { background: #ccfbf1; color: #134e4a; }
.badge-epf  { background: #dbeafe; color: #1e40af; }
.badge-fd   { background: #fef3c7; color: #92400e; }
.badge-coins     { background: #fef9c3; color: #713f12; }
.badge-jewellery { background: #fce7f3; color: #9d174d; }
.badge-bar       { background: #f1f5f9; color: #475569; }
.badge-life      { background: #d1fae5; color: #065f46; }
.badge-term      { background: #dbeafe; color: #1e40af; }
.badge-vehicle-ins { background: #fef3c7; color: #92400e; }

/* Loan badges */
.badge-loan-home      { background: #dbeafe; color: #1e40af; }
.badge-loan-car       { background: #fef3c7; color: #92400e; }
.badge-loan-personal  { background: #fee2e2; color: #991b1b; }
.badge-loan-education { background: #d1fae5; color: #065f46; }
.badge-loan-other     { background: #f1f5f9; color: #475569; }

/* Extra badges */
.badge-loan     { background: #fee2e2; color: #991b1b; }
.badge-personal { background: #ede9fe; color: #5b21b6; }
.badge-medical  { background: #fed7d7; color: #742a2a; }
.badge-salary   { background: #d1fae5; color: #065f46; }
[class^="badge-"]:not([class*=" "]) { background: #f1f5f9; color: #475569; }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar {
  height: 7px;
  background: var(--progress-bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: .4rem;
}
.progress-fill { height: 100%; border-radius: 999px; transition: width .6s cubic-bezier(.4,0,.2,1); }
.fill-ok   { background: linear-gradient(90deg, #10b981, #34d399); }
.fill-warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.fill-over { background: linear-gradient(90deg, #ef4444, #f87171); }

/* ── Layout helpers ──────────────────────────────────────────────────────── */
.two-col   { display: grid; grid-template-columns: 1fr 1fr; gap: 1.75rem; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.75rem; }

@media (min-width: 1600px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}
@media (min-width: 2000px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

.preview-bar {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .6rem;
  padding: .7rem 1rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.returned td { opacity: .4; text-decoration: line-through; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3.5rem; opacity: .2; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; line-height: 1.6; }

/* ── Category chips ──────────────────────────────────────────────────────── */
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem .2rem .2rem .6rem;
  font-size: .82rem;
  transition: all .15s ease;
}
.cat-chip:hover { border-color: var(--primary); }

.cat-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1;
  padding: .1rem .3rem;
  border-radius: 999px;
  transition: all .15s;
}
.cat-del:hover { background: var(--danger); color: white; }

.cat-edit {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .78rem;
  padding: .1rem .25rem;
  border-radius: 4px;
  transition: all .15s;
}
.cat-edit:hover { background: var(--primary); color: white; }

/* ── Member filter chips ─────────────────────────────────────────────────── */
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .85rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s ease;
  font-family: inherit;
}
.member-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--card-glow); }
.member-chip.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: var(--primary);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(59,130,246,.3);
}

/* ── Dashboard net worth ─────────────────────────────────────────────────── */
#nw-total {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--success), var(--teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -.03em;
}

/* ── Sold/inactive row styling ───────────────────────────────────────────── */
tr.sold td { opacity: .45; }
tr.sold td:first-child::before { content: '🏷️ '; }

/* ── Edit button ─────────────────────────────────────────────────────────── */
.btn-edit {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: .9rem;
  padding: .2rem .4rem;
  border-radius: var(--radius-xs);
  transition: all .15s;
}
.btn-edit:hover { background: var(--primary-light); }

/* ── Date group header in expenses table ─────────────────────────────────── */
tr.date-group-header td {
  border-top: 2px solid var(--border) !important;
  border-bottom: none !important;
  background: var(--surface2) !important;
  font-weight: 600;
}
tr.date-group-header + tr td { border-top: none; }
tr.date-group-header:nth-child(even) td,
tr.date-group-header:nth-child(odd) td { background: var(--surface2) !important; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 1px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Focus ring ──────────────────────────────────────────────────────────── */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Animations ──────────────────────────────────────────────────────────── */
.card {
  animation: cardIn .4s cubic-bezier(.4,0,.2,1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* Stagger card animations */
.cards .card:nth-child(1) { animation-delay: 0s; }
.cards .card:nth-child(2) { animation-delay: .04s; }
.cards .card:nth-child(3) { animation-delay: .08s; }
.cards .card:nth-child(4) { animation-delay: .12s; }
.cards .card:nth-child(5) { animation-delay: .16s; }
.cards .card:nth-child(6) { animation-delay: .2s; }
.cards .card:nth-child(7) { animation-delay: .24s; }
.cards .card:nth-child(8) { animation-delay: .28s; }

/* ── Responsive table columns ────────────────────────────────────────────── */
th { white-space: nowrap; }
td:nth-child(2) { white-space: normal; min-width: 100px; max-width: 200px; }
td:last-child, td:nth-last-child(2) { white-space: nowrap; }
#gold-list td, #sil-list td { white-space: nowrap; }
#gold-list td:nth-child(2), #sil-list td:nth-child(2) { white-space: normal; }
.main-content { overflow-x: hidden; }
.page { overflow-x: auto; }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .btn, button { display: none !important; }
  .page { display: none !important; }
  #page-dashboard { display: block !important; padding: 0; }
  body { background: white; }
  .panel, .card { box-shadow: none; border: 1px solid #e2e8f0; }
}

/* ── PWA / iOS safe areas ────────────────────────────────────────────────── */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: fixed;
    z-index: 100;
    max-height: 50vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,.2);
  }
  .sidebar-header { padding: .75rem; }
  .sidebar-logo { font-size: .95rem; }
  .sidebar-nav { display: flex; flex-wrap: wrap; padding: .25rem .5rem .5rem; }
  .nav-group { display: contents; }
  .nav-group-label { display: none; }
  .nav-btn { width: auto; padding: .35rem .7rem; font-size: .78rem; border-radius: var(--radius-xs); margin-right: 0; }
  .nav-btn.active::before { display: none; }
  .main-content { margin-top: 0; padding-top: .5rem; }
  .page { padding: .85rem; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
  .card .val { font-size: 1.1rem; }
  .row { gap: .5rem; }
  .field { min-width: 100px; }
  table { font-size: .78rem; }
  th, td { padding: .5rem .6rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE APP — Native-feeling PWA for iOS / Android
   ═══════════════════════════════════════════════════════════════════════════ */

/* Hide mobile nav on desktop */
.mobile-nav, .mob-sheet, .mob-sheet-overlay { display: none; }

@media (max-width: 768px) {

  /* ── Hide desktop sidebar, show mobile nav ─────────────────────────────── */
  .sidebar { display: none !important; }
  .mobile-nav { display: flex !important; }

  .app-layout { flex-direction: column; }

  .main-content {
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
    min-height: 100vh;
    overflow-x: hidden;
  }

  .page {
    padding: 1rem .85rem 2rem;
    animation: mobPageIn .25s ease;
  }
  @keyframes mobPageIn {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: none; }
  }

  /* ── Bottom Tab Bar ────────────────────────────────────────────────────── */
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex !important;
    justify-content: space-around;
    align-items: stretch;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 20px rgba(0,0,0,.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px 6px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-family: inherit;
    transition: all .2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-tab .mob-icon {
    font-size: 1.35rem;
    line-height: 1;
    transition: transform .2s ease;
  }

  .mob-tab .mob-label {
    font-size: .62rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
  }

  .mob-tab.active {
    color: var(--primary);
  }
  .mob-tab.active .mob-icon {
    transform: scale(1.15);
  }
  .mob-tab.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 3px 3px;
  }

  .mob-tab:active {
    transform: scale(.92);
  }

  /* ── Bottom Sheet (More menu) ──────────────────────────────────────────── */
  .mob-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1001;
    opacity: 0;
    transition: opacity .3s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
  }
  .mob-sheet-overlay.open {
    display: block;
    opacity: 1;
  }

  .mob-sheet {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: .75rem 1rem calc(1rem + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(.32,.72,0,1);
    box-shadow: 0 -10px 40px rgba(0,0,0,.15);
    max-height: 75vh;
    overflow-y: auto;
  }
  .mob-sheet.open {
    transform: translateY(0);
  }

  .mob-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 0 auto .75rem;
  }

  .mob-sheet-title {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    margin-bottom: .75rem;
    padding-left: .25rem;
  }

  .mob-sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .5rem;
  }

  .mob-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .85rem .5rem;
    background: var(--surface2);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 1.5rem;
    color: var(--text);
    transition: all .15s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-sheet-item span {
    font-size: .65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.2;
  }
  .mob-sheet-item:active {
    transform: scale(.94);
    background: var(--primary-light);
  }

  /* ── Mobile page header ────────────────────────────────────────────────── */
  .page-header {
    margin-bottom: 1.25rem;
  }
  .page-title {
    font-size: 1.35rem;
  }

  /* ── Mobile cards ──────────────────────────────────────────────────────── */
  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: .65rem;
    margin-bottom: 1.25rem;
  }
  .card {
    padding: .9rem 1rem;
    border-radius: var(--radius-sm);
  }
  .card .lbl { font-size: .6rem; }
  .card .val { font-size: 1.15rem; }

  /* ── Mobile panels ─────────────────────────────────────────────────────── */
  .panel {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
  }

  /* ── Mobile forms ──────────────────────────────────────────────────────── */
  .row {
    gap: .6rem;
  }
  .field {
    min-width: 0;
    flex: 1 1 calc(50% - .3rem);
  }
  .field input, .field select {
    padding: .6rem .75rem;
    font-size: .9rem;
    border-radius: var(--radius-xs);
  }

  /* ── Mobile tables ─────────────────────────────────────────────────────── */
  table { font-size: .76rem; }
  th { font-size: .6rem; padding: .55rem .5rem; }
  td { padding: .6rem .5rem; font-size: .78rem; }

  /* ── Mobile buttons ────────────────────────────────────────────────────── */
  .btn {
    padding: .55rem 1rem;
    font-size: .82rem;
    border-radius: var(--radius-xs);
  }
  .btn-sm { padding: .35rem .6rem; font-size: .72rem; }

  /* ── Two/three col → single col ────────────────────────────────────────── */
  .two-col, .three-col { grid-template-columns: 1fr; gap: 1rem; }

  /* ── Net worth on mobile ───────────────────────────────────────────────── */
  #nw-total { font-size: 1.6rem; }

  /* ── Member chips ──────────────────────────────────────────────────────── */
  .member-chip {
    padding: .3rem .65rem;
    font-size: .75rem;
  }

  /* ── Badge ─────────────────────────────────────────────────────────────── */
  .badge { font-size: .62rem; padding: .18rem .5rem; }

  /* ── Disable card hover effects on touch ───────────────────────────────── */
  .card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }

  /* ── Stagger animations faster on mobile ───────────────────────────────── */
  .cards .card:nth-child(n) { animation-delay: 0s; }
  .card { animation-duration: .2s; }
}

/* ── Extra small phones (iPhone SE, etc.) ────────────────────────────────── */
@media (max-width: 375px) {
  .cards { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .card .val { font-size: 1rem; }
  .mob-sheet-grid { grid-template-columns: repeat(3, 1fr); }
  .page { padding: .75rem .65rem 2rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.15rem;
  border-radius: 12px;
  font-size: .84rem;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  animation: toastIn .3s ease;
  max-width: 380px;
  backdrop-filter: blur(12px);
}
.toast.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.toast.toast-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.toast.toast-out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(40px); } }

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING SPINNER
   ═══════════════════════════════════════════════════════════════════════════ */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 2rem; color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   SORTABLE TABLE COLUMNS
   ═══════════════════════════════════════════════════════════════════════════ */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.2rem;
}
th.sortable:hover { color: var(--primary); }
th.sortable::after {
  content: '⇅';
  position: absolute;
  right: .3rem;
  font-size: .65rem;
  opacity: .35;
}
th.sortable.sort-asc::after { content: '▲'; opacity: .7; }
th.sortable.sort-desc::after { content: '▼'; opacity: .7; }

/* ═══════════════════════════════════════════════════════════════════════════
   FORM VALIDATION
   ═══════════════════════════════════════════════════════════════════════════ */
.field input:invalid:not(:placeholder-shown),
.field input.invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 2px rgba(239,68,68,.12);
}
.field .field-error {
  font-size: .68rem;
  color: var(--danger);
  margin-top: .15rem;
  display: none;
}
.field input.invalid + .field-error { display: block; }

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: .75rem;
  opacity: .4;
}
.empty-state p {
  font-size: .9rem;
  line-height: 1.6;
  max-width: 360px;
  margin: 0 auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   KEYBOARD SHORTCUT HINT
   ═══════════════════════════════════════════════════════════════════════════ */
.kbd {
  display: inline-block;
  padding: .1rem .35rem;
  font-size: .65rem;
  font-family: monospace;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOPBAR
   ═══════════════════════════════════════════════════════════════════════════ */
#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
@media (max-width: 768px) {
  #topbar { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   VIEWER MODE — hide write controls
   ═══════════════════════════════════════════════════════════════════════════ */
body.viewer-mode .admin-only,
body.viewer-mode .btn-red,
body.viewer-mode .btn-edit,
body.viewer-mode [onclick*="del"],
body.viewer-mode [onclick*="clear"],
body.viewer-mode [onclick*="Clear"] {
  display: none !important;
}
body.viewer-mode .bulk-chk-expenses,
body.viewer-mode .bulk-chk-income,
body.viewer-mode .bulk-chk-savings,
body.viewer-mode .bulk-chk-gold,
body.viewer-mode .bulk-chk-silver,
body.viewer-mode .bulk-chk-stocks,
body.viewer-mode .bulk-chk-mf,
body.viewer-mode .bulk-chk-realestate,
body.viewer-mode .bulk-chk-loans,
body.viewer-mode .bulk-chk-recurring,
body.viewer-mode .bulk-chk-goals,
body.viewer-mode [type="checkbox"][onchange*="toggleAll"] {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FUND SEARCH DROPDOWN
   ═══════════════════════════════════════════════════════════════════════════ */
.fund-search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  max-height: 250px;
  overflow-y: auto;
  z-index: 200;
  margin-top: 2px;
}
.fund-search-results .fund-item {
  padding: .45rem .7rem;
  font-size: .78rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.fund-search-results .fund-item:hover {
  background: var(--primary-light);
}
.fund-search-results .fund-item:last-child {
  border-bottom: none;
}


/* ═══════════════════════════════════════════════════════════════════════════
   DRAG AND DROP
   ═══════════════════════════════════════════════════════════════════════════ */
.drag-over {
  outline: 3px dashed var(--primary) !important;
  outline-offset: -3px;
  background: var(--primary-light) !important;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  transition: all .2s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}


/* ═══════════════════════════════════════════════════════════════════════════
   PRIVACY MODE — blur amounts on Dashboard and Insights
   ═══════════════════════════════════════════════════════════════════════════ */
body.privacy-mode #page-dashboard .val,
body.privacy-mode #page-dashboard td:nth-child(2),
body.privacy-mode #page-insights .val,
body.privacy-mode #page-insights td:nth-last-child(-n+4):not(:last-child) {
  filter: blur(8px);
  user-select: none;
  transition: filter .3s ease;
}
body.privacy-mode #page-dashboard .card:hover .val,
body.privacy-mode #page-insights .card:hover .val {
  filter: blur(0);
}
