/* styles.css — minimal black/white/accent expense tracker */

:root {
  --bg: #FFFFFF;
  --fg: #1A1A1A;
  --fg2: #888888;
  --line: #E5E5E5;
  --accent: #2D6A4F;
  --danger: #A04545;

  --mono: "SF Mono", "Roboto Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;
  --sans: "PingFang TC", "Noto Sans TC", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }

/* Hide scrollbars but keep scrolling — so layout never reflows when content grows */
html { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar { width: 0; height: 0; display: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }
* { scrollbar-width: none; -ms-overflow-style: none; }
body {
  font-family: var(--sans);
  color: var(--fg);
  background: #F2F2F2;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt";
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ── Phone shell ───────────────────────────────────────────────────────── */
.phone-stage {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
}
.phone {
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
@media (min-width: 500px) {
  .phone-stage { padding: 24px 0; align-items: flex-start; }
  .phone {
    height: 880px;
    border: 1px solid var(--line);
    border-radius: 4px;
  }
}

/* Generic screen — most are scrollable */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 80px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── Tab bar ───────────────────────────────────────────────────────────── */
.tabbar {
  flex-shrink: 0;
  height: 56px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--fg2);
  font-size: 11px;
  font-weight: 500;
  padding: 0;
  transition: opacity 150ms;
}
.tab.is-on { color: var(--fg); font-weight: 600; }
.tab:active { opacity: 0.6; }
.tab svg { display: block; }

/* phone bottom-pad: tabbar lives outside .screen now, so screen padding is small */
.phone { padding-bottom: 0; }
.phone > .screen { padding-bottom: 32px; }
.phone > .screen.entry { padding-bottom: 0; }
.phone > .tabbar { /* nothing */ }

/* iPhone 16 Pro Max viewport: 430×932 px (CSS px). The fixed-height card on
   desktop simulates that closely; on actual mobile we use 100dvh. */
@media (min-width: 500px) {
  .phone { height: 932px; }
}

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-mark {
  display: flex; gap: 8px; margin-top: 80px; margin-bottom: 32px;
}
.login-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--fg); }
.login-title { font-size: 32px; font-weight: 600; letter-spacing: 0.04em; }
.login-sub { color: var(--fg2); margin-top: 8px; margin-bottom: auto; font-size: 14px; }
.login-actions {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 80px;
}
.login-btn {
  appearance: none; border: 1px solid var(--fg);
  background: var(--fg); color: #FFF;
  height: 52px; border-radius: 4px;
  font-size: 16px; font-weight: 500;
  transition: opacity 150ms;
}
.login-btn.ghost { background: transparent; color: var(--fg); }
.login-btn:active { opacity: 0.7; }

/* ── Entry — split into scroll area + sticky pad ───────────────────────── */
.entry {
  padding: 0;
  overflow: hidden;
}
.entry-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 0;
  min-height: 0;
}
.entry-pad {
  flex-shrink: 0;
  background: var(--bg);
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Reserved height; the divider+keypad+save sit centered within. */
  min-height: 360px;
  justify-content: center;
}
/* Top divider as a pseudo so it can move down with the keypad block */
.entry-pad::before {
  content: "";
  display: block;
  height: 1px;
  background: var(--line);
  margin: 0 -16px 12px;
  flex-shrink: 0;
}

.edit-banner {
  display: flex; justify-content: space-between; align-items: center;
  background: #FAFAFA; border-bottom: 1px solid var(--line);
  padding: 8px 20px;
  font-size: 13px;
}
.edit-banner button {
  appearance: none; border: 0; background: transparent;
  color: var(--accent); font-weight: 500;
}

.entry-top {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.book-pill {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg);
  height: 30px; padding: 0 10px;
  border-radius: 4px;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500;
  white-space: nowrap;
  transition: opacity 150ms;
}
.book-pill:active { opacity: 0.7; }
.book-pill-dot { width: 6px; height: 6px; border-radius: 50%; }
.book-pill-caret { color: var(--fg2); font-size: 9px; }

.cam-btn {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg);
  width: 30px; height: 30px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
}
.cam-btn:active { opacity: 0.7; }

.amount-wrap {
  margin: 4px 0 4px;
  display: flex; align-items: baseline; gap: 8px;
}
.amount-currency {
  font-family: var(--mono); color: var(--fg2);
  font-size: 16px; font-weight: 500;
}
.amount-num {
  font-family: var(--mono); font-weight: 600;
  letter-spacing: -0.02em;
  flex: 1;
  word-break: break-all;
  line-height: 1;
}
.amount-preview {
  color: var(--fg2);
  font-size: 12px;
  margin: -2px 0 4px;
  text-align: right;
}

.pending-row { margin: 4px 0 12px; }
.pending-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--fg2);
  cursor: pointer;
}
.pending-toggle.is-on { color: var(--fg); font-weight: 500; }
.pending-toggle input { display: none; }
.pending-box {
  width: 18px; height: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 150ms, border-color 150ms;
  flex-shrink: 0;
}
.pending-tick {
  color: #FFF;
  font-size: 11px;
  line-height: 1;
  transition: opacity 150ms;
}

.payer-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.payer-label { font-size: 12px; color: var(--fg2); width: 32px; }

.seg {
  flex: 1;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
  height: 32px;
}
.seg-btn {
  appearance: none; border: 0; background: transparent;
  color: var(--fg2); font-size: 13px; font-weight: 500;
  border-right: 1px solid var(--line);
  transition: background 150ms, color 150ms;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn.is-on { background: var(--fg); color: #FFF; }

.cat-row {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  margin-bottom: 10px;
}
.cat-chip {
  appearance: none;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg2);
  height: 36px; border-radius: 4px;
  font-size: 15px; font-weight: 500;
  transition: opacity 150ms, color 150ms, border-color 150ms;
  padding: 0 4px;
}
.cat-chip.is-on { font-weight: 600; }

.tpl-list { display: flex; flex-direction: column; gap: 0; }
.tpl-list-row {
  appearance: none; background: transparent; border: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
  text-align: left;
}
.tpl-list-row:last-child { border-bottom: 0; }
.tpl-list-body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.tpl-list-name { font-size: 15px; font-weight: 500; color: var(--fg); }
.tpl-list-sub { font-size: 12px; color: var(--fg2); }

.tpl-mgmt-list { padding: 8px 20px 16px; display: flex; flex-direction: column; }
.tpl-mgmt-row {
  appearance: none; background: transparent; border: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
  text-align: left;
}
.tpl-mgmt-row:last-child { border-bottom: 0; }
.tpl-mgmt-body { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.tpl-mgmt-name { font-size: 15px; font-weight: 500; color: var(--fg); }
.tpl-mgmt-sub { font-size: 12px; color: var(--fg2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-delete-btn {
  appearance: none; width: 100%; height: 44px;
  background: transparent; border: 1px solid var(--line);
  border-radius: 4px; color: var(--danger);
  font-size: 14px; font-weight: 500;
}

.meta-list {
  border: 1px solid var(--line); border-radius: 4px;
  margin-bottom: 12px;
}
.row {
  display: flex; align-items: center;
  height: 40px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.row:last-child { border-bottom: 0; }
.row.note-row { align-items: flex-start; min-height: 40px; height: auto; padding: 8px 12px; }
.row.note-row .meta-k { padding-top: 4px; }
.note-area {
  resize: none;
  /* Aligns text right-edge with sibling rows' value text (which sits before
     the '›' caret). Measured ~9px from the row's right edge to match. */
  padding: 4px 9px 4px 0;
  line-height: 1.5;
  height: 24px;
  max-height: 120px;
  font-family: var(--sans);
  width: 100%;
  text-align: right;
}
.meta-k { color: var(--fg2); width: 48px; flex-shrink: 0; font-size: 13px; }
.meta-v { margin-left: auto; color: var(--fg); display: inline-flex; align-items: center; gap: 4px; }
.caret { color: var(--fg2); font-size: 16px; }
.meta-input {
  appearance: none; border: 0; background: transparent;
  flex: 1; height: 100%; outline: none;
  font-size: 14px; min-width: 0;
  text-align: right;
}
.meta-input::placeholder { color: #C8C8C8; }

.entry-error {
  color: var(--danger); font-size: 13px;
  margin-bottom: 8px;
}

/* ── Keypad ────────────────────────────────────────────────────────────── */
.kp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-bottom: 8px;
}
.kp-grid-calc { grid-template-columns: repeat(4, 1fr); }
.kp-btn {
  appearance: none; border: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-family: var(--mono); font-weight: 500;
  color: var(--fg);
  transition: opacity 150ms;
  user-select: none;
}
.kp-btn:active { opacity: 0.5; }
.kp-btn.kp-op {
  background: #FAFAFA; color: var(--fg2);
}
.kp-main { font-feature-settings: "tnum"; }

.save-btn {
  appearance: none; border: 0;
  width: 100%; height: 48px;
  background: var(--accent); color: #FFF;
  border-radius: 4px;
  font-size: 16px; font-weight: 600;
  font-family: var(--sans);
  transition: opacity 150ms;
}
.save-btn:active { opacity: 0.75; }

.toast {
  position: absolute;
  left: 50%; bottom: 80px; transform: translateX(-50%);
  background: rgba(26,26,26,.92); color: #FFF;
  font-size: 13px; padding: 8px 16px; border-radius: 4px;
  z-index: 10;
}

/* ── Sheet ─────────────────────────────────────────────────────────────── */
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.32);
  z-index: 20;
  display: flex; flex-direction: column; justify-content: flex-end;
  animation: fade 180ms ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  background: var(--bg);
  border-radius: 4px 4px 0 0;
  padding: 8px 20px 24px;
  max-height: 80%;
  overflow-y: auto;
  animation: slide 200ms ease;
}
@keyframes slide { from { transform: translateY(20px) } to { transform: translateY(0) } }
.sheet-grab {
  width: 36px; height: 4px; background: var(--line);
  border-radius: 2px; margin: 4px auto 12px;
}
.sheet-title {
  font-size: 15px; font-weight: 600; margin-bottom: 12px;
}
.sheet-body { display: flex; flex-direction: column; gap: 0; }
.sheet-done {
  appearance: none; border: 0; background: transparent;
  color: var(--accent); font-size: 15px; font-weight: 600;
  margin-top: 16px; align-self: flex-end;
}
.sheet-row {
  appearance: none; border: 0; background: transparent;
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 4px;
  border-bottom: 1px solid var(--line);
  font-size: 15px; color: var(--fg); text-align: left;
  width: 100%;
}
.sheet-row.is-on { font-weight: 600; }
.sheet-row-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sheet-row-l { flex: 1; }
.sheet-row-r { color: var(--fg2); font-size: 13px; }

/* ── Split picker ──────────────────────────────────────────────────────── */
.split-pick {}
.split-tabs {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
  margin-bottom: 16px;
}
.split-tab {
  appearance: none; border: 0; background: var(--bg);
  height: 40px; font-size: 14px; color: var(--fg2);
  border-right: 1px solid var(--line);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.split-tab:last-child { border-right: 0; }
.split-tab.is-on { color: var(--fg); }
.split-body { display: flex; flex-direction: column; gap: 12px; padding: 8px 0; }
.split-line {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 15px;
  padding: 10px 12px;
  background: #FAFAFA;
  border-radius: 4px;
}
.split-ratio-display {
  display: flex; justify-content: center; gap: 16px;
  font-family: var(--mono); font-size: 32px; font-weight: 600;
  margin: 4px 0;
}
.split-slider {
  width: 100%; height: 24px;
}
.split-slider.disabled { opacity: 0.25; pointer-events: none; }
.split-ratio-inputs {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin: 4px 0;
}
.split-ratio-inputs .custom-input {
  width: 90px; text-align: center; font-size: 22px;
  -moz-appearance: textfield;
}
.split-ratio-inputs .custom-input::-webkit-outer-spin-button,
.split-ratio-inputs .custom-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.mode-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
  margin-bottom: 8px;
}
.mode-btn {
  appearance: none; border: 0; background: var(--bg);
  height: 32px; font-size: 13px; color: var(--fg2);
  font-weight: 500;
  border-right: 1px solid var(--line);
}
.mode-btn:last-child { border-right: 0; }
.mode-btn.is-on { background: var(--fg); color: #FFF; }

.custom-line {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0;
  font-size: 15px;
}
.custom-input {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); padding: 8px 12px;
  border-radius: 4px; width: 140px; text-align: right;
  font-size: 15px; font-family: var(--mono);
  outline: none;
}
.custom-input.readonly { background: #FAFAFA; color: var(--fg2); }
.custom-input:focus { border-color: var(--fg); }
.split-hint { color: var(--fg2); font-size: 12px; padding: 4px 0; }
.treat-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.treat-btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg);
  color: var(--fg); height: 44px; border-radius: 4px;
  font-size: 14px; font-weight: 500;
}
.treat-btn.is-on { font-weight: 600; }

/* ── Item editor (明細) ───────────────────────────────────────────────── */
.item-editor { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.item-list { display: flex; flex-direction: column; }
.item-row {
  display: grid;
  grid-template-columns: 1fr 56px 80px 28px;
  align-items: center; gap: 8px;
  height: 40px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.item-row:last-child { border-bottom: 0; }
.item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-qty { color: var(--fg2); text-align: right; font-size: 13px; }
.item-price { text-align: right; }
.item-x {
  appearance: none; border: 0; background: transparent;
  color: var(--fg2); font-size: 18px; line-height: 1;
}
.item-add {
  display: grid;
  grid-template-columns: 1fr 56px 80px 28px;
  align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 8px;
  margin-top: 8px;
}
.item-in {
  appearance: none; border: 0; background: transparent;
  height: 32px; outline: none; font-size: 14px;
  min-width: 0;
}
.item-in.qty, .item-in.price { text-align: right; }
.item-plus {
  appearance: none; border: 0; background: transparent;
  font-size: 22px; line-height: 1; font-weight: 300;
  color: var(--accent);
}

/* ── OCR ───────────────────────────────────────────────────────────────── */
.ocr-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.94);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.ocr-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px;
}
.ocr-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.ocr-text { font-size: 15px; font-weight: 500; }
.ocr-sub { color: var(--fg2); font-size: 12px; }

.ocr-confirm { display: flex; flex-direction: column; gap: 16px; padding: 8px 0; }
.ocr-merchant { font-size: 14px; color: var(--fg2); }
.ocr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ocr-cell {
  border: 1px solid var(--line); border-radius: 4px; padding: 12px;
}
.ocr-cell-k { font-size: 12px; color: var(--fg2); margin-bottom: 4px; }
.ocr-cell-v { font-size: 18px; font-weight: 600; font-family: var(--mono); }
.ocr-items {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 12px;
}
.ocr-item-row {
  display: grid;
  grid-template-columns: 1fr 48px 72px;
  align-items: center; gap: 8px;
  height: 32px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.ocr-item-row:last-child { border-bottom: 0; }
.ocr-item-row > span:nth-child(2) { text-align: right; }
.ocr-item-row > span:nth-child(3) { text-align: right; }
.ocr-hint { font-size: 12px; color: var(--fg2); line-height: 1.5; }
.ocr-cat-row {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  margin-top: 2px;
}
.ocr-cat-chip {
  appearance: none;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg2);
  height: 30px; border-radius: 4px;
  font-size: 13px; font-weight: 500;
}
.ocr-cat-chip.is-on { font-weight: 600; }
.ocr-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.entry-items {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 12px; margin-bottom: 12px;
}
.entry-item-row {
  display: grid;
  grid-template-columns: 1fr 48px 80px 24px;
  align-items: center; gap: 8px;
  height: 36px;
  border-bottom: 1px solid #F5F5F5;
  font-size: 13px;
}
.entry-item-row:last-child { border-bottom: 0; }
.entry-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-item-qty { color: var(--fg2); text-align: right; font-size: 12px; }
.entry-item-price { text-align: right; }
.entry-item-x {
  appearance: none; border: 0; background: transparent;
  color: var(--fg2); font-size: 18px; line-height: 1;
}
.ocr-btn {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg);
  height: 44px; border-radius: 4px;
  font-size: 15px; font-weight: 500;
}
.ocr-btn.solid { color: #FFF; }

/* ── History ───────────────────────────────────────────────────────────── */
.history { padding: 0; padding-bottom: 0; }

.hist-header {
  padding: 16px 20px 0;
  border-bottom: 1px solid var(--line);
}
.hist-month-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.hist-month {
  appearance: none; border: 0; background: transparent;
  font-size: 22px; font-weight: 600;
  font-family: var(--mono);
  padding: 4px 20px 4px 0;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg2) 50%),
                    linear-gradient(135deg, var(--fg2) 50%, transparent 50%);
  background-position: calc(100% - 8px) 50%, calc(100% - 4px) 50%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
  outline: none;
}
.hist-trip-period {
  font-size: 14px; font-weight: 500;
  color: var(--fg);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #FAFAFA;
}
.hist-trip-dash { color: var(--fg2); font-weight: 400; }
.hist-total { display: flex; flex-direction: column; align-items: flex-end; }
.hist-total-l { font-size: 11px; color: var(--fg2); }
.hist-total-v { font-size: 18px; font-weight: 600; }

.hist-tabs {
  display: flex; gap: 16px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -20px; padding: 0 20px;
}
.hist-tabs::-webkit-scrollbar { display: none; }
.hist-tab {
  appearance: none; border: 0; background: transparent;
  font-size: 14px; color: var(--fg2);
  font-weight: 500;
  padding: 12px 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.hist-tab.is-on { color: var(--fg); border-bottom-color: var(--fg); font-weight: 600; }

.hist-list { padding: 0 20px 24px; }
.hist-day { padding: 16px 0 8px; border-bottom: 1px solid var(--line); }
.hist-day:last-child { border-bottom: 0; }
.hist-day-head {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--fg2);
  margin-bottom: 8px;
  font-weight: 500;
}
.hist-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #F5F5F5;
  transition: opacity 150ms;
}
.hist-item:last-child { border-bottom: 0; }
.hist-item:active { opacity: 0.6; }
.hist-item.compact { padding: 8px 0; }
.hist-cat {
  width: 32px; height: 32px;
  border: 1px solid var(--line); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 500;
  flex-shrink: 0;
  line-height: 1;
}
.hist-body { flex: 1; min-width: 0; }
.hist-l1 { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-l2 { font-size: 12px; color: var(--fg2); margin-top: 2px; }
.hist-r { font-size: 15px; font-weight: 500; }
.hist-items-tag { color: var(--fg2); font-size: 11px; }
.hist-item.settle .hist-cat { background: #FAFAFA; }
.hist-item.pending .hist-l1 { color: var(--fg2); }
.hist-item.pending {
  border-left: 2px solid currentColor;
  padding-left: 10px;
}
.pending-tag { font-size: 12px; font-weight: 600; color: var(--danger) !important; }

.pending-banner {
  appearance: none; border: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--fg);
  flex-shrink: 0;
}
.pending-banner:active { opacity: 0.6; }
.pending-banner-l { font-weight: 500; }
.pending-banner-r { color: var(--fg2); font-size: 16px; }

.hist-pending-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
  padding: 4px 0 12px;
}
.hist-pending-clear {
  appearance: none; border: 0; background: transparent;
  font-size: 13px; color: var(--fg2);
  padding: 4px 0;
}
.hist-search-row {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 0 12px;
}
.hist-search-input {
  flex: 1; appearance: none;
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; height: 32px;
  font-size: 15px; color: var(--fg);
  outline: none;
}
.hist-search-input:focus { border-bottom-color: var(--accent, #1F4E5F); }
.hist-search-cancel {
  appearance: none; border: 0; background: transparent;
  font-size: 14px; color: var(--fg2);
  padding: 4px 0;
}
.hist-search-btn {
  appearance: none; border: 0; background: transparent;
  margin-left: auto; padding: 0 0 12px 12px;
  color: var(--fg2);
  display: inline-flex; align-items: center;
  flex-shrink: 0;
}
.hist-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 8px 0 12px;
}
.hist-actions-3 { grid-template-columns: 1fr 1fr 1fr; }
.hist-actions button {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); height: 36px;
  border-radius: 4px; font-size: 13px; font-weight: 500;
}
.hist-actions:has(button:only-child) { grid-template-columns: 1fr; }
.hist-actions button.danger { color: var(--danger); }

.empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 64px 20px;
  text-align: center;
}
.empty-title { font-size: 16px; font-weight: 500; margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--fg2); }
.empty-mini { font-size: 13px; color: var(--fg2); padding: 32px; text-align: center; }

/* ── Settle ────────────────────────────────────────────────────────────── */
.settle-card {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 32px 20px;
  text-align: center;
  margin-bottom: 16px;
}
.settle-period { font-size: 12px; color: var(--fg2); margin-bottom: 16px; }
.settle-eq {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 16px; font-weight: 500;
  margin-bottom: 16px;
}
.settle-from { color: var(--fg); }
.settle-to { font-weight: 600; }
.settle-arrow { color: var(--fg2); }
.settle-amount {
  font-size: 40px; font-weight: 600;
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  margin-bottom: 24px;
}
.settle-cur { font-size: 16px; color: var(--fg2); font-weight: 500; }
.settle-zero { font-size: 28px; font-weight: 600; margin-top: 16px; }
.settle-zero-sub { font-size: 13px; color: var(--fg2); margin-top: 8px; }
.settle-action {}
.settle-btn {
  appearance: none; border: 0;
  background: var(--accent); color: #FFF;
  height: 48px; padding: 0 32px;
  border-radius: 4px;
  font-size: 15px; font-weight: 600;
  transition: opacity 150ms;
}
.settle-btn:active { opacity: 0.75; }

.settle-break {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 16px 16px 8px;
}
.settle-break-title { font-size: 12px; color: var(--fg2); margin-bottom: 12px; }
.settle-break-row {
  display: flex; justify-content: space-between;
  font-size: 14px; padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.settle-break-row:last-child { border-bottom: 0; }
.settle-break-row.muted { color: var(--fg2); }

.confirm-body { padding: 8px 0; display: flex; flex-direction: column; gap: 16px; }
.confirm-line { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.confirm-amt { font-size: 18px; font-weight: 600; }
.confirm-hint { font-size: 12px; color: var(--fg2); line-height: 1.6; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── Stats ─────────────────────────────────────────────────────────────── */
.stats-month-bar { margin-bottom: 16px; }
.stats-total {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 20px;
  margin-bottom: 24px;
}
.stats-total-l { font-size: 12px; color: var(--fg2); margin-bottom: 4px; }
.stats-total-v { font-size: 28px; font-weight: 600; }

.stats-section-title {
  font-size: 12px; color: var(--fg2);
  margin-bottom: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.stats-chart { margin-bottom: 16px; }
.stats-legend {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 32px;
}
.stats-legend-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.stats-legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.stats-legend-l { flex: 1; }
.stats-legend-v { width: 80px; text-align: right; }
.stats-legend-pct { width: 48px; text-align: right; color: var(--fg2); font-size: 12px; }

/* New horizontal-bar chart for category breakdown */
.stats-cat-bars {
  display: flex; flex-direction: column; gap: 14px;
  margin-bottom: 32px;
}
.stats-cat-row { display: flex; flex-direction: column; gap: 6px; }
.stats-cat-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.stats-cat-chip {
  width: 24px; height: 24px;
  border: 1px solid;
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.stats-cat-v { flex: 1; text-align: right; font-weight: 500; }
.stats-cat-pct { width: 44px; text-align: right; color: var(--fg2); font-size: 12px; }
.stats-cat-track {
  height: 6px; background: #F5F5F5; border-radius: 3px; overflow: hidden;
}
.stats-cat-fill { height: 100%; transition: width 200ms; }

.stats-bar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.stats-bar-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.stats-bar-l { width: 48px; }
.stats-bar-track {
  flex: 1; height: 8px; background: #F5F5F5; border-radius: 4px; overflow: hidden;
}
.stats-bar-fill { height: 100%; transition: width 200ms; }
.stats-bar-r { width: 80px; text-align: right; font-weight: 500; }

/* ── Books ─────────────────────────────────────────────────────────────── */
.books, .settings { padding: 0; padding-bottom: 0; }
.sub-header {
  display: flex; align-items: center;
  height: 48px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
}
.back {
  appearance: none; border: 0; background: transparent;
  width: 44px; height: 44px;
  font-size: 22px; color: var(--fg);
  font-weight: 300;
}
.sub-title { flex: 1; text-align: center; font-size: 15px; font-weight: 600; }
.sub-action {
  appearance: none; border: 0; background: transparent;
  height: 44px; padding: 0 16px;
  font-size: 14px; font-weight: 500;
}

.book-list { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; }
.book-card {
  border: 1px solid var(--line); border-radius: 4px;
  padding: 16px;
}
.book-card.archived { opacity: 0.5; }
.book-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.book-card-dot { width: 8px; height: 8px; border-radius: 50%; }
.book-card-name { font-size: 16px; font-weight: 600; flex: 1; }
.book-card-tag { font-size: 11px; color: var(--fg2); }
.book-card-period { font-size: 12px; color: var(--fg2); margin-bottom: 12px; }
.book-card-bot { display: flex; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.book-card-l { font-size: 13px; color: var(--fg2); }
.book-card-v { font-size: 16px; font-weight: 600; }
.book-card-arch {
  appearance: none; border: 1px solid var(--line);
  background: var(--bg); width: 100%;
  height: 36px; margin-top: 12px;
  border-radius: 4px; font-size: 13px; font-weight: 500;
}

/* ── Form ──────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 12px; padding: 8px 0 4px; }
.form-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 4px;
  padding: 0 12px; height: 44px;
}
.form-k { font-size: 13px; color: var(--fg2); width: 48px; }
.form-in {
  flex: 1; appearance: none; border: 0; background: transparent;
  height: 100%; outline: none; font-size: 14px;
  font-family: var(--sans);
  min-width: 0;
}
.form-in[type="date"] { font-family: var(--mono); }
.form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* ── Settings ──────────────────────────────────────────────────────────── */
.settings-section { padding: 16px 20px; border-bottom: 8px solid #FAFAFA; }
.settings-section-t { font-size: 12px; color: var(--fg2); margin-bottom: 12px; font-weight: 500; letter-spacing: 0.04em; }
.settings-hint { font-size: 12px; color: var(--fg2); margin-top: 8px; line-height: 1.5; }
.settings-save {
  appearance: none; border: 0; color: #FFF;
  width: 100%; height: 40px;
  border-radius: 4px;
  font-size: 14px; font-weight: 600;
  margin-top: 12px;
}
.settings-row {
  appearance: none; border: 0; background: transparent;
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; height: 44px; padding: 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.settings-row:last-child { border-bottom: 0; }
.settings-meta { text-align: center; padding: 24px; font-size: 11px; color: #C8C8C8; font-family: var(--mono); }

.theme-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.density-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.density-chip {
  appearance: none; border: 1px solid var(--line); background: var(--bg);
  height: 44px; border-radius: 4px;
  font-size: 14px; color: var(--fg);
  font-weight: 500;
  transition: border-color 150ms, color 150ms;
}
.density-chip.is-on { font-weight: 600; }
.theme-chip {
  appearance: none; border: 1px solid var(--line); background: var(--bg);
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 10px;
  border-radius: 4px;
  font-size: 13px; color: var(--fg);
  transition: border-color 150ms;
}
.theme-chip.is-on { border-color: var(--fg); border-width: 2px; padding: 0 9px; }
.theme-swatch { width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0; }
.theme-name { font-weight: 500; }

/* ── Photos (stage 4) ──────────────────────────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 0;
}
.photo-thumb {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  background-size: cover; background-position: center;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.photo-add {
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--line);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.photo-add-plus { font-size: 28px; line-height: 1; font-weight: 300; }
.photo-tip { font-size: 12px; color: var(--fg2); padding: 4px 0 8px; line-height: 1.5; }

.hist-photos {
  display: flex; gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
}
.hist-photo-thumb {
  width: 60px; height: 60px; flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background-size: cover; background-position: center;
  cursor: pointer;
}

.photo-preview {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.photo-preview-img {
  max-width: 92vw; max-height: 88vh;
  object-fit: contain;
  user-select: none; -webkit-user-select: none;
}
.photo-preview-close {
  position: absolute; top: 16px; right: 16px;
  appearance: none; border: 0; background: transparent;
  color: #fff; font-size: 32px; line-height: 1;
  width: 44px; height: 44px; border-radius: 22px;
  cursor: pointer;
}
.photo-preview-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  appearance: none; border: 0; background: rgba(255,255,255,0.12);
  color: #fff; font-size: 32px; line-height: 1; font-weight: 300;
  width: 44px; height: 44px; border-radius: 22px;
  cursor: pointer;
}
.photo-preview-nav.left  { left: 12px; }
.photo-preview-nav.right { right: 12px; }
.photo-preview-dots {
  position: absolute; bottom: 24px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 6px;
}
.photo-preview-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.4);
}
.photo-preview-dots span.is-on { background: #fff; }
