:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #f1ebe3;
  --ink: #221d24;
  --ink-2: #5e5662;
  --line: #e4dbd0;
  --accent: #5b3a55;
  --accent-ink: #ffffff;
  --accent-soft: #efe4ec;
  --pos: #2f6b4f;
  --neg: #b03a2e;
  --warn: #a5661a;
  --warn-soft: #fbf0df;
  --danger-soft: #f8e3e0;
  --ok-soft: #e3f0e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 29, 36, .06), 0 4px 16px rgba(34, 29, 36, .05);
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16141a; --surface: #211e26; --surface-2: #2a2630; --ink: #f1ecf2; --ink-2: #b4abb8; --line: #3a3541;
    --accent: #c99bbf; --accent-ink: #1a1418; --accent-soft: #3a2b37; --pos: #7fc8a0; --neg: #f08b7f; --warn: #e8b46a;
    --warn-soft: #3a2f1f; --danger-soft: #3d2423; --ok-soft: #1f3328; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: .01em; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: .98rem; font-weight: 700; }
p { margin: 0; }
.num, .stat-value, td.num, th.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--pos); }
.error { color: var(--neg); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* 版面 */
#app { min-height: 100vh; }
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--tab-h) + 32px + env(safe-area-inset-bottom)); }
.page.center { min-height: 100vh; display: grid; place-items: center; padding-bottom: 32px; }
.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stack.tight { gap: 8px; }
.row { display: flex; gap: 10px; align-items: flex-end; min-width: 0; }
.row > .field { flex: 1; min-width: 0; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; align-items: center; }
.row.end { justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-top: 4px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
h2.group { font-size: .8rem; color: var(--ink-2); font-weight: 500; letter-spacing: .08em; margin-top: 8px; }

/* 卡片 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.inset { background: var(--surface-2); box-shadow: none; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card .card-head:last-child { margin-bottom: 0; }
.dim { opacity: .55; }

/* 數字 */
.stats3, .stats2 { display: grid; gap: 8px; }
.stats3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; text-align: left; background: var(--surface-2); border: 0; border-radius: 10px; padding: 10px 10px 9px; min-width: 0; }
button.stat { cursor: pointer; }
button.stat:hover { background: var(--accent-soft); }
.stat-label { font-size: .78rem; color: var(--ink-2); }
.stat-value { font-size: 1.12rem; font-weight: 700; overflow-wrap: anywhere; }
.stat.big .stat-value { font-size: 1.8rem; }
.stat-sub { font-size: .76rem; color: var(--ink-2); }
.stat.pos .stat-value { color: var(--pos); }
.stat.neg .stat-value { color: var(--neg); }
.formula { font-variant-numeric: tabular-nums; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }

/* 工具列 */
.toolbar { display: flex; flex-direction: column; gap: 10px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-label { position: relative; font-weight: 700; font-size: 1.05rem; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.month-label:hover { background: var(--surface-2); }
.sr-only-input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.note { background: var(--surface-2); border-radius: 10px; padding: 9px 12px; font-size: .86rem; color: var(--ink-2); }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 9px 12px; font-size: .9rem; }

/* 按鈕 */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 10px 16px; font-weight: 500; cursor: pointer; min-height: 44px; line-height: 1.2; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.btn.danger:not(.ghost) { background: var(--neg); color: #fff; border-color: var(--neg); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 1.05rem; font-weight: 700; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn { appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; font-size: 1.3rem; cursor: pointer; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link { appearance: none; border: 0; background: none; color: var(--accent); padding: 4px 0; cursor: pointer; font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; }
.back { appearance: none; border: 0; background: none; color: var(--accent); font-weight: 500; padding: 4px 0; cursor: pointer; align-self: flex-start; }
.line-btn { appearance: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--surface-2); cursor: pointer; text-align: left; }
.line-btn:hover { background: var(--accent-soft); }

/* 分段選擇 */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; min-width: 0; }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; border-radius: 9px; padding: 8px 10px; min-height: 40px; cursor: pointer; color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 700; }
.tabs-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs-scroll .seg { width: max-content; min-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; cursor: pointer; min-height: 38px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* 表單 */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .label { font-size: .84rem; color: var(--ink-2); font-weight: 500; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.amount { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
select.unconfirmed { border-color: var(--warn); background: var(--warn-soft); }
.row select { width: auto; flex: 1; min-width: 0; }
.search { flex: 1; min-width: 160px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 36px; }
.check input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
legend { font-size: .84rem; color: var(--ink-2); padding: 0 4px; }
.file-btn { position: relative; display: flex; align-items: center; justify-content: center; min-height: 52px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; color: var(--ink-2); padding: 10px; text-align: center; overflow-wrap: anywhere; }
.file-btn:hover { border-color: var(--accent); color: var(--accent); }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: start; }
.step-n { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.step-title { font-weight: 700; }
.tier-edit input { width: 72px; flex: 1; }
.tier-edit span { flex: none; color: var(--ink-2); font-size: .9rem; padding-bottom: 12px; }
.tiers { display: flex; flex-wrap: wrap; gap: 6px; }
.tier { display: inline-flex; gap: 6px; align-items: baseline; background: var(--surface-2); padding: 4px 10px; border-radius: 8px; font-size: .88rem; }
.preview { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }

/* 徽章 */
.badge { display: inline-block; font-size: .74rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; font-weight: 500; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--neg); }
.badge.ok { background: var(--ok-soft); color: var(--pos); }
.badge.lock { background: var(--accent-soft); color: var(--accent); }

/* 清單 */
ul { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.list li:last-child { border-bottom: 0; }
.list.cards { display: flex; flex-direction: column; gap: 8px; }
.list.cards > li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0; border-bottom: 1px solid var(--line); display: block; }
.list.cards > li.row, .list.cards > li.stack { padding: 12px; display: flex; }
.exp { appearance: none; border: 0; background: none; width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; text-align: left; cursor: pointer; border-radius: 12px; }
.exp:hover { background: var(--surface-2); }
.exp .main, li .main { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.exp .main strong { overflow-wrap: anywhere; }
.exp .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.menu { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.menu li + li { border-top: 1px solid var(--line); }
.menu button { appearance: none; border: 0; background: none; width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; text-align: left; cursor: pointer; gap: 12px; }
.menu button > span:first-child { display: flex; flex-direction: column; }
.menu button:hover { background: var(--surface-2); }
.chev { color: var(--ink-2); font-size: 1.3rem; }
.todo { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.todo li { border-left: 4px solid var(--line); background: var(--surface-2); border-radius: 8px; }
.todo li.block { border-left-color: var(--neg); }
.todo li.warn { border-left-color: var(--warn); }
.todo li.info { border-left-color: var(--line); }
.todo li > div, .todo li > button { padding: 9px 12px; }
.todo button { appearance: none; border: 0; background: none; width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.audit li { flex-direction: column; align-items: stretch; gap: 2px; }

/* 課程 */
.day-head { display: flex; gap: 8px; align-items: center; font-size: .9rem; color: var(--ink-2); padding: 4px 2px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.day.today .day-head { color: var(--accent); }
.sessions { display: flex; flex-direction: column; gap: 6px; }
.session { appearance: none; width: 100%; display: grid; grid-template-columns: 48px minmax(0, 1fr) auto 68px; gap: 10px; align-items: center; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; cursor: pointer; }
.session:hover { border-color: var(--accent); }
.session .time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink-2); }
.session .main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session .count { font-size: .88rem; color: var(--ink-2); white-space: nowrap; }
.session .pay { text-align: right; font-weight: 700; }
.kv { display: grid; gap: 6px; }
.kv > div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; font-size: .92rem; }
.kv > div > span:last-child { overflow-wrap: anywhere; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--ink-2); font-weight: 500; background: var(--surface-2); white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
details summary { cursor: pointer; font-weight: 500; padding: 4px 0; }
details[open] summary { margin-bottom: 8px; }
li.block { color: var(--neg); }
li.warn { color: var(--warn); }

/* 底部分頁 */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { appearance: none; flex: 1; max-width: 128px; height: var(--tab-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .74rem; color: var(--ink-2); cursor: pointer; }
.tabbar .ico { font-size: 1.25rem; line-height: 1; }
.tabbar button.on { color: var(--accent); font-weight: 700; }
.tabbar .primary-tab .ico { width: 44px; height: 32px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 1.4rem; }

/* 抽屜 */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 16, 22, .42); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .18s; }
.overlay.show { opacity: 1; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; transform: translateY(24px); transition: transform .18s; outline: none; }
.overlay.show .sheet { transform: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 8px 8px 18px; border-bottom: 1px solid var(--line); gap: 8px; }
.sheet-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 16px 18px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }

/* 提示 */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; z-index: 100; opacity: 0; transition: all .2s; max-width: calc(100% - 32px); font-size: .92rem; pointer-events: none; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--neg); color: #fff; }

/* 登入 */
.login { width: 100%; max-width: 380px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; letter-spacing: .02em; flex: none; }
.demo-bar { background: var(--warn-soft); color: var(--warn); font-size: .82rem; padding: 6px 16px; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.demo-switch { width: auto; min-height: 32px; padding: 2px 8px; font-size: .82rem; }

@media (max-width: 380px) {
  .stats3 { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.05rem; }
  .session { grid-template-columns: 42px minmax(0, 1fr) 62px; }
  .session .count { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.statement-img { width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); background: #f6f2ec; }
