/* CB Locator — mobile-first, big touch targets. */
:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1b1f24; --muted: #6b7280; --line: #e3e6ea;
  --brand: #1d3557; --primary: #0b6bcb; --primary-ink: #fff; --ok: #1a7f37; --ok-bg: #e6f4ea;
  --err: #b42318; --err-bg: #fdecea; --warn: #9a6700; --warn-bg: #fff4d6;
  --radius: 12px; --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: .2rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
.warn { color: var(--warn); }
.grow { flex: 1 1 auto; min-width: 0; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .5rem;
  padding: .45rem max(12px, env(safe-area-inset-left)); background: var(--brand); color: #fff; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
.topnav a, .topnav .linkbtn { color: #dbe7f5; font-size: .9rem; }
.langs { display: inline-flex; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; overflow: hidden; }
.langs a { padding: .3rem .55rem; min-height: 34px; display: inline-flex; align-items: center; }
.langs a.on { background: #fff; color: var(--brand); font-weight: 600; }
.who { max-width: 7.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
form.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; padding: .25rem; color: var(--primary); font: inherit; cursor: pointer; min-height: 34px; }

.wrap { max-width: 720px; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-left)) 90px; }
.wrap.wide { max-width: 1100px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card.narrow { max-width: 420px; margin: 24px auto; }
details.card > summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details.card[open] > summary { margin-bottom: .6rem; }

/* forms */
label { display: block; font-size: .9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--ink); min-height: var(--tap); }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: #fff;
  border: 1px solid #c9ced6; border-radius: 10px; padding: .6rem .7rem; min-height: var(--tap); margin-top: .2rem; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; margin: 0; }
textarea { min-height: 6rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.stack > * + * { margin-top: .7rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.grid2.top { align-items: start; }
@media (max-width: 640px) { .wrap.wide .grid2.top { grid-template-columns: 1fr; } }
.row { display: flex; gap: .5rem; align-items: flex-end; }
.wrap-row { flex-wrap: wrap; }
.row label { flex: 0 1 auto; }
.row + .row, .row + form, form + .row { margin-top: .5rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap);
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid #c9ced6; background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; touch-action: manipulation; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.big { min-height: 58px; font-size: 1.1rem; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active { transform: translateY(1px); }

.flash { border-radius: 10px; padding: .6rem .8rem; margin: 0 0 12px; background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--err); }
.pw { font-size: 1.2rem; user-select: all; }

/* home */
.scan-hero { width: 100%; min-height: 120px; flex-direction: column; font-size: 1.6rem; border-radius: 16px;
  background: var(--primary); color: #fff; border: 0; margin-bottom: 12px; }
.scan-hero .icon { font-size: 2.2rem; line-height: 1; }
.scan-hero small { font-weight: 400; font-size: .9rem; opacity: .85; }
.searchbar { display: flex; gap: .5rem; margin-bottom: 12px; }
.searchbar input { margin-top: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  min-height: 84px; display: flex; flex-direction: column; justify-content: center; color: var(--ink); }
.tile b { font-size: 1.05rem; }
.tile small { color: var(--muted); }
@media (min-width: 900px) { .wide .tiles { grid-template-columns: repeat(5, 1fr); } }

/* badges / statuses */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef0f3; color: #374151; }
.st-blank { background: #eef0f3; color: #4b5563; }
.st-registered { background: var(--warn-bg); color: var(--warn); }
.st-located { background: var(--ok-bg); color: var(--ok); }
.st-out { background: #e8eefc; color: #1e40af; }
.st-void { background: var(--err-bg); color: var(--err); }
.piece-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.piece-head h1 { margin: 0; }
dl.facts { display: grid; grid-template-columns: 6.5rem 1fr; gap: .45rem .6rem; margin: .8rem 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.loc-link { font-weight: 700; }

/* events */
ul.events { list-style: none; padding: 0; margin: 0; }
ul.events li { padding: .5rem 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; }
ul.events li:first-child { border-top: 0; }
ul.events .when { flex-basis: 100%; }
.ev-action { font-weight: 700; font-size: .8rem; padding: .05rem .45rem; border-radius: 6px; background: #eef0f3; }
.ev-register { background: var(--warn-bg); color: var(--warn); }
.ev-locate, .ev-move { background: var(--ok-bg); color: var(--ok); }
.ev-out { background: #e8eefc; color: #1e40af; }
.ev-void { background: var(--err-bg); color: var(--err); }

/* scanner */
.scanner { margin-bottom: 10px; }
.cam { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 52vh; background: #000; border-radius: 12px; overflow: hidden; margin-bottom: .5rem; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide { position: absolute; inset: 14% 22%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.18); pointer-events: none; }
.flashfx { position: absolute; inset: 0; background: rgba(40, 200, 90, .45); opacity: 0; pointer-events: none; }
.flashfx.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.cam-label { position: absolute; left: 0; right: 0; bottom: 0; padding: .5rem; text-align: center; font-weight: 700; color: #fff; background: rgba(11,107,203,.85); }
.cam-label:empty { display: none; }
.cam-msg { background: var(--warn-bg); color: var(--warn); padding: .5rem .7rem; border-radius: 10px; }
.gun input, .debug input { margin-top: 0; }
.debug input { border-style: dashed; }

/* scan lists / basket */
.counter { font-weight: 600; }
.basket-head { display: flex; justify-content: space-between; align-items: center; margin: .6rem 0 .3rem; }
.flagged { color: var(--err); }
ul.scanlist { list-style: none; padding: 0; margin: 0 0 12px; max-height: 45vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
ul.scanlist li { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-top: 1px solid var(--line); min-height: var(--tap); }
ul.scanlist li:first-child { border-top: 0; }
ul.scanlist li.ok { background: #f6fbf7; }
ul.scanlist li.err { background: var(--err-bg); }
ul.scanlist li.err .flag { color: var(--err); font-weight: 600; }
ul.scanlist li.pending { opacity: .6; }
ul.scanlist .x { border: 0; background: none; font-size: 1.1rem; color: var(--muted); min-width: 40px; min-height: 40px; cursor: pointer; }
.rb-summary { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin-bottom: .6rem; }
.confirm-line { font-size: 1.3rem; font-weight: 700; }

/* picker */
.picker { position: relative; }
.picker-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 0; list-style: none;
  background: #fff; border: 1px solid #c9ced6; border-radius: 10px; max-height: 50vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.picker-list li { padding: .7rem; border-top: 1px solid var(--line); cursor: pointer; }
.picker-list li:first-child { border-top: 0; }
.picker-list li.active, .picker-list li:hover { background: #eef5fd; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
.tbl th, .tbl td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tr.dim td { color: var(--muted); }
.tbl td.dl a { white-space: nowrap; }
.card .tbl { border: 1px solid var(--line); }
tr.imp-error td { background: var(--err-bg); }
tr.imp-create td { background: #f6fbf7; }
tr.imp-update td { background: var(--warn-bg); }
.result-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
ul.plist { list-style: none; margin: 0; padding: 0; }
ul.plist li { display: flex; gap: .6rem; align-items: baseline; padding: .45rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
ul.plist li:first-child { border-top: 0; }

/* admin */
.subnav { display: flex; gap: .3rem; overflow-x: auto; margin: 0 0 12px; padding-bottom: 2px; }
.subnav a { white-space: nowrap; padding: .45rem .8rem; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--ink); font-size: .9rem; }
.subnav a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .6rem; display: flex; flex-direction: column; gap: .2rem; }
.stat b { font-size: 1.4rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; align-items: end; }
.printbar { margin: .4rem 0 .6rem; align-items: center; }
.printbar select { width: auto; margin: 0; }
pre.sample { background: #f6f8fa; padding: .6rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }

/* toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast { max-width: 560px; width: 100%; padding: .75rem 1rem; border-radius: 12px; color: #fff; background: var(--ok); font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .35s, transform .35s; }
.toast.err { background: var(--err); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* no awkward wraps inside codes / names on phones */
.mono, .loc-link, .tbl td b, ul.scanlist .mono { white-space: nowrap; }
.tbl th { text-transform: capitalize; }
@media (max-width: 480px) { .who { display: none; } .topnav { flex-wrap: nowrap; } }
.btn { white-space: nowrap; }
/* toasts at the top so they never cover the action buttons at the bottom of a basket */
#toasts { top: calc(56px + env(safe-area-inset-top)); bottom: auto; }
.toast.out { transform: translateY(-8px); }
