/* ============================================
   Pocket Bill — 極簡淡色系
   底：米白　卡片：淺灰　點綴：柔黃
   ============================================ */

:root {
  color-scheme: light; /* 日期選單等原生元件也固定淺色 */
  /* 色彩（可在 console 用 PB.setVar('--accent','#xxx') 即時調） */
  --bg: #EFEEE9;          /* 頁面底色：暖淺灰 */
  --card: #E2E1DA;        /* 色塊卡片：淺灰 */
  --card-2: #FBFAF7;      /* 清單列：暖白 */
  --ink: #21251E;         /* 主文字：墨綠近黑 */
  --ink-2: #62665C;       /* 次要文字 */
  --muted: #9EA096;       /* 淡灰標籤 */
  --accent: #C9E86F;      /* 特別色：萊姆綠 */
  --line: rgba(32,37,30,.08);/* 分隔線 */
  --danger: #C0442E;      /* 刪除紅 */
  /* 圖表分類色（已通過色盲驗證，順序固定不可循環） */
  --c-food: #C7522A; --c-transit: #0E93A6; --c-shop: #B58300;
  --c-stay: #7B5EA7; --c-ticket: #35854A; --c-other: #2E77BE;
  --radius: 22px;
}

/* 固定淺色版：不跟隨系統深色模式（Paian 指定淺灰色系為主） */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, "SF Pro Text", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg); color: var(--ink);
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
}
input, button { font-family: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
.num, .hero-num, .amount-jpy, .e-jpy { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }

/* ===== 頁面切換 ===== */
.view {
  display: none;
  padding: calc(env(safe-area-inset-top) + 20px) 22px 140px;
  max-width: 480px; margin: 0 auto;
}
.view.active { display: block; animation: fadeUp .28s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view.active, .sheet, .fab svg { animation: none !important; transition: none !important; } }

/* ===== 頁首 ===== */
.page-head { margin: 18px 0 26px; position: relative; }
.head-btn {
  position: absolute; top: 2px; right: 0;
  width: 44px; height: 44px; border-radius: 15px;
  background: var(--card); display: grid; place-items: center;
}
.head-btn svg { width: 21px; height: 21px; stroke: var(--ink); }
.page-head h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
/* 可編輯的標題（首頁旅程名） */
.h1-edit {
  display: block; padding-right: 56px; /* 避開右上角旅程按鈕 */
  text-align: left; color: inherit; font: inherit;
  overflow-wrap: anywhere; line-height: 1.25;
}
/* 鉛筆跟著文字流走，換行時才不會被孤立在第一行 */
.h1-edit .pen {
  display: inline-block; vertical-align: 15%;
  width: 18px; height: 18px; margin-left: 9px; stroke: var(--muted);
}
.h1-edit:active { opacity: .55; }
.page-head .subtitle { padding-right: 56px; }
.page-head .dot { color: var(--accent); }
.subtitle { color: var(--muted); font-size: .95rem; margin-top: 4px; font-weight: 400; }

/* ===== 提醒橫幅 ===== */
.banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-left: 3px solid var(--accent);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 18px;
  font-size: .85rem; color: var(--ink-2);
}
.banner-text { flex: 1; line-height: 1.5; }
.banner .btn-small { background: var(--ink); color: var(--bg); flex: 0 0 auto; }
.banner-x { color: var(--muted); font-size: 1.05rem; padding: 4px 6px; flex: 0 0 auto; }

/* ===== 快速重複 chips ===== */
.quick-chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin-bottom: 12px; }
.quick-chips:empty { display: none; }
.quick-chips::-webkit-scrollbar { display: none; }
.quick-chip {
  flex: 0 0 auto; background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: .8rem; color: var(--ink-2);
  display: flex; gap: 6px; align-items: center;
}
.quick-chip b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== 大數字 hero ===== */
.hero { margin-bottom: 26px; }
.hero-label { font-size: .8rem; color: var(--muted); letter-spacing: .04em; margin-bottom: 6px; }
.hero-num { font-size: 3.6rem; font-weight: 640; letter-spacing: -.035em; line-height: 1.05; }
.hero-yen { font-size: 2rem; font-weight: 500; color: var(--ink-2); margin-right: 2px; }
.chip-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.chip {
  background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: .8rem; color: var(--ink-2);
}
.chip-accent { background: var(--accent); color: #21251E; }

/* 現金日預算提示 */
.cash-hint { margin-top: 10px; font-size: .8rem; color: var(--ink-2); }
.cash-hint b { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ===== 天數選擇列 ===== */
.day-chips {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 -22px 18px;
  padding: 2px 22px 8px; scrollbar-width: none;
}
.day-chips::-webkit-scrollbar { display: none; }
.day-chip {
  flex: 0 0 auto; background: var(--card); border-radius: 16px;
  padding: 9px 14px; font-size: .82rem; color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: background .15s, color .15s;
}
.day-chip small { font-size: .66rem; color: var(--muted); }
.day-chip.active { background: var(--ink); color: var(--bg); }
.day-chip.active small { color: var(--bg); opacity: .6; }
.day-chip-edit {
  background: none; border: 1.5px dashed var(--muted); color: var(--ink-2);
  justify-content: center;
}
.day-chip-edit svg { width: 17px; height: 17px; stroke: currentColor; }

/* ===== 消費清單（可左滑刪除） ===== */
.entry-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.entry-row { position: relative; border-radius: 18px; overflow: hidden; }
.entry-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 80px;
  background: var(--danger); color: #fff;
  font-size: .85rem; font-weight: 600; border-radius: 0 18px 18px 0;
}
.entry {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 14px;
  background: var(--card-2); border-radius: 18px; padding: 14px 16px;
  transition: transform .2s ease; touch-action: pan-y;
}
.e-icon {
  width: 40px; height: 40px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--card);
}
.e-icon svg { width: 20px; height: 20px; stroke: var(--ink); }
.e-main { flex: 1; min-width: 0; }
.e-note { font-size: .92rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.e-time { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.e-amount { text-align: right; }
.e-jpy { font-size: 1rem; font-weight: 600; letter-spacing: -.01em; }
.e-twd { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.empty {
  text-align: center; color: var(--muted); font-size: .88rem;
  padding: 48px 0; line-height: 1.8;
}

/* ===== 旅程列表 ===== */
.trip-card { flex-wrap: wrap; padding: 18px; }
.t-name { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; flex: 1; display: flex; align-items: center; gap: 8px; }
.t-badge {
  font-size: .64rem; font-weight: 600; color: #21251E;
  background: var(--accent); border-radius: 999px; padding: 3px 9px;
}
.t-total { text-align: right; }
.t-jpy { font-size: 1.05rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.t-meta { width: 100%; margin-top: 6px; font-size: .76rem; color: var(--muted); }
.btn-new-trip {
  width: 100%; margin-top: 16px; height: 54px; border-radius: 18px;
  border: 1.5px dashed var(--muted); color: var(--ink-2);
  font-size: .95rem; font-weight: 500;
}
.sheet-title { font-size: 1.05rem; font-weight: 650; margin: 2px 0 14px; text-align: center; }

/* ===== 卡片（統計、設定） ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; margin-bottom: 14px;
}
.card-label { font-size: .74rem; color: var(--muted); letter-spacing: .06em; margin-bottom: 14px; }

/* ===== 圓環圖 ===== */
.donut-wrap { position: relative; width: 200px; margin: 6px auto 16px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.donut-center-name { font-size: .78rem; color: var(--muted); }
.donut-center-val { font-size: 1.15rem; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.donut-seg { transition: opacity .15s; cursor: pointer; }
.donut-seg.dim { opacity: .25; }

/* 分類圖例（也是數據表） */
.cat-legend { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.cat-legend li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; border-top: 1px solid var(--line); font-size: .88rem;
}
.cat-legend li:first-child { border-top: 0; }
.l-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.l-icon { width: 16px; height: 16px; flex: 0 0 auto; }
.l-icon svg { width: 16px; height: 16px; stroke: var(--ink-2); }
.l-name { flex: 1; }
.l-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.l-pct { color: var(--muted); font-size: .76rem; width: 42px; text-align: right; font-variant-numeric: tabular-nums; }

/* ===== 長條圖 ===== */
.bars-wrap { overflow-x: auto; scrollbar-width: none; }
.bars-wrap::-webkit-scrollbar { display: none; }
.bars-wrap svg { display: block; }
.bar-rect { cursor: pointer; }
.bars-tip { min-height: 1.2em; font-size: .8rem; color: var(--ink-2); text-align: center; margin-top: 8px; font-variant-numeric: tabular-nums; }

/* ===== 設定 ===== */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .92rem;
}
.setting-row:first-of-type { border-top: 0; }
.setting-row input[type="date"], .setting-row input[type="text"], .setting-row select {
  background: var(--card-2); border: 0; border-radius: 12px;
  padding: 9px 12px; font-size: .92rem; text-align: right; max-width: 170px;
  appearance: none; -webkit-appearance: none; color: var(--ink);
}
/* 設定頁：整列都可點的按鈕 */
.row-btn { width: 100%; text-align: left; font-size: .92rem; }
.row-btn > span:first-child { flex: 0 0 auto; }
/* 內容過長時省略，不要撐成兩行 */
.row-val {
  color: var(--muted); font-size: .84rem; text-align: right;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-btn::after { content: '›'; color: var(--muted); flex: 0 0 auto; }

.btn-small {
  background: var(--card-2); border-radius: 999px; padding: 8px 14px;
  font-size: .8rem; font-weight: 500;
}
.btn-small.danger { color: var(--danger); }
.version { text-align: center; margin-top: 24px; }

/* ===== 新增按鈕 ===== */
.fab {
  position: fixed; right: 22px; bottom: calc(env(safe-area-inset-bottom) + 88px);
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #21251E;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  transition: transform .12s;
  z-index: 20;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 24px; height: 24px; }

/* ===== 底部分頁列 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 10px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: .68rem; color: var(--muted); padding: 2px 18px;
  transition: color .15s;
}
.tab-icon svg { width: 22px; height: 22px; stroke: currentColor; }
.tab.active { color: var(--ink); }

/* ===== 輸入面板 ===== */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.28);
  opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 30;
}
.sheet-mask.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 22px calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(105%); transition: transform .28s cubic-bezier(.32,.72,.32,1);
  max-width: 480px; margin: 0 auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,.10);
}
.sheet.show { transform: none; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }

/* 記到哪一天 */
.sheet-day {
  display: flex; align-items: center; gap: 5px; margin: 0 auto 10px;
  background: var(--card); border-radius: 999px; padding: 6px 14px;
  font-size: .78rem; color: var(--ink-2);
}
.sheet-day b { color: var(--ink); font-weight: 600; }
.day-grid { grid-template-columns: repeat(4, 1fr); }

/* 分類明細清單 */
.cat-entries { list-style: none; margin-top: 4px; }
.cat-entries:empty { display: none; }
.cat-entries li {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 2px; border-top: 1px solid var(--line); font-size: .84rem;
}
.ce-note { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ce-day { color: var(--muted); font-size: .74rem; flex: 0 0 auto; }
.ce-amt { font-weight: 600; font-variant-numeric: tabular-nums; }

.amount-block { text-align: center; margin-bottom: 16px; }
.amount-jpy { font-size: 2.9rem; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; }
.amount-jpy .yen { font-size: 1.6rem; color: var(--ink-2); font-weight: 500; margin-right: 2px; }
.amount-twd { font-size: .85rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* 幣別／付款方式切換 */
.toggle-row { display: flex; gap: 8px; margin-bottom: 12px; }
.cur-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--ink); color: var(--bg); border-radius: 999px;
  padding: 8px 0; font-size: .84rem; font-weight: 500;
}
.cur-btn .caret { opacity: .55; font-size: .7rem; }
.cur-sheet { z-index: 33; }
.cur-hint { text-align: center; margin: -6px 0 14px; }
.cur-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  max-height: 46vh; overflow-y: auto; padding-bottom: 6px;
}
.cur-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); border-radius: 14px; padding: 12px 4px 10px;
  font-size: .78rem; color: var(--ink-2);
}
.cur-grid button b { font-size: 1.02rem; color: var(--ink); font-weight: 600; }
.cur-grid button.active { background: var(--ink); color: var(--bg); }
.cur-grid button.active b { color: var(--bg); }
.cur-grid .cur-tag { font-size: .6rem; color: var(--accent); }
.toggle-row .cur-toggle { flex: 1; margin-bottom: 0; }
.cur-toggle {
  display: flex; background: var(--card); border-radius: 999px;
  padding: 4px; margin-bottom: 12px;
}
.cur-toggle button {
  flex: 1; border-radius: 999px; padding: 8px 0;
  font-size: .84rem; font-weight: 500; color: var(--ink-2);
  transition: background .15s, color .15s;
}
.cur-toggle button.active { background: var(--ink); color: var(--bg); }

/* 分類選擇 */
.cat-chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 12px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--card); border-radius: 14px; padding: 10px 2px 8px;
  font-size: .66rem; color: var(--ink-2); transition: background .15s, color .15s;
}
.cat-chip svg { width: 20px; height: 20px; stroke: currentColor; }
.cat-chip.active { background: var(--ink); color: var(--bg); }

.note-input {
  width: 100%; background: var(--card); border: 0; border-radius: 14px;
  padding: 12px 14px; font-size: .9rem; margin-bottom: 12px;
}
.note-input::placeholder { color: var(--muted); }

/* 數字鍵盤 */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.keypad button {
  background: var(--card); border-radius: 16px; height: 54px;
  font-size: 1.35rem; font-weight: 500; font-variant-numeric: tabular-nums;
  transition: background .1s;
}
.keypad button:active { background: var(--line); }

.sheet-actions { display: flex; gap: 10px; }
.btn-save {
  flex: 1; background: var(--ink); color: var(--bg);
  border-radius: 999px; height: 52px; font-size: 1rem; font-weight: 600;
  transition: transform .12s;
}
.btn-save:active { transform: scale(.97); }
.btn-delete {
  flex: 0 0 auto; padding: 0 22px; height: 52px; border-radius: 999px;
  background: var(--card); color: var(--danger); font-size: .92rem; font-weight: 500;
}

/* 桌機預覽時置中窄欄 */
@media (min-width: 520px) {
  body { display: flex; justify-content: center; }
  .view { width: 480px; }
  .tabbar, .sheet { max-width: 480px; left: 50%; transform: translateX(-50%); }
  .sheet { transform: translate(-50%, 105%); }
  .sheet.show { transform: translate(-50%, 0); }
  .fab { right: calc(50% - 240px + 22px); }
}

/* 鍵盤焦點可見 */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
