/* One stylesheet for the whole app. Phones first: the technician screens are
   used one-handed in a stockroom, so tap targets are large and text is plain. */

:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #15181d;
  --muted: #5a6370;
  --line: #dce0e6;
  --bar: #14181f;
  --bar-ink: #ffffff;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --brand-soft: #e7edfd;
  --ok: #15703f;
  --ok-soft: #e2f4e9;
  --warn: #8a5200;
  --warn-soft: #fff1cf;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --tap: 48px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #181c23;
    --surface-2: #1e232b;
    --ink: #eceff3;
    --muted: #98a2b0;
    --line: #2b323c;
    --bar: #0a0c10;
    --brand: #7c9dff;
    --brand-ink: #0a1024;
    --brand-soft: #1a2442;
    --ok: #62d39b;
    --ok-soft: #12301f;
    --warn: #f0b44a;
    --warn-soft: #382908;
    --bad: #ff8d84;
    --bad-soft: #3a1613;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.375rem; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.0625rem; font-weight: 650; }
h3 { font-size: .9375rem; font-weight: 650; }
a { color: var(--brand); text-underline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.icon {
  width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.22em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Top bar and menu ---------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 8px 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  background: var(--bar); color: var(--bar-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.shop-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 46vw;
  height: 36px; padding: 0 12px; border-radius: 18px;
  background: rgba(255, 255, 255, .12); color: inherit; text-decoration: none; font-size: .875rem; font-weight: 600;
}
.shop-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-chip.unset { background: #f5b82e; color: #1f1600; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap);
  border: 0; border-radius: 10px; background: none; color: inherit; cursor: pointer;
}
.icon-btn .icon { width: 24px; height: 24px; }

.menu {
  position: fixed; inset: 56px 0 0 0; z-index: 25; overflow-y: auto;
  background: var(--surface); padding: 8px 8px calc(24px + env(safe-area-inset-bottom));
}
.menu a, .menu button.link {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--tap);
  padding: 0 12px; border: 0; border-radius: 10px; background: none;
  color: var(--ink); font: inherit; font-weight: 550; text-decoration: none; text-align: left; cursor: pointer;
}
.menu a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.menu a:hover, .menu button.link:hover { background: var(--surface-2); }
.menu .icon { color: var(--muted); }
.menu a[aria-current="page"] .icon { color: inherit; }
.menu .count { margin-left: auto; }
.menu-label { margin: 16px 12px 4px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.menu-user { margin: 16px 12px 4px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }

main { padding: 16px; padding-bottom: 32px; max-width: 640px; margin: 0 auto; }
body.wide main { max-width: 1180px; }
body.has-bar main { padding-bottom: 120px; }

@media (min-width: 960px) {
  body.wide .shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); align-items: start; }
  body.wide .menu {
    display: block !important; position: sticky; top: 56px; inset: auto; height: calc(100vh - 56px);
    border-right: 1px solid var(--line); padding: 12px 8px;
  }
  body.wide .menu a, body.wide .menu button.link { min-height: 40px; font-size: .9375rem; }
  body.wide #menu-btn { display: none; }
  body.wide main { margin: 0; padding: 24px 28px 48px; }
  body:not(.wide) .menu { inset: 56px 0 auto auto; width: 320px; max-height: calc(100vh - 56px); border-radius: 0 0 0 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); }
}

/* --- Building blocks ----------------------------------------------------- */

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
.page-head h1 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumb { display: inline-flex; align-items: center; gap: 2px; margin-bottom: 8px; color: var(--muted); font-size: .875rem; font-weight: 550; text-decoration: none; }
.lede { color: var(--muted); margin: -8px 0 16px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card > h2, .card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; }
.card-head a { font-size: .875rem; font-weight: 600; text-decoration: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: .9375rem; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-lg { min-height: 56px; padding: 0 20px; border-radius: 14px; font-size: 1.0625rem; }
.btn-block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-link { border: 0; background: none; padding: 0; min-height: 0; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge-low { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--brand-soft); color: var(--ink); font-size: .9375rem; }
.notice .icon { margin-top: 2px; color: var(--brand); }
.notice-success { background: var(--ok-soft); } .notice-success .icon { color: var(--ok); }
.notice-error { background: var(--bad-soft); } .notice-error .icon { color: var(--bad); }
.notice-warning { background: var(--warn-soft); } .notice-warning .icon { color: var(--warn); }
.messages { display: grid; gap: 8px; margin-bottom: 16px; }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; margin-bottom: 8px; stroke-width: 1.5; }
.empty p + p { margin-top: 4px; }
.empty .btn { margin-top: 16px; }

/* Lists of things you tap (cart lines, checkouts, search results). */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.list .meta { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.list a.rowlink { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; margin: -12px -16px; padding: 12px 16px; color: inherit; text-decoration: none; }
.list a.rowlink:hover, .list button.rowlink:hover { background: var(--surface-2); }
.list button.rowlink { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; margin: -12px -16px; padding: 12px 16px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.list .chev { color: var(--muted); }

/* --- Forms --------------------------------------------------------------- */

label, .label { display: block; margin-bottom: 6px; font-size: .875rem; font-weight: 600; }
input[type="text"], input[type="search"], input[type="email"], input[type="url"], input[type="number"],
input[type="date"], input[type="tel"], input[type="file"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; /* 16px keeps iPhones from zooming in on focus */
}
textarea { min-height: 72px; resize: vertical; }
select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.field { margin-bottom: 16px; }
.field .help { margin-top: 4px; color: var(--muted); font-size: .8125rem; }
.field .error, .errorlist { margin: 4px 0 0; padding: 0; list-style: none; color: var(--bad); font-size: .875rem; font-weight: 600; }
.field.check label { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 1rem; font-weight: 500; }
.field.check .help { margin-left: 30px; }
.form-grid { display: grid; gap: 0 16px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.narrow { max-width: 720px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 12px; margin-bottom: 16px; }
.filters .f { flex: 1 1 150px; min-width: 0; }
.filters .f.wide { flex: 2 1 220px; }
.filters .f.fit { flex: 0 0 auto; }
.filters label { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.filters input, .filters select { min-height: 40px; padding-top: 7px; padding-bottom: 7px; font-size: .9375rem; }
.filters .check { display: flex; align-items: center; gap: 8px; min-height: 40px; margin: 0; font-size: .9375rem; color: var(--ink); }

/* --- Tables (manager side) ----------------------------------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
thead th { border-top: 0; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
thead th:first-child { border-top-left-radius: var(--radius); } thead th:last-child { border-top-right-radius: var(--radius); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td a.main { font-weight: 600; text-decoration: none; }
td .sub { display: block; color: var(--muted); font-size: .8125rem; }
tfoot td { background: var(--surface-2); font-weight: 700; }
tr.is-low td.qty { color: var(--warn); font-weight: 700; }
tr.is-neg td.qty { color: var(--bad); font-weight: 700; }
.neg { color: var(--bad); } .pos { color: var(--ok); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { min-height: 32px; padding: 0 10px; font-size: .8125rem; border-radius: 8px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: .875rem; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { display: block; padding: 14px 16px; color: inherit; text-decoration: none; }
.tile .k { color: var(--muted); font-size: .8125rem; font-weight: 600; }
.tile .v { margin-top: 2px; font-size: 1.625rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .d { color: var(--muted); font-size: .8125rem; }
.tile.alert .v { color: var(--warn); } .tile.bad .v { color: var(--bad); }
a.tile:hover { border-color: var(--brand); }

.cols { display: grid; gap: 16px; }
@media (min-width: 1000px) { .cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } .cols.even { grid-template-columns: 1fr 1fr; } }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; padding: 16px; }
dl.facts dt { color: var(--muted); font-size: .875rem; }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.steps { margin: 0; padding: 0 16px 8px; list-style: none; counter-reset: step; }
.steps li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); counter-increment: step; }
.steps li:first-child { border-top: 0; }
.steps li::before { content: counter(step); display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .875rem; }
.steps li.done::before { content: "✓"; background: var(--ok-soft); color: var(--ok); }

/* --- Dialogs and the bottom sheet ---------------------------------------- */

dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(8, 10, 14, .55); }
dialog .dlg-head { display: flex; align-items: flex-start; gap: 8px; padding: 16px 8px 0 20px; }
dialog .dlg-head h2 { flex: 1; padding-top: 10px; font-size: 1.125rem; overflow-wrap: anywhere; }
dialog .dlg-body { padding: 8px 20px 20px; }
dialog .dlg-body > .muted { margin-bottom: 16px; }

@media (max-width: 599px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 20px 20px 0 0; }
  dialog.sheet .dlg-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* --- Technician: cart ----------------------------------------------------- */

.scan-cta { margin-bottom: 12px; }
.search-box { position: relative; margin-bottom: 20px; }
.search-box .icon { position: absolute; left: 14px; top: 14px; color: var(--muted); pointer-events: none; }
.search-box input { min-height: var(--tap); padding-left: 42px; border-radius: 12px; }
.search-results { margin-top: 8px; }

.section-head { display: flex; align-items: baseline; gap: 8px; margin: 0 4px 8px; }
.section-head h2 { flex: 1; }

.stepper { display: inline-flex; align-items: center; flex: none; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.stepper button { display: grid; place-items: center; width: 44px; height: 44px; border: 0; background: none; color: var(--ink); cursor: pointer; }
.stepper button:active { background: var(--surface-2); }
.stepper input { width: 56px; min-height: 44px; padding: 0; border: 0; border-radius: 0; background: none; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper input:focus { outline: 2px solid var(--brand); outline-offset: -2px; }
.stepper.big button { width: 64px; height: 64px; } .stepper.big button .icon { width: 28px; height: 28px; }
.stepper.big input { width: 96px; min-height: 64px; font-size: 1.75rem; }

.list > li.cart-line { display: block; }
.cart-line .head, .cart-line .body { display: flex; align-items: center; gap: 12px; }
.cart-line .head { align-items: flex-start; }
.cart-line .title { flex: 1; min-width: 0; padding-top: 4px; }
.cart-line .body .meta { flex: 1; min-width: 0; }
.cart-line .remove { width: 40px; height: 40px; margin: -4px -8px 0 0; color: var(--muted); }
.short-note { color: var(--warn); font-weight: 600; }

.sticky-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.sticky-bar .inner { max-width: 608px; margin: 0 auto; }

.sheet-item { margin-bottom: 4px; font-size: 1.1875rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.sheet-qty { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 20px 0; }
.sheet-warn { margin-bottom: 16px; }

.toast-wrap { position: fixed; left: 12px; right: 12px; top: 68px; z-index: 2147483000; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 420px; padding: 12px 16px; border-radius: 12px; background: #111418; color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
.toast.ok { background: #136c3d; } .toast.bad { background: #a8231c; }

/* --- Technician: scanner -------------------------------------------------- */

.scanner { position: fixed; inset: 0; z-index: 100; background: #000; color: #fff; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 8px 24px 16px; background: linear-gradient(rgba(0, 0, 0, .7), transparent); font-weight: 650; }
.scanner-top .grow { flex: 1; }
.scanner-frame { position: absolute; left: 50%; top: 45%; width: min(68vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); overflow: visible; border-radius: 9%; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .42); fill: none; stroke: #f5b82e; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, .9)); }
.scanner-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 32px 16px calc(16px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0, 0, 0, .8)); text-align: center; }
.scanner-status { min-height: 1.5em; margin-bottom: 12px; font-weight: 600; }
.scanner .btn { border-color: transparent; }
.scanner-error { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; padding: 32px; background: #101318; text-align: center; }
.scanner-error p { max-width: 34ch; color: #c9d0da; }

/* --- Technician: checkout and history ------------------------------------- */

.job-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { display: inline-flex; flex-direction: column; align-items: flex-start; max-width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.chip b { font-weight: 700; } .chip span { color: var(--muted); font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.picked { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 2px solid var(--brand); border-radius: 12px; background: var(--brand-soft); }
.picked .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.done-banner { display: flex; align-items: center; gap: 14px; padding: 18px 16px; border-radius: var(--radius); background: var(--ok-soft); color: var(--ok); }
.done-banner .icon { width: 36px; height: 36px; stroke-width: 2.5; }
.done-block { margin-bottom: 28px; }
.done-banner b { display: block; font-size: 1.125rem; color: var(--ink); }
.done-banner span { color: var(--ink); }

.shop-list { display: grid; gap: 10px; }
.shop-list button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.shop-list button.current { border: 2px solid var(--brand); background: var(--brand-soft); }
.shop-list b { display: block; font-size: 1.0625rem; }

/* --- Sign-in --------------------------------------------------------------- */

.login { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 32px 24px; text-align: center; }
.login .mark { width: 64px; height: 64px; margin-bottom: 16px; border-radius: 16px; }
.login h1 { margin-bottom: 4px; }
.login .btn { margin-top: 24px; }
.login .notice { margin-top: 16px; text-align: left; }
.g-mark { width: 20px; height: 20px; }

/* --- Printing reports ------------------------------------------------------ */

@media print {
  .topbar, .menu, .filters, .page-head .actions, .sticky-bar, .crumb, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { max-width: none !important; padding: 0 !important; }
  .card { border: 0; box-shadow: none; }
  body.wide .shell { display: block; }
}
