/* ===================================================
   สมุดบัญชีส่วนตัว — Design System
   Aesthetic: Warm Editorial / Japanese Ledger
   =================================================== */

   @import url('https://fonts.googleapis.com/css2?family=Noto+Serif+Thai:wght@700;900&family=Noto+Sans+Thai:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

   /* ===================================================
      TOKENS
      =================================================== */
   :root {
     --color-base:       #faf6f0;
     --color-surface:    #fff9f5;
     --color-surface2:   #f5ede3;
     --color-border:     #e8e0d5;
     --color-border-med: #cfc4b6;
   
     --color-accent:     #c94a2a;
     --color-accent-lt:  #fdeae5;
     --color-accent-dk:  #a03820;
   
     --color-income:     #2d6a4f;
     --color-income-lt:  #d8f3dc;
     --color-expense:    #c94a2a;
     --color-expense-lt: #fdeae5;
     --color-saving:     #457b9d;
     --color-saving-lt:  #d6eaf8;
     --color-warning:    #e76f51;
     --color-warning-lt: #fce4dc;
     --color-danger:     #e63946;
     --color-danger-lt:  #fde8ea;
     --color-neutral:    #6b6560;
     --color-neutral-lt: #f5f0ea;
     --color-text:       #2c2420;
     --color-text-2:     #5a524c;
     --color-text-3:     #8c7e75;
   
     --font-display: 'Noto Serif Thai', serif;
     --font-body:    'Noto Sans Thai', sans-serif;
     --font-mono:    'JetBrains Mono', 'Courier New', monospace;
   
     --space-xs: 4px;
     --space-sm: 8px;
     --space-md: 16px;
     --space-lg: 24px;
     --space-xl: 40px;
   
     --radius-sm: 8px;
     --radius-md: 12px;
     --radius-lg: 18px;
     --radius-xl: 24px;
   
     --shadow-card:  0 1px 3px rgba(101,80,60,.08), 0 4px 12px rgba(101,80,60,.04);
     --shadow-hover: 0 4px 16px rgba(101,80,60,.12);
     --shadow-modal: 0 20px 60px rgba(44,36,32,.18);
   
     --nav-h: 56px;
     --sidebar-w: 220px;
     --transition: 200ms ease;
   }
   
   /* ===================================================
      RESET & BASE
      =================================================== */
   *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
   
   html { font-size: 15px; -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }
   
   body {
     font-family: var(--font-body);
     background: var(--color-base);
     color: var(--color-text);
     line-height: 1.6;
     min-height: 100vh;
     overflow-x: hidden;
   }
   
   button {
     cursor: pointer;
     font-family: var(--font-body);
     border: none;
     background: none;
     font-size: inherit;
   }
   
   input, select, textarea {
     font-family: var(--font-body);
     font-size: inherit;
     color: inherit;
   }
   
   a { color: var(--color-accent); text-decoration: none; }
   
   /* ===================================================
      SKIP LINK
      =================================================== */
   .skip-link {
     position: absolute;
     top: -100px;
     left: 8px;
     background: var(--color-accent);
     color: #fff;
     padding: 8px 16px;
     border-radius: var(--radius-sm);
     z-index: 9999;
     font-weight: 600;
     transition: top .2s;
   }
   .skip-link:focus { top: 8px; }
   
   /* ===================================================
      LAYOUT
      =================================================== */
   #app { display: flex; min-height: 100vh; }
   
   /* Sidebar (desktop) */
   #sidebar {
     width: var(--sidebar-w);
     background: var(--color-surface);
     border-right: 1px solid var(--color-border);
     display: flex;
     flex-direction: column;
     position: sticky;
     top: 0;
     height: 100vh;
     overflow-y: auto;
     z-index: 100;
     flex-shrink: 0;
   }
   
   .sidebar-logo {
     padding: var(--space-lg) var(--space-md);
     border-bottom: 1px solid var(--color-border);
   }
   .sidebar-logo h1 {
     font-family: var(--font-display);
     font-size: 1.1rem;
     font-weight: 900;
     color: var(--color-accent);
     line-height: 1.2;
   }
   .sidebar-logo p {
     font-size: .75rem;
     color: var(--color-text-3);
     margin-top: 2px;
   }
   
   #sync-status-bar {
     padding: var(--space-sm) var(--space-md);
     font-size: .75rem;
     color: var(--color-text-3);
     border-bottom: 1px solid var(--color-border);
     display: flex;
     align-items: center;
     gap: 6px;
   }
   #sync-status-bar .dot {
     width: 6px; height: 6px;
     border-radius: 50%;
     background: var(--color-neutral);
     flex-shrink: 0;
   }
   #sync-status-bar.syncing .dot { background: var(--color-saving); animation: pulse 1s infinite; }
   #sync-status-bar.synced  .dot { background: var(--color-income); }
   #sync-status-bar.error   .dot { background: var(--color-danger); }
   #sync-status-bar.offline .dot { background: var(--color-warning); }
   
   @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
   
   nav[role="tablist"] {
     padding: var(--space-sm) 0;
     flex: 1;
   }
   nav[role="tablist"] button[role="tab"] {
     display: flex;
     align-items: center;
     gap: 10px;
     width: 100%;
     padding: 10px var(--space-md);
     font-size: .9rem;
     font-weight: 500;
     color: var(--color-text-2);
     border-radius: 0;
     transition: background var(--transition), color var(--transition);
     text-align: left;
     min-height: 44px;
   }
   nav[role="tablist"] button[role="tab"]:hover { background: var(--color-neutral-lt); }
   nav[role="tablist"] button[role="tab"][aria-selected="true"] {
     background: var(--color-accent-lt);
     color: var(--color-accent-dk);
     font-weight: 600;
     border-right: 3px solid var(--color-accent);
   }
   nav[role="tablist"] button[role="tab"] .tab-icon { font-size: 1.1rem; width: 22px; text-align: center; }
   
   .sidebar-bottom {
     padding: var(--space-md);
     border-top: 1px solid var(--color-border);
     display: flex;
     flex-direction: column;
     gap: var(--space-sm);
   }
   
   /* Main content */
   #main-content {
     flex: 1;
     min-width: 0;
     display: flex;
     flex-direction: column;
   }
   
   .tab-panel {
     display: none;
     padding: var(--space-lg);
     max-width: 1100px;
     width: 100%;
     margin: 0 auto;
     animation: fadeIn .2s ease;
   }
   .tab-panel.active { display: block; }
   
   @keyframes fadeIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
   
   /* Mobile top bar */
   #mobile-topbar {
     display: none;
     position: fixed;
     top: 0; left: 0; right: 0;
     height: 52px;
     background: var(--color-surface);
     border-bottom: 1px solid var(--color-border);
     z-index: 200;
     align-items: center;
     justify-content: space-between;
     padding: 0 var(--space-md);
     padding-top: env(safe-area-inset-top);
   }
   #mobile-title {
     font-weight: 700;
     font-size: .95rem;
     color: var(--color-text);
   }
   #hamburger-btn {
     width: 44px; height: 44px;
     display: flex; flex-direction: column;
     align-items: center; justify-content: center;
     gap: 5px; cursor: pointer; background: none; border: none;
     padding: 4px;
   }
   #hamburger-btn span {
     display: block;
     width: 22px; height: 2px;
     background: var(--color-text);
     border-radius: 2px;
     transition: all .25s ease;
     transform-origin: center;
   }
   #hamburger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
   #hamburger-btn.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
   #hamburger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
   .mobile-sync-btn {
     width: 44px; height: 44px;
     display: flex; align-items: center; justify-content: center;
     font-size: 1.1rem; cursor: pointer; background: none; border: none;
   }
   
   /* Drawer overlay */
   #drawer-overlay {
     display: none;
     position: fixed; inset: 0;
     background: rgba(44,36,32,.45);
     z-index: 300;
     backdrop-filter: blur(2px);
   }
   #drawer-overlay.open { display: block; }
   
   /* Drawer */
   #drawer {
     position: fixed;
     top: 0; left: 0; bottom: 0;
     width: 260px;
     background: var(--color-surface);
     z-index: 400;
     display: flex;
     flex-direction: column;
     transform: translateX(-100%);
     transition: transform .28s cubic-bezier(.4,0,.2,1);
     box-shadow: 4px 0 24px rgba(44,36,32,.12);
     padding-top: env(safe-area-inset-top);
   }
   #drawer.open { transform: translateX(0); }
   .drawer-header {
     padding: var(--space-lg) var(--space-md) var(--space-sm);
     border-bottom: 1px solid var(--color-border);
   }
   .drawer-logo { font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
   .drawer-sync {
     display: flex; align-items: center; gap: 6px;
     font-size: .75rem; color: var(--color-text-3);
   }
   .drawer-sync .dot {
     width: 6px; height: 6px; border-radius: 50%;
     background: var(--color-neutral); flex-shrink: 0;
   }
   .drawer-sync.syncing .dot { background: var(--color-saving); animation: pulse 1s infinite; }
   .drawer-sync.synced  .dot { background: var(--color-income); }
   .drawer-sync.error   .dot { background: var(--color-danger); }
   .drawer-sync.offline .dot { background: var(--color-warning); }
   #drawer nav { flex: 1; overflow-y: auto; padding: var(--space-sm) 0; }
   #drawer nav button[role="tab"] {
     display: flex; align-items: center; gap: 12px;
     width: 100%; padding: 12px var(--space-md);
     font-size: .95rem; font-weight: 500;
     color: var(--color-text-2);
     text-align: left; min-height: 48px;
     transition: background var(--transition), color var(--transition);
   }
   #drawer nav button[role="tab"]:hover { background: var(--color-neutral-lt); }
   #drawer nav button[role="tab"][aria-selected="true"] {
     background: var(--color-accent-lt);
     color: var(--color-accent-dk);
     font-weight: 700;
     border-right: 3px solid var(--color-accent);
   }
   #drawer nav button[role="tab"] .tab-icon { font-size: 1.2rem; width: 26px; text-align: center; }
   .drawer-bottom {
     padding: var(--space-md);
     border-top: 1px solid var(--color-border);
     padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
   }
   
   /* ===================================================
      TYPOGRAPHY
      =================================================== */
   .stat-number {
     font-family: var(--font-display);
     font-size: clamp(1.6rem, 3.5vw, 2.2rem);
     font-weight: 900;
     letter-spacing: -.02em;
     line-height: 1;
   }
   h2 { font-size: 1rem; font-weight: 600; color: var(--color-text); }
   h3 { font-size: .95rem; font-weight: 600; }
   .mono { font-family: var(--font-mono); font-size: .85rem; }
   .amount { font-family: var(--font-mono); font-weight: 500; }
   .income-color { color: var(--color-income); }
   .expense-color { color: var(--color-expense); }
   .saving-color { color: var(--color-saving); }
   
   /* ===================================================
      STAT CARDS
      =================================================== */
   .stat-grid {
     display: grid;
     grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
     gap: var(--space-md);
     margin-bottom: var(--space-lg);
   }
   
   .stat-card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     box-shadow: var(--shadow-card);
     cursor: pointer;
     transition: box-shadow var(--transition), transform var(--transition);
     position: relative;
     overflow: hidden;
   }
   .stat-card::before {
     content: '';
     position: absolute;
     top: 0; left: 0; right: 0;
     height: 3px;
     background: currentColor;
     opacity: .3;
   }
   .stat-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
   .stat-card .stat-label { font-size: .78rem; color: var(--color-text-3); font-weight: 500; margin-bottom: 6px; }
   .stat-card .stat-change { font-size: .75rem; color: var(--color-text-3); margin-top: 4px; }
   .stat-card.income-card { color: var(--color-income); }
   .stat-card.expense-card { color: var(--color-expense); }
   .stat-card.saving-card { color: var(--color-saving); }
   .stat-card.debt-card { color: var(--color-warning); }
   .stat-card.neutral-card { color: var(--color-neutral); }
   
   .quick-stats-row {
     display: grid;
     grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
     gap: var(--space-sm);
     margin-bottom: var(--space-lg);
     padding: var(--space-md);
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-md);
   }
   .quick-stat { text-align: center; }
   .quick-stat .qs-label { font-size: .72rem; color: var(--color-text-3); }
   .quick-stat .qs-value { font-family: var(--font-mono); font-size: .9rem; font-weight: 600; color: var(--color-text); }
   .quick-stat .qs-value.negative { color: var(--color-danger); }
   .quick-stat .qs-value.positive { color: var(--color-income); }
   
   /* ===================================================
      SECTION HEADERS
      =================================================== */
   .section-header {
     display: flex;
     align-items: center;
     justify-content: space-between;
     margin-bottom: var(--space-md);
     margin-top: var(--space-lg);
   }
   .section-header:first-child { margin-top: 0; }
   .section-header h2 { font-size: 1rem; font-weight: 700; }
   
   /* ===================================================
      QUICK-ADD FORM
      =================================================== */
   #quick-add-form {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     margin-bottom: var(--space-lg);
     box-shadow: var(--shadow-card);
   }
   .form-grid {
     display: grid;
     grid-template-columns: 130px 1fr auto auto;
     gap: var(--space-sm);
     align-items: start;
   }
   .form-grid-bottom {
     display: flex;
     align-items: center;
     gap: var(--space-sm);
     margin-top: var(--space-sm);
     flex-wrap: wrap;
   }
   .form-field { display: flex; flex-direction: column; gap: 3px; }
   .form-field label { font-size: .75rem; font-weight: 500; color: var(--color-text-2); }
   .form-field .error-msg { font-size: .72rem; color: var(--color-danger); min-height: 14px; }
   
   input[type="text"], input[type="number"], input[type="date"],
   input[type="tel"], input[type="email"], select, textarea {
     width: 100%;
     padding: 8px 10px;
     border: 1px solid var(--color-border-med);
     border-radius: var(--radius-sm);
     background: var(--color-base);
     color: var(--color-text);
     transition: border-color var(--transition), box-shadow var(--transition);
     font-size: .9rem;
     min-height: 40px;
   }
   input:focus, select:focus, textarea:focus {
     outline: none;
     border-color: var(--color-accent);
     box-shadow: 0 0 0 3px rgba(201,74,42,.12);
   }
   input.invalid, select.invalid { border-color: var(--color-danger); }
   textarea { resize: vertical; min-height: 80px; }
   
   /* Radio type buttons */
   .type-radio { display: flex; gap: var(--space-sm); }
   .type-radio input[type="radio"] { display: none; }
   .type-radio label {
     display: flex; align-items: center; gap: 4px;
     padding: 6px 14px;
     border: 1px solid var(--color-border-med);
     border-radius: var(--radius-sm);
     font-size: .85rem;
     cursor: pointer;
     transition: all var(--transition);
     min-height: 36px;
   }
   .type-radio input[type="radio"]:checked + label.income-label {
     background: var(--color-income-lt);
     border-color: var(--color-income);
     color: var(--color-income);
     font-weight: 600;
   }
   .type-radio input[type="radio"]:checked + label.expense-label {
     background: var(--color-expense-lt);
     border-color: var(--color-expense);
     color: var(--color-expense);
     font-weight: 600;
   }
   
   /* ===================================================
      BUTTONS
      =================================================== */
   .btn {
     display: inline-flex;
     align-items: center;
     gap: 6px;
     padding: 8px 16px;
     border-radius: var(--radius-sm);
     font-weight: 500;
     font-size: .88rem;
     min-height: 40px;
     transition: all var(--transition);
     white-space: nowrap;
   }
   .btn-primary {
     background: var(--color-accent);
     color: #fff;
   }
   .btn-primary:hover { background: var(--color-accent-dk); }
   .btn-secondary {
     background: var(--color-surface);
     color: var(--color-text-2);
     border: 1px solid var(--color-border-med);
   }
   .btn-secondary:hover { background: var(--color-neutral-lt); }
   .btn-danger {
     background: var(--color-danger-lt);
     color: var(--color-danger);
     border: 1px solid var(--color-danger);
   }
   .btn-danger:hover { background: var(--color-danger); color: #fff; }
   .btn-ghost {
     color: var(--color-text-3);
     padding: 6px 10px;
     min-height: 36px;
   }
   .btn-ghost:hover { background: var(--color-neutral-lt); color: var(--color-text); }
   .btn-sm { padding: 5px 10px; font-size: .8rem; min-height: 32px; }
   .btn-icon {
     width: 44px; height: 44px;
     display: inline-flex; align-items: center; justify-content: center;
     padding: 0;
     border-radius: var(--radius-sm);
   }
   
   button:focus-visible, a:focus-visible {
     outline: 2px solid var(--color-accent);
     outline-offset: 2px;
   }
   
   /* ===================================================
      TRANSACTION LIST
      =================================================== */
   .tx-list {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     overflow: hidden;
     box-shadow: var(--shadow-card);
   }
   .tx-row {
     display: grid;
     grid-template-columns: 36px 1fr auto auto;
     align-items: center;
     gap: var(--space-sm);
     padding: 10px var(--space-md);
     border-bottom: 1px solid var(--color-border);
     transition: background var(--transition);
   }
   .tx-row:last-child { border-bottom: none; }
   .tx-row:hover { background: var(--color-neutral-lt); }
   .tx-row.deleted-tx { opacity: .45; text-decoration: line-through; }
   .tx-icon { font-size: 1.2rem; text-align: center; }
   .tx-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
   .tx-date { font-size: .75rem; color: var(--color-text-3); font-family: var(--font-mono); }
   .tx-desc { font-size: .88rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
   .tx-cat { font-size: .72rem; color: var(--color-text-3); background: var(--color-neutral-lt); border-radius: 4px; padding: 1px 5px; display: inline-block; }
   .tx-amount { font-family: var(--font-mono); font-weight: 600; font-size: .92rem; text-align: right; white-space: nowrap; }
   .tx-amount.income  { color: var(--color-income); }
   .tx-amount.expense { color: var(--color-expense); }
   .tx-del-btn {
     width: 32px; height: 32px;
     display: flex; align-items: center; justify-content: center;
     color: var(--color-text-3);
     border-radius: 6px;
     transition: all var(--transition);
     flex-shrink: 0;
   }
   .tx-del-btn:hover { background: var(--color-danger-lt); color: var(--color-danger); }
   .tx-pending-badge {
     font-size: .65rem;
     background: var(--color-warning-lt);
     color: var(--color-warning);
     border-radius: 4px;
     padding: 1px 5px;
     font-weight: 600;
   }
   
   /* ===================================================
      FILTER BAR
      =================================================== */
   .filter-bar {
     display: flex;
     gap: var(--space-sm);
     flex-wrap: wrap;
     margin-bottom: var(--space-md);
     align-items: center;
   }
   .filter-bar input, .filter-bar select {
     min-width: 0;
     width: auto;
     min-height: 38px;
     font-size: .85rem;
     padding: 6px 10px;
   }
   .filter-bar .search-input { flex: 1; min-width: 150px; }
   
   /* ===================================================
      CHARTS
      =================================================== */
   .chart-card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     box-shadow: var(--shadow-card);
     margin-bottom: var(--space-lg);
   }
   .chart-header {
     display: flex;
     align-items: center;
     justify-content: space-between;
     margin-bottom: var(--space-md);
   }
   .chart-toggle { display: flex; gap: 4px; }
   .chart-toggle button {
     padding: 4px 10px;
     border-radius: 20px;
     font-size: .78rem;
     color: var(--color-text-3);
     border: 1px solid var(--color-border);
     transition: all var(--transition);
   }
   .chart-toggle button.active {
     background: var(--color-accent);
     color: #fff;
     border-color: var(--color-accent);
   }
   .chart-wrap { position: relative; }
   .chart-empty {
     display: flex;
     align-items: center;
     justify-content: center;
     height: 200px;
     color: var(--color-text-3);
     font-size: .9rem;
   }
   
   /* ===================================================
      CARDS (generic)
      =================================================== */
   .card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     box-shadow: var(--shadow-card);
     margin-bottom: var(--space-md);
   }
   .card-grid {
     display: grid;
     grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
     gap: var(--space-md);
   }
   
   /* ===================================================
      PROGRESS BAR
      =================================================== */
   .progress-bar-wrap { background: var(--color-border); border-radius: 99px; height: 10px; overflow: hidden; }
   .progress-bar {
     height: 100%;
     border-radius: 99px;
     background: var(--color-income);
     transition: width .5s ease;
   }
   .progress-bar.warn   { background: var(--color-warning); }
   .progress-bar.danger { background: var(--color-danger); }
   
   /* ===================================================
      BUDGET CARDS
      =================================================== */
   .budget-card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-md);
     padding: var(--space-md);
     cursor: pointer;
     transition: box-shadow var(--transition);
   }
   .budget-card:hover { box-shadow: var(--shadow-hover); }
   .budget-meta {
     display: flex;
     justify-content: space-between;
     align-items: center;
     margin-bottom: 8px;
   }
   .budget-cat { font-weight: 600; font-size: .88rem; display: flex; align-items: center; gap: 6px; }
   .budget-amounts { font-family: var(--font-mono); font-size: .82rem; color: var(--color-text-2); }
   .budget-pct {
     font-family: var(--font-mono);
     font-size: .78rem;
     text-align: right;
     margin-top: 4px;
     color: var(--color-text-3);
   }
   .budget-pct.over { color: var(--color-danger); font-weight: 700; }
   
   /* ===================================================
      GOAL CARDS
      =================================================== */
   .goal-card {
     position: relative;
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     box-shadow: var(--shadow-card);
     transition: box-shadow var(--transition);
   }
   .goal-card:hover { box-shadow: var(--shadow-hover); }
   .goal-card.complete-card { border-color: var(--color-income); background: var(--color-income-lt); }
   .goal-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
   .goal-amounts { font-family: var(--font-mono); font-size: .85rem; color: var(--color-text-2); margin-bottom: 8px; }
   .goal-eta { font-size: .78rem; color: var(--color-text-3); margin-top: 6px; }
   .goal-actions { display: flex; gap: var(--space-sm); margin-top: var(--space-sm); }
   .goal-save-inline { display: none; align-items: center; gap: var(--space-sm); margin-top: 10px; }
   .goal-save-inline.open { display: flex; }
   .complete-badge {
     position: absolute; top: 12px; right: 12px;
     background: var(--color-income);
     color: #fff;
     font-size: .72rem;
     font-weight: 700;
     padding: 3px 8px;
     border-radius: 99px;
   }
   
   /* ===================================================
      RECURRING ITEMS
      =================================================== */
   .rec-card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-md);
     padding: var(--space-md);
   }
   .rec-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
   .rec-name { font-weight: 600; font-size: .9rem; }
   .rec-amount { font-family: var(--font-mono); font-weight: 700; color: var(--color-expense); }
   .rec-badge {
     display: inline-block;
     font-size: .7rem;
     font-weight: 700;
     padding: 2px 8px;
     border-radius: 99px;
     text-transform: uppercase;
     letter-spacing: .04em;
   }
   .rec-badge.PAID     { background: var(--color-income-lt);  color: var(--color-income); }
   .rec-badge.DUE_TODAY{ background: var(--color-warning-lt); color: var(--color-warning); }
   .rec-badge.OVERDUE  { background: var(--color-danger-lt);  color: var(--color-danger); }
   .rec-badge.UPCOMING { background: var(--color-neutral-lt); color: var(--color-neutral); }
   .rec-pay-inline { display: none; align-items: center; gap: var(--space-sm); margin-top: 8px; }
   .rec-pay-inline.open { display: flex; }
   
   /* ===================================================
      DEBT CARDS
      =================================================== */
   .debt-card {
     background: var(--color-surface);
     border: 1px solid var(--color-border);
     border-radius: var(--radius-lg);
     padding: var(--space-md) var(--space-lg);
     box-shadow: var(--shadow-card);
   }
   .debt-card.settled { opacity: .6; }
   .debt-creditor { font-weight: 700; margin-bottom: 6px; font-size: .95rem; }
   .debt-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-sm); margin: 10px 0; }
   .debt-stat { text-align: center; }
   .debt-stat .label { font-size: .7rem; color: var(--color-text-3); }
   .debt-stat .value { font-family: var(--font-mono); font-weight: 600; font-size: .9rem; }
   .debt-payoff { font-size: .8rem; color: var(--color-text-2); padding: 8px; background: var(--color-neutral-lt); border-radius: var(--radius-sm); margin-top: 8px; }
   .debt-pay-inline { display: none; align-items: center; gap: var(--space-sm); margin-top: 8px; }
   .debt-pay-inline.open { display: flex; }
   
   /* ===================================================
      NET WORTH TABLE
      =================================================== */
   .nw-table {
     width: 100%;
     border-collapse: collapse;
     font-size: .9rem;
     margin-bottom: var(--space-lg);
   }
   .nw-table td { padding: 8px var(--space-md); border-bottom: 1px solid var(--color-border); }
   .nw-table tr:last-child td { font-weight: 700; border-top: 2px solid var(--color-border-med); border-bottom: none; font-size: 1rem; }
   .nw-table td:last-child { text-align: right; font-family: var(--font-mono); }
   
   /* ===================================================
      MODAL / DIALOG
      =================================================== */
   .modal-overlay {
     position: fixed; inset: 0;
     background: rgba(44,36,32,.5);
     backdrop-filter: blur(4px);
     z-index: 500;
     display: flex;
     align-items: center;
     justify-content: center;
     padding: var(--space-md);
     animation: fadeIn .15s ease;
   }
   .modal {
     background: var(--color-surface);
     border-radius: var(--radius-xl);
     padding: var(--space-xl);
     max-width: 480px;
     width: 100%;
     box-shadow: var(--shadow-modal);
     animation: slideUp .2s ease;
   }
   .modal h3 { margin-bottom: var(--space-md); font-size: 1.1rem; }
   .modal-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; margin-top: var(--space-lg); }
   
   @keyframes slideUp { from{transform:translateY(12px);opacity:0} to{transform:translateY(0);opacity:1} }
   
   /* ===================================================
      TOAST
      =================================================== */
   #toast-container {
     position: fixed;
     bottom: calc(var(--nav-h) + var(--space-md));
     left: 50%;
     transform: translateX(-50%);
     z-index: 1000;
     display: flex;
     flex-direction: column;
     gap: var(--space-sm);
     align-items: center;
     pointer-events: none;
   }
   .toast {
     background: var(--color-text);
     color: #fff;
     border-radius: var(--radius-md);
     padding: 10px 20px;
     font-size: .88rem;
     font-weight: 500;
     box-shadow: 0 4px 20px rgba(0,0,0,.2);
     opacity: 0;
     transform: translateY(8px);
     transition: opacity .2s, transform .2s;
     max-width: 340px;
     text-align: center;
     pointer-events: auto;
   }
   .toast--visible { opacity: 1; transform: translateY(0); }
   .toast--success { background: var(--color-income); }
   .toast--warning { background: var(--color-warning); }
   .toast--error   { background: var(--color-danger); }
   
   /* ===================================================
      SKELETON LOADER
      =================================================== */
   .skeleton { background: var(--color-border); border-radius: var(--radius-sm); animation: shimmer 1.4s ease infinite; }
   @keyframes shimmer { 0%,100%{opacity:1} 50%{opacity:.5} }
   .skeleton-card { height: 80px; margin-bottom: var(--space-sm); }
   
   /* ===================================================
      EMPTY STATE
      =================================================== */
   .empty-state {
     text-align: center;
     padding: var(--space-xl);
     color: var(--color-text-3);
   }
   .empty-state .empty-icon { font-size: 2.5rem; margin-bottom: var(--space-sm); }
   .empty-state p { font-size: .9rem; }
   
   /* ===================================================
      SETUP / WIZARD
      =================================================== */
   #setup-screen {
     position: fixed; inset: 0;
     background: var(--color-base);
     z-index: 900;
     display: flex;
     align-items: center;
     justify-content: center;
     padding: var(--space-lg);
   }
   .setup-box {
     background: var(--color-surface);
     border-radius: var(--radius-xl);
     padding: var(--space-xl);
     max-width: 520px;
     width: 100%;
     box-shadow: var(--shadow-modal);
   }
   .setup-step { display: none; }
   .setup-step.active { display: block; }
   .setup-box h2 { font-family: var(--font-display); font-size: 1.4rem; margin-bottom: var(--space-md); }
   .setup-box ol { padding-left: 20px; line-height: 2; font-size: .9rem; color: var(--color-text-2); }
   .setup-code-block {
     background: var(--color-text);
     color: #e8d5c0;
     border-radius: var(--radius-md);
     padding: var(--space-md);
     font-family: var(--font-mono);
     font-size: .78rem;
     margin: var(--space-md) 0;
     white-space: pre-wrap;
     word-break: break-all;
     max-height: 180px;
     overflow-y: auto;
   }
   .setup-test-result { font-size: .85rem; margin-top: var(--space-sm); min-height: 20px; }
   .setup-test-result.ok { color: var(--color-income); }
   .setup-test-result.fail { color: var(--color-danger); }
   
   /* ===================================================
      REPORT PAGE
      =================================================== */
   .profile-form .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); margin-bottom: var(--space-md); }
   .kpi-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
   .kpi-table td, .kpi-table th { padding: 8px var(--space-md); border-bottom: 1px solid var(--color-border); }
   .kpi-table th { text-align: left; font-weight: 600; color: var(--color-text-2); }
   .kpi-table td:last-child { text-align: right; font-family: var(--font-mono); font-weight: 600; }
   
   /* ===================================================
      UTILITY
      =================================================== */
   .sr-only {
     position: absolute; width: 1px; height: 1px;
     overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap;
   }
   .flex { display: flex; align-items: center; }
   .flex-between { display: flex; justify-content: space-between; align-items: center; }
   .gap-sm { gap: var(--space-sm); }
   .gap-md { gap: var(--space-md); }
   .text-right { text-align: right; }
   .text-sm { font-size: .82rem; }
   .text-xs { font-size: .75rem; }
   .text-muted { color: var(--color-text-3); }
   .mt-sm { margin-top: var(--space-sm); }
   .mt-md { margin-top: var(--space-md); }
   .mb-md { margin-bottom: var(--space-md); }
   .w-full { width: 100%; }
   .hidden { display: none !important; }
   .divider { border: none; border-top: 1px solid var(--color-border); margin: var(--space-lg) 0; }
   
   /* ===================================================
      RESPONSIVE
      =================================================== */
   @media (max-width: 720px) {
     #sidebar { display: none; }
     #mobile-topbar { display: flex; }
     #main-content { padding-top: 52px; padding-bottom: var(--space-lg); }
     #toast-container { bottom: var(--space-xl); }
   
     .tab-panel { padding: var(--space-md); }
     .form-grid { grid-template-columns: 1fr 1fr; }
     .form-grid > :nth-child(1) { grid-column: 1; }
     .form-grid > :nth-child(2) { grid-column: 1/-1; }
     .stat-grid { grid-template-columns: 1fr 1fr; }
     .quick-stats-row { grid-template-columns: repeat(2, 1fr); }
     .tx-row { grid-template-columns: 32px 1fr auto auto; }
     .profile-form .form-row { grid-template-columns: 1fr; }
     .debt-stats { grid-template-columns: 1fr 1fr; }
   }
   
   @media (max-width: 400px) {
     .stat-grid { grid-template-columns: 1fr; }
     .quick-stats-row { grid-template-columns: 1fr 1fr; }
   }
   
   /* ===================================================
      CONFETTI (goal complete)
      =================================================== */
   .confetti-particle {
     position: fixed;
     pointer-events: none;
     z-index: 9999;
     border-radius: 2px;
     animation: confetti-fall linear forwards;
   }
   @keyframes confetti-fall {
     0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
     100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
   }