:root {
  /* ---------- Typography ---------- */
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', sans-serif;
  --font-num: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, monospace;

  /* Type scale — 5 steps only */
  --t-caption: 11px;
  --t-body: 13px;
  --t-ui: 15px;
  --t-title: 19px;
  --t-hero: 32px;

  /* Weights */
  --w-regular: 400;
  --w-medium: 500;
  --w-bold: 640;

  /* Tracking */
  --tr-tight: -0.02em;
  --tr-normal: 0;
  --tr-wide: 0.04em;

  /* ---------- Spacing (4px baseline) ---------- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* ---------- Colors (light mode) ---------- */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #0f0f14;
  --text-muted: #5c5c66;
  --text-soft: #8a8a95;
  --text-ghost: #b4b4bd;
  --border: #e4e4e0;
  --border-soft: #eeeeea;

  --primary: #2c7fd6;
  --primary-bg: #e6f0fb;
  --primary-text: #185fa5;
  --accent: #d97a0f; /* amber — EV/energy signal */
  --success: #0e8f63;
  --warn-bg: #fff4e0;
  --warn-border: #ef9f27;
  --warn-text: #9e5f0e;
  --danger: #d93a38;

  /* Elevation */
  --elev-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --elev-2: 0 2px 4px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c0f;
    --surface: #17181c;
    --surface-2: #1f2025;
    --text: #e9e9ef;
    --text-muted: #a0a0aa;
    --text-soft: #7a7a82;
    --text-ghost: #55555b;
    --border: #2a2b31;
    --border-soft: #202126;

    --primary: #6fa8f5;
    --primary-bg: #1a2f4f;
    --primary-text: #9fc4f8;
    --accent: #f5a637;
    --success: #3fd19b;
    --warn-bg: #2e220a;
    --warn-border: #c38618;
    --warn-text: #e9b259;
    --danger: #ff6b6b;

    /* On dark, use subtle top highlight + stronger drop shadow for depth */
    --elev-1: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 1px 2px rgba(0, 0, 0, 0.4);
    --elev-2: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

/* Numbers use tabular figures everywhere they appear — so $1,234 stays aligned
   vertically across rows in lists and stat cards. */
.num,
.stat-v,
.item-amt,
.loan-v,
.ev-v,
.bar-val,
.trend-v {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  background: var(--bg);
  font-family: var(--font-ui);
  color: var(--text);
  /* Tell the browser to theme native form controls (date picker icon,
     scrollbars, etc.) according to OS preference. */
  color-scheme: light dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  max-width: 520px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

/* All interactive elements give visible feedback on tap */
button:active,
.cat-btn:active,
.type-btn:active,
.nav-btn:active,
.sort-btn:active,
.io-btn:active,
.item-body:active {
  opacity: 0.65;
  transform: scale(0.98);
}
.item-body:active {
  transform: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Top chrome (sync bar + large title) removed — content starts at top;
   manual sync is via pull-to-refresh, sync state surfaces via toast. */

/* ---------- Stats ---------- */
.stats {
  display: block;
  padding: 6px 12px 10px;
}
.stats > .stat.hero {
  width: 100%;
  text-align: left;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Month switcher above hero ---------- */
.hero-month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-bottom: 8px;
  padding: 0 8px;
}
.hero-month-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 22px;
  font-weight: var(--w-medium);
  border-radius: 50%;
  transition:
    background 0.15s,
    transform 0.15s;
  padding: 0;
  line-height: 1;
}
.hero-month-btn:hover {
  background: var(--primary-bg);
}
.hero-month-btn:active {
  transform: scale(0.9);
}
.hero-month-btn:disabled {
  color: var(--text-ghost);
  cursor: default;
  opacity: 0.4;
}
.hero-month-btn:disabled:hover {
  background: transparent;
}
.hero-month-label {
  flex: 1;
  text-align: center;
  font-size: var(--t-body);
  font-weight: var(--w-medium);
  color: var(--text);
  letter-spacing: var(--tr-tight);
}
.onboarding {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
}
.stat {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--elev-1);
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-l {
  font-size: var(--t-caption);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-wide);
  color: var(--text-soft);
  text-transform: uppercase;
  margin-bottom: var(--s-1);
}
.stat-v {
  font-size: var(--t-title);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-tight);
  color: var(--text);
  line-height: 1.1;
}
.stat-s {
  font-size: var(--t-caption);
  color: var(--text-ghost);
  margin-top: 3px;
}

/* Hero stat — spans 2 columns, 1.7× weight/size. Use for the "本月擁車成本" card. */
/* Hero stat — Apple Wallet pass aesthetic.
   Single unified card: primary number on top, three secondary metrics in a
   divided strip along the bottom. No more orphan small cards. */
.stat.hero {
  padding: 16px 48px 14px 20px;
  border-radius: 16px;
  background:
    radial-gradient(
      circle at 100% 0%,
      color-mix(in srgb, var(--primary) 38%, transparent) 0%,
      transparent 62%
    ),
    linear-gradient(135deg, #1b2b47 0%, #0f1a2e 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.stat.hero::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.32), transparent);
}
.stat.hero::after {
  /* SVG bolt icon rendered via background-image mask, inherits color. */
  content: '';
  position: absolute;
  top: 14px;
  right: 18px;
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.38);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='13,2 4,14 12,14 11,22 20,10 12,10 13,2'/></svg>")
    center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='13,2 4,14 12,14 11,22 20,10 12,10 13,2'/></svg>")
    center / contain no-repeat;
}
.stat.hero .stat-l {
  color: rgba(255, 255, 255, 0.65);
  font-size: var(--t-caption);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
}
.stat.hero .stat-v {
  font-family: var(--font-num);
  font-size: 32px;
  font-weight: var(--w-bold);
  letter-spacing: -0.025em;
  color: #fff;
  line-height: 1.05;
  margin-top: 4px;
}
.stat.hero .stat-s {
  color: rgba(255, 255, 255, 0.55);
  font-size: var(--t-caption);
}
.stat-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  min-height: 18px;
}
.mom-badge {
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: var(--w-bold);
  letter-spacing: var(--tr-tight);
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  flex-shrink: 0;
}
.mom-badge.mom-up {
  background: rgba(255, 107, 107, 0.22);
  color: #ffb8b8;
}
.mom-badge.mom-down {
  background: rgba(63, 209, 155, 0.2);
  color: #9be9c7;
}
.mom-badge.mom-flat {
  color: rgba(255, 255, 255, 0.65);
}

/* Chevron affordance — hero is tappable to expand */
.hero-chevron {
  position: absolute;
  bottom: 10px;
  right: 16px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 18px;
  line-height: 1;
  transition: transform 0.25s;
}
.stat.hero.expanded .hero-chevron {
  transform: rotate(180deg);
}

/* Category breakdown shown when hero is tapped */
.hero-expand {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 0.5px solid rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: hero-expand-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes hero-expand-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.hero-cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
}
.hero-cat-ico {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.hero-cat-name {
  font-size: var(--t-body);
  color: rgba(255, 255, 255, 0.85);
  flex-shrink: 0;
  width: 64px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hero-cat-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.hero-cat-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-cat-amt {
  font-family: var(--font-num);
  font-size: var(--t-body);
  font-weight: var(--w-medium);
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: var(--tr-tight);
  width: 68px;
  text-align: right;
  flex-shrink: 0;
}
.hero-cat-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: var(--t-body);
  padding: 12px 0;
}

/* ---------- Pills below hero (previously embedded meta strip) ---------- */
.stat-pills {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.stat-pill {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 8px 11px;
  text-align: center;
  box-shadow: var(--elev-1);
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}
.stat-pill:active {
  transform: scale(0.97);
}
.stat-pill-l {
  font-size: 10px;
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 4px;
}
.stat-pill-v {
  font-family: var(--font-num);
  font-size: var(--t-ui);
  font-weight: var(--w-bold);
  letter-spacing: var(--tr-tight);
  color: var(--text);
  line-height: 1;
}

/* ---------- Icon utilities ---------- */
/* Any <svg> rendered inline — default sizing + currentColor */
svg {
  display: inline-block;
  vertical-align: middle;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
/* Small icon rendered beside text (e.g. '[icon] 匯出 CSV') */
.inline-ico {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
}
.inline-ico svg {
  width: 16px;
  height: 16px;
}
/* Category icon in picker buttons */
.cat-btn .ci svg {
  width: 22px;
  height: 22px;
}
/* Category dot in list items */
.cat-dot svg {
  width: 20px;
  height: 20px;
}
/* Chevrons in month switcher + hero expand */
.hero-month-btn svg {
  width: 18px;
  height: 18px;
}
.hero-chevron svg {
  width: 18px;
  height: 18px;
  transition: transform 0.25s;
}
.stat.hero.expanded .hero-chevron svg {
  transform: rotate(180deg);
}
/* Nav icons */
.nav-btn svg {
  width: 22px;
  height: 22px;
}
/* Swipe action buttons */
.item-actions .act-ico svg {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}
/* Hero expanded category row icon */
.hero-cat-ico svg {
  width: 16px;
  height: 16px;
  color: rgba(255, 255, 255, 0.85);
}
/* Chart bar label icon */
.bar-label-ico {
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  vertical-align: middle;
}
.bar-label-ico svg {
  width: 14px;
  height: 14px;
}
/* Empty state icon */
.empty-state .empty-icon {
  display: flex;
  justify-content: center;
  margin-bottom: var(--s-3);
}
.empty-state .empty-icon svg {
  width: 44px;
  height: 44px;
  color: var(--text-ghost);
  opacity: 0.7;
}
/* Onboarding icon (large hero-style) */
.onboarding-ico {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.onboarding-ico svg {
  width: 36px;
  height: 36px;
  color: var(--primary);
}
.onboarding-title {
  font-size: var(--t-ui);
  font-weight: var(--w-bold);
  letter-spacing: var(--tr-tight);
  color: var(--text);
  margin-bottom: 4px;
}
.onboarding-sub {
  font-size: var(--t-body);
  color: var(--text-soft);
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  .stat.hero {
    background:
      radial-gradient(
        circle at 100% 0%,
        color-mix(in srgb, var(--primary) 48%, transparent) 0%,
        transparent 65%
      ),
      linear-gradient(135deg, #1e3258 0%, #111a2e 100%);
  }
}

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--elev-1);
  margin: 0 12px;
  padding: 14px;
}

/* ---------- Form ---------- */
label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
input,
select {
  width: 100%;
  height: 44px;
  box-sizing: border-box;
  font-size: 16px; /* 16px avoids iOS auto-zoom on focus */
  line-height: 1.2;
  padding: 0 12px;
  border: 0.5px solid #ccc;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}
/* Centre date text vertically (Chrome renders type=date with its own box) */
input[type='date'] {
  display: flex;
  align-items: center;
  padding-right: 10px;
}
input[type='date']::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}
input[type='date']::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
  padding: 4px;
  margin-left: 4px;
}
input[type='date']::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}
/* Remove Chrome/Edge number spinners to match date width visually */
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type='number'] {
  -moz-appearance: textfield;
}
input:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.field {
  margin-bottom: 12px;
}
.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  min-height: 16px;
}

/* ---------- Segmented control (iOS-style) ---------- */
.type-row {
  display: flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  gap: 0;
  margin-bottom: 14px;
  position: relative;
  box-shadow:
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.04),
    inset 0 1px 2px rgba(0, 0, 0, 0.04);
}
.type-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: var(--w-medium);
  color: var(--text-muted);
  transition:
    color 0.2s,
    background 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  z-index: 1;
}
.type-btn.on {
  background: var(--surface);
  color: var(--text);
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-weight: var(--w-bold);
}
/* vertical dividers between unselected buttons (iOS pattern) */
.type-btn:not(.on) + .type-btn:not(.on)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 0.5px;
  background: var(--border);
}

.sect-title {
  font-size: 12px;
  color: var(--text-ghost);
  font-weight: 500;
  margin-bottom: 8px;
}

/* ---------- Category grid ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.cat-btn {
  min-height: 54px;
  padding: 7px 4px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.3;
  transition:
    border-color 0.2s,
    background 0.2s,
    color 0.2s,
    transform 0.2s;
}
.cat-btn .ci {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1px;
  line-height: 1;
}
.cat-btn.sel {
  font-weight: 500;
}

/* ---------- Buttons ---------- */
.btn-primary {
  width: 100%;
  padding: 13px 0;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.3s;
}
.btn-primary.ok {
  background: var(--success);
}
.btn-save {
  width: 100%;
  padding: 13px 0;
  background: var(--bg);
  color: var(--text);
  border: 0.5px solid #ccc;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
}
.btn-save.ok {
  background: var(--success);
  color: #fff;
}

.edit-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 9px 14px;
  background: var(--warn-bg);
  border-radius: 8px;
  border: 1px solid var(--warn-border);
}
.edit-bar span {
  font-size: 13px;
  color: var(--warn-text);
  font-weight: 500;
}
.edit-bar button {
  font-size: 13px;
  color: var(--warn-text);
  background: none;
  border: none;
  font-weight: 500;
}

/* ---------- Loan ---------- */
.loan-card {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.loan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px;
}
.loan-row:last-child {
  border-bottom: none;
}
.loan-k {
  color: var(--text-muted);
}
.loan-v {
  font-family: var(--font-num);
  font-weight: var(--w-medium);
  color: var(--text);
  letter-spacing: var(--tr-tight);
}
.loan-v.loan-hero {
  font-size: 26px;
  font-weight: var(--w-bold);
  color: var(--primary);
}
.loan-status {
  font-size: 12px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
  text-align: center;
}
.loan-status.pending {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}
.loan-status.done {
  background: #e1f5ee;
  color: #0f6e56;
  border: 1px solid #1d9e75;
}
.progress {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin: 12px 0 4px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 5px;
  transition: width 0.3s;
}

/* ---------- Import/Export ---------- */
.io-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.io-btn {
  flex: 1;
  padding: 8px 0;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: 6px;
}

/* ---------- List ---------- */
.filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.filter-row select {
  flex: 1;
  font-size: 13px;
  padding: 8px 10px;
}
.sort-row {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.sort-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-soft);
}
.sort-btn.on {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary-text);
  font-weight: 500;
}
.item {
  position: relative;
  overflow: hidden;
  border-bottom: 0.5px solid var(--border-soft);
}
.item-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  z-index: 1;
}
.item-actions button {
  width: 76px;
  color: #fff;
  border: none;
  font-size: 11px;
  font-weight: var(--w-bold);
  letter-spacing: var(--tr-wide);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: filter 0.15s;
}
.item-actions button:active {
  filter: brightness(0.85);
}
.item-actions .edit {
  background: #ff9500; /* iOS system orange */
}
.item-actions .del {
  background: #ff3b30; /* iOS system red */
}
.item-actions button span {
  font-size: 18px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}
.item-body {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  background: var(--surface);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  z-index: 2;
}
.item-body.swiped {
  transform: translateX(-152px);
}
.cat-dot {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.item-info {
  flex: 1;
  min-width: 0;
}
.item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
}
.pill {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 4px;
}
.pill-r {
  background: #e1f5ee;
  color: #0f6e56;
}
.pill-o {
  background: #eeedfe;
  color: #534ab7;
}
.pill-kwh {
  background: #e6f1fb;
  color: #185fa5;
}
.pill-odo {
  background: #f1efe8;
  color: #634441;
}

/* ---------- EV stats ---------- */
.ev-stats {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.ev-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.ev-cell {
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
.ev-l {
  font-size: var(--t-caption);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 3px;
}
.ev-v {
  font-family: var(--font-num);
  font-size: var(--t-ui);
  font-weight: var(--w-medium);
  color: var(--text);
  letter-spacing: var(--tr-tight);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-u {
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--text-ghost);
  font-weight: var(--w-regular);
  margin-left: 1px;
}
.item-right {
  text-align: right;
  flex-shrink: 0;
}
.item-amt {
  font-family: var(--font-num);
  font-size: var(--t-ui);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-tight);
}
.hint {
  font-size: 10px;
  color: var(--text-ghost);
  margin-top: 2px;
}
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-ghost);
  font-size: 13px;
}

/* ---------- Chart ---------- */
.trend-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 80px;
  margin-bottom: 4px;
}
.trend-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.trend-v {
  font-family: var(--font-num);
  font-size: 10px;
  color: var(--text-soft);
  line-height: 1;
}
.trend-fill {
  width: 100%;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}
.trend-labels {
  display: flex;
  gap: 5px;
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.trend-label {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--text-ghost);
}
.trend-label.cur {
  color: var(--primary);
  font-weight: 500;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.bar-label {
  font-size: 12px;
  color: var(--text-soft);
  width: 72px;
  text-align: right;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 12px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s;
}
.bar-val {
  font-family: var(--font-num);
  font-size: var(--t-body);
  font-weight: var(--w-medium);
  letter-spacing: var(--tr-tight);
  width: 72px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text);
}

/* ---------- Nav ---------- */
.nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  z-index: 99;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  min-height: 52px;
  padding: 8px 4px 10px;
  border: none;
  background: none;
  color: var(--text-ghost);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: color 0.15s;
}
.nav-btn.on {
  color: var(--primary);
}
.nav-icon {
  font-size: 22px;
  line-height: 1;
}

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(17, 17, 17, 0.92);
  color: #fff;
  padding: 10px 14px 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 360px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.2s ease-out;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.toast.err {
  background: rgba(226, 75, 74, 0.95);
}
.toast-action {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: var(--w-bold);
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background 0.15s,
    transform 0.15s;
}
.toast-action:hover {
  background: rgba(255, 255, 255, 0.28);
}
.toast-action:active {
  transform: scale(0.95);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hide {
  display: none;
}

/* ---------- iOS-style bottom sheet (used for edit from list) ---------- */
body.sheet-open {
  overflow: hidden;
}
body.sheet-open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: saturate(140%) blur(6px);
  -webkit-backdrop-filter: saturate(140%) blur(6px);
  z-index: 90;
  animation: fade-in 0.25s ease;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes sheet-up {
  from {
    transform: translate(-50%, 100%);
  }
  to {
    transform: translate(-50%, 0);
  }
}
body.sheet-open #tab-add {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translate(-50%, 0);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
  animation: sheet-up 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}
body.sheet-open #tab-add::before {
  content: '';
  display: block;
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  margin: 6px auto 14px;
}
body.sheet-open .nav,
body.sheet-open .stats {
  /* keep behind backdrop — don't hide (keeps layout stable on close) */
  pointer-events: none;
}

/* ---------- Empty state ---------- */
.empty-state {
  padding: var(--s-8) var(--s-4);
  text-align: center;
  color: var(--text-soft);
}
.empty-icon {
  font-size: 40px;
  margin-bottom: var(--s-3);
  opacity: 0.45;
  filter: grayscale(0.3);
}
.empty-title {
  font-size: var(--t-ui);
  font-weight: var(--w-medium);
  color: var(--text-muted);
  margin-bottom: var(--s-1);
}
.empty-sub {
  font-size: var(--t-body);
  color: var(--text-soft);
  max-width: 280px;
  margin: 0 auto;
  line-height: 1.5;
}

/* ---------- Motion ---------- */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes progress-sweep {
  from {
    width: 0;
  }
}
@keyframes bar-grow {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 40%, transparent);
  }
  100% {
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary) 0%, transparent);
  }
}

/* stat cards: stagger rise on first paint */
.stats > .stat {
  animation: rise 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.stats > .stat:nth-child(1) {
  animation-delay: 20ms;
}
.stats > .stat:nth-child(2) {
  animation-delay: 90ms;
}
.stats > .stat:nth-child(3) {
  animation-delay: 160ms;
}

/* loan card rises when tab opens */
.loan-card,
.ev-stats,
.empty-state {
  animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* List items stagger in (max 6 to avoid long animation) */
.item {
  animation: slide-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.item:nth-child(1) {
  animation-delay: 0ms;
}
.item:nth-child(2) {
  animation-delay: 30ms;
}
.item:nth-child(3) {
  animation-delay: 60ms;
}
.item:nth-child(4) {
  animation-delay: 90ms;
}
.item:nth-child(5) {
  animation-delay: 120ms;
}
.item:nth-child(6) {
  animation-delay: 150ms;
}

/* Chart bars expand from left */
.bar-fill {
  transform-origin: left center;
  animation: progress-sweep 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.trend-fill {
  transform-origin: bottom center;
  animation: bar-grow 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.progress-fill {
  animation: progress-sweep 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Tab switch transition — cross-fade when changing main panel */
.card > section {
  animation: rise 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Cat button selection pulse ring */
.cat-btn.sel {
  animation: pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cat-btn:active {
  transform: scale(0.96);
}

/* Submit success state gets a pop */
.btn-primary.ok {
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Nav button active — indicator slides in */
.nav-btn.on::before {
  animation: slide-in 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Toast already has its own keyframe — leave it */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Nav active indicator ---------- */
.nav-btn {
  position: relative;
}
.nav-btn.on::before {
  content: '';
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  height: 2px;
  background: var(--primary);
  border-radius: 0 0 2px 2px;
}

/* ---------- Pull to refresh ---------- */
.ptr {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border-radius: 0 0 12px 12px;
  font-size: 12px;
  font-weight: 500;
  z-index: 60;
  transition: transform 0.2s;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.ptr.show {
  transform: translate(-50%, 0);
}
