/* 貝卡漫記帳 — 天空藍 + 黃金 + 深墨藍（對齊 becca 系列） */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,700;1,500;1,700&display=swap');

:root {
  --brand-blue: #4ea8de;
  --brand-blue-deep: #2e86c1;
  --brand-blue-soft: #eaf4fc;
  --brand-blue-mist: #f7fbfe;
  --brand-gold: #c8a951;
  --brand-gold-deep: #a07d2a;
  --brand-ink: #1a2b4a;
  --brand-ink-soft: #4a5b7a;

  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-text: #1a2b4a;
  --color-text-muted: #6b7a99;
  --color-border: #dbe8f3;
  --color-primary: #4ea8de;
  --color-primary-soft: #eaf4fc;
  --color-accent: #c8a951;

  --status-green: #d1fae5; --status-green-text: #047857;
  --status-orange: #ffedd5; --status-orange-text: #c2410c;
  --status-gray: #eef2f6; --status-gray-text: #4a5b7a;
  --status-red: #fee2e2; --status-red-text: #b91c1c;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 18px; --radius-xl: 24px;
  --shadow-sm: 0 1px 2px rgba(26,43,74,.04), 0 1px 3px rgba(26,43,74,.06);
  --shadow-md: 0 4px 12px rgba(26,43,74,.06), 0 10px 24px rgba(26,43,74,.08);

  --font-sans: "Yuanti TC", "Hiragino Maru Gothic ProN", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Playfair Display", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  background:
    radial-gradient(ellipse at top, var(--brand-blue-mist) 0%, transparent 60%),
    linear-gradient(180deg, #fff 0%, var(--brand-blue-mist) 100%);
  background-attachment: fixed; min-height: 100vh;
  color: var(--color-text); font-family: var(--font-sans); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

/* ===== Spinner / Loading ===== */
.spinner { width: 18px; height: 18px; border: 2px solid var(--brand-blue-soft); border-top-color: var(--brand-blue); border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 60vh; display: flex; align-items: center; justify-content: center; }
.loading-screen .spinner { width: 32px; height: 32px; border-width: 3px; }

/* ===== App Bar ===== */
.appbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; max-width: 640px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) 16px 14px; }
.appbar .title-wrap { min-width: 0; }
.appbar .eyebrow { font-family: var(--font-display); font-style: italic; font-size: 11px; color: var(--brand-gold-deep); letter-spacing: .18em; text-transform: uppercase; display: block; }
.appbar h1 { font-size: 22px; font-weight: 700; color: var(--brand-ink); letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .actions { display: flex; gap: 8px; flex-shrink: 0; }
.appbar .back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--brand-ink-soft); background: none; border: none; cursor: pointer; padding: 4px 0; }

/* ===== Buttons ===== */
.btn { font-family: inherit; font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: #fff; color: var(--brand-ink); cursor: pointer; transition: all .15s ease; white-space: nowrap; }
.btn:hover { border-color: var(--brand-blue); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: var(--brand-blue-deep); border-color: var(--brand-blue-deep); }
.btn-danger { background: #fff; border-color: var(--status-red); color: var(--status-red-text); }
.btn-danger:hover { background: var(--status-red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-ink-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-round { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; padding: 0; font-size: 17px; background: #fff; border: 1px solid var(--color-border); cursor: pointer; }
.btn-round-primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn-round:active { transform: scale(.94); }

/* FAB */
.fab { position: fixed; right: max(20px, calc(50% - 320px + 20px)); bottom: calc(24px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; background: var(--brand-blue); color: #fff; border: none; font-size: 26px; box-shadow: var(--shadow-md); cursor: pointer; z-index: 50; display: flex; align-items: center; justify-content: center; }
.fab:active { transform: scale(.93); }

/* 列表頁右上「新增帳本」 */
.btn-add { padding: 9px 15px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-sm); }

/* ===== 帳本卡片 ===== */
.book-card { background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 18px; margin-bottom: 12px; cursor: pointer; transition: all .15s ease; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.book-card:hover { border-color: var(--brand-blue); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.book-card .bc-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.book-card .bc-name { font-size: 17px; font-weight: 700; color: var(--brand-ink); }
.book-card .bc-type { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; flex-shrink: 0; }
.bc-type.personal { background: var(--brand-blue-soft); color: var(--brand-blue-deep); }
.bc-type.group { background: #fdf3d7; color: var(--brand-gold-deep); }
.book-card .bc-bottom { display: flex; align-items: baseline; justify-content: space-between; }
.book-card .bc-total { font-size: 22px; font-weight: 700; color: var(--brand-ink); }
.book-card .bc-meta { font-size: 12px; color: var(--color-text-muted); }
.book-card .bc-members { font-size: 12px; color: var(--brand-ink-soft); margin-top: 4px; }

/* ===== Segment toggle（個人/團體）===== */
.segment { display: flex; background: var(--brand-blue-soft); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segment button { flex: 1; border: none; background: transparent; padding: 9px; font-size: 14px; font-weight: 600; color: var(--brand-ink-soft); border-radius: calc(var(--radius-sm) - 2px); cursor: pointer; transition: all .15s; }
.segment button.active { background: #fff; color: var(--brand-blue-deep); box-shadow: var(--shadow-sm); }

/* ===== Summary 區 ===== */
.summary { background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.summary .s-total { font-size: 30px; font-weight: 800; color: var(--brand-ink); letter-spacing: -.01em; }
.summary .s-label { font-size: 13px; color: var(--color-text-muted); margin-bottom: 12px; }
.rates-row { font-size: 12px; color: var(--brand-ink-soft); margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.rates-live { color: var(--brand-gold-deep); }
.cat-bars { display: flex; flex-direction: column; gap: 7px; margin-top: 6px; }
.cat-bar { display: grid; grid-template-columns: 1fr auto; row-gap: 3px; align-items: center; font-size: 13px; }
.cat-bar .cat-head { display: flex; justify-content: space-between; grid-column: 1 / -1; }
.cat-bar .cat-label { color: var(--brand-ink); }
.cat-bar .cat-amt { font-weight: 600; }
.cat-bar .cat-track { grid-column: 1 / -1; height: 6px; background: var(--brand-blue-soft); border-radius: 999px; overflow: hidden; }
.cat-bar .cat-fill { height: 100%; background: linear-gradient(90deg, var(--brand-blue), var(--brand-gold)); border-radius: 999px; }

/* ===== 費用列表 ===== */
.exp-group { margin-bottom: 16px; }
.exp-group-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--brand-ink-soft); padding: 6px 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 4px; }
.exp-list { list-style: none; }
.exp-item { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--brand-blue-soft); cursor: pointer; }
.exp-item:active { background: var(--brand-blue-mist); }
.exp-cat { font-size: 22px; width: 30px; text-align: center; flex-shrink: 0; }
.exp-body { flex: 1; min-width: 0; }
.exp-name { display: block; font-size: 15px; font-weight: 600; color: var(--brand-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-note { display: block; font-size: 12px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-right { text-align: right; flex-shrink: 0; }
.exp-ntd { display: block; font-size: 15px; font-weight: 700; color: var(--brand-ink); }
.exp-orig { display: block; font-size: 12px; color: var(--color-text-muted); }
.exp-cam { font-size: 13px; opacity: .6; }

/* ===== 結算 ===== */
.settle { background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px; margin-top: 14px; box-shadow: var(--shadow-sm); }
.settle h3 { font-size: 15px; font-weight: 700; color: var(--brand-ink); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.balance-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 14px; border-bottom: 1px solid var(--brand-blue-soft); }
.balance-row .amt { font-weight: 700; }
.balance-row.positive .amt { color: var(--status-green-text); }
.balance-row.negative .amt { color: var(--status-red-text); }
.balance-row.zero .amt { color: var(--color-text-muted); }
.bal-label { font-size: 11px; font-weight: 500; color: var(--color-text-muted); margin-left: 4px; }
.transfers-title { font-size: 12px; color: var(--color-text-muted); margin: 14px 0 8px; }
.transfer-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--brand-blue-mist); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 14px; }
.transfer-row .t-amt { margin-left: auto; font-weight: 700; color: var(--brand-blue-deep); }
.settle-ok { font-size: 13px; color: var(--status-green-text); padding: 8px; text-align: center; }

/* ===== Empty ===== */
.empty { padding: 40px 24px; text-align: center; border: 1px dashed var(--color-border); border-radius: var(--radius-md); color: var(--color-text-muted); background: rgba(255,255,255,.5); }
.empty .emoji { font-size: 40px; margin-bottom: 10px; }
.empty p { font-size: 14px; }
.empty .hint { font-size: 12px; margin-top: 6px; }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(26,43,74,.4); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 86vh; border-radius: var(--radius-lg); display: flex; flex-direction: column; animation: modalpop .2s ease; box-shadow: 0 20px 60px rgba(26,43,74,.25); }
@keyframes modalpop { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--color-border); }
.modal-head h2 { font-size: 18px; font-weight: 700; color: var(--brand-ink); }
.modal-close { background: none; border: none; font-size: 20px; color: var(--color-text-muted); cursor: pointer; padding: 4px; }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px 16px; border-top: 1px solid var(--color-border); }

/* ===== Form ===== */
.form-row { margin-bottom: 16px; }
.form-row > label { display: block; font-size: 13px; font-weight: 600; color: var(--brand-ink-soft); margin-bottom: 7px; }
.form-row input[type=text], .form-row input[type=date], .form-row input[type=number], .form-row select, .form-row textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 15px; font-family: inherit; color: var(--brand-ink); background: var(--brand-blue-mist); transition: all .15s; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--brand-gold); background: #fff; box-shadow: 0 0 0 3px rgba(200,169,81,.12); }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.amount-input-wrap { position: relative; display: flex; align-items: center; }
.amount-prefix { position: absolute; left: 14px; font-size: 15px; color: var(--brand-ink-soft); pointer-events: none; }
.amount-input-wrap input { padding-left: 44px !important; font-weight: 700; }

/* 明細編輯器 */
.items-editor { display: flex; flex-direction: column; gap: 8px; }
.items-empty { font-size: 13px; color: var(--color-text-muted); background: var(--brand-blue-mist); border: 1px dashed var(--color-border); border-radius: var(--radius-sm); padding: 12px 14px; line-height: 1.4; }
.item-row { display: grid; grid-template-columns: 1fr 44px 92px 34px; gap: 6px; align-items: center; }
.item-row input { padding: 10px 10px !important; font-size: 14px !important; }
.item-row .it-qty { text-align: center; padding: 10px 4px !important; }
.item-row .it-amount { text-align: right; font-weight: 600; }
.it-del { height: 38px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: #fff; color: var(--color-text-muted); cursor: pointer; font-size: 13px; padding: 0; }
.it-del:hover { border-color: var(--status-red); color: var(--status-red-text); background: var(--status-red); }
.btn-add-item { margin-top: 10px; width: 100%; font-size: 13px; padding: 9px; border-style: dashed; color: var(--brand-blue-deep); }
.btn-add-item:hover { border-color: var(--brand-blue); background: var(--brand-blue-soft); }

.date-quick-chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.date-chip { padding: 7px 13px; border: 1px solid var(--color-border); border-radius: 999px; background: #fff; font-size: 13px; cursor: pointer; }
.date-chip.active { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.date-input-inline { flex: 1; min-width: 130px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check { display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border: 1px solid var(--color-border); border-radius: 999px; font-size: 14px; cursor: pointer; background: #fff; user-select: none; }
.chip-check input { accent-color: var(--brand-blue); }
.chip-check:has(input:checked) { background: var(--brand-blue-soft); border-color: var(--brand-blue); color: var(--brand-blue-deep); }
.split-toggle { font-weight: 600; }
.split-fields { margin-top: 14px; }

/* 收據 OCR */
.receipt-loading { display: flex; align-items: center; gap: 8px; padding: 12px; background: var(--brand-blue-soft); border-radius: var(--radius-sm); font-size: 14px; color: var(--brand-blue-deep); margin-bottom: 14px; }
.receipt-thumb { margin-bottom: 14px; position: relative; }
.receipt-thumb img { width: 100%; max-height: 220px; object-fit: contain; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: var(--brand-blue-mist); }
.receipt-thumb .rm { position: absolute; top: 8px; right: 8px; background: rgba(26,43,74,.7); color: #fff; border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 15px; }
.ocr-hint { font-size: 12px; color: var(--brand-gold-deep); margin-top: 6px; }

/* members editor */
.member-edit { display: flex; gap: 8px; margin-bottom: 8px; }
.member-edit input { flex: 1; }
.member-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.member-tag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 12px; background: var(--brand-blue-soft); border-radius: 999px; font-size: 14px; color: var(--brand-blue-deep); }
.member-tag.me { background: #fdf3d7; color: var(--brand-gold-deep); }
.member-tag button { background: none; border: none; color: inherit; cursor: pointer; font-size: 14px; opacity: .7; }

/* ===== Toast ===== */
#toast-root { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--brand-ink); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-md); animation: toastin .2s ease; max-width: 90vw; }
.toast.ok { background: var(--status-green-text); }
.toast.err { background: var(--status-red-text); }
@keyframes toastin { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.sync-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--color-text-muted); }
.section-gap { height: 4px; }

/* ===== 篩選列 ===== */
.summary.is-filtered { border-color: var(--brand-gold); box-shadow: 0 0 0 3px rgba(200,169,81,.1); }
.summary.is-filtered .s-label { color: var(--brand-gold-deep); font-weight: 600; }
.filter-bar { margin-bottom: 14px; }
.filter-search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--color-border); border-radius: 999px; padding: 4px 6px 4px 14px; box-shadow: var(--shadow-sm); }
.filter-search .fs-icon { font-size: 14px; opacity: .6; flex-shrink: 0; }
.filter-search input { flex: 1; border: none; background: none; font-size: 15px; font-family: inherit; color: var(--brand-ink); padding: 8px 0; }
.filter-search input:focus { outline: none; }
.filter-search .f-clear { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--brand-blue-soft); color: var(--brand-blue-deep); font-size: 14px; cursor: pointer; }
.filter-more { margin-top: 8px; }
.filter-more > summary { list-style: none; cursor: pointer; font-size: 13px; color: var(--brand-ink-soft); padding: 6px 4px; user-select: none; display: inline-flex; align-items: center; gap: 4px; }
.filter-more > summary::-webkit-details-marker { display: none; }
.filter-more > summary::before { content: '⌄'; transition: transform .2s; display: inline-block; }
.filter-more[open] > summary::before { transform: rotate(180deg); }
.fchips { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.fchip { padding: 7px 13px; border: 1px solid var(--color-border); border-radius: 999px; background: #fff; font-size: 13px; cursor: pointer; transition: all .15s; }
.fchip.active { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.fdates { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.fdates label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--brand-ink-soft); }
.fdates input { padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; color: var(--brand-ink); background: var(--brand-blue-mist); }

/* ===== 費用明細展開 ===== */
.exp-expand { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--color-border); background: #fff; color: var(--brand-ink-soft); font-size: 15px; line-height: 1; cursor: pointer; transition: transform .2s; margin-left: 2px; }
.exp-expand.open { transform: rotate(180deg); background: var(--brand-blue-soft); border-color: var(--brand-blue); color: var(--brand-blue-deep); }
.exp-detail { list-style: none; padding: 4px 8px 14px 50px; background: var(--brand-blue-mist); border-bottom: 1px solid var(--brand-blue-soft); }
.det-items { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.det-item { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--brand-ink); padding: 3px 0; border-bottom: 1px dashed var(--color-border); }
.det-item .di-name em { font-style: normal; color: var(--color-text-muted); font-size: 12px; }
.det-item .di-amt { color: var(--brand-ink-soft); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.det-note { font-size: 13px; color: var(--color-text-muted); margin-bottom: 8px; white-space: pre-wrap; }
.det-receipt img { max-width: 160px; max-height: 200px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); cursor: zoom-in; object-fit: cover; }

/* ===== Lightbox ===== */
.lightbox { position: fixed; inset: 0; background: rgba(26,43,74,.88); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px; cursor: zoom-out; animation: toastin .15s ease; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius-sm); box-shadow: 0 20px 60px rgba(0,0,0,.4); }

/* ===== 匯出選單 ===== */
.export-modal .modal-body { padding: 16px 20px 22px; }
.export-opt { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: #fff; cursor: pointer; margin-bottom: 12px; transition: all .15s; }
.export-opt:hover { border-color: var(--brand-blue); background: var(--brand-blue-mist); }
.export-opt:active { transform: translateY(1px); }
.export-opt .eo-emoji { font-size: 26px; flex-shrink: 0; }
.export-opt .eo-text { display: flex; flex-direction: column; gap: 3px; }
.export-opt .eo-text b { font-size: 15px; color: var(--brand-ink); }
.export-opt .eo-text small { font-size: 12px; color: var(--color-text-muted); }
