/* ==========================================================================
   記帳簿 Pocket Ledger — 樣式系統
   三層 token：primitive → semantic → component（全部集中在 :root）
   ========================================================================== */

/* ---------- 1. Primitive tokens ---------- */
:root {
  --c-white: #ffffff;
  --c-slate-50: #f8fafc;
  --c-slate-100: #f1f5f9;
  --c-slate-200: #e2e8f0;
  --c-slate-300: #cbd5e1;
  --c-slate-400: #94a3b8;
  --c-slate-500: #64748b;
  --c-slate-600: #475569;
  --c-slate-700: #334155;
  --c-slate-800: #1e293b;
  --c-slate-900: #0f172a;
  --c-slate-950: #080d1a;

  --c-indigo-400: #818cf8;
  --c-indigo-500: #6366f1;
  --c-indigo-600: #4f46e5;
  --c-indigo-700: #4338ca;

  --c-rose-500: #f43f5e;
  --c-rose-600: #e11d48;
  --c-emerald-500: #10b981;
  --c-emerald-600: #059669;
  --c-amber-500: #f59e0b;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 999px;

  --font-sans: "PingFang HK", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-num: "SF Mono", ui-monospace, "Menlo", "Roboto Mono", monospace;

  --dur-fast: 120ms;
  --dur-base: 200ms;
  --ease: cubic-bezier(0.32, 0.72, 0.28, 1);
}

/* ---------- 2. Semantic tokens（淺色） ---------- */
:root,
[data-theme="light"] {
  --bg: var(--c-slate-50);
  --bg-accent: radial-gradient(1200px 600px at 12% -8%, #e0e7ff 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #ccfbf1 0%, transparent 55%);
  --surface: var(--c-white);
  --surface-2: var(--c-slate-100);
  --surface-3: var(--c-slate-200);
  --border: var(--c-slate-200);
  --border-strong: var(--c-slate-300);
  --text: var(--c-slate-900);
  --text-muted: var(--c-slate-500);
  --text-faint: var(--c-slate-400);
  --accent: var(--c-indigo-600);
  --accent-soft: #eef2ff;
  --accent-text: var(--c-white);
  --expense: var(--c-rose-600);
  --expense-soft: #fff1f2;
  --income: var(--c-emerald-600);
  --income-soft: #ecfdf5;
  --warn: var(--c-amber-500);
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 4%);
  --shadow-md: 0 4px 16px rgb(15 23 42 / 8%), 0 1px 3px rgb(15 23 42 / 4%);
  --shadow-lg: 0 20px 50px rgb(15 23 42 / 16%);
  --nav-bg: rgb(255 255 255 / 88%);
}

[data-theme="dark"] {
  --bg: var(--c-slate-950);
  --bg-accent: radial-gradient(1200px 600px at 10% -10%, #1e1b4b 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #042f2e 0%, transparent 55%);
  --surface: #101728;
  --surface-2: #182034;
  --surface-3: #222c44;
  --border: #26314c;
  --border-strong: #35415f;
  --text: #e8edf7;
  --text-muted: #98a4bd;
  --text-faint: #6b7793;
  --accent: var(--c-indigo-400);
  --accent-soft: #1c2340;
  --accent-text: #0b1020;
  --expense: #fb7185;
  --expense-soft: #2a1721;
  --income: #34d399;
  --income-soft: #0d2a22;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 45%);
  --shadow-lg: 0 24px 60px rgb(0 0 0 / 60%);
  --nav-bg: rgb(16 23 40 / 88%);
}

/* ---------- 3. Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1, h2, h3, h4, p {
  margin: 0;
}

ul, ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--accent);
  color: var(--accent-text);
}

/* 數字一律等寬，對齊好看 */
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- 4. 版面：手機底部 tab、桌面左側欄 ---------- */
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
}

.sidebar {
  display: none;
}

.main {
  min-width: 0;
  padding: var(--space-4) var(--space-4) calc(84px + env(safe-area-inset-bottom, 0px));
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--border);
}

.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) var(--space-1);
  border: 0;
  background: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.tabbar__item[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.tabbar__icon {
  font-size: 19px;
  line-height: 1;
}

@media (min-width: 900px) {
  .shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-6) var(--space-4);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100dvh;
    background: color-mix(in srgb, var(--surface) 55%, transparent);
    backdrop-filter: blur(8px);
  }

  .tabbar {
    display: none;
  }

  .main {
    padding: var(--space-8) var(--space-8) var(--space-10);
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.brand__mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 20px;
  background: linear-gradient(140deg, var(--c-indigo-500), #0ea5e9);
  box-shadow: var(--shadow-sm);
}

.brand__name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand__sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sidebar__item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__item[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-text);
}

.sidebar__spacer {
  flex: 1;
}

/* ---------- 5. 頁首 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.topbar__title {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.topbar__sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* 月份切換器 */
.monthnav {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
}

.monthnav__btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-muted);
  font-size: 16px;
  display: grid;
  place-items: center;
}

.monthnav__btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.monthnav__label {
  min-width: 96px;
  text-align: center;
  font-weight: 650;
  font-size: 14px;
}

/* ---------- 6. 卡片與區塊 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-4);
}

.card--flush {
  padding: var(--space-4) var(--space-5);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: 15px;
  font-weight: 700;
}

.card__hint {
  font-size: 12px;
  color: var(--text-muted);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: var(--space-6) 0 var(--space-3);
}

.section-title:first-child {
  margin-top: 0;
}

/* ---------- 7. 統計磚 ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (min-width: 640px) {
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.tile--balance {
  grid-column: span 2;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #0ea5e9));
  border-color: transparent;
  color: var(--accent-text);
}

@media (min-width: 640px) {
  .tile--balance {
    grid-column: span 1;
  }
}

.tile__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.tile--balance .tile__label {
  color: color-mix(in srgb, var(--accent-text) 78%, transparent);
}

.tile__value {
  margin-top: var(--space-2);
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.tile--balance .tile__value {
  font-size: 28px;
}

.tile__meta {
  margin-top: var(--space-1);
  font-size: 11px;
  color: var(--text-muted);
}

.tile--balance .tile__meta {
  color: color-mix(in srgb, var(--accent-text) 72%, transparent);
}

.amount-expense {
  color: var(--expense);
}

.amount-income {
  color: var(--income);
}

.tile--balance .amount-expense,
.tile--balance .amount-income {
  color: inherit;
}

/* ---------- 8. 表單元件 ---------- */
.field {
  display: block;
  margin-bottom: var(--space-4);
}

.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 11px var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.textarea {
  min-height: 72px;
  resize: vertical;
}

.field__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* 大金額輸入 */
.amount-field {
  text-align: center;
  padding: var(--space-4) 0 var(--space-5);
}

.amount-field__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.amount-field__row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--space-2);
}

.amount-field__symbol {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-muted);
}

.amount-field__input {
  width: min(260px, 62vw);
  border: 0;
  background: none;
  text-align: center;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0;
}

.amount-field__input:focus {
  outline: none;
}

.amount-field__input::placeholder {
  color: var(--text-faint);
  opacity: 0.5;
}

.amount-field--expense .amount-field__input {
  color: var(--expense);
}

.amount-field--income .amount-field__input {
  color: var(--income);
}

.amount-field__error {
  min-height: 18px;
  margin-top: var(--space-2);
  font-size: 12px;
  color: var(--expense);
}

/* 分段控制 */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.segmented__btn {
  border: 0;
  background: none;
  padding: 8px var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 650;
  font-size: 14px;
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.segmented__btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented__btn[aria-pressed="true"][data-type="expense"] {
  color: var(--expense);
}

.segmented__btn[aria-pressed="true"][data-type="income"] {
  color: var(--income);
}

/* 分類 chip 格 */
.chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: var(--space-2);
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-3) var(--space-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.chip:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.chip__icon {
  font-size: 20px;
  line-height: 1.1;
}

.chip__name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip[aria-pressed="true"] {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.chip--small {
  flex-direction: row;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  font-size: 12px;
}

.chips--row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip__dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  flex: none;
}

/* ---------- 9. 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-weight: 650;
  font-size: 14px;
  color: var(--text);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: scale(0.985);
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, #000);
}

.btn--ghost {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn--danger {
  color: var(--expense);
  border-color: color-mix(in srgb, var(--expense) 40%, var(--border));
  background: var(--expense-soft);
}

.btn--block {
  width: 100%;
}

.btn--lg {
  padding: 14px var(--space-5);
  font-size: 15px;
  border-radius: var(--radius-lg);
}

.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.btn--icon {
  padding: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------- 10. 交易清單 ---------- */
.daygroup {
  margin-bottom: var(--space-4);
}

.daygroup__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 var(--space-1) var(--space-2);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 650;
}

.daygroup__head b {
  color: var(--text);
  font-weight: 700;
}

.tx-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.tx-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  width: 100%;
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}

.tx-row:last-child {
  border-bottom: 0;
}

.tx-row:hover {
  background: var(--surface-2);
}

.tx-row__icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--surface-2);
}

.tx-row__main,
.tx-row__title,
.tx-row__sub {
  display: block;
}

.tx-row__main {
  min-width: 0;
}

.tx-row__title {
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-row__sub {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-row__amount {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

/* ---------- 11. 圖表 ---------- */
.chart-donut {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: var(--space-5);
  align-items: center;
}

@media (max-width: 559px) {
  .chart-donut {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: var(--space-4);
  }
}

.donut {
  position: relative;
  width: 168px;
  height: 168px;
}

.donut svg {
  transform: rotate(-90deg);
  overflow: visible;
}

.donut__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.donut__center-label {
  font-size: 11px;
  color: var(--text-muted);
}

.donut__center-value {
  font-size: 18px;
  font-weight: 750;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  width: 100%;
}

.legend__row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
}

.legend__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend__share {
  color: var(--text-muted);
  font-size: 12px;
}

.legend__value {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: var(--space-2);
  align-items: end;
}

.bars__col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.bars__pair {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 120px;
}

.bars__bar {
  width: 13px;
  border-radius: 6px;
  transition: height var(--dur-base) var(--ease);
}

.bars__bar--expense {
  background: linear-gradient(180deg, color-mix(in srgb, var(--expense) 70%, #fff), var(--expense));
}

.bars__bar--income {
  background: linear-gradient(180deg, color-mix(in srgb, var(--income) 70%, #fff), var(--income));
}

.bars__label {
  font-size: 11px;
  color: var(--text-muted);
}

.bars__value {
  font-size: 10px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 預算進度 */
.progress {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  transition: width var(--dur-base) var(--ease);
}

.progress__bar--over {
  background: linear-gradient(90deg, var(--warn), var(--expense));
}

.budget__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 13px;
  color: var(--text-muted);
}

.budget__value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- 12. 空狀態、載入、吐司 ---------- */
.empty {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--text-muted);
}

.empty__icon {
  font-size: 40px;
  margin-bottom: var(--space-3);
}

.empty__title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.empty__text {
  font-size: 13px;
  margin-bottom: var(--space-4);
}

.boot {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  gap: var(--space-3);
  color: var(--text-muted);
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
  width: min(92vw, 420px);
}

@media (min-width: 900px) {
  .toast-host {
    bottom: var(--space-6);
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--c-slate-900);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur-base) var(--ease);
}

[data-theme="dark"] .toast {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.toast--error {
  background: var(--c-rose-600);
}

.toast--success {
  background: var(--c-emerald-600);
}

.toast__action {
  border: 0;
  background: rgb(255 255 255 / 18%);
  color: inherit;
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 12.5px;
  pointer-events: auto;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

/* ---------- 13. 彈出面板（modal sheet） ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(8 13 26 / 46%);
  backdrop-filter: blur(3px);
  display: grid;
  align-items: end;
  animation: fade-in var(--dur-fast) var(--ease);
}

@media (min-width: 640px) {
  .sheet-backdrop {
    align-items: center;
    justify-items: center;
  }
}

.sheet {
  width: 100%;
  max-height: 92dvh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-lg);
  animation: sheet-up var(--dur-base) var(--ease);
}

@media (min-width: 640px) {
  .sheet {
    width: min(560px, 92vw);
    border-radius: var(--radius-xl);
    padding-bottom: var(--space-5);
  }
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.sheet__title {
  font-size: 17px;
  font-weight: 750;
}

.sheet__grabber {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  margin: 0 auto var(--space-4);
}

@media (min-width: 640px) {
  .sheet__grabber {
    display: none;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ---------- 14. 其他 ---------- */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.row--between {
  justify-content: space-between;
}

.row--wrap {
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 12px;
}

.tiny {
  font-size: 11px;
  color: var(--text-faint);
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row__label {
  font-weight: 600;
  font-size: 14px;
}

.list-row__hint {
  font-size: 12px;
  color: var(--text-muted);
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  transition: background var(--dur-fast) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--c-white);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease);
}

.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: transparent;
}

.switch[aria-checked="true"]::after {
  transform: translateX(18px);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge--warn {
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: color-mix(in srgb, var(--warn) 70%, var(--text));
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}

.install-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  margin-bottom: var(--space-4);
  font-size: 13px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  padding: 0;
}

.swatch[aria-pressed="true"] {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface) inset;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: var(--space-1);
  max-height: 168px;
  overflow: auto;
  padding: var(--space-2);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.icon-grid__btn {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  font-size: 19px;
}

.icon-grid__btn:hover {
  background: var(--surface);
}

.icon-grid__btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.month-swipe {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.trend-legend {
  display: flex;
  gap: var(--space-4);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-3);
}

.trend-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  display: inline-block;
}

.dot--expense {
  background: var(--expense);
}

.dot--income {
  background: var(--income);
}

.danger-zone {
  border: 1px solid color-mix(in srgb, var(--expense) 34%, var(--border));
}

.cat-manage-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.cat-manage-row:last-child {
  border-bottom: 0;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-wrap .input {
  padding-left: 34px;
}

.search-wrap__icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 14px;
  pointer-events: none;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar__cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px;
}

.calendar__cell--empty {
  background: none;
}

.calendar__cell--today {
  border-color: var(--accent);
}

.calendar__day {
  font-weight: 650;
  font-size: 12px;
  color: var(--text);
}

.calendar__amount {
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  color: var(--expense);
  line-height: 1;
}

.calendar__amount--zero {
  color: transparent;
}

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

/* ==========================================================================
   15. 雲端同步狀態列
   ========================================================================== */
.statusbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 8px var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 650;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.statusbar:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.statusbar--main {
  margin-bottom: var(--space-4);
}

.statusbar--side {
  display: none;
}

@media (min-width: 900px) {
  .statusbar--main {
    display: none;
  }
  .statusbar--side {
    display: flex;
  }
  .sidebar__status {
    padding: 0 var(--space-2) var(--space-3);
  }
}

.statusbar__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex: none;
  background: var(--text-faint);
}

.statusbar[data-state="idle"] .statusbar__dot {
  background: var(--income);
}

.statusbar[data-state="syncing"] .statusbar__dot,
.statusbar[data-state="connecting"] .statusbar__dot {
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

.statusbar[data-state="offline"] .statusbar__dot {
  background: var(--warn);
}

.statusbar[data-state="error"] .statusbar__dot {
  background: var(--expense);
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.8);
  }
}

/* ==========================================================================
   16. 連線表單與 AI 建議
   ========================================================================== */
.hint-box {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

.hint-box code,
code.inline {
  font-family: var(--font-num);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
}

.steps {
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--text-muted);
}

.steps > li {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}

.steps > li::before {
  counter-increment: step;
  content: counter(step);
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.insight-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.insight {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
}

.insight--warn {
  border-left-color: var(--expense);
  background: var(--expense-soft);
}

.insight--good {
  border-left-color: var(--income);
  background: var(--income-soft);
}

.insight--info {
  border-left-color: var(--accent);
}

.insight__icon {
  font-size: 15px;
  line-height: 1.3;
}

.insight__title {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 2px;
}

.insight__detail {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.55;
}

.ai-text {
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.ai-text strong {
  font-weight: 700;
}

.ai-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: 11.5px;
  color: var(--text-faint);
}

.spinner--sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.kv:last-child {
  border-bottom: 0;
}

.kv__label {
  color: var(--text-muted);
}

.kv__value {
  font-weight: 650;
  text-align: right;
  word-break: break-all;
}

.truncate {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
