/* Trip Ledger — Apple 風格極簡 + 莫蘭迪冷色系(灰綠/煙灰藍/薰衣草紫,低對比不傷眼)
   與 COS ORG 的暖棕粉色盤刻意區隔,兩個 App 一眼可辨 */
:root {
  --color-bg: #F1F3F0;           /* 帶灰綠底的米白 */
  --color-surface: #FFFFFF;
  --color-text: #363A38;         /* 墨綠灰,比純黑柔和 */
  --color-text-muted: #878E88;
  --color-border: #DFE4DE;
  --color-accent: #8FA391;       /* 莫蘭迪灰綠(主色) */
  --color-accent-strong: #75897A;
  --color-lavender: #A69CB8;     /* 薰衣草紫 */
  --color-green: #9DB2A0;
  --color-green-deep: #56705C;
  --color-blue: #8CA0B4;         /* 煙灰藍 */
  --color-warn: #D6C591;         /* estimated 黃 */
  --color-warn-deep: #98834E;
  --color-danger: #BC8A90;
  --color-danger-deep: #94575F;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: 96px;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(241, 243, 240, 0.92);
  backdrop-filter: blur(10px);
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--color-border);
}
.topbar h1 { font-size: 21px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar-row h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn {
  border: none; background: none; font-size: 22px; color: var(--color-accent-strong);
  padding: 4px 8px 4px 0; cursor: pointer; line-height: 1;
}
.top-action {
  border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; color: var(--color-text);
  cursor: pointer; box-shadow: var(--shadow); white-space: nowrap;
}
.top-action.primary { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }

main { padding: 16px 16px 0; max-width: 640px; margin: 0 auto; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title { font-size: 13px; color: var(--color-text-muted); margin: 0 0 10px; font-weight: 600; letter-spacing: 0.02em; }

/* 行程卡 */
.trip-card { display: block; }
.trip-card .trip-name { font-size: 17px; font-weight: 600; }
.trip-card .trip-dates { font-size: 12.5px; color: var(--color-text-muted); margin-top: 3px; }
.trip-card .trip-meta { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.trip-card .trip-total { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--color-accent-strong); }

/* ---------- 頭像 ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 700; flex-shrink: 0;
  user-select: none;
}
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-right: -6px; border: 2px solid var(--color-surface); }

/* 頭像單選/多選(44px 觸控目標) */
.avatar-pick { display: flex; gap: 10px; flex-wrap: wrap; }
.avatar-pick .pick {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 52px; padding: 6px 4px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent; cursor: pointer; background: none;
}
.avatar-pick .pick .avatar { opacity: 0.35; transition: opacity .12s; }
.avatar-pick .pick.on .avatar { opacity: 1; }
.avatar-pick .pick.on { border-color: var(--color-accent); background: rgba(143,163,145,0.10); }
.avatar-pick .pick span.nm { font-size: 11px; color: var(--color-text-muted); }

/* ---------- 摘要條 ---------- */
.summary-strip { display: flex; gap: 10px; margin-bottom: 14px; }
.summary-box {
  flex: 1; background: var(--color-surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.summary-box .lb { font-size: 11.5px; color: var(--color-text-muted); }
.summary-box .vl { font-size: 19px; font-weight: 700; margin-top: 2px; letter-spacing: -0.01em; }
.summary-box .vl.bump { animation: bump .45s ease; }
@keyframes bump { 0% { transform: scale(1);} 35% { transform: scale(1.12); color: var(--color-accent-strong);} 100% { transform: scale(1);} }

/* ---------- 收據列表 ---------- */
.date-group { margin-bottom: 6px; }
.date-head {
  display: flex; align-items: baseline; padding: 10px 4px 6px;
  font-size: 13px; font-weight: 600; color: var(--color-text-muted);
}
.date-head .day-total { margin-left: auto; font-weight: 600; font-size: 12.5px; }
.receipt-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--color-surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.receipt-row .r-main { flex: 1; min-width: 0; }
.receipt-row .r-store { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-row .r-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.receipt-row .r-amt { text-align: right; }
.receipt-row .r-amt .fx { font-size: 14.5px; font-weight: 600; }
.receipt-row .r-amt .twd { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; padding: 2px 8px; letter-spacing: 0.02em;
}
.badge-est { background: rgba(214,197,145,0.28); color: var(--color-warn-deep); }
.badge-act { background: rgba(157,178,160,0.28); color: var(--color-green-deep); }
.badge-fund { background: rgba(140,160,180,0.25); color: #56718A; }
.badge-cash { background: rgba(185,156,166,0.28); color: #8C616D; }
.badge-refund { background: rgba(166,156,184,0.25); color: #6F638C; }

/* ---------- 表單 ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; color: var(--color-text-muted); margin-bottom: 6px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); padding: 12px 14px; font-size: 16px; color: var(--color-text);
  outline: none; appearance: none;
}
.input:focus { border-color: var(--color-accent); }
.input.err { border-color: var(--color-danger); }
.field .hint { font-size: 11.5px; color: var(--color-text-muted); margin-top: 4px; }
.field .hint.error { color: var(--color-danger-deep); font-weight: 600; }
.row2 { display: flex; gap: 10px; }
.row2 > .field { flex: 1; }

/* chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 9px 16px; border-radius: 999px; background: var(--color-surface);
  color: var(--color-text-muted); font-size: 13.5px; border: 1px solid var(--color-border);
  cursor: pointer; white-space: nowrap; min-height: 38px;
}
.chip.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }

/* segmented(分攤模式 / 支付種類) */
.seg {
  display: flex; background: var(--color-bg); border-radius: 999px; padding: 3px;
  border: 1px solid var(--color-border);
}
.seg button {
  flex: 1; border: none; background: none; border-radius: 999px; padding: 8px 0;
  font-size: 12.5px; color: var(--color-text-muted); cursor: pointer; min-height: 34px;
}
.seg button.active { background: var(--color-surface); color: var(--color-text); font-weight: 600; box-shadow: var(--shadow); }

/* toggle */
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.switch-row .sw-label { font-size: 14.5px; font-weight: 600; }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob {
  position: absolute; inset: 0; background: var(--color-border); border-radius: 999px;
  transition: background .15s; cursor: pointer;
}
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
.switch input:checked + .knob { background: var(--color-green); }
.switch input:checked + .knob::after { transform: translateX(20px); }

/* ---------- 品項編輯 ---------- */
.item-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px;
}
.item-head { display: flex; gap: 8px; align-items: center; }
.item-head input.i-name { flex: 1; }
.item-head .i-del {
  border: none; background: none; color: var(--color-text-muted); font-size: 18px;
  padding: 8px; cursor: pointer; min-width: 40px; min-height: 40px;
}
.item-nums { display: flex; gap: 8px; margin-top: 8px; }
.item-nums .field { flex: 1; margin-bottom: 0; }
.item-line-total { font-size: 12px; color: var(--color-text-muted); text-align: right; margin-top: 6px; }
.split-box { margin-top: 10px; border-top: 1px dashed var(--color-border); padding-top: 10px; }
.split-members { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.split-num { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.split-num input {
  width: 58px; text-align: center; border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: 8px 4px; font-size: 15px; outline: none;
}
.split-num input:focus { border-color: var(--color-accent); }
.split-status { font-size: 11.5px; margin-top: 8px; font-weight: 600; }
.split-status.ok { color: var(--color-green-deep); }
.split-status.bad { color: var(--color-danger-deep); }

.add-item-btn {
  width: 100%; border: 1.5px dashed var(--color-border); background: none;
  border-radius: var(--radius-sm); padding: 13px; font-size: 14px; color: var(--color-text-muted);
  cursor: pointer; margin-bottom: 12px; min-height: 46px;
}
.bulk-row { display: flex; gap: 8px; margin-bottom: 12px; }
.bulk-row button {
  flex: 1; border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: 999px; padding: 9px; font-size: 12.5px; color: var(--color-text); cursor: pointer;
}

/* 總計列 */
.total-bar {
  display: flex; align-items: baseline; gap: 8px; padding: 12px 4px;
  font-size: 15px; font-weight: 600;
}
.total-bar .t-twd { margin-left: auto; color: var(--color-text-muted); font-size: 13px; font-weight: 500; }

/* ---------- 底部主按鈕(拇指熱區) ---------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(241,243,240,0.94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; max-width: 640px; margin: 0 auto;
}
.btn-primary {
  flex: 1; border: none; background: var(--color-accent); color: #fff;
  border-radius: var(--radius); padding: 15px; font-size: 16.5px; font-weight: 700;
  cursor: pointer; min-height: 52px; letter-spacing: 0.02em;
}
.btn-primary:active { background: var(--color-accent-strong); }
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost {
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-danger-deep);
  border-radius: var(--radius); padding: 15px 18px; font-size: 14px; cursor: pointer; min-height: 52px;
}

.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 20;
  width: 58px; height: 58px; border-radius: 50%; background: var(--color-accent);
  color: #fff; font-size: 30px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(117,137,122,0.38); border: none; cursor: pointer;
}
.fab:active { background: var(--color-accent-strong); }

/* ---------- 底部滑出面板 ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(58,58,58,0.35); z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--color-bg); border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .22s ease;
  max-height: 88vh; overflow-y: auto; max-width: 640px; margin: 0 auto;
}
.sheet.show { transform: translateY(0); }
.sheet h2 { font-size: 17px; margin: 0 0 14px; }

/* ---------- 結算頁 ---------- */
.member-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.member-row:last-child { border-bottom: none; }
.member-row .m-name { font-size: 14.5px; font-weight: 600; flex: 1; }
.member-row .m-nums { text-align: right; font-size: 13px; }
.member-row .m-nums .n1 { font-weight: 600; }
.member-row .m-nums .n2 { color: var(--color-text-muted); font-size: 11.5px; margin-top: 1px; }

.transfer-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--color-border); font-size: 15px;
}
.transfer-row:last-child { border-bottom: none; }
.transfer-row .arrow { color: var(--color-text-muted); }
.transfer-row .t-amt { margin-left: auto; font-weight: 700; font-size: 16px; }

.fund-card-line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; }
.fund-card-line .k { color: var(--color-text-muted); }
.fund-remain { font-size: 20px; font-weight: 700; margin: 6px 0 2px; }
.fund-note { font-size: 11.5px; color: var(--color-text-muted); }

/* 回填列表 */
.backfill-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.backfill-row:last-child { border-bottom: none; }
.backfill-row .b-main { flex: 1; min-width: 0; }
.backfill-row .b-store { font-size: 13.5px; font-weight: 600; }
.backfill-row .b-sub { font-size: 11.5px; color: var(--color-text-muted); }
.backfill-row input {
  width: 96px; border: 1px solid var(--color-warn); border-radius: var(--radius-sm);
  padding: 10px 8px; font-size: 15px; text-align: right; outline: none; background: #FAFBF5;
}
.backfill-row button {
  border: none; background: var(--color-accent); color: #fff; border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; cursor: pointer; min-height: 40px;
}

/* ---------- 其他 ---------- */
.empty-state { text-align: center; color: var(--color-text-muted); font-size: 14px; padding: 56px 20px; line-height: 1.7; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 99;
  transform: translateX(-50%) translateY(8px);
  background: #2B2E2C; color: #fff; font-size: 13.5px; padding: 11px 18px;
  border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,0.22);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-success { background: var(--color-green-deep); }
#toast.toast-error { background: var(--color-danger-deep); }

.offline-banner {
  display: none; background: var(--color-warn); color: #554A26;
  font-size: 12px; text-align: center; padding: 6px;
}
.offline-banner.show { display: block; }

.section-gap { height: 8px; }
.muted { color: var(--color-text-muted); }
.small { font-size: 12px; }
