:root {
  --bg: #f5f5f2; --card: #fff; --ink: #1f2328; --muted: #6b7076; --line: #e3e2dc;
  --brand: #8b2c1f; --brand-ink: #fff; --ok: #1f7a4a; --ok-bg: #e6f4ec;
  --err: #b42318; --err-bg: #fdecea; --warn: #9a6200; --warn-bg: #fff4dc;
  --out: #b45309; --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .9rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }

/* 頂部 */
.top { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: .75rem; padding: .55rem 1rem; }
.logo { color: #fff; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.logo span { opacity: .75; font-weight: 400; font-size: .85rem; margin-left: .35rem; }
.nav { display: flex; gap: .2rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #fff; opacity: .82; padding: .35rem .65rem; border-radius: 7px; white-space: nowrap; font-size: .95rem; }
.nav a:hover { text-decoration: none; opacity: 1; background: rgba(255,255,255,.12); }
.nav a.on { opacity: 1; background: rgba(255,255,255,.2); }
.who { font-size: .85rem; white-space: nowrap; opacity: .9; }
.who a { color: #fff; opacity: .85; margin-left: .5rem; }
@media (max-width: 760px) {
  .top-inner { flex-wrap: wrap; row-gap: .3rem; }
  .nav { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1.1rem 1rem 3rem; }
.narrow { max-width: 640px; }

/* 卡片、表單 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
label { display: block; font-size: .88rem; color: var(--muted); margin: .55rem 0 .2rem; }
input, select, textarea {
  width: 100%; font: inherit; padding: .55rem .65rem; border: 1px solid #cfcdc4; border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(139,44,31,.25); border-color: var(--brand); }
textarea { min-height: 70px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem; }
.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.inline > * { flex: 1 1 140px; }
.inline > .btn, .inline > button { flex: 0 0 auto; }
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  background: var(--brand); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover, button:hover { text-decoration: none; filter: brightness(1.08); }
.btn.sec, button.sec { background: #fff; color: var(--ink); border-color: #cfcdc4; }
.btn.ok, button.ok { background: var(--ok); }
.btn.warn, button.warn { background: var(--out); }
.btn.small, button.small { padding: .3rem .65rem; font-size: .88rem; }
.btn.big, button.big { padding: .9rem 1.2rem; font-size: 1.15rem; width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }

/* 提示 */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .8rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: .5rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #faf9f6; font-weight: 600; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.overdue td { background: #fff1ee; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 600; letter-spacing: .01em; }
.nowrap { white-space: nowrap; }

/* 狀態標籤 */
.tag { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.tag.在庫 { background: var(--ok-bg); color: var(--ok); }
.tag.借出 { background: #fdf0e1; color: var(--out); }
.tag.已退還當事人 { background: #eceef1; color: #4b5563; }
.tag.註銷 { background: #eceef1; color: #9ca3af; text-decoration: line-through; }
.tag.red { background: var(--err-bg); color: var(--err); }
.tag.新增 { background: var(--ok-bg); color: var(--ok); }
.tag.更新 { background: #e8f0fe; color: #1d4ed8; }
.tag.續約 { background: #f3e8ff; color: #7e22ce; }
.tag.不變 { background: #eceef1; color: #6b7280; }
.tag.錯誤 { background: var(--err-bg); color: var(--err); }

.pager { display: flex; gap: .4rem; align-items: center; margin: .8rem 0; flex-wrap: wrap; }
.stats { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem .9rem; }
.stat b { font-size: 1.25rem; display: block; }
dl.kv { display: grid; grid-template-columns: 6.5rem 1fr; gap: .35rem .8rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* 掃描畫面 */
.scan-wrap { max-width: 560px; margin: 0 auto; }
.scan-input { display: flex; gap: .5rem; }
.scan-input input { font-size: 1.2rem; padding: .75rem .8rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; margin-top: .8rem; display: none; }
#reader.on { display: block; }
#reader video { width: 100% !important; }
.result { border-radius: var(--radius); padding: 1rem 1.1rem; margin-top: 1rem; border: 2px solid var(--line); background: var(--card); }
.result.s-在庫 { border-color: var(--ok); }
.result.s-借出 { border-color: var(--out); }
.result.s-err { border-color: var(--err); background: var(--err-bg); }
.result .serial { font-size: 1.7rem; font-weight: 800; font-family: ui-monospace, Menlo, Consolas, monospace; line-height: 1.2; }
.result .head { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.banner { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 50; pointer-events: none; font-size: 1.6rem; font-weight: 800; color: #fff; text-align: center; padding: 1rem; }
.banner.ok { display: flex; background: rgba(31,122,74,.92); }
.banner.err { display: flex; background: rgba(180,35,24,.92); }
.toggle { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); margin: .6rem 0 0; }
.toggle input { width: auto; }

.login { max-width: 360px; margin: 10vh auto; }
.login .logo-big { text-align: center; color: var(--brand); font-size: 1.6rem; font-weight: 800; margin-bottom: .2rem; }
.hint { font-size: .85rem; color: var(--muted); }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
@media print { .top, .no-print { display: none !important; } }
