/* Pallet Weigh-Up: shipping-label look, built for phones in the warehouse and a desk in the office */
:root {
  --bg: #eceff2; --surface: #ffffff; --sunk: #f4f6f8; --ink: #18212b; --muted: #5a6875; --line: #d3d9df;
  --kraft: #a8743c; --kraft-soft: #f3e7d8; --steel: #1f4a80; --steel-soft: #e1eaf5;
  --ok: #2b7a4b; --ok-soft: #dff1e6; --warn: #9a5c00; --warn-soft: #fbefd9; --bad: #b3261e; --bad-soft: #f9e0de;
  --font-display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --surface: #19212a; --sunk: #141b22; --ink: #e5eaef; --muted: #95a3b0; --line: #2c3742;
    --kraft: #d6a368; --kraft-soft: #2e2519; --steel: #82aee6; --steel-soft: #1b2a3c;
    --ok: #6cc592; --ok-soft: #16301f; --warn: #e3a64a; --warn-soft: #2f2414; --bad: #f08a83; --bad-soft: #3a1a18;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
a { color: var(--steel); }
h1, h2 { font-family: var(--font-display); font-weight: 700; margin: 0; text-wrap: balance; text-transform: uppercase; }
h1 { font-size: 30px; line-height: 1.05; letter-spacing: .01em; }
h2 { font-size: 20px; letter-spacing: .04em; }
code { font-family: var(--font-mono); font-size: .92em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--steel); outline-offset: 2px; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.foot { font-size: 12px; color: var(--muted); margin: 0; }
.crumb { margin: 0; font-size: 14px; }

/* Top bar */
.topnav { background: var(--ink); color: var(--surface); padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.navin { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; padding-block: 10px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 18px; text-transform: uppercase; letter-spacing: .06em; }
.links { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.links a { color: var(--surface); text-decoration: none; padding: 5px 10px; border-radius: 4px; font-weight: 500; opacity: .8; }
.links a:hover { opacity: 1; }
.links a.on { background: color-mix(in srgb, var(--surface) 16%, transparent); opacity: 1; }
.who { font-size: 13px; opacity: .8; }
.who a { color: var(--surface); }

.wrap { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px calc(48px + env(safe-area-inset-bottom, 0px)); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.fields { display: grid; grid-template-columns: minmax(0, 1.4fr) 110px minmax(0, 1.2fr); gap: 10px; flex: 1 1 520px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 0; }
.t { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; width: 100%; min-width: 0; font-size: 15px; }
.t.narrow { width: auto; }
.t:focus { border-color: var(--steel); outline: none; }
label.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
label.check input { width: 18px; height: 18px; accent-color: var(--steel); }

/* Totals strip, styled like a carton label */
.label-strip { background: var(--surface); border: 2px solid var(--ink); border-radius: 4px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.label-strip > div { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.label-strip > div + div { border-left: 2px solid var(--ink); }
.big { font-family: var(--font-display); font-weight: 700; font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.big small { font-size: 16px; font-weight: 600; margin-left: 2px; }
.label-strip .strip-note { grid-column: 1 / -1; border-top: 2px solid var(--ink); border-left: 0; font-size: 13px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.pill.tiny { font-size: 10px; padding: 1px 6px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--steel-soft); color: var(--steel); }

/* Sides */
.sides { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.side { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.side .ph { aspect-ratio: 3 / 4; max-width: 100%; background: var(--sunk); display: grid; place-items: center; position: relative; }
.side .ph a, .side .ph img { display: block; width: 100%; height: 100%; }
.side .ph img { object-fit: cover; }
.side .ph .empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.side .tag { position: absolute; top: 8px; left: 8px; background: var(--ink); color: var(--surface); font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 3px; }
.side .count { position: absolute; top: 8px; right: 8px; }
.side .secs { position: absolute; bottom: 8px; right: 8px; background: var(--ink); color: var(--surface); font-family: var(--font-mono); font-size: 12px; padding: 2px 6px; border-radius: 3px; }
.side .act { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); }
.side .msg { font-size: 12px; color: var(--muted); min-height: 1.2em; overflow-wrap: anywhere; }
.side .msg.err { color: var(--bad); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 9px 12px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--steel); border-color: var(--steel); color: var(--surface); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.big-btn { padding: 13px 20px; font-size: 16px; }
.danger-btn { border-color: var(--bad); color: var(--bad); }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions form { margin: 0; }

.callout { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 6px; padding: 10px 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.callout.info { background: var(--steel-soft); border-color: var(--steel); justify-content: flex-start; }
.callout.good { background: var(--ok-soft); border-color: var(--ok); justify-content: flex-start; }

/* Case list */
.cases { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.case { display: grid; grid-template-columns: 28px minmax(0, 1fr) 108px auto; gap: 10px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); }
.case:first-child { border-top: 0; }
.case.off { opacity: .55; }
.case.off .kgbox input { text-decoration: line-through; }
.case.flagged { background: var(--warn-soft); }
.case > input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--steel); }
.case .who { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.case .line1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.case input.code { width: 8ch; border: 0; background: none; padding: 0; font-weight: 600; font-size: 15px; }
.case .name { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.case .meta, .user-row .meta { font-size: 11px; color: var(--muted); letter-spacing: .02em; }
.case .flag { grid-column: 2 / -1; font-size: 12px; color: var(--warn); margin-top: -4px; }
.kgbox { display: flex; align-items: center; gap: 4px; }
.kgbox input { width: 100%; min-width: 0; text-align: right; padding: 8px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; border: 1px solid var(--line); border-radius: 5px; background: var(--sunk); font-size: 15px; }
.kgbox span { font-size: 12px; color: var(--muted); }
.rowbtns { display: flex; gap: 2px; }
.x, .okbtn { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 6px; border-radius: 4px; min-width: 32px; }
.x:hover { color: var(--bad); background: var(--sunk); }
.okbtn { color: var(--ok); font-size: 18px; border: 1px solid var(--ok); }
.empty-list { padding: 22px 16px; text-align: center; color: var(--muted); font-size: 14px; }

.submit-box { background: var(--surface); border: 2px solid var(--ink); border-radius: 4px; padding: 14px; }
.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.issues li { display: flex; gap: 8px; align-items: baseline; }

/* Tables */
.tbl { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table.bd { width: 100%; border-collapse: collapse; font-size: 14px; }
table.bd th, table.bd td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.bd tr:last-child td { border-bottom: 0; }
table.bd th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.bd .n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.bd tr.dim td { color: var(--muted); }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: var(--sunk); }
table.list a { text-decoration: none; font-weight: 600; }

.prod-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line); margin: 0; }
.prod-row:first-child { border-top: 0; }
.code-cell { font-weight: 600; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-top: 1px solid var(--line); }
.user-row:first-child { border-top: 0; }
.user-row.off { opacity: .6; }
.user-row .who { display: flex; flex-direction: column; }
.user-row .t { width: 170px; padding: 6px 10px; font-size: 14px; }
.add-user { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
.check-row { display: grid; grid-template-columns: 60px minmax(0, 220px) minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 10px 12px; border-top: 1px solid var(--line); }
.check-row:first-child { border-top: 0; }
.check-row .pill { text-align: center; }
details summary { cursor: pointer; font-weight: 600; }
details.danger summary { color: var(--bad); }
.login { max-width: 380px; width: 100%; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 12px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div:first-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .links { order: 3; flex: 1 1 100%; margin-left: -10px; }
  .navin { justify-content: space-between; }
  .sides { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fields { grid-template-columns: minmax(0, 1fr) 100px; }
  .fields label:last-child { grid-column: 1 / -1; }
  .add-user { grid-template-columns: 1fr; }
  .check-row { grid-template-columns: 56px minmax(0, 1fr); }
  .check-row .muted { grid-column: 2; }
}
@media (max-width: 420px) {
  .big { font-size: 27px; }
  h1 { font-size: 26px; }
  .case { grid-template-columns: 24px minmax(0, 1fr) 92px auto; gap: 8px; padding: 10px; }
  .label-strip > div { padding: 8px 9px 10px; }
  .user-row .t { width: 100%; }
}
