/* ========== 设计令牌 ========== */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --card: #ffffff;
  --soft: #f0efea;
  --line: #e8e7e2;
  --text: #1c1c1a;
  --muted: #6f6e69;
  --faint: #a3a29c;
  --ink: #18181b;
  --on-ink: #ffffff;
  --accent: #2a78d6;
  --accent-soft: #e9f1fb;
  --bar: #257de0;
  --bar-2: #f47230;
  --danger: #cf3f36;
  --danger-soft: #fcebe9;
  --warn: #9a5b00;
  --warn-soft: #fbf1db;
  --good: #16794c;
  --good-soft: #e4f4eb;
  --hero-bg: linear-gradient(145deg, #1f1f22 0%, #2b2b30 100%);
  --hero-fg: #ffffff;
  --hero-muted: rgba(255,255,255,.62);
  --hero-line: rgba(255,255,255,.12);
  --shadow: 0 1px 2px rgba(20,20,15,.04), 0 4px 16px rgba(20,20,15,.04);
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f0e;
    --card: #1a1a19;
    --soft: #242422;
    --line: #2b2b29;
    --text: #f0efec;
    --muted: #a7a69e;
    --faint: #6f6e69;
    --ink: #f0efec;
    --on-ink: #141413;
    --accent: #3987e5;
    --accent-soft: #172638;
    --bar: #338ced;
    --bar-2: #e76624;
    --danger: #f07167;
    --danger-soft: #3a1d1a;
    --warn: #e9b44c;
    --warn-soft: #3a2e14;
    --good: #4cc38a;
    --good-soft: #15301f;
    --hero-bg: linear-gradient(145deg, #26262a 0%, #1d1d20 100%);
    --hero-fg: #f5f5f2;
    --hero-muted: rgba(245,245,242,.6);
    --hero-line: rgba(255,255,255,.08);
    --shadow: none;
  }
}

/* ========== 基础 ========== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 560px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) 16px 24px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pos { color: var(--good); }
.neg { color: var(--danger); }
[hidden] { display: none !important; }

/* ========== 顶栏 ========== */
.top { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 12px; }
.top h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow);
  display: inline-grid; place-items: center; cursor: pointer; flex: none; color: var(--text); font-size: 17px; }
.chip-me { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip-me b { font-weight: 600; }

/* ========== 卡片 ========== */
.card { background: var(--card); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .sp { flex: 1; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.section-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; display: flex; justify-content: space-between; }

.hero { background: var(--hero-bg); color: var(--hero-fg); border-radius: var(--r-lg); padding: 18px 18px 16px; margin-bottom: 12px; }
.hero .label { font-size: 13px; color: var(--hero-muted); }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin: 2px 0 12px; }
.hero .row { display: flex; gap: 0; border-top: 1px solid var(--hero-line); padding-top: 12px; }
.hero .row > div { flex: 1; min-width: 0; }
.hero .row > div + div { padding-left: 14px; border-left: 1px solid var(--hero-line); }
.hero .row b { display: block; font-size: 17px; font-weight: 600; }
.hero .meta { font-size: 13px; color: var(--hero-muted); margin-top: -8px; margin-bottom: 12px; }

.banner { border-radius: var(--r-md); padding: 10px 14px; font-size: 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.banner.lock { background: var(--soft); color: var(--muted); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner .sp { flex: 1; }

/* ========== 列表 ========== */
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin: 16px 4px 6px; }
.list { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
.item:active { background: var(--soft); }
.cat { width: 38px; height: 38px; border-radius: 12px; background: var(--soft); display: grid; place-items: center; font-size: 19px; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .t, .item .s { display: block; }
.item .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { text-align: right; flex: none; }
.item .amt b { display: block; font-weight: 600; font-size: 16px; }
.item .amt span { font-size: 12px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .e { font-size: 40px; margin-bottom: 6px; }

/* ========== 按钮 ========== */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--soft); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: none; color: var(--accent); padding: 6px 8px; font-weight: 500; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; }
.btns > .btn { flex: 1; }

.fab { position: fixed; right: max(16px, calc(50vw - 264px)); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  border: 0; background: var(--ink); color: var(--on-ink); border-radius: 999px; padding: 14px 20px; font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22); cursor: pointer; }

/* ========== 底部导航 ========== */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.tabbar .in { max-width: 560px; margin: 0 auto; display: flex; }
.tabbar button { flex: 1; border: 0; background: none; padding: 6px 0; font-size: 11px; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabbar button .i { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .6; }
.tabbar button.on { color: var(--text); font-weight: 600; }
.tabbar button.on .i { filter: none; opacity: 1; }

/* ========== 分段 / 选项片 ========== */
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 0; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.chip.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.chip .x { opacity: .6; }

/* ========== 表单 ========== */
.field { margin-bottom: 14px; }
.field > label, .field > .lab { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px; outline: none; font-size: 16px; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 64px; }
.amount-input { font-size: 34px; font-weight: 700; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; padding: 4px 0 6px 26px; background: transparent; width: 100%; outline: none; }
.amount-input:focus { border-color: var(--ink); }
.amount-wrap { position: relative; }
.amount-wrap .sym { position: absolute; left: 0; top: 10px; font-size: 24px; font-weight: 600; color: var(--muted); pointer-events: none; }
.chip.small-chip { padding: 4px 10px; font-size: 13px; }
.fx-box { background: var(--card); border-radius: 12px; padding: 10px 12px; margin: -4px 0 14px; box-shadow: var(--shadow); }
.cur-tag { font-weight: 600; color: var(--text); }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; min-width: 0; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0; }

.split-rows { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.split-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.split-row + .split-row { border-top: 1px solid var(--line); }
.split-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-row input { width: 64px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px; text-align: center; background: var(--card); font-size: 15px; }
.split-row input.money { width: 80px; }
.split-row .r { width: 72px; text-align: right; font-weight: 600; }
.preview { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.7; }

/* ========== 图片 ========== */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--soft); border: 0; padding: 0; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .del { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; line-height: 22px; padding: 0; cursor: pointer; }
.thumb.add { display: grid; place-items: center; font-size: 26px; color: var(--muted); border: 1.5px dashed var(--line); background: none; }
#viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
#viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
#viewer .close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; }

/* ========== 结算 ========== */
.xfer { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.xfer + .xfer { border-top: 1px solid var(--line); }
.xfer.me { background: var(--accent-soft); }
.xfer .who { flex: 1; min-width: 0; }
.xfer .who b { font-weight: 600; }
.xfer .arrow { color: var(--faint); margin: 0 4px; }
.xfer .amt { font-weight: 700; font-size: 16px; }
.xfer .acts { display: flex; gap: 6px; flex: none; }
.bal-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.bal-table th { font-weight: 400; color: var(--muted); font-size: 12px; text-align: right; padding: 0 0 6px; }
.bal-table th:first-child, .bal-table td:first-child { text-align: left; }
.bal-table td { padding: 8px 0; border-top: 1px solid var(--line); text-align: right; }
.bal-table td:first-child { font-weight: 500; }
.done-big { text-align: center; padding: 10px 0 4px; }
.done-big .e { font-size: 38px; }
.done-big b { display: block; font-size: 17px; margin: 4px 0; }

/* ========== 统计 ========== */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: var(--r-md); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .l { font-size: 12.5px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.hbar { margin-bottom: 12px; }
.hbar .lab { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 8px; }
.hbar .lab span:last-child { color: var(--muted); white-space: nowrap; }
.hbar .track { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 4px; background: var(--bar); min-width: 2px; }
.hbar .fill.b2 { background: var(--bar-2); }
.hbar .track + .track { margin-top: 3px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin: -4px 0 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--bar); }
.legend i.b2 { background: var(--bar-2); }
.vbars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 18px; border-bottom: 1px solid var(--line); }
.vbars .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; }
.vbars .col .b { width: 100%; max-width: 28px; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.vbars .col:hover .b, .vbars .col.on .b { filter: brightness(1.15); }
.vbars .col .tip { position: absolute; bottom: calc(100% - 16px); font-size: 11px; color: var(--muted); white-space: nowrap; opacity: 0; transition: opacity .12s; pointer-events: none; }
.vbars .col:hover .tip, .vbars .col.on .tip { opacity: 1; color: var(--text); font-weight: 600; }
.vlabels { display: flex; gap: 4px; margin-top: 4px; }
.vlabels span { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.net-bar { position: relative; height: 8px; background: var(--soft); border-radius: 4px; margin-top: 4px; }
.net-bar .mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--faint); }
.net-bar .f { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.net-bar .f.pos { background: var(--good); left: 50%; }
.net-bar .f.neg { background: var(--danger); right: 50%; }

/* ========== 成员 ========== */
.mem { display: flex; align-items: center; gap: 10px; padding: 11px 14px; }
.mem + .mem { border-top: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; background: var(--soft); }
.mem .main { flex: 1; min-width: 0; }
.mem .s { font-size: 12.5px; color: var(--muted); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--soft); color: var(--muted); margin-left: 4px; font-weight: 500; vertical-align: 1px; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.ink { background: var(--ink); color: var(--on-ink); }

.log-item { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.log-item:first-child { border-top: 0; }
.log-item .when { font-size: 12px; color: var(--muted); }

/* ========== 游玩列表（管理员） ========== */
.trip { display: block; width: 100%; text-align: left; border: 0; background: var(--card); border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 10px; cursor: pointer; color: var(--text); }
.trip .r1 { display: flex; align-items: baseline; gap: 8px; }
.trip .r1 b { flex: 1; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip .r1 .amt { font-weight: 700; font-size: 17px; }
.trip .r2 { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; gap: 8px; }

/* ========== 弹层 ========== */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 40; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 600px; margin: 0 auto; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #sheet { animation: none; } }
#sheet .grab { width: 38px; height: 5px; background: var(--line); border-radius: 3px; margin: 0 auto 10px; }
#sheet .sh-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
#sheet .sh-head h3 { margin: 0; font-size: 18px; flex: 1; }

#toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translate(-50%, -20px); z-index: 80;
  background: var(--ink); color: var(--on-ink); padding: 9px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; font-weight: 800; font-size: 20px; margin-bottom: 16px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; gap: 12px; }
.kv:first-child { border-top: 0; }
.kv > span:first-child { color: var(--muted); flex: none; }
.kv > span:last-child { text-align: right; min-width: 0; word-break: break-all; }
.code-box { text-align: center; }
.code-box img { max-width: 100%; max-height: 60vh; border-radius: 12px; }
.note-box { white-space: pre-wrap; background: var(--card); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
