/* ===== DESIGN TOKENS ===== */
:root {
  color-scheme: light;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-alpha: rgba(99,102,241,0.12);
  --success: #10b981;
  --success-alpha: rgba(16,185,129,0.12);
  --warning: #f59e0b;
  --warning-alpha: rgba(245,158,11,0.12);
  --danger: #ef4444;
  --danger-alpha: rgba(239,68,68,0.12);
  --info: #3b82f6;
  --info-alpha: rgba(59,130,246,0.12);

  /* Light mode */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --text-2: #334155;
  --text-muted: #64748b;
  --text-placeholder: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.10), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.10), 0 10px 10px -5px rgba(0,0,0,0.04);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
  --topbar-h: 56px;
  --bottomnav-h: 64px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #162032;
  --surface-3: #0f172a;
  --border: #2d3f55;
  --border-soft: #1e293b;
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --text-muted: #94a3b8;
  --text-placeholder: #475569;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.30);
  --shadow: 0 1px 3px rgba(0,0,0,0.40), 0 1px 2px rgba(0,0,0,0.30);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.40), 0 2px 4px -1px rgba(0,0,0,0.30);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.40), 0 4px 6px -2px rgba(0,0,0,0.30);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.50), 0 10px 10px -5px rgba(0,0,0,0.30);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none;
  transition: background var(--transition), color var(--transition);
}

::selection { background: var(--primary); color: #fff; }

/* Thin, unobtrusive scrollbars on pointer devices (desktop) */
@media (hover: hover) and (pointer: fine) {
  * { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
  *::-webkit-scrollbar { width: 8px; height: 8px; }
  *::-webkit-scrollbar-track { background: transparent; }
  *::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
  *::-webkit-scrollbar-thumb:hover { background: var(--text-placeholder); }
}

/* Keyboard-accessible focus ring, invisible for mouse/touch */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

@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;
  }
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ===== LAYOUT ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100svh;
}

/* ===== TOPBAR ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  transition: background var(--transition), border-color var(--transition), left var(--transition);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { color: var(--primary); display: flex; align-items: center; }
.topbar-title { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  margin-top: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 80px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  transition: margin-left var(--transition);
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  display: flex;
  align-items: stretch;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 0 var(--border), var(--shadow-md);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 4px;
  min-height: 44px;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.nav-item::before {
  content: '';
  position: absolute;
  top: 0; left: 50%; transform: translateX(-50%);
  width: 0; height: 2px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
  transition: width var(--transition);
}

.nav-item.active { color: var(--primary); }
.nav-item.active::before { width: 40px; }
.nav-item svg { transition: transform var(--transition); }
.nav-item.active svg { transform: scale(1.1); }

@media (hover: hover) and (pointer: fine) {
  .nav-item:hover { color: var(--text); }
  .nav-item.active:hover { color: var(--primary); }
}

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 16px);
  right: 20px;
  z-index: 99;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(99,102,241,0.4), var(--shadow-lg);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.fab:active { transform: scale(0.94); box-shadow: 0 2px 8px rgba(99,102,241,0.3); }
@media (hover: hover) and (pointer: fine) {
  .fab:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 6px 20px rgba(99,102,241,0.45), var(--shadow-lg); }
}

/* ===== ICON BUTTONS ===== */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-3); color: var(--text); transform: scale(0.92); }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-3); color: var(--text); }
}

/* ===== USER MENU ===== */
.user-menu {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 4px);
  right: 12px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 220px;
  overflow: hidden;
  animation: dropIn 0.15s ease;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.user-menu-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-menu-name { font-weight: 600; font-size: 14px; color: var(--text); }
.user-menu-divider { height: 1px; background: var(--border); }

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}
.user-menu-item:hover { background: var(--surface-3); }
.user-menu-item.danger { color: var(--danger); }
.user-menu-item.danger:hover { background: var(--danger-alpha); }

/* ===== SECTION CONTAINERS ===== */
.view-container { padding: 16px; max-width: 600px; margin: 0 auto; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 10px;
  margin-top: 20px;
}
.section-title:first-child { margin-top: 0; }

/* ===== STAT CARDS ROW ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:active { transform: scale(0.98); }
@media (hover: hover) and (pointer: fine) {
  .stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
}
.stat-card-accent { position: absolute; top: 0; left: 0; right: 0; height: 3px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.stat-card-icon { font-size: 22px; margin-bottom: 8px; }
.stat-card-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card-value { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); line-height: 1.1; }
.stat-card-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

.card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.card-action { font-size: 13px; font-weight: 600; color: var(--primary); background: none; border: none; cursor: pointer; padding: 4px; }

/* ===== EXPENSE LIST ITEMS ===== */
.expense-list { display: flex; flex-direction: column; }

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.expense-item:last-child { border-bottom: none; }
.expense-item:active { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) {
  .expense-item:hover { background: var(--surface-2); }
}

.expense-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.expense-info { flex: 1; min-width: 0; }
.expense-title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.expense-right { text-align: right; flex-shrink: 0; }
.expense-amount { font-size: 15px; font-weight: 700; color: var(--text); }
.expense-due { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge-pending  { background: var(--warning-alpha); color: #b45309; }
.badge-paid     { background: var(--success-alpha); color: #065f46; }
.badge-overdue  { background: var(--danger-alpha);  color: #b91c1c; }
.badge-primary  { background: var(--primary-alpha); color: var(--primary-dark); }

[data-theme="dark"] .badge-pending { color: #fbbf24; }
[data-theme="dark"] .badge-paid    { color: #34d399; }
[data-theme="dark"] .badge-overdue { color: #f87171; }
[data-theme="dark"] .badge-primary { color: var(--primary-light); }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border-soft);
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.filter-chip:active { transform: scale(0.96); }
.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ===== SEARCH BAR ===== */
.search-bar-wrap {
  padding: 10px 16px 4px;
  position: sticky;
  top: 55px;
  background: var(--bg);
  z-index: 9;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  transition: border-color var(--transition);
}

.search-bar:focus-within { border-color: var(--primary); }
.search-bar svg { color: var(--text-muted); flex-shrink: 0; }
.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}

.search-bar input::placeholder { color: var(--text-placeholder); }

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-state-icon { font-size: 56px; margin-bottom: 16px; opacity: 0.6; }
.empty-state-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state-desc { font-size: 14px; color: var(--text-muted); max-width: 260px; line-height: 1.6; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #dc2626);
  color: white;
  box-shadow: 0 2px 8px rgba(239,68,68,0.25);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #059669);
  color: white;
  box-shadow: 0 2px 8px rgba(16,185,129,0.25);
}

.btn-ghost { background: transparent; color: var(--primary); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-icon { gap: 6px; }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { box-shadow: 0 4px 14px rgba(99,102,241,0.4); transform: translateY(-1px); }
  .btn-secondary:hover { background: var(--surface-2); border-color: var(--text-placeholder); }
  .btn-danger:hover { box-shadow: 0 4px 14px rgba(239,68,68,0.35); transform: translateY(-1px); }
  .btn-success:hover { box-shadow: 0 4px 14px rgba(16,185,129,0.35); transform: translateY(-1px); }
  .btn-ghost:hover { background: var(--primary-alpha); }
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--text-placeholder); }
.form-select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 20px; padding-right: 38px; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 6px; }
.form-hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.input-with-icon { position: relative; }
.input-with-icon .form-input { padding-right: 44px; }
.input-icon-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px;
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.input-icon-btn:hover { color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.form-toggle-label { font-size: 14px; font-weight: 500; color: var(--text); }

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 28px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15,23,42,0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92svh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.22s cubic-bezier(0.34, 1.25, 0.64, 1);
  padding-bottom: env(safe-area-inset-bottom);
}

@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-close { width: 32px; height: 32px; }

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-footer .btn { flex: 1; }

/* ===== LOGIN ===== */
.login-screen {
  height: 100svh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  background:
    radial-gradient(circle at 15% 10%, rgba(99,102,241,0.16), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(16,185,129,0.12), transparent 45%),
    var(--bg);
}

.login-card {
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: slideUp 0.35s cubic-bezier(0.34, 1.25, 0.64, 1);
}

.login-logo { display: flex; justify-content: center; margin-bottom: 16px; }
.login-title { text-align: center; font-size: 24px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

/* ===== LINK BUTTON (forgot password, etc) ===== */
.link-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  margin-top: 14px;
  padding: 8px;
  cursor: pointer;
  min-height: 32px;
}
@media (hover: hover) and (pointer: fine) {
  .link-btn:hover { text-decoration: underline; }
}

/* ===== AUDIT LOG ===== */
.audit-list { display: flex; flex-direction: column; }
.audit-item {
  display: flex;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border-soft);
}
.audit-item:last-child { border-bottom: none; }
.audit-icon { font-size: 18px; flex-shrink: 0; line-height: 1.4; }
.audit-info { flex: 1; min-width: 0; }
.audit-line { font-size: 13px; color: var(--text); line-height: 1.5; }
.audit-entity { color: var(--text-muted); font-weight: 500; }
.audit-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.audit-time { font-size: 11px; color: var(--text-placeholder); margin-top: 3px; }

/* ===== CATEGORY CARDS ===== */
.category-grid { display: flex; flex-direction: column; gap: 10px; }

.category-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.category-card:active { transform: scale(0.98); }
@media (hover: hover) and (pointer: fine) {
  .category-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary-light); transform: translateY(-1px); }
}

.category-icon-wrap {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.category-info { flex: 1; min-width: 0; }
.category-name { font-size: 15px; font-weight: 700; color: var(--text); }
.category-desc { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.category-stats { text-align: right; flex-shrink: 0; }
.category-total { font-size: 16px; font-weight: 800; color: var(--text); }
.category-count { font-size: 12px; color: var(--text-muted); }

/* ===== REPORTS ===== */
.report-month-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  justify-content: center;
}

.month-nav-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 18px;
}
.month-nav-btn:active { background: var(--primary-alpha); border-color: var(--primary); color: var(--primary); }

.month-label { font-size: 17px; font-weight: 700; color: var(--text); min-width: 140px; text-align: center; }

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.chart-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.chart-canvas-wrap { position: relative; height: 220px; }

.report-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.report-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.report-stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px; }
.report-stat-value { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }

/* ===== TOASTS ===== */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s cubic-bezier(0.34, 1.25, 0.64, 1);
  pointer-events: all;
}

@keyframes toastIn { from { opacity: 0; transform: translateY(-16px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px) scale(0.95); } }
.toast.hiding { animation: toastOut 0.2s ease forwards; }

.toast-success { background: #064e3b; color: #6ee7b7; border: 1px solid #065f46; }
.toast-error   { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }
.toast-info    { background: #1e3a5f; color: #93c5fd; border: 1px solid #1d4ed8; }

/* ===== QUICK ACTIONS ===== */
.quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.quick-action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.quick-action-btn:active { transform: scale(0.96); background: var(--surface-2); }
.quick-action-btn svg { color: var(--primary); }

/* ===== LOADING ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ===== OVERDUE ALERT ===== */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
}

.alert-danger { background: var(--danger-alpha); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: var(--warning-alpha); color: #92400e; border: 1px solid rgba(245,158,11,0.2); }

[data-theme="dark"] .alert-warning { color: var(--warning); }

/* ===== AMOUNT INPUT ===== */
.amount-input-wrap {
  position: relative;
}
.amount-prefix {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}
.amount-input-wrap .form-input { padding-left: 30px; font-size: 18px; font-weight: 700; }

/* ===== RESPONSIVE ===== */
@media (min-width: 600px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .modal { border-radius: var(--radius-xl); }
  .modal-overlay { align-items: center; }
  .login-card { padding: 40px 36px; }
}

/* ===== DESKTOP CONTENT WIDTH ===== */
/* Single bottom nav stays on every screen size — no sidebar. This breakpoint
   only widens the content area so it isn't stranded in a narrow column. */
@media (min-width: 960px) {
  /* Fill the available width instead of a narrow centered column — only cap
     at an extreme so cards don't stretch absurdly wide on 4K/ultrawide rigs. */
  .view-container { max-width: 2400px; width: 100%; padding: 28px 40px; margin: 0; }
  .filter-bar, .search-bar-wrap { max-width: 2400px; margin: 0; padding-left: 40px; padding-right: 40px; }
  .report-month-picker { justify-content: center; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }

  /* Category cards: use the width with a responsive multi-column grid
     instead of one long full-width column per card. */
  .category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }

  /* Reports: two charts side by side instead of stacked when there's room. */
  .report-charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; margin-bottom: 16px; }
  .report-charts-row .chart-wrap { margin-bottom: 0; }
}

@media (min-width: 1400px) {
  .view-container { padding: 32px 56px; }
  .filter-bar, .search-bar-wrap { padding-left: 56px; padding-right: 56px; }
}

/* ===== FORCE PASSWORD CHANGE BANNER ===== */
.force-change-banner {
  background: linear-gradient(135deg, var(--warning), #d97706);
  color: white;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--transition);
}
.force-change-banner:hover { opacity: 0.9; }

/* ===== COLOR SWATCH ===== */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.color-swatch {
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: transform var(--transition), border-color var(--transition);
}
.color-swatch:active { transform: scale(0.9); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* ===== PULL INDICATOR (visual affordance) ===== */
.scroll-top-btn {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 80px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 50;
  display: none;
}

/* ===== 5-ITEM BOTTOM NAV ===== */
.nav-item span { font-size: 10px; }
@media (max-width: 380px) { .nav-item span { display: none; } .nav-item { gap: 0; } }

/* ===== BULK ACTION BAR ===== */
.bulk-bar {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 12px);
  left: 50%; transform: translateX(-50%);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.2s ease;
  white-space: nowrap;
}
.bulk-bar-count { font-size: 13px; font-weight: 700; color: var(--text); }

/* ===== CHECKBOX ===== */
.expense-checkbox { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; border-radius: 4px; }
.expense-item.selected { background: var(--primary-alpha); }
.expense-item-row { display: flex; align-items: center; gap: 10px; width: 100%; }

/* ===== BUDGET PROGRESS ===== */
.budget-bar-wrap { margin-top: 8px; }
.budget-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.budget-bar-track { height: 5px; background: var(--border); border-radius: 4px; overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }

/* ===== REVENUE STATS ===== */
.profit-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-lg);
  padding: 18px;
  color: white;
  margin-bottom: 16px;
  box-shadow: 0 4px 14px rgba(99,102,241,0.3);
}
.profit-card-label { font-size: 12px; font-weight: 600; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.profit-card-value { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.profit-card-sub   { font-size: 13px; opacity: 0.75; margin-top: 4px; }

.revenue-item { cursor: pointer; transition: background var(--transition); -webkit-tap-highlight-color: transparent; }
.revenue-item:active { background: var(--surface-2); }

/* ===== YoY COMPARISON ===== */
.yoy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.yoy-row:last-child { border-bottom: none; }
.yoy-label { font-size: 13px; color: var(--text-muted); }
.yoy-value { font-size: 14px; font-weight: 700; color: var(--text); }
.yoy-change { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 12px; }
.yoy-up   { background: var(--danger-alpha);  color: var(--danger); }
.yoy-down { background: var(--success-alpha); color: var(--success); }
.yoy-flat { background: var(--border);        color: var(--text-muted); }

/* ===== INVOICE UPLOAD ===== */
.invoice-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.invoice-upload-area:hover { border-color: var(--primary); background: var(--primary-alpha); }
.invoice-upload-area input[type=file] { display: none; }
.invoice-upload-icon { font-size: 28px; margin-bottom: 6px; }
.invoice-upload-text { font-size: 13px; color: var(--text-muted); }

.invoice-attached {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--success-alpha);
  border: 1px solid rgba(16,185,129,0.25);
  border-radius: var(--radius);
}
.invoice-attached-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--success); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== SETTINGS FORM ===== */
.settings-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin: 18px 0 10px; }
.settings-section-title:first-child { margin-top: 0; }

/* ===== USER TABLE ===== */
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-alpha);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; color: var(--text); }
.user-meta { font-size: 12px; color: var(--text-muted); }
.badge-viewer { background: var(--warning-alpha); color: #92400e; }
[data-theme="dark"] .badge-viewer { color: var(--warning); }
.badge-bookkeeper { background: var(--success-alpha); color: #065f46; }
[data-theme="dark"] .badge-bookkeeper { color: var(--success); }

/* ===== NAV REVENUE ICON ===== */
.nav-item[data-view="revenue"].active { color: var(--success); }
.nav-item[data-view="revenue"].active::before { background: var(--success); }

/* ===== CSV IMPORT ===== */

/* Step indicator bar */
.import-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 20px;
  padding: 0 4px;
}
.import-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  position: relative;
}
.import-step::after {
  content: '';
  position: absolute;
  top: 14px; left: calc(50% + 14px);
  right: calc(-50% + 14px);
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.import-step:last-child::after { display: none; }
.import-step-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
  transition: all var(--transition);
  position: relative;
}
.import-step-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-muted);
  white-space: nowrap;
}
.import-step.active .import-step-dot {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.import-step.active .import-step-label { color: var(--primary); }
.import-step.done .import-step-dot {
  border-color: var(--success);
  background: var(--success);
  color: white;
}
.import-step.done .import-step-label { color: var(--success); }
.import-step.done::after { background: var(--success); }

/* Upload drop zone */
.csv-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-2);
  position: relative;
}
.csv-drop-zone:hover, .csv-drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-alpha);
}
.csv-drop-zone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.csv-drop-icon { font-size: 44px; margin-bottom: 10px; }
.csv-drop-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.csv-drop-sub { font-size: 13px; color: var(--text-muted); }

/* Mapping table */
.import-map-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.import-map-table th {
  text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}
.import-map-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.import-map-table tr:last-child td { border-bottom: none; }
.import-map-table tr:hover td { background: var(--surface-2); }
.map-col-name {
  font-weight: 600; color: var(--text);
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-col-sample {
  color: var(--text-muted); font-style: italic;
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-select {
  padding: 6px 28px 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; background-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.map-select.mapped { border-color: var(--success); background-color: var(--success-alpha); }
.map-select.required-missing { border-color: var(--danger); background-color: var(--danger-alpha); }

/* Import preview table */
.import-preview-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}
.import-preview-table th {
  background: var(--surface-3);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.import-preview-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}
.import-preview-table tr:last-child td { border-bottom: none; }

/* Result boxes */
.import-result-success {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; border-radius: var(--radius-lg);
  background: var(--success-alpha);
  border: 1px solid rgba(16,185,129,0.25);
  margin-bottom: 12px;
}
.import-result-success-num {
  font-size: 36px; font-weight: 900; color: var(--success); line-height: 1;
}
.import-result-success-label { font-size: 14px; font-weight: 600; color: var(--success); }
.import-result-success-sub { font-size: 12px; color: var(--text-muted); }

.import-error-list {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 12px;
}
.import-error-item {
  display: flex; gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.import-error-item:last-child { border-bottom: none; }
.import-error-row { font-weight: 700; color: var(--danger); flex-shrink: 0; width: 50px; }
.import-error-reason { color: var(--text-muted); }

/* Sample CSV hint box */
.csv-format-hint {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  margin-top: 12px;
  overflow-x: auto;
  white-space: nowrap;
}

/* ===== SHEET PICKER ===== */
.sheet-pick-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 13px 16px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.sheet-pick-btn:hover:not(.sheet-pick-empty) {
  border-color: var(--primary);
  background: var(--primary-alpha);
}
.sheet-pick-btn:active:not(.sheet-pick-empty) { transform: scale(0.98); }
.sheet-pick-empty { opacity: 0.45; cursor: not-allowed; }
