:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #dde1e7;
  --text: #1d2330;
  --muted: #667085;
  --accent: #2f5bd3;
  --accent-weak: #e7edfb;
  --ok: #1f7a4d;
  --ok-weak: #e3f4ea;
  --warn: #9a6200;
  --warn-weak: #fff3d6;
  --bad: #b42318;
  --bad-weak: #fde8e6;
  --info-weak: #eef2f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --panel: #1a1e26; --panel-2: #222733; --border: #2e3442; --text: #e6e9ef; --muted: #98a2b3;
    --accent: #7c9cff; --accent-weak: #232c45; --ok: #5cc995; --ok-weak: #1b3127; --warn: #f0b955; --warn-weak: #3a2f17;
    --bad: #ff8a80; --bad-weak: #3d2020; --info-weak: #232833; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1a1e26; --panel-2: #222733; --border: #2e3442; --text: #e6e9ef; --muted: #98a2b3;
  --accent: #7c9cff; --accent-weak: #232c45; --ok: #5cc995; --ok-weak: #1b3127; --warn: #f0b955; --warn-weak: #3a2f17;
  --bad: #ff8a80; --bad-weak: #3d2020; --info-weak: #232833; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 52px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active { color: var(--text); background: var(--panel-2); text-decoration: none; }
.spacer { flex: 1; }
#user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { padding: 20px; max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

button, .btn { font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
textarea { width: 100%; font-family: var(--mono); font-size: 12.5px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.bad .value { color: var(--bad); }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; background: var(--warn-weak); color: var(--warn); }
.banner.info { background: var(--info-weak); color: var(--text); }

table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; z-index: 1; }
tr:hover td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.bad { background: var(--bad-weak); color: var(--bad); }
.badge.accent { background: var(--accent-weak); color: var(--accent); }

/* ---- 校正頁 ---- */
.review { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.side { position: sticky; top: 68px; max-height: calc(100vh - 84px); overflow: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { min-width: 240px; flex: 1; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.chip .n { font-variant-numeric: tabular-nums; margin-left: 4px; opacity: .8; }

.lines td { font-size: 13px; }
.lines .group td { background: var(--panel-2); font-weight: 600; cursor: pointer; border-top: 2px solid var(--border); }
.lines .group .meta { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.lines tr.selected td { background: var(--accent-weak); }
.lines tr.flash td { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--warn-weak); } to { background: transparent; } }
.lines .acct { min-width: 170px; max-width: 240px; word-break: break-all; }
.lines .camp { max-width: 360px; word-break: break-all; color: var(--muted); }
.lines .case-cell { min-width: 210px; }
.lines tr.st-unassigned .case-input { border-color: var(--bad); background: var(--bad-weak); }
.lines tr.st-excluded td:not(.case-cell) { opacity: .55; }
.case-input { width: 140px; font-family: var(--mono); font-size: 12.5px; padding: 3px 6px; }
.case-name { display: block; font-size: 11.5px; color: var(--muted); max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edited { color: var(--accent); font-weight: 600; }

.bulkbar { position: sticky; bottom: 12px; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--accent); box-shadow: 0 4px 16px rgba(0,0,0,.12); border-radius: var(--radius); padding: 10px 14px; margin-top: 10px; }

.ac { position: absolute; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.16); max-height: 320px; overflow: auto; min-width: 420px; }
.ac div.opt { padding: 6px 10px; cursor: pointer; display: grid; grid-template-columns: 110px 1fr; gap: 2px 10px; }
.ac div.opt:hover, .ac div.opt.active { background: var(--accent-weak); }
.ac .code { font-family: var(--mono); font-size: 12.5px; }
.ac .sub { grid-column: 2; font-size: 11.5px; color: var(--muted); }
.ac .empty { padding: 8px 10px; color: var(--muted); }

.case-list .case { border-bottom: 1px solid var(--border); padding: 8px 0; }
.case-list .case:last-child { border-bottom: 0; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.bar.over > span { background: var(--bad); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 420px; display: flex; gap: 10px; align-items: center; }
.toast.bad { background: var(--bad); color: #fff; }
.toast button { background: transparent; color: inherit; border-color: currentColor; }

.login { max-width: 380px; margin: 80px auto; }
.empty-state { text-align: center; padding: 40px; color: var(--muted); }

@media (max-width: 1100px) {
  .review { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar nav a { padding: 6px 6px; }
  .ac { min-width: 280px; }
}
