/* ============ Design tokens ============ */
:root {
  --accent: #d97757;
  --accent-dark: #c1613f;
  --accent-soft: #f5e6dc;
  --income: #3f9463;
  --expense: #c1484f;

  --bg: #f7f5f0;
  --sidebar-bg: #fbfaf6;
  --card-bg: #ffffff;
  --border: #e8e4d9;
  --text: #1c1a16;
  --text-muted: #8a8574;
  --text-faint: #b5b0a0;
  --shadow: 0 1px 2px rgba(28, 26, 22, 0.04);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent-soft: #3a2a20;
    --bg: #16150f;
    --sidebar-bg: #1b1a13;
    --card-bg: #201f18;
    --border: #33312a;
    --text: #f1efe7;
    --text-muted: #a49f8e;
    --text-faint: #6f6b5c;
    --shadow: 0 1px 2px rgba(0,0,0,0.3);
  }
}

:root[data-theme="dark"] {
  --accent-soft: #3a2a20;
  --bg: #16150f;
  --sidebar-bg: #1b1a13;
  --card-bg: #201f18;
  --border: #33312a;
  --text: #f1efe7;
  --text-muted: #a49f8e;
  --text-faint: #6f6b5c;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }
.icon { width: 20px; height: 20px; display: block; }
.muted { color: var(--text-muted); }
.muted-link { color: var(--accent); font-size: 13px; font-weight: 600; }

/* ============ App shell ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
}
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--accent);
  border-radius: 9px;
  color: #fff;
}
.brand-mark .icon { width: 18px; height: 18px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.sidebar-close { display: none; margin-left: auto; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: var(--text-muted);
}
.nav-link:hover { background: var(--accent-soft); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,18,14,0.35);
  z-index: 35;
}

.main-col { flex: 1; margin-left: 240px; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px;
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
#sidebarOpen { display: none; }

.content { padding: 24px 28px 100px; flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn .icon { width: 17px; height: 17px; }
.icon-btn-sm { width: 30px; height: 30px; }

/* ============ Buttons & forms ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600; font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--card-bg); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-add span { display: inline; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 16px; }
.field input, .field select {
  font: inherit;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-weight: 500;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field small { font-size: 12px; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.form-card {
  max-width: 560px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
}
.form-card h2 { margin: 0 0 20px; font-family: var(--font-display); font-size: 19px; letter-spacing: -0.01em; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 18px; }
.type-toggle label {
  flex: 1; text-align: center;
  padding: 10px; border-radius: 10px;
  border: 1px solid var(--border);
  font-weight: 700; font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}
.type-toggle input { display: none; }
.type-toggle label.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; background: var(--sw); cursor: pointer; display: inline-block; position: relative; border: 2px solid transparent; }
.swatch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.swatch:has(input:checked) { border-color: var(--text); box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--sw); }

.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 18px; border: 1px solid transparent; }
.alert-success { background: #eaf5ee; color: #2b6b46; border-color: #c9e6d3; }
.alert-error { background: #fbeceb; color: #a8332f; border-color: #f2cfcc; }

/* ============ Page layout helpers ============ */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-sub { color: var(--text-muted); font-size: 14px; margin: 0; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 60px 20px;
  background: var(--card-bg); border: 1px dashed var(--border); border-radius: var(--radius-lg);
  color: var(--text-muted);
}
.empty-state .icon { width: 40px; height: 40px; color: var(--text-faint); }
.empty-state h3 { margin: 4px 0 0; color: var(--text); font-size: 17px; font-family: var(--font-display); }
.empty-state p { margin: 0 0 6px; max-width: 380px; }
.empty-inline { padding: 30px 0; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ============ Stat cards & dashboard ============ */
.currency-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.cur-tab { padding: 7px 16px; border-radius: 999px; border: 1px solid var(--border); font-weight: 700; font-size: 13px; color: var(--text-muted); background: var(--card-bg); }
.cur-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
}
.stat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-dark);
  margin-bottom: 14px;
}
.stat-icon.icon-up { background: #e6f3ea; color: var(--income); }
.stat-icon.icon-down { background: #fbeceb; color: var(--expense); }
.stat-icon .icon { width: 19px; height: 19px; }
.stat-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-family: var(--font-display); font-size: 27px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
.stat-foot { font-size: 12.5px; color: var(--text-faint); font-weight: 600; }
.trend-up { color: var(--income); }
.trend-down { color: var(--expense); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.dash-grid-bottom { grid-template-columns: 1fr 1fr; }

.panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-family: var(--font-display); font-size: 15.5px; font-weight: 700; }
.chart-panel canvas { max-height: 260px; }

.mini-account-list li, .mini-txn-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.mini-account-list li:last-child, .mini-txn-list li:last-child { border-bottom: none; }
.acc-dot, .cat-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.acc-name { flex: 1; font-weight: 600; font-size: 14px; }
.acc-balance { font-family: var(--font-display); font-weight: 700; font-size: 14px; }

.mini-txn-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mini-txn-desc { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-txn-meta { font-size: 12.5px; color: var(--text-faint); }
.mini-txn-amt { font-family: var(--font-display); font-weight: 700; font-size: 14px; white-space: nowrap; }
.amt-income { color: var(--income); }
.amt-expense { color: var(--expense); }

/* ============ Accounts grid ============ */
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.account-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  position: relative;
}
.account-card.is-archived { opacity: 0.6; }
.account-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.account-label-group { display: flex; align-items: center; gap: 8px; min-width: 0; padding-top: 4px; }
.account-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.account-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card-menu { display: flex; gap: 6px; flex-shrink: 0; }
.account-bank { font-size: 13px; color: var(--text-faint); margin-bottom: 10px; }
.account-balance { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 16px; }

.account-mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.mini-stat { display: flex; flex-direction: column; gap: 3px; }
.mini-stat-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.mini-stat-value { font-family: var(--font-display); font-size: 14px; font-weight: 700; }

.account-tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill-tag { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--accent-soft); color: var(--text-muted); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 9px; }

/* ============ Categories ============ */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.category-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.category-list li:last-child { border-bottom: none; }
.cat-name { flex: 1; font-size: 14px; font-weight: 500; }
.inline-add-form { display: flex; gap: 8px; margin-top: 14px; }
.inline-add-form input { flex: 1; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }

/* ============ Transactions ============ */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; align-items: center; }
.filter-bar select, .filter-bar input {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--text); font: inherit; font-size: 13px;
}
.filter-bar input[type="search"] { min-width: 180px; }

.table-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); overflow-x: auto; }
.txn-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.txn-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; color: var(--text-faint); padding: 14px 18px; border-bottom: 1px solid var(--border); }
.txn-table td { padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 14px; }
.txn-table tr:last-child td { border-bottom: none; }
.txn-table .num { text-align: right; font-family: var(--font-display); font-weight: 700; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--pc) 14%, transparent); color: var(--pc); }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.page-link { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); font-weight: 600; font-size: 13px; background: var(--card-bg); }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ============ Mobile bottom nav & FAB ============ */
.mobile-tabbar { display: none; }
.fab { display: none; }

/* ============ Auth pages ============ */
.auth-body { background: var(--bg); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 34px 30px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }
.auth-form { margin-top: 6px; }

/* ============ Responsive ============ */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .dash-grid-bottom, .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 60px rgba(0,0,0,0.15); }
  .sidebar-close { display: inline-flex; }
  .sidebar-overlay.open { display: block; }
  .main-col { margin-left: 0; }
  #sidebarOpen { display: inline-flex; }
  .topbar { padding: 14px 16px; }
  .content { padding: 18px 16px 90px; }
  .btn-add span { display: none; }
  .btn-add { padding: 10px; }

  .mobile-tabbar {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 30;
  }
  .tab-link { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; font-size: 10.5px; font-weight: 600; color: var(--text-faint); border-radius: 10px; }
  .tab-link .icon { width: 20px; height: 20px; }
  .tab-link.active { color: var(--accent); }

  .fab {
    display: grid; place-items: center;
    position: fixed; right: 18px; bottom: 74px;
    width: 54px; height: 54px; border-radius: 50%;
    background: var(--accent); color: #fff;
    box-shadow: 0 10px 24px -6px rgba(217,119,87,0.5);
    z-index: 30;
  }
  .fab .icon { width: 24px; height: 24px; }

  .stat-grid { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }

  .txn-table thead { display: none; }
  .txn-table, .txn-table tbody, .txn-table tr, .txn-table td { display: block; width: 100%; }
  .txn-table tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .txn-table td { padding: 3px 0; border: none; display: flex; justify-content: space-between; gap: 10px; }
  .txn-table td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); font-weight: 700; }
  .txn-table .num { text-align: right; }
  .row-actions { justify-content: flex-end; padding-top: 8px; }
  .row-actions::before { content: none; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .account-mini-stats { grid-template-columns: repeat(3, 1fr); gap: 4px; }
}
