/* ===========================================================
   SpendersChoice — styles
   Mobile-first, calm, minimalist. Desktop = centered phone-ish
   pane so the app feels equally at home on both.
   =========================================================== */

:root {
  /* Brand — calm teal/mint */
  --brand-1: #5EEAD4;
  --brand-2: #14B8A6;

  /* Surfaces (dark default) */
  --bg: #0F1B26;
  --surface: #162533;
  --surface-2: #1E3041;
  --surface-3: #283E54;
  --border: #2A3F55;
  --text: #ECEEF7;
  --text-dim: #A3AAC4;
  --text-faint: #7780A0;

  /* Semantic */
  --primary: #14B8A6;
  --primary-ink: #04231A;
  --success: #28C68A;
  --danger: #E5484D;
  --warn:    #F2A93B;
  --info:    #6EA8FE;

  /* Sizing */
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
  --shadow-soft: 0 2px 10px rgba(0,0,0,0.18);

  /* Layout */
  --app-max: 520px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg: #F4F7F6;
  --surface: #FFFFFF;
  --surface-2: #F2F6F5;
  --surface-3: #E5ECEA;
  --border: #DDE5E3;
  --text: #0F2A33;
  --text-dim: #4E6571;
  --text-faint: #84939B;
  --primary-ink: #04231A;
  --shadow: 0 8px 30px rgba(15,42,51,0.10);
  --shadow-soft: 0 2px 10px rgba(15,42,51,0.06);
}

@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg: #F4F7F6;
    --surface: #FFFFFF;
    --surface-2: #F2F6F5;
    --surface-3: #E5ECEA;
    --border: #DDE5E3;
    --text: #0F2A33;
    --text-dim: #4E6571;
    --text-faint: #84939B;
    --primary-ink: #04231A;
    --shadow: 0 8px 30px rgba(15,42,51,0.10);
    --shadow-soft: 0 2px 10px rgba(15,42,51,0.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }

/* ---------- App shell ---------- */
.app {
  max-width: var(--app-max);
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: calc(96px + var(--safe-bot));
  position: relative;
}

@media (min-width: 640px) {
  body {
    background:
      radial-gradient(1200px 600px at 20% -10%, rgba(94,234,212,0.10), transparent 60%),
      radial-gradient(900px 500px at 110% 110%, rgba(20,184,166,0.10), transparent 60%),
      var(--bg);
  }
  .app {
    margin-top: 32px;
    margin-bottom: 32px;
    min-height: calc(100dvh - 64px);
    background: var(--surface);
    border-radius: 28px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    padding-bottom: 112px;
  }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 28px; height: 28px; }
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.icon-btn {
  background: transparent;
  color: var(--text);
  border: 0;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 6px 14px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* ---------- Generic list pane ---------- */
.pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 14px 24px;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 4px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.section-head .count {
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}

/* ---------- Account card ---------- */
.account {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.account:hover {
  box-shadow: var(--shadow-soft);
  border-color: color-mix(in srgb, var(--cat-color, var(--brand-2)) 45%, var(--border));
}
.account-stripe {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--cat-color, var(--brand-2));
}
.account-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 6px;
}
.account-icon {
  display: inline-flex;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--cat-color, var(--brand-2)) 16%, transparent);
  color: var(--cat-color, var(--brand-2));
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}
.account-title {
  flex: 1;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.account-balances {
  padding-left: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.account-balance {
  display: flex;
  align-items: center;
  gap: 10px;
}
.account-balance .amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.account-balance .currency {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.account-balance.is-negative .amount { color: var(--danger); }

.account-meta {
  padding-left: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-dim);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 999px;
}
.chip .dot { width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.chip.chip-income {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}
.chip.chip-expense {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger);
}
.chip.chip-transfer {
  background: color-mix(in srgb, var(--info) 18%, transparent);
  color: var(--info);
}
.chip.chip-cat {
  background: color-mix(in srgb, var(--chip-color, var(--brand-2)) 18%, transparent);
  color: var(--chip-color, var(--brand-2));
}
.chip.chip-cat .dot { background: var(--chip-color, var(--brand-2)); }

/* ---------- Quick forecast row on account card ---------- */
.account-forecast {
  margin-left: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px;
}
.account-forecast .cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-faint);
}
.account-forecast .cell strong {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.account-forecast .cell .v.is-negative { color: var(--danger); }

/* ---------- Big forecast view ---------- */
.forecast-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.forecast-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.forecast-title { font-weight: 700; font-size: 15px; }
.forecast-sub { color: var(--text-dim); font-size: 12px; }
.forecast-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.forecast-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.forecast-tile .label {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}
.forecast-tile .value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.forecast-tile .value.is-negative { color: var(--danger); }
.forecast-tile .sub {
  font-size: 12px;
  color: var(--text-dim);
}
.forecast-tile .flow-sub {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}
.forecast-tile .flow-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.forecast-tile .flow-label { color: var(--text-faint); }
.forecast-tile .flow-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.forecast-tile .flow-val.pos { color: var(--success); }
.forecast-tile .flow-val.neg { color: var(--danger); }

.forecast-chart-wrap {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 6px 4px;
}
.forecast-chart {
  width: 100%;
  display: block;
  height: 180px;
}
.forecast-chart text {
  font-family: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.allowance-card {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand-2) 22%, var(--surface)),
                                       color-mix(in srgb, var(--brand-1) 12%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--brand-2) 35%, var(--border));
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.allowance-card .label {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
}
.allowance-card .amount {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.allowance-card .amount.is-negative { color: var(--danger); }
.allowance-card .body { font-size: 13px; color: var(--text-dim); }

/* ---------- Rule / transaction row ---------- */
.row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.row-card:hover {
  border-color: color-mix(in srgb, var(--brand-2) 45%, var(--border));
  box-shadow: var(--shadow-soft);
}
.row-card .row-icon {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 16px;
  flex-shrink: 0;
}
.row-card.is-income .row-icon { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.row-card.is-expense .row-icon { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.row-card.is-transfer .row-icon { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }

.row-card .row-body { flex: 1; min-width: 0; }
.row-card .row-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.row-card .row-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 2px;
}
.row-card .row-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.row-card .row-meta > span:not(.chip):not(:first-child)::before {
  content: "·";
  margin-right: 6px;
  color: var(--text-faint);
}
.arrow-rt {
  display: inline-block;
  vertical-align: middle;
  opacity: 0.7;
  flex-shrink: 0;
}
.chip-clickable {
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}
.chip-clickable:hover { filter: brightness(1.15); }

/* Occurrences list (rule modal preview) */
.occurrences-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.occurrences-list.expanded {
  max-height: 280px;
  overflow-y: auto;
  padding-right: 2px;
}
.occurrence-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.occurrence-item.is-past { opacity: 0.65; }
.occurrence-item.is-skipped .dt-parts {
  text-decoration: line-through;
  opacity: 0.55;
}
.occurrence-item .occ-skip-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-faint);
  border-radius: 6px;
  width: 26px; height: 26px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.occurrence-item .occ-skip-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}
.occurrence-item.is-skipped .occ-skip-btn { color: var(--brand-2); }
.occurrence-item .occ-num {
  color: var(--text-faint);
  font-weight: 700;
  min-width: 28px;
  text-align: right;
}
/* Datetime rendered as fixed-width parts so months/weekdays line up */
.dt-parts {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.dt-parts .dt-weekday { min-width: 30px; color: var(--text-dim); }
.dt-parts .dt-day     { min-width: 18px; text-align: right; }
.dt-parts .dt-month   { min-width: 30px; color: var(--text-dim); }
.dt-parts .dt-year    { min-width: 36px; color: var(--text-dim); }
.dt-parts .dt-time    { min-width: 40px; text-align: right; }
.occurrences-empty {
  color: var(--text-faint);
  font-style: italic;
  padding: 4px 0;
}
.row-card .row-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  text-align: right;
  flex-shrink: 0;
}
.row-card .row-amount .currency {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 600;
  margin-left: 4px;
}
.row-card.is-income .row-amount { color: var(--success); }
.row-card.is-expense .row-amount { color: var(--danger); }
.row-card.is-paused { opacity: 0.55; }

/* ---------- Account detail screen ---------- */
.detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 14px 24px;
}
.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 0;
}
.detail-head .back {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.detail-head .title {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.detail-balances-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.detail-balances-card .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.detail-balances-card .title-row {
  display: flex; align-items: center; gap: 10px;
}
.detail-balances-card .actions {
  display: flex; gap: 6px;
}
.balances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.balance-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.balance-tile .balance-tile-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.balance-tile .currency {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-faint);
}
.balance-tile .amount {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.balance-tile .amount.is-negative { color: var(--danger); }
.balance-tile .quick-set {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.balance-tile .quick-set:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: color-mix(in srgb, var(--brand-2) 45%, var(--border));
}

/* ---------- Stats card ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.stat-tile .label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
  line-height: 1.3;
}
.stat-tile .value-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat-tile .value {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  min-width: 0;
}
.stat-tile .value .num {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-tile .value.is-negative .num { color: var(--danger); }
.stat-tile .value.is-empty .num { color: var(--text-faint); font-weight: 600; }
.stat-tile .value .currency {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
  flex-shrink: 0;
}
.stat-tile .sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: -2px;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-dim);
}
.empty-logo { width: 64px; height: 64px; opacity: 0.6; margin-bottom: 8px; }
.empty h2 { margin: 8px 0 4px; color: var(--text); font-size: 18px; }
.empty p { margin: 0 0 16px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 22px;
  bottom: calc(22px + var(--safe-bot));
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: var(--primary-ink);
  border: 0;
  box-shadow: 0 10px 24px rgba(20,184,166,0.40);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: transform .15s ease;
}
.fab:active { transform: scale(0.96); }

@media (min-width: 640px) {
  .fab {
    position: absolute;
    right: 24px;
    bottom: 24px;
  }
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: var(--primary-ink);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(20,184,166,0.30);
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ---------- Onboarding ---------- */
.onboard {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #162533 0%, #0F1B26 100%);
  color: #ECEEF7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
[data-theme="light"] .onboard,
[data-theme="auto"] .onboard {
  background:
    radial-gradient(700px 400px at 20% 0%, rgba(94,234,212,0.12), transparent 70%),
    radial-gradient(600px 400px at 100% 100%, rgba(20,184,166,0.12), transparent 70%),
    var(--bg);
  color: var(--text);
}

.onboard-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  position: relative;
}
.step { display: none; animation: fade .25s ease; }
.step.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.onboard-logo { width: 72px; height: 72px; display: block; margin: 0 auto 8px; }
.onboard-title {
  text-align: center;
  font-size: 26px;
  letter-spacing: -0.01em;
  margin: 4px 0 4px;
}
.onboard-sub {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 24px;
}
.step-title { margin: 4px 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.step-sub { margin: 0 0 16px; color: var(--text-dim); font-size: 14px; }
.step-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}
.dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
}
.dots .dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: var(--border);
  transition: width .15s ease, background .15s ease;
}
.dots .dot.is-active {
  width: 20px;
  background: var(--brand-2);
}
.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.lang-grid .lang {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}
.lang-grid .lang.is-active {
  border-color: var(--brand-2);
  background: color-mix(in srgb, var(--brand-2) 12%, var(--surface-2));
}
.lang-grid .lang small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---------- Drawer (settings) ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
}
.drawer-scrim {
  position: absolute; inset: 0;
  background: rgba(8,10,20,0.55);
  backdrop-filter: blur(2px);
  animation: scrimIn .2s ease;
}
@keyframes scrimIn { from { opacity: 0; } to { opacity: 1; } }
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: drawerIn .22s ease;
}
@keyframes drawerIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body {
  overflow: auto;
  padding: 16px 18px 32px;
  display: flex; flex-direction: column; gap: 22px;
}
.setting h3 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.footer-note { text-align: center; margin: 24px 0 0; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.seg button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) {
  .modal { align-items: center; }
}
.modal-scrim {
  position: absolute; inset: 0;
  background: rgba(8,10,20,0.55);
  animation: scrimIn .2s ease;
}
.modal-card {
  position: relative;
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 8px 0 12px;
  box-shadow: var(--shadow);
  animation: sheetIn .22s ease;
  max-height: 92dvh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-card { border-radius: 22px; }
}
@keyframes sheetIn { from { transform: translateY(20px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 18px 8px;
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 18px 12px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > legend {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}
.field input[type="text"], .field input[type="number"], .field input[type="datetime-local"], .field input[type="date"], .field input[type="time"], .field select, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  outline: none;
  transition: border-color .15s ease;
  width: 100%;
  color: var(--text);
  color-scheme: dark light;
}
[data-theme="dark"] .field input[type="time"],
[data-theme="dark"] .field input[type="date"],
[data-theme="dark"] .field input[type="datetime-local"] {
  color-scheme: dark;
}
[data-theme="light"] .field input[type="time"],
[data-theme="light"] .field input[type="date"],
[data-theme="light"] .field input[type="datetime-local"] {
  color-scheme: light;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: color-mix(in srgb, var(--brand-2) 60%, var(--border));
}
.field-row {
  border: 0; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 8px;
  align-items: center;
}
.field-row.amount-all { grid-template-columns: 1fr; }
.field-row legend {
  grid-column: 1 / -1;
  padding: 0;
  margin-bottom: 4px;
}
.field-3 {
  border: 0; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: 1fr 90px 110px;
  gap: 8px;
  align-items: center;
}
.field-3 legend { grid-column: 1 / -1; padding: 0; margin-bottom: 4px; }

.modal-actions {
  display: flex; gap: 8px; align-items: center;
  padding-top: 6px;
}

/* Toggle (switch style) */
.toggle, .toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input, .toggle-field input { display: none; }
.toggle-slider {
  position: relative;
  width: 40px; height: 22px;
  background: var(--surface-3);
  border-radius: 999px;
  transition: background .15s ease;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked ~ .toggle-slider,
.toggle-field input:checked ~ .toggle-slider {
  background: var(--brand-2);
}
.toggle input:checked ~ .toggle-slider::after,
.toggle-field input:checked ~ .toggle-slider::after {
  transform: translateX(18px);
}
.toggle-label { font-size: 14px; color: var(--text); }

/* Type segmented selector */
.type-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.type-seg button {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 10px 6px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.type-seg button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}
.type-seg button.is-active[data-type="income"] { color: var(--success); }
.type-seg button.is-active[data-type="expense"] { color: var(--danger); }
.type-seg button.is-active[data-type="transfer"] { color: var(--info); }

/* Balance rows inside account modal */
.balance-edit-row {
  display: grid;
  grid-template-columns: 1fr 100px 32px;
  gap: 8px;
  align-items: center;
}
.balance-edit-row select, .balance-edit-row input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.balance-edit-row .del {
  background: transparent;
  color: var(--text-faint);
  border: 0; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.balance-edit-row .del:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bot));
  transform: translate(-50%, 30px);
  background: var(--surface-3);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* ---------- Small modal card variant ---------- */
.modal-card-sm {
  max-width: 380px;
  border-radius: 22px;
  padding-bottom: 16px;
}
@media (max-width: 639px) {
  .modal-card-sm {
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
  }
}
.dlg-title {
  margin: 4px 0 6px;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.dlg-body {
  margin: 0 0 12px;
  font-size: 14px;
}

/* ---------- Icon picker ---------- */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin: 8px 0 12px;
  max-height: 280px;
  overflow-y: auto;
}
.icon-cell {
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 0;
  font-size: 22px;
  cursor: pointer;
  transition: all .12s ease;
}
.icon-cell:hover { background: var(--surface-3); }
.icon-cell.is-active {
  border-color: var(--brand-2);
  background: color-mix(in srgb, var(--brand-2) 12%, var(--surface-2));
}
.icon-pick-btn {
  width: 40px; height: 40px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ---------- Category cards ---------- */
.category-list, .currency-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.cat-row {
  display: grid;
  grid-template-columns: 36px 1fr 32px 32px;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}
.cat-row input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
}
.cat-row input[type="color"] {
  width: 32px; height: 32px;
  padding: 0; border: 1px solid var(--border); border-radius: 8px; background: transparent;
  cursor: pointer;
}
.cat-row .del {
  background: transparent;
  color: var(--text-faint);
  border: 0; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.cat-row .del:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.currency-row {
  display: grid;
  grid-template-columns: 80px 1fr 32px;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}
.currency-row input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.currency-row .code { font-weight: 700; letter-spacing: 0.04em; text-align: center; }
.currency-row .del {
  background: transparent;
  color: var(--text-faint);
  border: 0; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.currency-row .del:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

/* ---------- Date-range chips ---------- */
.range-chips {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.range-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.range-chip:hover { color: var(--text); }
.range-chip.is-active {
  background: color-mix(in srgb, var(--brand-2) 14%, var(--surface-2));
  border-color: var(--brand-2);
  color: var(--text);
}

/* ---------- Update banner ---------- */
.update-banner {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bot));
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 12px 10px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  z-index: 80;
  font-size: 14px;
}
.update-banner .btn { padding: 6px 12px; font-size: 13px; }

/* ---------- Position grid (rule modal) ---------- */
.position-grid {
  display: grid;
  grid-template-columns: 1fr 80px 1fr 1fr;
  gap: 6px;
  align-items: center;
}
.position-grid select,
.position-grid input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
  width: 100%;
}
@media (max-width: 480px) {
  .position-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.position-warn  { color: var(--warn) !important; }
.position-error { color: var(--danger) !important; }

/* ---------- Position row (Pattern direction + N + period) ---------- */
.position-row {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  gap: 6px;
  align-items: center;
}
.position-row select,
.position-row input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
  width: 100%;
  color-scheme: dark light;
}
@media (max-width: 480px) {
  .position-row { grid-template-columns: 1fr 1fr; }
  .position-row select { grid-column: span 2; }
  .position-row input[type="number"] { grid-column: span 2; }
}

/* ---------- Rule modal recurring section ---------- */
#ruleRecurringFields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Color swatch button (replacement for native picker trigger) ---------- */
.color-swatch {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
  flex-shrink: 0;
  transition: border-color .15s ease, transform .12s ease;
}
.color-swatch:hover {
  border-color: var(--brand-2);
  transform: scale(1.05);
}
.cat-row .color-swatch { width: 32px; height: 32px; border-radius: 8px; }

/* The native color input only stays in the picker modal (for "Custom color"),
   so style it cleanly there too. */
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border: none; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }
input[type="color"]::-moz-color-swatch    { border: none; border-radius: 6px; }

/* ---------- Color palette grid (color picker modal) ---------- */
.color-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 8px 0 4px;
}
.color-cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  padding: 0;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
  transition: transform .12s ease, border-color .12s ease;
}
.color-cell:hover { transform: scale(1.08); }
.color-cell.is-active {
  border-color: var(--text);
}

/* ---------- Weekday toggles ---------- */
.weekday-toggles {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.weekday-toggles label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  color: var(--text-dim);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.weekday-toggles label:has(input:checked) {
  background: color-mix(in srgb, var(--brand-2) 18%, var(--surface-2));
  border-color: var(--brand-2);
  color: var(--text);
}
.weekday-toggles input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
@media (max-width: 380px) {
  .weekday-toggles { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Page title (consistent header per page) ---------- */
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 6px 18px 4px;
  color: var(--text);
}

/* ---------- Top dropdown menu ---------- */
.dropdown-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 200px;
  z-index: 110;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dropdown-menu button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.dropdown-menu button:hover { background: var(--surface-2); }
.dropdown-menu button.is-active {
  background: color-mix(in srgb, var(--brand-2) 18%, var(--surface));
  color: var(--text);
}
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

/* Brief highlight when scrolling a settings section into view */
.settings-focus-flash {
  animation: settingsFocusFlash 1.6s ease;
  border-radius: 12px;
}
@keyframes settingsFocusFlash {
  0%   { background: color-mix(in srgb, var(--brand-2) 22%, transparent); }
  100% { background: transparent; }
}

/* ---------- Utility ---------- */
[hidden] { display: none !important; }
.spacer { flex: 1; }
.scroll-area { overflow-y: auto; }

/* Helper: subtle divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* For long lists make scroll smooth */
.scroll-area { -webkit-overflow-scrolling: touch; }
