:root {
  --brand: #c8102e; --brand-dark: #9e0c24; --ink: #1c1f24; --muted: #667080; --line: #e3e6ea;
  --bg: #f5f6f8; --card: #fff; --ok: #1d7a46; --warn: #b26a00; --bad: #b3261e; --tint: #fdecef;
  --radius: 8px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h1 small { font-size: 14px; font-weight: 400; color: var(--muted); }
h2 { font-size: 16px; margin: 0 0 12px; }
h2 .small { font-weight: 400; font-size: 13px; margin-left: 8px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.top { display: flex; align-items: center; gap: 20px; background: #111; color: #fff; padding: 0 20px; min-height: 52px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand .mark { background: var(--brand); padding: 2px 7px; border-radius: 4px; margin-right: 4px; letter-spacing: .5px; }
.brand small { font-weight: 400; color: #aaa; font-size: 12px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: #d6d6d6; padding: 15px 10px; border-bottom: 3px solid transparent; }
.nav a:hover { color: #fff; text-decoration: none; }
.nav a.on { color: #fff; border-bottom-color: var(--brand); }
.who { display: flex; align-items: center; gap: 10px; color: #aaa; font-size: 12.5px; margin: 0; }
.envbar { background: #fff3cd; color: #6b4e00; text-align: center; font-size: 12px; padding: 3px; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; min-width: 0; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.narrow-l { max-width: 720px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols + .card, .cols + .cols { margin-top: 18px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink); display: flex; flex-direction: column; }
a.tile:hover { border-color: var(--brand); text-decoration: none; }
.tile b { font-size: 26px; font-variant-numeric: tabular-nums; }
.tile span { font-weight: 600; }
.tile small { color: var(--muted); }
.tile.warn { border-left: 4px solid var(--warn); }
.tile.bad { border-left: 4px solid var(--bad); }
.btn { display: inline-block; border: 1px solid #c9ced5; background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash.success { background: #e8f5ee; border-color: #b7dfc8; color: #12532f; }
.flash.error { background: var(--tint); border-color: #f2b8c2; color: #7d0a1c; }
.flash.info { background: #eef4fb; border-color: #c4d8ee; color: #1b3d63; }
.flash div + div { margin-top: 3px; }
.tablewrap { overflow-x: auto; }
.tablewrap.short { max-height: 420px; overflow-y: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 2px solid var(--line); padding: 7px 8px; white-space: nowrap; background: var(--card); position: sticky; top: 0; }
.grid td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: top; }
.grid tr:hover td { background: #fafbfc; }
.grid .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); font-weight: 600; }
.warnc { color: var(--warn); font-weight: 600; }
.dim td { opacity: .55; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef0f3; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #e8f5ee; color: var(--ok); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c9ced5; border-radius: 6px; background: #fff; color: var(--ink); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200, 16, 46, .25); border-color: var(--brand); }
.filters input[type=search] { min-width: 240px; }
label.inl { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.stack label .muted { font-weight: 400; }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form.inline { display: flex; gap: 12px; align-items: center; margin: 10px 0 14px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
dl.specs { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
dl.specs dt { color: var(--muted); }
dl.specs dd { margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 0; font-size: 13px; }
ul.plain li { padding: 3px 0; }
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 16px 0; }
@media (max-width: 700px) {
  .cols { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .wrap { padding: 16px; }
  dl.specs { grid-template-columns: 1fr; }
  .who span { display: none; }
}
.stack > .btn { align-self: flex-start; }
.card > h2:not(:first-child), .card > table + h2 { margin-top: 24px; }
@media (max-width: 900px) {
  .top { padding: 8px 16px 0; gap: 8px; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav a { padding: 10px 10px; white-space: nowrap; }
  .who { margin-left: auto; }
}

[hidden] { display: none !important; }

/* Phone scan page (/scan) */
.scan { max-width: 480px; margin: 0 auto; }
.scan-find { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.scan-find label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.scan-row { display: flex; gap: 8px; }
.scan-row input { flex: 1; min-width: 0; }
.scan input, .scan select, .scan .btn { font-size: 18px; padding: 11px 12px; }
.scan-cam { width: 100%; }
.scan-video { width: 100%; border-radius: var(--radius); background: #000; }
.scan-card { padding: 16px; }
.scan-sku { font-size: 22px; font-weight: 700; }
.scan-name { color: var(--muted); margin-bottom: 12px; }
.scan-onhand { display: flex; align-items: baseline; gap: 8px; }
.scan-onhand b { font-size: 44px; font-variant-numeric: tabular-nums; line-height: 1; }
.scan-lots { margin: 0 0 12px; padding-left: 18px; font-size: 13px; }
.scan-lots:empty { display: none; }
.scan-modes { display: flex; flex-direction: column; gap: 6px; }
.scan-modes label { flex-direction: row !important; align-items: center; gap: 10px !important; font-size: 16px !important; font-weight: 400 !important; }
.scan-modes input { width: 20px; height: 20px; }
.scan-extra { margin-top: 10px; }
.scan-save { width: 100%; }
@media (max-width: 600px) {
  .wrap { padding: 14px 12px 40px; }
  .top { gap: 8px 14px; padding: 0 12px; }
  .nav a { padding: 10px 7px; }
}
.scan-suggest { margin-bottom: 14px; }
.scan-suggest p { margin: 0 0 6px; }
.scan-pick { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; margin-bottom: 6px; font-size: 16px !important; }
.scan-pick span { font-weight: 400; font-size: 13px; color: var(--muted); }
.scan-photo { text-align: center; }
/* The file input covers the whole button, so the tap lands on the input itself (iPhone Safari ignores forwarded taps). */
.scan-photo { position: relative; overflow: hidden; }
.scan .scan-photo-input { position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; font-size: 0; }
.scan-tabs { display: flex; gap: 0; margin-bottom: 14px; }
.scan-tabs button { flex: 1; font: inherit; font-size: 16px; font-weight: 600; padding: 10px; background: #fff; color: var(--muted); border: 1px solid #c9ced5; cursor: pointer; }
.scan-tabs button:first-child { border-radius: 6px 0 0 6px; }
.scan-tabs button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.scan-tabs button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.scan-order-lines { list-style: none; margin: 0; padding: 0; }
.scan-order-lines li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.scan-order-lines li.done { color: var(--ok); }
.scan-order-lines li.done b::before { content: "✓ "; }
.scan-order-lines li span { color: var(--muted); font-size: 13px; }
.scan-order-lines li.done span { color: var(--ok); }
.scan-shipline { margin: 0; font-size: 16px; }
.dev-card { border: 2px dashed var(--warn); }
.dev-num { width: 80px; padding: 4px 6px; }
.dev-clear { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* App shell: menu fixed at the top, page content scrolls underneath. */
html, body { height: 100%; }
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.chrome { flex: none; position: relative; z-index: 5; }
.scroller { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* List pages: title, filters, table header and pager stay; only the rows scroll. */
@media (min-height: 520px) {
  .scroller.fill { overflow: hidden; display: flex; }
  .scroller.fill > .wrap { flex: 1; width: 100%; min-height: 0; display: flex; flex-direction: column; padding-bottom: 12px; }
  .scroller.fill > .wrap > * { flex: none; }
  .scroller.fill > .wrap > .fill-rows { flex: 1 1 auto; min-height: 120px; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
  .scroller.fill > .wrap > .pager, .scroller.fill > .wrap > p { margin: 8px 0 0; }
}
.fill-rows .grid th { z-index: 1; box-shadow: inset 0 -2px 0 var(--line); }
.tablewrap.short .grid th { z-index: 1; }

/* Phones: one-line menu that scrolls sideways, so the fixed header stays slim. */
@media (max-width: 600px) {
  .nav { flex-wrap: nowrap; overflow-x: auto; width: 100%; order: 3; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; }
}

/* List beside an edit form (Users, Locations): rows scroll inside the list, the form stays in view. */
.fill-card > .fill-rows { max-height: 60vh; overflow: auto; }
@media (min-width: 900px) and (min-height: 520px) {
  .scroller.fill-cols-page { overflow: hidden; display: flex; }
  .scroller.fill-cols-page > .wrap { flex: 1; width: 100%; min-height: 0; display: flex; flex-direction: column; padding-bottom: 12px; }
  .scroller.fill-cols-page > .wrap > * { flex: none; }
  .scroller.fill-cols-page > .wrap > .fill-cols { flex: 1 1 auto; min-height: 0; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); grid-template-rows: minmax(0, 1fr); }
  .fill-cols > .card { max-height: 100%; min-height: 0; overflow: auto; }
  .fill-cols > .fill-card { display: flex; flex-direction: column; overflow: hidden; }
  .fill-card > .fill-rows { flex: 1 1 auto; max-height: none; min-height: 120px; }
  .fill-card > p { flex: none; margin-bottom: 0; }
}
.actions-row { margin-top: 12px; }
.scan-pickable { cursor: pointer; text-decoration: underline dotted; }
