/* =============================================================
   Smart Finance Wallet — Mobile Banking UI
   css/mobile.css
   ============================================================= */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Kanit:wght@300;400;500;600;700&family=IBM+Plex+Sans+Thai:wght@400;500;600;700&display=swap");

/* ── Design Tokens ───────────────────────────────────────── */
:root {
  /* Colors — Minimal Indigo Palette */
  --color-primary: #4f46e5;
  --color-primary-light: #818cf8;
  --color-primary-dark: #3730a3;
  --color-income: #059669;
  --color-expense: #e11d48;
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-surface-2: #f3f4f6;
  --color-border: #e5e7eb;
  --color-text-primary: #0f172a;
  --color-text-secondary: #4b5563;
  --color-text-tertiary: #9ca3af;
  --color-overlay: rgba(15, 23, 42, 0.6);

  /* Typography Scale — 8pt Grid */
  --text-display-xl: 32px;
  --text-display-lg: 28px;
  --text-heading-lg: 22px;
  --text-heading-md: 18px;
  --text-body-lg: 16px;
  --text-body-md: 14px;
  --text-label: 13px;
  --text-caption: 12px;
  --text-micro: 11px;

  /* Font Families */
  --font-ui: "Kanit", sans-serif;
  --font-numeric: "Inter", "IBM Plex Sans Thai", sans-serif;

  /* Spacing — 8pt Grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border Radius */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm:
    0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md:
    0 4px 16px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.03);
  --shadow-lg:
    0 12px 40px rgba(15, 23, 42, 0.1), 0 4px 8px rgba(15, 23, 42, 0.05);
  --shadow-card: 0 12px 40px rgba(79, 70, 229, 0.22);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 380ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --header-h: 60px;
  --bottomnav-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Dark Mode ────────────────────────────────────────────── */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-2: #273249;
  --color-border: #334155;
  --color-text-primary: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-primary: #818cf8;
  --color-primary-light: #a5b4fc;
  --color-primary-dark: #6366f1;
}

/* ── Reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: var(--font-ui);
  font-size: var(--text-body-lg);
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
img,
svg {
  display: block;
  max-width: 100%;
}
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}
input,
textarea,
select {
  font-family: inherit;
  outline: none;
  border: none;
}
a {
  color: inherit;
  text-decoration: none;
}
ul,
ol {
  list-style: none;
}

/* ── App Shell ────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ── Fixed Header ─────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
[data-theme="dark"] .app-header {
  background: rgba(30, 41, 59, 0.92);
}
.header-title {
  font-size: var(--text-body-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.1px;
}
.header-logo {
  font-size: var(--text-body-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.header-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.header-action {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: background var(--transition-fast);
}
.header-action:active {
  background: var(--color-surface-2);
}

/* ── Content Area ─────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.page-content::-webkit-scrollbar {
  display: none;
}

/* ── Pages ────────────────────────────────────────────────── */
.page {
  display: none;
  animation: pageIn var(--transition-slow) forwards;
  min-height: 100%;
}
.page.active {
  display: block;
}

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

/* ── Bottom Navigation ────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: var(--space-2);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
  box-shadow: 0 -1px 0 var(--color-border);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  padding: var(--space-1) var(--space-2);
  transition: color var(--transition-fast);
  color: var(--color-text-tertiary);
  position: relative;
}
.nav-item.active {
  color: var(--color-primary);
}
.nav-icon-wrap {
  width: 44px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
}
.nav-item.active .nav-icon-wrap {
  background: #eef2ff;
}
[data-theme="dark"] .nav-item.active .nav-icon-wrap {
  background: rgba(129, 140, 248, 0.15);
}
.nav-item .nav-label {
  font-size: var(--text-micro);
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* FAB (Center Add Button) */
.nav-fab-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  position: relative;
  top: -14px;
}
.nav-fab {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.nav-fab:active {
  transform: scale(0.93);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.nav-fab-label {
  font-size: var(--text-micro);
  font-weight: 600;
  color: var(--color-primary);
  margin-top: 2px;
}

/* ── Wallet Card ──────────────────────────────────────────── */
.wallet-section {
  padding: var(--space-5);
  background: var(--color-bg);
}
.wallet-card {
  background: linear-gradient(145deg, #0f172a 0%, #1e1b4b 55%, #312e81 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.wallet-card::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -30px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(129, 140, 248, 0.18) 0%,
    transparent 70%
  );
}
.wallet-card::after {
  content: "";
  position: absolute;
  bottom: -80px;
  left: -50px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(79, 70, 229, 0.14) 0%,
    transparent 70%
  );
}
.wallet-label {
  font-size: var(--text-label);
  font-weight: 400;
  opacity: 0.8;
  letter-spacing: 0.3px;
}
.wallet-balance {
  font-family: var(--font-numeric);
  font-size: var(--text-display-xl);
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.2;
  margin-top: var(--space-1);
}
.wallet-update {
  font-size: var(--text-caption);
  opacity: 0.65;
  margin-top: 4px;
}
.wallet-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  position: relative;
  z-index: 1;
}
.wallet-stat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.wallet-stat-label {
  font-size: var(--text-caption);
  opacity: 0.75;
  display: flex;
  align-items: center;
  gap: 4px;
}
.wallet-stat-value {
  font-family: var(--font-numeric);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.wallet-stat-value.income {
  color: #6ee7b7;
}
.wallet-stat-value.expense {
  color: #fca5a5;
}
.saving-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  font-size: var(--text-caption);
  font-weight: 600;
  margin-top: var(--space-3);
  position: relative;
  z-index: 1;
}

/* ── Quick Actions ────────────────────────────────────────── */
.quick-actions {
  padding: var(--space-2) var(--space-5) var(--space-4);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}
.quick-btn {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  min-height: 82px;
  position: relative;
  overflow: hidden;
}
.quick-btn:active {
  transform: scale(0.96);
  box-shadow: none;
}
.quick-btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.quick-btn-icon.income {
  background: #d1fae5;
  color: #059669;
}
.quick-btn-icon.expense {
  background: #ffe4e6;
  color: #e11d48;
}
.quick-btn-icon.budget {
  background: #e0e7ff;
  color: var(--color-primary);
}
.quick-btn-label {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-align: center;
  letter-spacing: 0.1px;
}

/* ── Section ──────────────────────────────────────────────── */
.section {
  padding: 0 var(--space-5) var(--space-2);
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  padding: var(--space-4) 0 0;
}
.section-title {
  font-size: var(--text-heading-md);
  font-weight: 600;
  color: var(--color-text-primary);
}
.section-action {
  font-size: var(--text-body-md);
  font-weight: 500;
  color: var(--color-primary);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.section-action:active {
  background: var(--color-surface-2);
}

/* ── Transaction List ─────────────────────────────────────── */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.tx-date-group {
  margin-bottom: var(--space-2);
}
.tx-date-label {
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: var(--space-2) 0 var(--space-1);
}
.tx-item {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition: transform var(--transition-fast);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  min-height: 64px;
}
.tx-item:active {
  transform: scale(0.99);
}
.tx-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  background: var(--color-surface-2);
}
.tx-info {
  flex: 1;
  min-width: 0;
}
.tx-name {
  font-size: var(--text-body-md);
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tx-meta {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
  margin-top: 2px;
}
.tx-amount {
  font-family: var(--font-numeric);
  font-size: var(--text-body-lg);
  font-weight: 700;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}
.tx-amount.income {
  color: var(--color-income);
}
.tx-amount.expense {
  color: var(--color-expense);
}

/* Swipe-to-delete */
.tx-delete-bg {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  background: var(--color-expense);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: var(--space-5);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: var(--text-label);
  font-weight: 600;
  gap: 6px;
  z-index: 0;
  min-width: 90px;
}
.tx-item-inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  transition: transform var(--transition-normal);
}

/* ── Bottom Sheet Modal ───────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.show {
  opacity: 1;
  pointer-events: all;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 201;
  padding: 0 var(--space-5) calc(var(--space-6) + var(--safe-bottom));
  max-height: 95vh;
  overflow-y: auto;
  transition: transform var(--transition-slow);
  box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.2);
}
.bottom-sheet.show {
  transform: translateX(-50%) translateY(0);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  margin: var(--space-3) auto var(--space-4);
}
.sheet-title {
  font-size: var(--text-heading-md);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-5);
  text-align: center;
}

/* ── Type Toggle ──────────────────────────────────────────── */
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: var(--space-5);
  gap: 4px;
}
.type-btn {
  padding: var(--space-3);
  border-radius: calc(var(--radius-md) - 2px);
  font-size: var(--text-body-md);
  font-weight: 600;
  text-align: center;
  transition: all var(--transition-fast);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.type-btn.active.income {
  background: #059669;
  color: #fff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}
.type-btn.active.expense {
  background: #e11d48;
  color: #fff;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.3);
}

/* ── Amount Input ─────────────────────────────────────────── */
.amount-wrap {
  text-align: center;
  padding: var(--space-4) 0 var(--space-5);
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-5);
}
.amount-currency {
  font-size: var(--text-heading-md);
  color: var(--color-text-tertiary);
  font-family: var(--font-numeric);
  font-weight: 600;
}
.amount-input {
  font-family: var(--font-numeric);
  font-size: var(--text-display-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  text-align: center;
  letter-spacing: 0.2px;
  caret-color: var(--color-primary);
}
.amount-input::placeholder {
  color: var(--color-border);
}

/* ── Form Fields ──────────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-4);
}
.form-label {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--color-text-secondary);
  display: block;
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-body-md);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast);
  min-height: 48px;
}
.form-input:focus {
  border-color: var(--color-primary);
}
.form-input.error {
  border-color: var(--color-expense);
}

/* ── Category Grid ────────────────────────────────────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  transition: all var(--transition-fast);
  cursor: pointer;
  min-height: 72px;
}
.cat-item:active,
.cat-item.selected {
  border-color: var(--color-primary);
  background: #eff6ff;
}
[data-theme="dark"] .cat-item:active,
[data-theme="dark"] .cat-item.selected {
  background: rgba(59, 130, 246, 0.15);
}
.cat-icon {
  font-size: 26px;
  line-height: 1;
}
.cat-name {
  font-size: var(--text-micro);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-align: center;
}

/* ── Save Button ──────────────────────────────────────────── */
.save-btn {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: var(--text-body-lg);
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
  transition: all var(--transition-fast);
  min-height: 56px;
  margin-top: var(--space-4);
}
.save-btn:active {
  transform: scale(0.98);
  opacity: 0.92;
}
.save-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Month Filter ─────────────────────────────────────────── */
.month-filter {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-4) var(--space-5);
  scrollbar-width: none;
}
.month-filter::-webkit-scrollbar {
  display: none;
}
.month-chip {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: nowrap;
  min-height: 36px;
  display: flex;
  align-items: center;
  transition: all var(--transition-fast);
}
.month-chip.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ── Analytics Charts ─────────────────────────────────────── */
.chart-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.chart-title {
  font-size: var(--text-heading-md);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-4);
}
.chart-wrap {
  position: relative;
}

/* ── Insight Cards ────────────────────────────────────────── */
.insight-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.insight-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.insight-card.positive {
  border-left: 4px solid var(--color-income);
}
.insight-card.warning {
  border-left: 4px solid #f59e0b;
}
.insight-card.info {
  border-left: 4px solid var(--color-primary-light);
}
.insight-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.insight-text {
  font-size: var(--text-body-md);
  color: var(--color-text-primary);
  line-height: 1.5;
}

/* ── Settings ─────────────────────────────────────────────── */
.settings-section {
  padding: var(--space-4) var(--space-5) 0;
}
.settings-group {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-4);
}
.settings-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  min-height: 56px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.settings-item:last-child {
  border-bottom: none;
}
.settings-item:active {
  background: var(--color-surface-2);
}
.settings-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-2);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.settings-label {
  flex: 1;
  font-size: var(--text-body-md);
  font-weight: 500;
  color: var(--color-text-primary);
}
.settings-arrow {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
}
.settings-item.danger .settings-label {
  color: var(--color-expense);
}
.settings-item.danger .settings-icon {
  background: #fff1f2;
  color: var(--color-expense);
}

/* Toggle Switch */
.toggle-switch {
  width: 50px;
  height: 28px;
  background: var(--color-border);
  border-radius: 14px;
  position: relative;
  transition: background var(--transition-fast);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-fast);
}
.toggle-switch.on {
  background: var(--color-primary);
}
.toggle-switch.on::after {
  transform: translateX(22px);
}

/* ── Auth Screen ──────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
  background: var(--color-bg);
}
.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
  color: #fff;
  box-shadow: 0 8px 28px rgba(79, 70, 229, 0.35);
}
.auth-app-name {
  font-size: var(--text-display-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-1);
}
.auth-tagline {
  font-size: var(--text-body-md);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-8);
  text-align: center;
}
.auth-card {
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}
.auth-input-wrap {
  position: relative;
  margin-bottom: var(--space-4);
}
.auth-input-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
}
.auth-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-4) var(--space-4) 48px;
  font-size: var(--text-body-lg);
  color: var(--color-text-primary);
  min-height: 56px;
  transition: border-color var(--transition-fast);
}
.auth-input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
}
.auth-btn {
  width: 100%;
  padding: var(--space-4);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: var(--text-body-lg);
  font-weight: 700;
  min-height: 56px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
  margin-top: var(--space-2);
}
.auth-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* ── Skeleton Loader ──────────────────────────────────────── */
@keyframes shimmer {
  0% {
    background-position: -400px 0;
  }
  100% {
    background-position: 400px 0;
  }
}
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-border) 25%,
    var(--color-surface-2) 50%,
    var(--color-border) 75%
  );
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
.skeleton-card {
  height: 200px;
  border-radius: var(--radius-lg);
  margin: var(--space-5);
}
.skeleton-item {
  height: 72px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + var(--space-3));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  width: calc(100% - var(--space-10));
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  background: var(--color-text-primary);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-body-md);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
  animation:
    toastIn 0.3s ease,
    toastOut 0.3s ease 2.7s forwards;
  pointer-events: all;
}
.toast.success {
  background: #065f46;
  border-left: 4px solid var(--color-income);
}
.toast.error {
  background: #7f1d1d;
  border-left: 4px solid var(--color-expense);
}
.toast.info {
  background: #312e81;
  border-left: 4px solid var(--color-primary-light);
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
  }
}

/* ── Budget Progress ──────────────────────────────────────── */
.budget-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.budget-item:last-child {
  border-bottom: none;
}
.budget-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.budget-cat {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.budget-cat-icon {
  font-size: 18px;
}
.budget-cat-name {
  font-size: var(--text-body-md);
  font-weight: 500;
}
.budget-amounts {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
}
.progress-bar {
  height: 8px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-income);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-fill.warning {
  background: #f59e0b;
}
.progress-fill.over {
  background: var(--color-expense);
}

/* ── Ripple Effect ────────────────────────────────────────── */
.ripple-host {
  position: relative;
  overflow: hidden;
}
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  animation: rippleAnim 0.5s linear;
  pointer-events: none;
}
@keyframes rippleAnim {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* ── Loading Overlay ──────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: var(--space-4);
  transition: opacity 0.4s ease;
}
.loading-overlay.hide {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-text {
  font-size: var(--text-body-md);
  font-weight: 500;
  color: var(--color-text-secondary);
}

/* ── Utility ──────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.hidden {
  display: none !important;
}
.flex {
  display: flex;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-2 {
  gap: var(--space-2);
}
.gap-3 {
  gap: var(--space-3);
}
.mt-4 {
  margin-top: var(--space-4);
}
.mb-4 {
  margin-bottom: var(--space-4);
}
.text-income {
  color: var(--color-income);
}
.text-expense {
  color: var(--color-expense);
}
.text-primary {
  color: var(--color-primary);
}
.font-numeric {
  font-family: var(--font-numeric);
}
.font-bold {
  font-weight: 700;
}
.text-center {
  text-align: center;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.empty-icon {
  font-size: 48px;
  line-height: 1;
}
.empty-text {
  font-size: var(--text-body-md);
  color: var(--color-text-tertiary);
  line-height: 1.6;
}

/* ── Desktop Enhancement ──────────────────────────────────── */
@media (min-width: 480px) {
  #app {
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
  }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-2: #273249;
    --color-border: #334155;
    --color-text-primary: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-tertiary: #64748b;
    --color-primary: #818cf8;
    --color-primary-light: #a5b4fc;
    --color-primary-dark: #6366f1;
  }
}

/* =============================================================
   RECURRING EXPENSES & CATEGORY MANAGEMENT
   ============================================================= */

/* ── Page Toolbar ─────────────────────────────────────────── */
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-2);
}
.page-toolbar-title {
  font-size: var(--text-body-md);
  font-weight: 600;
  color: var(--color-text-secondary);
}
.toolbar-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-full);
  font-size: var(--text-label);
  font-weight: 600;
  font-family: "Kanit", sans-serif;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
  transition: opacity var(--transition-fast);
}
.toolbar-add-btn:active {
  opacity: 0.8;
}

/* ── Recurring Summary Card (Home Page) ──────────────────── */
.recurring-summary-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  margin-bottom: var(--space-3);
}
.recurring-summary-card:empty {
  display: none;
}
.rec-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.rec-summary-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--text-label);
  font-weight: 700;
  color: var(--color-text-primary);
}
.rec-summary-row {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.rec-summary-item {
  flex: 1;
  text-align: center;
  padding: var(--space-2) var(--space-1);
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
}
.rec-summary-label {
  font-size: var(--text-micro);
  color: var(--color-text-tertiary);
  margin-bottom: 3px;
  font-family: "Kanit", sans-serif;
}
.rec-summary-value {
  font-size: var(--text-label);
  font-weight: 700;
  font-family: var(--font-numeric);
}
.rec-summary-value.income {
  color: var(--color-income);
}
.rec-summary-value.expense {
  color: var(--color-expense);
}

/* ── Progress Bar ────────────────────────────────────────── */
.rec-prog-wrap {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 6px;
}
.rec-prog-bar {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--color-primary),
    var(--color-primary-light)
  );
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
  min-width: 0%;
  max-width: 100%;
}
.rec-prog-label {
  font-size: var(--text-micro);
  color: var(--color-text-tertiary);
  text-align: right;
  font-family: var(--font-numeric);
}

/* ── Recurring Status Card (Page Top) ────────────────────── */
.rec-status-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  margin-bottom: var(--space-4);
}
.rec-stat-row {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.rec-stat {
  flex: 1;
  text-align: center;
}
.rec-stat-num {
  font-size: var(--text-body-md);
  font-weight: 700;
  font-family: var(--font-numeric);
  color: var(--color-text-primary);
  margin-bottom: 3px;
}
.rec-stat-num.income {
  color: var(--color-income);
}
.rec-stat-num.expense {
  color: var(--color-expense);
}
.rec-stat-label {
  font-size: var(--text-micro);
  color: var(--color-text-tertiary);
  font-family: "Kanit", sans-serif;
}

/* ── Alert Banners ────────────────────────────────────────── */
.rec-alert {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--text-label);
  font-weight: 600;
  font-family: "Kanit", sans-serif;
  margin-bottom: var(--space-3);
}
.rec-alert.overdue {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}
.rec-alert.due-soon {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}
[data-theme="dark"] .rec-alert.overdue {
  background: rgba(190, 18, 60, 0.15);
  border-color: rgba(190, 18, 60, 0.3);
}
[data-theme="dark"] .rec-alert.due-soon {
  background: rgba(180, 83, 9, 0.15);
  border-color: rgba(180, 83, 9, 0.3);
}

/* ── Recurring Item Card ──────────────────────────────────── */
.rec-item {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  transition: opacity var(--transition-fast);
}
.rec-item.paid {
  opacity: 0.65;
}
.rec-item-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}
.rec-item-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.rec-item-info {
  min-width: 0;
}
.rec-item-name {
  font-size: var(--text-body-md);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-item-meta {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
  margin-top: 2px;
  font-family: "Kanit", sans-serif;
}
.rec-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}
.rec-item-amount {
  font-size: var(--text-body-md);
  font-weight: 700;
  color: var(--color-expense);
  font-family: var(--font-numeric);
}

/* ── Status Badge ────────────────────────────────────────── */
.rec-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: 700;
  font-family: "Kanit", sans-serif;
  letter-spacing: 0.2px;
}
.rec-status-badge.paid {
  background: #d1fae5;
  color: #065f46;
}
.rec-status-badge.overdue {
  background: #ffe4e6;
  color: #be123c;
}
.rec-status-badge.due-soon {
  background: #fef3c7;
  color: #92400e;
}
.rec-status-badge.pending {
  background: var(--color-surface-2);
  color: var(--color-text-tertiary);
}
[data-theme="dark"] .rec-status-badge.paid {
  background: rgba(6, 95, 70, 0.25);
  color: #34d399;
}
[data-theme="dark"] .rec-status-badge.overdue {
  background: rgba(190, 18, 60, 0.2);
  color: #fb7185;
}
[data-theme="dark"] .rec-status-badge.due-soon {
  background: rgba(146, 64, 14, 0.2);
  color: #fbbf24;
}

/* ── Item Action Buttons ─────────────────────────────────── */
.rec-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.rec-pay-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: 700;
  font-family: "Kanit", sans-serif;
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
  transition: all var(--transition-fast);
}
.rec-pay-btn:active {
  opacity: 0.75;
}
.rec-pay-btn.paid {
  background: var(--color-surface-2);
  color: var(--color-text-tertiary);
  border-color: var(--color-border);
}
[data-theme="dark"] .rec-pay-btn {
  background: rgba(5, 150, 105, 0.15);
  border-color: rgba(5, 150, 105, 0.3);
}
[data-theme="dark"] .rec-pay-btn.paid {
  background: var(--color-surface-2);
  border-color: var(--color-border);
}

.rec-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.rec-icon-btn.edit {
  background: #eef2ff;
  color: var(--color-primary);
}
.rec-icon-btn.delete {
  background: #fff1f2;
  color: var(--color-expense);
}
.rec-icon-btn:active {
  opacity: 0.7;
}
[data-theme="dark"] .rec-icon-btn.edit {
  background: rgba(79, 70, 229, 0.15);
}
[data-theme="dark"] .rec-icon-btn.delete {
  background: rgba(225, 29, 72, 0.15);
}

/* ── Inline Badge ────────────────────────────────────────── */
.rec-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: 700;
  font-family: "Kanit", sans-serif;
}
.rec-badge.overdue {
  background: #ffe4e6;
  color: #be123c;
}

/* ── Category Manager Sheet ──────────────────────────────── */
.sheet-tall {
  max-height: 88vh;
  height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cat-manager-toolbar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.cat-add-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px var(--space-3);
  border-radius: var(--radius-lg);
  font-size: var(--text-label);
  font-weight: 600;
  font-family: "Kanit", sans-serif;
  border: 2px dashed;
  transition: opacity var(--transition-fast);
}
.cat-add-btn.expense {
  color: var(--color-expense);
  border-color: var(--color-expense);
  background: #fff1f2;
}
.cat-add-btn.income {
  color: var(--color-income);
  border-color: var(--color-income);
  background: #f0fdf4;
}
[data-theme="dark"] .cat-add-btn.expense {
  background: rgba(225, 29, 72, 0.1);
}
[data-theme="dark"] .cat-add-btn.income {
  background: rgba(5, 150, 105, 0.1);
}
.cat-add-btn:active {
  opacity: 0.7;
}

/* ── Category List Items ─────────────────────────────────── */
.cat-manage-group-title {
  font-size: var(--text-label);
  font-weight: 700;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
  padding-left: 2px;
}
.cat-manage-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  margin-bottom: var(--space-2);
}
.cat-manage-icon {
  font-size: 22px;
  width: 36px;
  text-align: center;
}
.cat-manage-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.cat-manage-name {
  font-size: var(--text-body-md);
  font-weight: 600;
  color: var(--color-text-primary);
}
.cat-default-badge {
  font-size: var(--text-micro);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-border);
  font-family: "Kanit", sans-serif;
}
.cat-manage-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.cat-action-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition-fast);
}
.cat-action-btn.edit {
  background: #eef2ff;
  color: var(--color-primary);
}
.cat-action-btn.delete {
  background: #fff1f2;
  color: var(--color-expense);
}
.cat-action-btn:active {
  opacity: 0.7;
}
[data-theme="dark"] .cat-action-btn.edit {
  background: rgba(79, 70, 229, 0.15);
}
[data-theme="dark"] .cat-action-btn.delete {
  background: rgba(225, 29, 72, 0.15);
}

/* ── Form Select ─────────────────────────────────────────── */
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px !important;
  cursor: pointer;
}
