/* Colors match the public site (static/site/site.css):
   red #ed0038, med red #b30037, dark red #820024, gray #cfd0d2 / #404040. */
:root {
  --bg: #eeeff1;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --border: #dcdde0;
  --text: #262626;
  --muted: #5f6063;
  --accent: #b30037;
  --accent-ink: #ffffff;
  --accent-soft: #fbe6ec;
  --ok: #1d7a46;
  --ok-ink: #ffffff;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #c0352b;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --bar: #404040;
  --bar-ink: #ffffff;
  --bar-muted: #cfd0d2;
  --brand-red: #ed0038;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

/* Dark palette: follows the OS unless the theme selector (static/theme.js)
   sets data-theme on <html>. The two blocks below must stay identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1d;
    --surface: #262627;
    --surface-2: #303032;
    --border: #3d3d40;
    --text: #ececed;
    --muted: #a5a6a9;
    --accent: #ff5c7f;
    --accent-ink: #1c0008;
    --accent-soft: #45121f;
    --ok: #4cc485;
    --ok-ink: #06210f;
    --ok-soft: #13301f;
    --warn: #f0b350;
    --warn-soft: #33270f;
    --bad: #ff7a6e;
    --bad-soft: #3a1714;
    --shadow: none;
    --bar: #2b2b2c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1c1d;
  --surface: #262627;
  --surface-2: #303032;
  --border: #3d3d40;
  --text: #ececed;
  --muted: #a5a6a9;
  --accent: #ff5c7f;
  --accent-ink: #1c0008;
  --accent-soft: #45121f;
  --ok: #4cc485;
  --ok-ink: #06210f;
  --ok-soft: #13301f;
  --warn: #f0b350;
  --warn-soft: #33270f;
  --bad: #ff7a6e;
  --bad-soft: #3a1714;
  --shadow: none;
  --bar: #2b2b2c;
  color-scheme: dark;
}

/* Off production (db.environment_label sets data-env on <html>): an orange
   top bar and a TEST/LOCAL badge, so nobody mistakes it for the live system.
   After the dark blocks so it wins in both themes. */
:root[data-env] { --bar: #b84f00; --bar-muted: #ffe6d1; }
:root[data-env] .topbar { border-bottom-color: #7a3400; }
:root[data-env] .brand span:last-child { color: #fff; }
:root[data-env] .nav a.active { background: rgba(0, 0, 0, 0.28); }
:root[data-env] .nav a.active .nav-icon { stroke: #fff; }
:root[data-env] .login-card { border-top-color: #b84f00; }
.env-badge {
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: #fff; color: #b84f00; font-weight: 700; font-size: 11px; letter-spacing: 0.08em;
}
.login-wrap .env-badge { justify-self: center; background: #b84f00; color: #fff; font-size: 13px; padding: 4px 12px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 Verdana, Geneva, Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
h1.mono { font-size: 22px; }
h2.mono { font-size: 16px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* --- top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--bar); border-bottom: 3px solid var(--brand-red);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13px; color: var(--bar-ink); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 50%; }
.brand span:last-child { color: var(--brand-red); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 4px; color: var(--bar-muted); font-weight: 600;
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: var(--bar-ink); text-decoration: none; }
.nav a.active { background: var(--brand-red); color: #fff; }
.userbox { display: flex; align-items: center; gap: 12px; color: var(--bar-muted); }
.userbox .btn.ghost { color: var(--bar-ink); }
.userbox .btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.theme-select { padding: 5px 8px; font-size: 13px; color: var(--bar-ink); background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.2); }
.theme-select option { color: var(--text); background: var(--surface); }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
/* Queue header: the title and its sentence take what's left and wrap, so the
   search and the two buttons stay together on one row beside them. */
.queue-head > div:first-child { flex: 1 1 320px; min-width: 0; }
.queue-head > .toolbar { flex-wrap: nowrap; }
.queue-head input[type=search] { width: 230px; }

/* --- cards & layout --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.grid-doc { grid-template-columns: minmax(0, 1fr) 280px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 960px) { .grid-2, .grid-4, .grid-doc { grid-template-columns: 1fr; } }

.stat { padding: 16px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
a.stat { color: inherit; display: block; }
a.stat:hover { text-decoration: none; border-color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* --- tables --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.desc { color: var(--muted); font-size: 13px; max-width: 360px; }
tr.row-error td { background: var(--bad-soft); }
/* Queue lines without enough stock to ship stay red, even on hover. */
tbody tr.row-short td { background: var(--bad-soft); }
tbody tr.row-short td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
tr.selected td { background: var(--accent-soft); }
th.select-col, td.select-col { width: 36px; padding-right: 0; }
.select-col input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.select-col input[type=checkbox]:disabled { cursor: not-allowed; opacity: 0.4; }
.bulk-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr.htmx-request td { opacity: 0.55; }

/* Sortable column headers (products list): the whole header is the link. */
th.sortable { padding: 0; }
th.sortable a { display: block; padding: 9px 12px; color: inherit; white-space: nowrap; }
th.sortable a:hover { color: var(--text); text-decoration: none; }
th.sortable[aria-sort] a { color: var(--accent); }
.sort-arrow { font-size: 9px; margin-left: 4px; vertical-align: 1px; }

/* Cells edited in place (partials/product_cell.html): saved on change. */
td.edit-cell { position: relative; padding-top: 6px; padding-bottom: 6px; }
input.inline-edit { padding: 4px 8px; background: transparent; }
input.inline-edit:hover { background: var(--surface); }
input.inline-edit.qty { width: 72px; }
input.inline-edit.loc { width: 150px; font-family: var(--mono); font-size: 12px; }
input.inline-edit.sku { width: 150px; }
input.inline-edit.invalid { border-color: var(--bad); }
input.inline-edit.htmx-request { opacity: 0.55; }
input.inline-edit.just-saved { animation: saved-flash 2s ease-out; }
.saved-note {
  position: absolute; top: 0; right: 16px; padding: 0 4px; border-radius: 4px; background: var(--surface);
  font-size: 10.5px; font-weight: 600; color: var(--ok);
  pointer-events: none; animation: saved-fade 2.5s ease-in forwards;
}
@keyframes saved-flash { from { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); } }
@keyframes saved-fade { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }

/* --- badges --- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.type-I { background: var(--ok-soft); color: var(--ok); }
.type-O { background: var(--accent-soft); color: var(--accent); }
.type-A { background: var(--warn-soft); color: var(--warn); }
.type-C, .type-T, .type-R { background: var(--surface-2); color: var(--text); }
.stock-short { color: var(--bad); font-weight: 700; }
.stock-ok { color: var(--ok); font-weight: 600; }
.qty-neg { color: var(--bad); }
.qty-pos { color: var(--ok); }

/* --- forms & buttons --- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.qty { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
input.sku { width: 130px; font-family: var(--mono); font-size: 13px; }
input.uom { width: 56px; text-transform: uppercase; }
label { display: grid; gap: 4px; font-weight: 550; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 260px; }

/* --- search (dashboard and /search): one box, products and orders below --- */
.search-box { position: relative; margin-bottom: 16px; }
.search-box input { width: 100%; padding: 11px 14px 11px 42px; font-size: 16px; border-radius: 10px; }
.search-icon {
  position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
#search-results > * { margin-bottom: 16px; }
.grid-search { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid-search { grid-template-columns: 1fr; } }
.card-head .count { margin-left: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li + li { border-top: 1px solid var(--border); }
.result-list a { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; color: var(--text); }
.result-list a:hover { background: var(--surface-2); text-decoration: none; }
.result-main, .result-side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result-side { flex-shrink: 0; align-items: flex-end; }
.result-sub { overflow: hidden; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.success { background: var(--ok); border-color: var(--ok); color: var(--ok-ink); }
.btn.success:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.inline { display: inline; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .queue-sort { margin-left: auto; font-weight: 500; }
.tab-count { font-weight: 500; font-size: 12px; color: var(--muted); }

/* --- flashes --- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 550; background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.inline-error { color: var(--bad); font-size: 12px; font-weight: 600; }

/* --- queue order cards --- */
.order-card .card-head { align-items: flex-start; }
.order-card.order-short { border-left: 4px solid var(--bad); }
/* The order's action buttons: small, with the secondary ones joined into one
   segmented group, so all of them fit on one row on a phone. */
.order-actions { gap: 6px; }
.order-actions .btn { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
.btn-group { display: inline-flex; }
.btn-group > * + * { margin-left: -1px; }
.btn-group .btn { border-radius: 0; }
.btn-group > :first-child, .btn-group > :first-child .btn { border-radius: 6px 0 0 6px; }
.btn-group > :last-child, .btn-group > :last-child .btn { border-radius: 0 6px 6px 0; }
.btn-group > :only-child, .btn-group > :only-child .btn { border-radius: 6px; }
.order-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.order-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 4px; }
.order-notes { white-space: pre-wrap; font-size: 13px; color: var(--muted); padding: 10px 16px; border-top: 1px solid var(--border); max-height: 140px; overflow: auto; }

/* --- pager --- */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); }

/* --- legacy file viewer --- */
pre.doc {
  margin: 0; padding: 20px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.4;
  background: var(--surface); color: var(--text);
}

.big-stock { font-size: 40px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* --- login --- */
.login-page { background: url(site/images/pg_bkgrnd.jpg) no-repeat center top #404040; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 20px; padding: 24px; }
.login-logo img { width: 140px; height: 140px; border-radius: 50%; display: block; }
.login-card { width: 100%; max-width: 360px; border-top: 4px solid var(--brand-red); }
.login-card form { display: grid; gap: 14px; }

/* --- document upload (macros.upload_form, static/upload.js) --- */
.upload-form { display: grid; gap: 12px; }
.camera-btn { display: none; position: relative; }
@media (pointer: coarse) { .camera-btn { display: inline-flex; } }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.nav-icon, .nav-short { display: none; }

/* --- phones, and the installed app (Add to Home Screen) ---
   The menu becomes a tab bar along the bottom; env(safe-area-inset-*)
   keeps clear of the notch and home indicator (viewport-fit=cover). */
@media (max-width: 700px) {
  .topbar {
    height: auto; min-height: 52px; gap: 10px;
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .topbar > * { margin-block: 8px; }
  .brand { font-size: 12px; gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .brand-city { display: none; }
  .theme-select { margin-left: auto; padding: 4px 6px; flex-shrink: 0; }
  .userbox .who { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
    padding: 4px max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    background: var(--bar); border-top: 1px solid rgba(255, 255, 255, 0.12);
  }
  .nav a { flex-direction: column; gap: 3px; padding: 6px 0 4px; font-size: 10.5px; letter-spacing: 0.02em; text-transform: none; }
  .nav a.active { background: none; color: #fff; }
  .nav a.active .nav-icon { stroke: var(--brand-red); }
  .nav-icon { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  main {
    padding: 16px max(14px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  /* iPhone zooms into any field under 16px when it's tapped. */
  input, select, textarea { font-size: 16px; }
  input.inline-edit.loc { font-size: 16px; width: 170px; }
  input.inline-edit.sku { font-size: 16px; width: 140px; }
  .btn.small { padding: 6px 12px; }
  .order-actions .btn { padding: 6px 10px; }
  .tabs { overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .page-head > .toolbar, .page-head > form.toolbar { width: 100%; }
  .queue-head > .toolbar { flex-wrap: wrap; }
  .queue-head > .toolbar > form { flex: 1 1 100%; }
  .queue-head > .toolbar > .btn { flex: 1; }
  .toolbar input[type=search] { width: auto; flex: 1; }
  .login-wrap { padding-top: max(24px, env(safe-area-inset-top)); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 24px; }
}

/* --- pick list and stock list (templates/pick_list.html, stock_list.html): one <pre> per printed page --- */
.pick-page + .pick-page { border-top: 1px dashed var(--border); }
.daily-pick { margin-bottom: 12px; }
@media print {
  @page { margin: 0.5in; }
  .topbar, .no-print, .flash { display: none !important; }
  body, main { background: #fff; padding: 0; margin: 0; }
  .card.pick-list { border: 0; box-shadow: none; background: #fff; }
  pre.doc.pick-page { padding: 0; overflow: visible; background: #fff; color: #000; font-size: 8pt; line-height: 1.2; }
  .pick-page + .pick-page { border: 0; break-before: page; }
  .card.daily-list { border: 0; box-shadow: none; }
}
