:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2330; --muted: #677084; --line: #dfe2e8;
  --accent: #1f5fd1; --accent-ink: #fff; --ok: #1e8e4e; --warn: #b7791f; --bad: #c53030; --hold: #6b46c1;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 54px; background: #172033; color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand small { font-weight: 400; opacity: .7; margin-left: 6px; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; color: #c8d0e0; padding: 16px 14px; font: inherit; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button:hover { color: #fff; }
.tabs button.active { color: #fff; border-bottom-color: #6ea0ff; }
.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 13px; }
.userbox button { background: rgba(255,255,255,.1); color: #fff; border: 0; border-radius: 6px; padding: 6px 10px; cursor: pointer; font: inherit; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } main { padding: 12px; } }

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid #c9ced8; border-radius: 6px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9dbcf5; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.btn { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid #c9ced8; background: #fff; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f1f3f7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #194fb0; }
.btn.danger { color: var(--bad); }
.btn.hold { background: var(--hold); border-color: var(--hold); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }

/* ---------- scan box ---------- */
.scanbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.scan-input { font-size: 26px; padding: 14px 16px; font-family: Consolas, "Cascadia Mono", monospace; letter-spacing: .5px; width: 100%; border-width: 2px; }
.scan-input:focus { outline: 3px solid #9dbcf5; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
kbd { background: #eef0f4; border: 1px solid #d5d9e1; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: inherit; }

.result { border-left: 5px solid var(--line); }
.result.match { border-left-color: var(--ok); }
.result.warn { border-left-color: var(--warn); }
.result.bad { border-left-color: var(--bad); }
.result.hold { border-left-color: var(--hold); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; margin-bottom: 14px; }
.kv div span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.kv div b { font-weight: 600; word-break: break-word; }
.big { font-size: 20px; font-weight: 700; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; position: sticky; top: 0; }
td { padding: 8px 10px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f5f8ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef0f4; color: #3b4456; white-space: nowrap; }
.pill.RECEIVED { background: #e3edff; color: #1f4fa8; }
.pill.HOLD { background: #efe7fb; color: #5a35a8; }
.pill.DISCREPANCY { background: #fdecec; color: #a52a2a; }
.pill.INSPECTED { background: #e6f4f1; color: #1d6b5c; }
.pill.REFURB { background: #fff3dc; color: #8a5a00; }
.pill.READY { background: #e3f5e9; color: #1b6e3c; }
.pill.RTV { background: #fde9f1; color: #9c2a5a; }
.pill.DISPOSED { background: #e9eaee; color: #4a5162; }
.pill.NONE { background: #fff; border: 1px dashed #c3c8d2; color: var(--muted); }
.flag { color: var(--bad); font-weight: 700; }
.okmark { color: var(--ok); font-weight: 700; }

/* ---------- KPIs ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile span { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile b { display: block; font-size: 26px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile.alert b { color: var(--bad); }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 140px 1fr 56px; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { background: #eef0f4; border-radius: 4px; height: 14px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; border-radius: 4px; }
.bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.chart svg { width: 100%; height: 200px; display: block; }
.progress { background: #eef0f4; border-radius: 4px; height: 8px; width: 120px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.progress i { display: block; height: 100%; background: var(--ok); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 50; display: flex; justify-content: flex-end; }
.modal { background: var(--bg); width: min(860px, 100%); height: 100%; overflow-y: auto; padding: 20px; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; flex: 1; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.photo img { width: 100%; height: 110px; object-fit: cover; display: block; cursor: zoom-in; }
.photo .acts { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px; font-size: 11px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ""; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; position: absolute; left: -5px; top: 11px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 60; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1d2330; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); font-weight: 600; max-width: 420px; }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--bad); } .toast.warn { background: var(--warn); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 22px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--bad); font-weight: 600; min-height: 18px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 8px; }
  .brand small { display: none; }
  .userbox { margin-left: auto; }
  .userbox span { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { padding: 10px 12px; }
  .bar { grid-template-columns: 100px 1fr 44px; }
}
