/* 家族總帳本 — 莫蘭迪高辨識度極簡樣式（全文字按鈕，無小圖示） */

:root {
  /* 莫蘭迪基底色 */
  --bg: #EFECE6;
  --surface: #FAF8F5;
  --surface-soft: #F3EFE9;
  --surface-muted: #E7E2DA;
  --border: #DDD7CE;
  --border-strong: #C9C1B6;

  /* 文字階層（確保高可讀性） */
  --text: #3B3834;
  --text-sub: #666058;
  --text-muted: #8C857B;

  /* 莫蘭迪主色（沉穩霧藍） */
  --primary: #526778;
  --primary-bright: #5F7688;
  --primary-soft: #E6ECEF;

  /* 莫蘭迪語意色（柔雅但彼此辨識度鮮明） */
  --income: #5C7D99;
  --income-bg: #E6EEF4;
  --ok: #537F71;
  --ok-bg: #E5EFEA;
  --expense: #B56558;
  --expense-bg: #F4E7E4;
  --warn: #A88446;
  --warn-bg: #F4EDE0;
  --danger: #A65252;
  --danger-bg: #F3E5E5;

  --radius-sm: 9px;
  --radius-md: 13px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(59, 56, 52, 0.05);
  --shadow-md: 0 8px 22px rgba(59, 56, 52, 0.08);
  --shadow-sheet: 0 -10px 32px rgba(59, 56, 52, 0.16);

  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

button:focus-visible {
  box-shadow: 0 0 0 2px rgba(82, 103, 120, 0.35);
}

[hidden] {
  display: none !important;
}

.tnum {
  font-variant-numeric: tabular-nums;
}

/* ===== 外殼與頂部列 ===== */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: clip;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(250, 248, 245, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(59, 56, 52, 0.04);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 14px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--text);
}

.sync-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.sync-dot.loading {
  background: var(--warn);
  animation: pulse 1s infinite;
}

.sync-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.top-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  background: var(--surface-muted);
  color: var(--text-sub);
  font-size: 12.5px;
  font-weight: 700;
  border: 1px solid var(--border);
  transition: background 0.15s;
}

.top-btn:active {
  background: var(--border);
}

.top-btn.loading {
  opacity: 0.6;
}

.filter-trigger {
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--surface-muted);
  color: var(--text);
  font-weight: 700;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.filter-trigger.has-active {
  background: var(--primary);
  color: #FAF8F5;
  border-color: var(--primary);
}

.badge-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #FAF8F5;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}

/* ===== 第一層快捷篩選列（完全收縮於螢幕內，無需左右滑動） ===== */
.quickbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.quickbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.active-chips::-webkit-scrollbar {
  display: none;
}

.month-stepper.full-stepper {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  background: var(--surface-muted);
  border-radius: 9px;
  padding: 2px;
}

.step-btn {
  height: 27px;
  padding: 0 10px;
  border-radius: 7px;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.period-title {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
}

.pill {
  padding: 5px 2px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  background: var(--surface-muted);
  text-align: center;
  white-space: nowrap;
  transition: all 0.15s;
}

.pill.active {
  background: var(--primary);
  color: #FAF8F5;
}

.dual-seg-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.seg-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.qchip {
  padding: 5px 2px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-sub);
  background: transparent;
  text-align: center;
  white-space: nowrap;
  transition: all 0.15s;
}

.qchip.active {
  background: var(--primary);
  color: #FAF8F5;
  box-shadow: none;
}

.qchip[data-type="支出"].active,
.qchip[data-type="收入"].active {
  background: var(--primary);
  color: #FAF8F5;
}

.kpi-card.clickable {
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.kpi-card.clickable:hover,
.kpi-card.clickable:active {
  border-color: var(--primary-bright);
  background: var(--surface-soft);
}

/* 已啟用進階條件標籤列 */
.active-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: 2px;
}

.achip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid #C6D3DC;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.achip .x {
  font-size: 11px;
  opacity: 0.75;
}

.achip.reset-all {
  background: var(--danger-bg);
  border-color: #DFC2C2;
  color: var(--danger);
}

/* ===== 主內容容器 ===== */
.main-content {
  max-width: 1180px;
  width: 100%;
  flex: 1 0 auto;
  margin: 0 auto;
  padding: 14px;
  overflow-x: clip;
}

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.view.active {
  display: flex;
}

.view.slide-from-right {
  animation: viewSlideFromRight 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.view.slide-from-left {
  animation: viewSlideFromLeft 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes viewSlideFromRight {
  from { opacity: 0.55; transform: translateX(26px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes viewSlideFromLeft {
  from { opacity: 0.55; transform: translateX(-26px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== 卡片與面板 ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head.wrap-head {
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.text-link {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary);
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--primary-soft);
  white-space: nowrap;
}

/* ===== KPI 指標卡片 ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--primary-bright);
}

.kpi-card.is-exp::before { background: var(--expense); }
.kpi-card.is-inc::before { background: var(--income); }
.kpi-card.is-neg::before { background: var(--danger); }
.kpi-card.is-cnt::before { background: #8A7998; }

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-delta {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.kpi-delta.up-bad { background: var(--expense-bg); color: var(--expense); }
.kpi-delta.down-good { background: var(--ok-bg); color: var(--ok); }
.kpi-delta.up-good { background: var(--income-bg); color: var(--income); }
.kpi-delta.down-bad { background: var(--expense-bg); color: var(--expense); }
.kpi-delta.flat { background: var(--surface-muted); color: var(--text-muted); }

.kpi-val {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.kpi-val.exp { color: var(--expense); }
.kpi-val.inc { color: var(--income); }
.kpi-val.pos { color: var(--primary); }
.kpi-val.neg { color: var(--danger); }

.kpi-foot {
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ===== 本週家庭預算儀表 ===== */
.wk-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mini-btn {
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
}

.mini-btn:active {
  background: var(--border);
}

.budget-summary {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 10px;
}

.budget-main-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.budget-left-big {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
}

.budget-left-big.ok { color: var(--ok); }
.budget-left-big.warn { color: var(--warn); }
.budget-left-big.over { color: var(--danger); }

.budget-ratio-tag {
  font-size: 12px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
}

.budget-ratio-tag.ok { background: var(--ok-bg); color: var(--ok); }
.budget-ratio-tag.warn { background: var(--warn-bg); color: var(--warn); }
.budget-ratio-tag.over { background: var(--danger-bg); color: var(--danger); }

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
  margin: 10px 0 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-fill.ok { background: #6A9485; }
.progress-fill.warn { background: #BD9B60; }
.progress-fill.over { background: #B56558; }

.budget-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-sub);
}

.chart-box {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.chart-week { height: 220px; }
.chart-cat { height: 280px; }
.chart-trend { height: 260px; }

.chart-hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

/* ===== 支出分類排行清單（莫蘭迪純色條） ===== */
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rank-item {
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border-radius: 11px;
  background: var(--surface-soft);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.rank-item:hover, .rank-item:active {
  border-color: var(--border-strong);
  background: var(--surface);
}

.rank-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.rank-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.color-pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.rank-name {
  font-weight: 800;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-cnt {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.rank-right {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-shrink: 0;
}

.rank-amt {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.rank-pct {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-muted);
  min-width: 38px;
  text-align: right;
}

.rank-bar-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 999px;
}

/* ===== 圖表頁切換與下鑽 ===== */
.seg-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  background: var(--surface-muted);
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
}

.seg-btn {
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--primary);
  color: #FAF8F5;
  box-shadow: none;
}

.drill-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid #C6D3DC;
}

.drill-back {
  padding: 4px 10px;
  border-radius: 7px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.drill-current {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drill-detail-btn {
  padding: 4px 10px;
  border-radius: 7px;
  background: var(--primary);
  color: #FAF8F5;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.cat-legend-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

@media (min-width: 640px) {
  .cat-legend-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.cat-mini-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  text-align: left;
  min-width: 0;
}

.cat-mini-card:hover {
  border-color: var(--primary-bright);
}

.cat-mini-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.cat-mini-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-mini-val {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-sub);
  white-space: nowrap;
  flex-shrink: 0;
}

.compare-bars {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ===== 明細查詢頁（極簡整齊按日期分組） ===== */
.details-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-box {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 0 11px;
  height: 39px;
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13.5px;
}

.search-clear {
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text-sub);
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
}

.sort-select {
  height: 39px;
  padding: 0 10px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-sub);
  flex-shrink: 0;
}

.details-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.strip-cell .s-lbl {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.strip-cell .s-val {
  margin-top: 2px;
  font-size: clamp(11.5px, 3.3vw, 14px);
  font-weight: 800;
  white-space: nowrap;
}

.grouped-tx-container {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.day-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 13px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.day-title {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-sub);
  letter-spacing: 0.02em;
}

.day-totals {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 800;
}

.day-totals .d-exp { color: var(--expense); }
.day-totals .d-inc { color: var(--income); }

.tx-list {
  display: flex;
  flex-direction: column;
}

/* 極簡整齊交易列：左色條 ＋ 中間兩行純文字 ＋ 右側固定金額與歸屬 */
.tx-row {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px 11px 11px;
  border-bottom: 1px solid #ECE7DF;
  border-left: 3.5px solid transparent;
  transition: background 0.12s;
}

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

.tx-row:hover, .tx-row:active {
  background: var(--surface-soft);
}

.tx-main {
  min-width: 0;
  flex: 1;
}

.tx-line1 {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tx-ledger {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.45;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--text-sub);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}

.tx-ledger.is-family {
  background: #E7EEF2;
  color: #526D82;
  border-color: #CCD9E2;
}

.tx-ledger.is-restaurant {
  background: #F5EAE4;
  color: #A86446;
  border-color: #E4CFC4;
}

.tx-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-cat-sub {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.tx-no {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 5px;
  line-height: 1.5;
  white-space: nowrap;
  flex-shrink: 0;
}

.tx-line2 {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-right {
  text-align: right;
  flex-shrink: 0;
}

.tx-amt {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.tx-amt.exp { color: var(--expense); }
.tx-amt.inc { color: var(--income); }

.tx-meta-right {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 6px 0 8px;
}

/* ===== 固定支出與貸款分頁 ===== */
.subtab-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.subtab {
  padding: 8px 4px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-sub);
  text-align: center;
  white-space: nowrap;
}

.subtab.active {
  background: var(--primary);
  color: #FAF8F5;
  border-color: var(--primary);
}

.asset-pane {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.asset-pane.active {
  display: flex;
}

.loan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.loan-card.settled {
  opacity: 0.65;
  background: var(--surface-soft);
}

.loan-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.loan-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.loan-rate {
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}

.loan-rate.done-badge {
  background: var(--ok-bg);
  color: var(--ok);
}

.loan-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 9px;
}

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

.lm-item .lm-v {
  font-size: 14px;
  font-weight: 800;
  margin-top: 2px;
}

.loan-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 8px;
}

.rules-group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px;
}

.rules-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.rules-type-text {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-left: auto;
}

.rules-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rule-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

/* ===== 底部導覽列（時尚日式和紙書籤 × 莫蘭迪藍底線） ===== */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 6px 12px calc(6px + var(--safe-bottom));
  background: rgba(251, 248, 243, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid #DDD4C6;
  box-shadow: 0 -4px 18px rgba(59, 56, 52, 0.045);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav-track {
  position: relative;
  width: 100%;
  max-width: 680px;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  --active-idx: 0;
  --drag-offset: 0;
}

/* 淡青磁和紙書籤底卡 ＋ 按鍵下方莫蘭迪藍小橫線 */
.nav-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 25%;
  transform: translate3d(calc((var(--active-idx, 0) + var(--drag-offset, 0)) * 100%), 0, 0);
  transition: transform 0.32s cubic-bezier(0.24, 0.86, 0.34, 1);
  pointer-events: none;
  z-index: 0;
  will-change: transform;
}

.nav-indicator::before {
  content: "";
  position: absolute;
  inset: 2px 4px;
  border-radius: 10px;
  background: #E8EEF1;
  border: 1px solid #C8D6DE;
  box-shadow: 0 2px 10px rgba(78, 100, 117, 0.09);
  transition: box-shadow 0.24s ease;
}

.nav-indicator::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 34%;
  height: 3px;
  transform: translateX(-50%);
  border-radius: 3px 3px 0 0;
  background: #5C7D99;
}

/* 滑動手勢拖曳中改為貼手平順跟隨 */
.bottom-nav-track.is-dragging .nav-indicator {
  transition: none;
}

.bottom-nav-track.is-dragging .nav-indicator::before {
  box-shadow: 0 3px 12px rgba(78, 100, 117, 0.14);
}

.nav-item {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
  border-radius: 10px;
  color: #7E766B;
  transition: color 0.22s ease, transform 0.16s ease, background 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
}

/* 極細日式垂直分隔線 */
.nav-item + .nav-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 28%;
  bottom: 28%;
  width: 1px;
  background: rgba(196, 187, 174, 0.45);
  transition: opacity 0.2s ease;
}

.nav-item.active::before,
.nav-item.active + .nav-item::before {
  opacity: 0;
}

.nav-item:hover:not(.active) {
  color: #485E6E;
}

.nav-item:active {
  transform: scale(0.97);
}

/* 手勢左右滑動達到切頁門檻時，預先染上柔和和紙底 */
.nav-item.is-target-hint:not(.active) {
  color: #3D5262;
  background: rgba(232, 238, 241, 0.65);
}

.nav-label {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.06em;
  white-space: nowrap;
  transition: transform 0.22s ease, letter-spacing 0.22s ease;
}

.nav-item.active {
  color: #2E4251;
}

.nav-item.active .nav-label {
  font-weight: 800;
  letter-spacing: 0.09em;
  transform: translateY(-0.5px);
}

/* ===== 底部抽屜 (Bottom Sheet) ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(59, 56, 52, 0.44);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.18s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideUp {
  from { transform: translateY(36px); opacity: 0.75; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.sheet-header {
  padding: 6px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.sheet-header h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
  white-space: nowrap;
}

.sheet-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.text-btn {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary);
  padding: 4px 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.text-btn.danger {
  color: var(--danger);
}

.close-btn {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text-sub);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-body {
  padding: 14px 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sheet-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.f-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.f-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.f-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.f-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.mini-search {
  width: 130px;
  padding: 4px 9px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-size: 12px;
  background: var(--surface-soft);
}

.date-range-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

/* ===== 莫蘭迪雙模式區間日曆（點兩次跨月 ＋ 按住拖曳） ===== */
.cal-range-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
}

.cal-range-text {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-range-ops {
  display: inline-flex;
  gap: 5px;
  flex-shrink: 0;
}

.cal-op-btn {
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-sub);
  white-space: nowrap;
}

.cal-op-btn:active {
  background: var(--primary);
  color: #FAF8F5;
}

.cal-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px 9px;
  user-select: none;
  -webkit-user-select: none;
}

.cal-head {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.cal-nav-btn {
  padding: 4px 6px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
  white-space: nowrap;
}

.cal-nav-btn:active {
  background: var(--primary);
  color: #FAF8F5;
}

.cal-ym-label {
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cal-cell {
  position: relative;
  height: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  border-radius: 0;
  cursor: pointer;
}

.cal-cell.is-other {
  color: #B5AEA4;
  font-weight: 600;
}

.cal-cell.is-today {
  box-shadow: inset 0 0 0 1.5px var(--primary-bright);
  border-radius: 8px;
}

.cal-cell.in-range {
  background: #DCE5EB;
  color: var(--primary);
}

.cal-cell.is-start,
.cal-cell.is-end {
  background: var(--primary);
  color: #FAF8F5;
  font-weight: 800;
  box-shadow: none;
}

.cal-cell.is-start {
  border-radius: 8px 0 0 8px;
}

.cal-cell.is-end {
  border-radius: 0 8px 8px 0;
}

.cal-cell.is-start.is-end {
  border-radius: 8px;
}

.cal-cell.is-pending {
  background: var(--primary);
  color: #FAF8F5;
  border-radius: 8px;
  box-shadow: 0 0 0 2px rgba(82, 103, 120, 0.28);
}

.cal-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--expense);
  margin-top: 1px;
}

.cal-cell.is-start .cal-dot,
.cal-cell.is-end .cal-dot,
.cal-cell.is-pending .cal-dot {
  background: rgba(250, 248, 245, 0.85);
}

.date-range-inputs input,
.full-input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  font-size: 13px;
}

.range-sep {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.compact-grid {
  max-height: 155px;
  overflow-y: auto;
  padding: 2px 0;
}

.fchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1.5px solid transparent;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-sub);
  transition: all 0.12s;
}

.fchip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #FAF8F5;
}

.fchip.selected .dot {
  box-shadow: 0 0 0 1.5px rgba(250, 248, 245, 0.85);
}

.fchip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.preset-chip .del-preset {
  color: var(--text-muted);
  font-size: 11px;
  padding-left: 2px;
}

.btn-primary {
  height: 44px;
  padding: 0 18px;
  border-radius: 11px;
  background: var(--primary);
  color: #FAF8F5;
  font-size: 14px;
  font-weight: 800;
}

.btn-secondary {
  height: 40px;
  padding: 0 20px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--primary);
  font-weight: 800;
  font-size: 13px;
}

.full-btn {
  width: 100%;
}

/* 交易詳情卡 */
.detail-hero {
  text-align: center;
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--border);
}

.detail-hero-cat {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.detail-hero-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin-top: 3px;
}

.detail-hero-amt {
  font-size: 28px;
  font-weight: 900;
  margin-top: 6px;
}

.detail-hero-no {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.1s;
}

.detail-hero-no:active {
  background: var(--primary);
  color: #FAF8F5;
  transform: scale(0.96);
}

.detail-tap {
  display: inline;
  padding: 1px 4px;
  margin: -1px -4px;
  border-radius: 6px;
  color: var(--primary);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(82, 103, 120, 0.45);
  text-underline-offset: 3px;
  cursor: pointer;
  transition: background 0.12s;
}

.detail-tap:hover,
.detail-tap:active {
  background: var(--primary-soft);
}

.detail-hero-title .detail-tap {
  color: var(--text);
  text-decoration-color: rgba(59, 56, 52, 0.3);
}

.detail-hero-amt.exp { color: var(--expense); }
.detail-hero-amt.inc { color: var(--income); }

.detail-kv-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-kv {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.detail-kv:last-child {
  border-bottom: none;
}

.detail-kv .dk {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 700;
  flex-shrink: 0;
}

.detail-kv .dv {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  word-break: break-word;
}

/* 空狀態與提示 */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty-state .empty-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-sub);
}

.empty-state .empty-desc {
  font-size: 12.5px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 120;
  background: rgba(59, 56, 52, 0.92);
  color: #FAF8F5;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

/* ===== 平板與電腦寬螢幕自適應 ===== */
@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
  .kpi-val {
    font-size: 24px;
  }
  .chart-cat { height: 320px; }
  .chart-trend { height: 290px; }
}

@media (min-width: 960px) {
  .desktop-two-col {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
  }
  .main-content {
    padding: 18px 20px;
  }
  .sheet {
    border-radius: 18px;
    margin-bottom: 24px;
    max-height: 82vh;
  }
  .sheet-backdrop {
    align-items: center;
  }
}

/* ===== Telegram 安全登入閘門 ===== */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.auth-badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.auth-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.auth-desc {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.55;
}

.auth-status {
  font-size: 13px;
  color: var(--primary);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
}

.auth-status.is-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: rgba(166, 82, 82, 0.25);
}

.tg-widget-wrap {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.auth-denied-box {
  text-align: left;
  background: var(--warn-bg);
  border: 1px solid rgba(168, 132, 70, 0.35);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
}

.auth-denied-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-denied-who {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.auth-id-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 12px;
}

.auth-id-label {
  font-size: 12px;
  color: var(--text-sub);
}

.auth-id-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  user-select: all;
}

.auth-denied-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-denied-actions button {
  padding: 9px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.auth-footnote {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
}
