:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e2e5ea; --border-strong: #cdd2da;
  --text: #1a1d23; --muted: #6a7280; --faint: #9aa1ad;
  --primary: #2453d4; --primary-hover: #1c43b0; --primary-soft: #eaf0ff; --on-primary: #ffffff;
  --success: #12804a; --success-soft: #e6f5ec; --warn: #a65b00; --warn-soft: #fff3e0;
  --danger: #c3312b; --danger-soft: #fdecea; --focus: #2453d455;
  --radius: 10px; --shadow: 0 1px 2px #0000000d, 0 2px 8px #0000000a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --surface-2: #1b2028; --border: #272d37; --border-strong: #3a424f;
    --text: #e6e9ee; --muted: #98a1ae; --faint: #6b7380;
    --primary: #5a86ff; --primary-hover: #7a9dff; --primary-soft: #1b2643; --on-primary: #0b1020;
    --success: #4cc68a; --success-soft: #12291d; --warn: #f0a646; --warn-soft: #2d2212;
    --danger: #ff6b63; --danger-soft: #2f1716; --focus: #5a86ff66;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- 表單元件 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent; background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--primary-hover); }
.btn:focus-visible, .input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--border-strong); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.input, select, textarea { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
textarea { height: auto; min-height: 140px; padding: 10px; resize: vertical; line-height: 1.6; }
.input.mono { font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; }
.field > small { color: var(--muted); font-size: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- 登入 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 32px; }
.login h1 { font-size: 22px; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- 版面 ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 16px; font-weight: 700; padding: 0 10px 16px; }
.brand small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.nav-group { font-size: 11.5px; color: var(--faint); font-weight: 600; letter-spacing: .04em; padding: 14px 10px 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; height: 36px; padding: 0 10px; border-radius: 8px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; width: 100%; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; }
.count:empty { display: none; }
.side-foot { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.main { min-width: 0; }
.topbar { display: none; }
.page { max-width: 1180px; margin: 0 auto; padding: 28px 32px 96px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* ---------- 總覽 ---------- */
.todo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.todo { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; text-align: left; font: inherit; color: inherit; transition: border-color .12s; }
.todo:hover { border-color: var(--primary); }
.todo b { font-size: 30px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.todo.hot b { color: var(--danger); }
.todo span { color: var(--muted); font-size: 13px; }
.todo em { font-style: normal; color: var(--primary); font-size: 13px; font-weight: 600; margin-top: 6px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); }
.metric { padding: 16px 20px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12.5px; }
.metric b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.metric small { color: var(--faint); font-size: 12px; }
.setup { list-style: none; margin: 0; padding: 0; }
.setup li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; border-top: 1px solid var(--border); }
.setup li:first-child { border-top: 0; }
.dot { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); margin-top: 1px; }
.setup li.done .dot { background: var(--success); border-color: var(--success); }
.setup li.done .t { color: var(--muted); text-decoration: line-through; }
.setup .t { font-weight: 600; }

/* ---------- 篩選 ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { height: 30px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .count { margin-left: 4px; }

/* ---------- 審核卡片 ---------- */
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.qcard { display: flex; flex-direction: column; }
.qcard .qhead { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.qcard .qhead b { font-size: 15px; }
.qcard .qbody { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.qcard .qfoot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.qcard .qfoot .btn:first-child { flex: 1; }
.shot { width: 100%; height: 260px; object-fit: contain; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.dl { display: grid; grid-template-columns: 84px 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.payout { background: var(--primary-soft); border-radius: 8px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: baseline; }
.payout span { color: var(--muted); font-size: 13px; }
.payout b { font-size: 22px; color: var(--primary); font-variant-numeric: tabular-nums; }
.addr { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.addr code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
td .input, td select { height: 32px; }
tr.dirty td { background: var(--warn-soft); }
tr.off td { color: var(--faint); }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.bar i { display: block; height: 100%; background: var(--primary); }

/* ---------- 會員 ---------- */
.balances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.balance { padding: 18px 20px; }
.balance span { color: var(--muted); font-size: 13px; }
.balance b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }

/* ---------- 設定 ---------- */
.section { display: grid; grid-template-columns: 260px 1fr; gap: 24px; padding: 24px; border-top: 1px solid var(--border); }
.section:first-child { border-top: 0; }
.section h2 { font-size: 15px; margin-bottom: 4px; }
.section > div:first-child p { margin: 0; color: var(--muted); font-size: 13px; }
.qr-box { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.qr { width: 160px; height: 160px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--border); }
.qr-empty { width: 160px; height: 160px; border-radius: 8px; border: 1px dashed var(--border-strong); display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 12px; padding: 12px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- 底部儲存列 ---------- */
.savebar { position: fixed; left: 232px; right: 0; bottom: 0; padding: 12px 32px; background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: 10px; box-shadow: 0 -4px 16px #00000014; z-index: 5; }
.savebar span { margin-right: auto; font-weight: 600; }

/* ---------- 對話框、大圖、提示 ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px #00000040; }
dialog::backdrop { background: #0008; }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h3 { font-size: 17px; }
dialog p { margin: 0; color: var(--muted); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.lightbox { position: fixed; inset: 0; background: #000d; display: grid; place-items: center; z-index: 20; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 8px); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; z-index: 30; font-weight: 600; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

/* ---------- 工具列（搜尋、篩選） ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .search { flex: 1 1 240px; max-width: 340px; }
.toolbar select { width: auto; min-width: 120px; }
.toolbar .date { width: 150px; }
.toolbar .to { color: var(--muted); }
.toolbar .result { margin-left: auto; color: var(--muted); font-size: 13px; }
.summary { padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 13px; color: var(--muted); }
.summary b { color: var(--text); }
td.actions { text-align: right; width: 1%; }
td.actions .btn + .btn { margin-left: 4px; }
.btn.link-danger { background: none; color: var(--danger); }
.btn.link-danger:hover { background: var(--danger-soft); }

/* ---------- 表單對話框 ---------- */
dialog.form-dlg { width: min(600px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.form-dlg form { gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-dlg .note { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin: 0; }
.form-dlg .static { min-height: 36px; display: flex; align-items: center; font-weight: 600; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- 手機 ---------- */
@media (max-width: 1000px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .section { grid-template-columns: 1fr; gap: 12px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 15; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px #0004; }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: #0006; z-index: 14; }
  .topbar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
  .topbar b { flex: 1; }
  .page { padding: 20px 16px 96px; }
  .todo-grid, .balances { grid-template-columns: 1fr; }
  .queue { grid-template-columns: 1fr; }
  .savebar { left: 0; padding: 12px 16px; }
}

/* 細節修正 */
i.count { font-style: normal; }
.card-head select, .row select { width: auto; min-width: 130px; }
.addr { flex-wrap: wrap; }
.addr code { flex: 1 1 100%; }
.addr code + .btn { margin-left: auto; }
