/* BRC PRQ – mobile-first stylesheet */
:root {
  --bg: #eef2f3;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --line: #dde3e6;
  --text: #15232a;
  --muted: #5d6f78;
  --primary: #0a5c6b;
  --primary-ink: #ffffff;
  --primary-soft: #dcefF2;
  --accent: #f08c00;
  --danger: #c92a2a;
  --danger-soft: #ffe3e3;
  --ok: #2b8a3e;
  --ok-soft: #d3f9d8;
  --amber: #b35c00;
  --amber-soft: #fff1d6;
  --blue: #1864ab;
  --blue-soft: #dbeafe;
  --violet: #6741d9;
  --violet-soft: #ebe4ff;
  --grey-soft: #e9ecef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 50, .06), 0 2px 8px rgba(16, 40, 50, .05);
  --nav-h: 64px;
  --head-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1517; --surface: #152126; --surface-2: #1b2a30; --line: #27373e; --text: #e6eef0; --muted: #93a7ae;
    --primary: #3fb3c4; --primary-ink: #04252b; --primary-soft: #133a42;
    --danger: #ff8787; --danger-soft: #3d1c1f; --ok: #69db7c; --ok-soft: #173322; --amber: #ffc078; --amber-soft: #3a2a12;
    --blue: #74c0fc; --blue-soft: #15304a; --violet: #b197fc; --violet-soft: #2a2245; --grey-soft: #263238;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; background: var(--bg); color: var(--text);
  min-height: 100vh; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 20px; letter-spacing: -.01em; }
h3 { font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- App shell */
.app-head {
  position: sticky; top: 0; z-index: 20; height: calc(var(--head-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0; display: flex; align-items: center; gap: 10px;
  background: var(--primary); color: var(--primary-ink);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; flex: 1; min-width: 0; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.16); display: grid; place-items: center; font-size: 11px; font-weight: 800; }
@media (prefers-color-scheme: dark) { .brand .logo { background: rgba(0,0,0,.18); } }
.brand .title { font-size: 17px; }
.brand .sub { font-size: 11px; font-weight: 500; opacity: .8; display: block; margin-top: -2px; }
.head-btn { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.head-btn:active { background: rgba(255,255,255,.15); }
.sync-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.16); border: 0; color: inherit; cursor: pointer; white-space: nowrap;
}
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #8ce99a; }
.sync-chip.offline .dot { background: #ffa8a8; }
.sync-chip.pending .dot { background: #ffd43b; }
.sync-chip.syncing .dot { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

main#view { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 860px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600; position: relative;
}
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--primary); }
.tabbar a.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
.tabbar .badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10.5px; display: grid; place-items: center; }

@media (min-width: 900px) {
  .tabbar { left: 50%; transform: translateX(-50%); width: 620px; bottom: 14px; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 6px 24px rgba(0,0,0,.08); padding-bottom: 0; height: var(--nav-h); }
}

/* ---------- Cards & lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.pad { padding: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 8px; }
.section-title h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 2px 14px; }
.page-head p { margin: 2px 0 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 14px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list > li.tap { cursor: pointer; }
.list > li.tap:active { background: var(--surface-2); }
.item-title { font-weight: 650; font-size: 15.5px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12.5px; margin-top: 3px; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 6px; }

/* ---------- Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  text-align: left; cursor: pointer; position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, var(--primary)); }
.stat .n { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat.on { outline: 2px solid var(--c, var(--primary)); outline-offset: -2px; }

/* ---------- Status chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--grey-soft); color: var(--muted); }
.chip.pending_purchase { background: var(--amber-soft); color: var(--amber); }
.chip.awaiting_receiving, .chip.awaiting { background: var(--blue-soft); color: var(--blue); }
.chip.partially_received, .chip.partial { background: var(--violet-soft); color: var(--violet); }
.chip.received { background: var(--ok-soft); color: var(--ok); }
.chip.overdue, .chip.void, .chip.closed_short { background: var(--danger-soft); color: var(--danger); }
.chip.local { background: var(--amber-soft); color: var(--amber); }
.chip.superseded { background: var(--grey-soft); color: var(--muted); text-decoration: line-through; }
.days { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Forms */
label.f { display: block; }
label.f > span { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); margin: 0 0 5px 2px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 11px; border: 1.5px solid var(--line); background: var(--surface);
  outline: none; transition: border-color .15s; -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 70px; resize: vertical; }
.input:focus { border-color: var(--primary); }
.input.big { font-size: 18px; font-weight: 650; }
.input-wrap { position: relative; }
.input-wrap .prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; font-weight: 700; pointer-events: none; }
.input-wrap .prefix + .input { padding-left: 52px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search .input { padding-left: 38px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 0 auto; min-height: 40px; padding: 6px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 650; cursor: pointer; }
.seg button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; user-select: none; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--primary); flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 12px;
  border: 1.5px solid transparent; background: var(--primary); color: var(--primary-ink); font-weight: 700; cursor: pointer; text-align: center;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--primary); border-color: var(--line); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { min-height: 36px; padding: 6px 12px; border-radius: 10px; font-size: 13.5px; }
.btn svg { width: 18px; height: 18px; }
.link-btn { background: none; border: 0; padding: 4px 2px; color: var(--primary); font-weight: 650; cursor: pointer; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--line); width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.danger { color: var(--danger); }

.sticky-foot {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); margin-top: 14px; z-index: 5;
}
@media (min-width: 900px) { .sticky-foot { bottom: calc(var(--nav-h) + 26px); } }

/* ---------- Typeahead */
.ta-list { margin-top: 6px; max-height: 300px; overflow: auto; }
.ta-list button { display: flex; width: 100%; text-align: left; align-items: center; gap: 10px; padding: 12px 14px; border: 0; border-top: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.ta-list button:first-child { border-top: 0; }
.ta-list button:active, .ta-list button.hl { background: var(--surface-2); }
.ta-list button.add { color: var(--primary); font-weight: 700; }
.ta-list mark { background: transparent; color: var(--primary); font-weight: 800; }
.picked { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; border: 1.5px solid var(--primary); background: var(--primary-soft); border-radius: 11px; min-height: 46px; }
.picked .grow { font-weight: 650; }

/* ---------- Request lines */
.line { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.line .idx { width: 24px; height: 24px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 800; display: grid; place-items: center; flex: none; }
.line .name { flex: 1; font-weight: 600; min-width: 0; }

/* ---------- Price hints */
.hint { margin-top: 8px; display: grid; gap: 4px; font-size: 12.5px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.hint b { font-variant-numeric: tabular-nums; }
.hint .best { color: var(--ok); }
.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
.cmp th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.cmp td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cmp tr:last-child td { border-bottom: 0; }
.cmp tr.best td { background: var(--ok-soft); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.mini-p { margin-top: 8px; border-left: 3px solid var(--line); padding: 2px 0 2px 10px; font-size: 12.5px; }
.mini-p + .mini-p { margin-top: 4px; }

/* ---------- Receiving */
.rc { padding: 12px 14px; border-top: 1px solid var(--line); }
.rc:first-child { border-top: 0; }
.rc.on { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.rc .qtys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; text-align: center; }
.rc .qtys div { background: var(--surface-2); border-radius: 9px; padding: 5px 4px; }
.rc .qtys b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.rc .qtys span { font-size: 11px; color: var(--muted); font-weight: 600; }
.rc .qtys .out b { color: var(--blue); }
.rc .entry { margin-top: 10px; display: grid; gap: 8px; }
.var { font-size: 12.5px; font-weight: 700; }
.var.short { color: var(--danger); }
.var.excess { color: var(--amber); }
.var.exact { color: var(--ok); }

.cargo-pills { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 -14px; padding-left: 14px; scrollbar-width: none; }
.cargo-pills button { flex: none; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 650; cursor: pointer; white-space: nowrap; }
.cargo-pills button.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.cargo-pills button .c { opacity: .7; margin-left: 4px; font-weight: 600; }

/* ---------- Tabs */
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font-weight: 650; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Summary grid */
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kv > div { background: var(--surface-2); border-radius: 11px; padding: 10px 12px; }
.kv .k { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kv .v { font-weight: 700; margin-top: 2px; }
.kv .s { font-size: 12px; color: var(--muted); }

/* ---------- Timeline */
.tl { position: relative; }
.tl-p { padding: 12px 14px; border-top: 1px solid var(--line); }
.tl-p:first-child { border-top: 0; }
.tl-p.void { opacity: .6; }
.tl-r { margin: 8px 0 0 6px; padding: 6px 0 6px 12px; border-left: 2px solid var(--ok); font-size: 13px; }
.tl-r.superseded, .tl-r.void { border-left-color: var(--line); color: var(--muted); }

/* ---------- Modal / sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(5, 20, 25, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b)); animation: up .2s ease-out;
}
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 20px; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Toasts & banners */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 14px; }
.toast { background: #15232a; color: #fff; padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; pointer-events: auto; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@media (prefers-color-scheme: dark) { .toast.ok, .toast.err { color: #0d1517; } }
.banner { padding: 10px 12px; border-radius: 12px; font-size: 13.5px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.banner.warn { background: var(--amber-soft); color: var(--amber); }
.banner.info { background: var(--blue-soft); color: var(--blue); }
.banner.err { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner svg { width: 18px; height: 18px; flex: none; }

.success-card { text-align: center; padding: 26px 16px; }
.success-card .big-id { font-family: var(--mono); font-size: 22px; font-weight: 800; margin: 8px 0 2px; letter-spacing: .02em; }
.success-card svg { width: 54px; height: 54px; color: var(--ok); }

/* ---------- Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 18px; background: linear-gradient(170deg, var(--primary) 0 38%, var(--bg) 38%); }
.login-card { width: 100%; max-width: 400px; }
.login-brand { color: #fff; text-align: center; margin-bottom: 18px; }
@media (prefers-color-scheme: dark) { .login-brand { color: var(--primary-ink); } }
.login-brand .mark { width: 64px; height: 64px; border-radius: 18px; background: rgba(255,255,255,.18); display: grid; place-items: center; margin: 0 auto 10px; font-weight: 900; font-size: 18px; letter-spacing: .04em; }
.login-brand h1 { font-size: 24px; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 64px; border-radius: 12px; background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 10px; }
@keyframes sk { to { background-position: -200% 0; } }

.menu-list a, .menu-list button { display: flex; align-items: center; gap: 12px; padding: 14px; width: 100%; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; color: var(--text); font-weight: 600; cursor: pointer; }
.menu-list > :first-child { border-top: 0; }
.menu-list svg { width: 20px; height: 20px; color: var(--muted); }
.menu-list .count { margin-left: auto; }

.audit-d { font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-word; color: var(--muted); margin-top: 4px; }

body.is-login .app-head, body.is-login .tabbar { display: none; }
body.is-login main#view { padding: 0; max-width: none; }
.ta-list button svg { width: 18px; height: 18px; flex: none; }
.btn { white-space: nowrap; }

/* ---------- Product thumbnails */
.thumb { width: var(--s, 40px); height: var(--s, 40px); flex: none; border-radius: 10px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: inline-grid; place-items: center; cursor: zoom-in; }
.thumb.ph { cursor: default; color: var(--primary); background: var(--primary-soft); border-color: transparent; font-weight: 800; font-size: calc(var(--s, 40px) * .42); }
.line .thumb { margin-left: -4px; }
.check .thumb { margin-top: 0; }

/* ---------- Bulk purchase */
.selbox { display: grid; place-items: center; width: 30px; height: 44px; flex: none; cursor: pointer; }
.selbox input { width: 22px; height: 22px; accent-color: var(--primary); }
.brow { padding: 12px 14px; border-top: 1px solid var(--line); }
.brow:first-child { border-top: 0; }
.bgrid { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; margin-top: 8px; }
.bgrid .input { min-height: 42px; padding: 8px 10px; }
.bgrid .input-wrap .prefix + .input { padding-left: 46px; }
