:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e5ea;
  --primary: #1f5fbf; --primary-ink: #fff; --danger: #c62828; --ok: #2e7d32; --warn: #b26a00;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --card: #1e2229; --text: #e6e8ec; --muted: #9aa1ad; --line: #2e333c; --primary: #4a8ef0; --danger: #ef5350; --ok: #66bb6a; --warn: #ffb74d; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: .3em 0 .6em; }
h2 { font-size: 1.15rem; margin: 1.4em 0 .5em; }
h2.sub { margin: 0 0 .5em; font-weight: 500; }
h3 { font-size: 1rem; margin: 1.2em 0 .4em; }
.muted { color: var(--muted); }
.small, small { font-size: .85em; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.danger { color: var(--danger); font-weight: 600; }
.num { text-align: right; }
pre { background: var(--bg); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: .85em; }

/* header */
.top { display: flex; align-items: center; gap: 12px; padding: 0 16px; background: #1b2a41; color: #fff; min-height: 52px; position: sticky; top: 0; z-index: 10; }
.top .brand { color: #fff; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.top nav a { color: #cfd8e6; padding: 15px 10px; }
.top nav a.active, .top nav a:hover { color: #fff; text-decoration: none; box-shadow: inset 0 -3px #4a8ef0; }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 24px; cursor: pointer; }
.acting { background: #ffecb3; color: #5d4300; padding: 6px 16px; font-size: .9em; }
@media (max-width: 860px) {
  .menu-btn { display: block; }
  .top { flex-wrap: wrap; }
  .top nav { display: none; width: 100%; flex-direction: column; padding-bottom: 8px; }
  .nav-open .top nav { display: flex; }
  .top nav a { padding: 10px 4px; }
}

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.narrow { max-width: 640px; }
.auth { max-width: 380px; margin: 8vh auto; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid2.top { align-items: start; gap: 0 24px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.actions form { margin: 0; }
.actions.center { justify-content: center; margin: 12px 0; }

/* forms */
label { display: block; margin: 0 0 12px; font-weight: 500; font-size: .92em; }
label small { display: block; font-weight: 400; color: var(--muted); margin-top: 3px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 7px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.big-input { font-size: 1.3em; padding: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; margin: 0; }
.filters input[type=search] { flex: 1 1 220px; }
.filters label { margin: 0; display: flex; align-items: center; gap: 6px; font-weight: 400; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; margin: 0; }
form.inline { display: inline; }

.btn { display: inline-block; padding: 9px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.wide { width: 100%; }
.btn.big { padding: 13px 18px; font-size: 1.05em; }
.btn.small { padding: 5px 10px; font-size: .85em; }
.btn:disabled { opacity: .6; }
.danger-btn { color: var(--danger); border-color: var(--danger); background: transparent; }

.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 12px; border-left: 4px solid; background: var(--card); }
.flash.ok { border-color: var(--ok); }
.flash.err { border-color: var(--danger); color: var(--danger); }
.flash.warn { border-color: var(--warn); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8em; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--bg); }
tr.dim { opacity: .55; }
.sticky-actions { position: sticky; bottom: 0; padding: 10px 0; background: linear-gradient(transparent, var(--bg) 40%); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78em; font-weight: 600; background: var(--line); color: var(--text); vertical-align: middle; }
.s-available { background: #e3f4e4; color: #1b5e20; }
.s-checked_out { background: #e1ecfb; color: #0d47a1; }
.s-repair { background: #fff1d6; color: #8a5200; }
.s-missing { background: #fde3e3; color: #a31515; }
.s-retired { background: #e6e6e6; color: #555; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat b { display: block; font-size: 2em; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .9em; }
.stat.alert b { color: var(--danger); }
.simple-list { padding-left: 18px; }

/* item pages */
.item-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.item-head .qr { width: 130px; height: 130px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.item-head .qr img, .item-head .qr canvas { width: 100% !important; height: auto !important; }
.item-head h1 { margin-top: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.notes { white-space: pre-wrap; background: var(--card); border-left: 3px solid var(--line); padding: 6px 10px; }
.stock { font-size: 1.3em; margin: .2em 0 .6em; }
.action-card { border-top: 3px solid var(--primary); }
.tabs { display: flex; gap: 4px; margin: 16px 0 -12px; flex-wrap: wrap; }
.tabs > * { padding: 9px 14px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; }
.tabs > .active { background: var(--card); color: var(--primary); font-weight: 600; }
div.tabs:not([data-tabs]) { margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--radius); overflow: hidden; }
.sandbox { background: repeating-linear-gradient(45deg, #ff9800, #ff9800 12px, #f57c00 12px, #f57c00 24px); color: #000; font-weight: 700; text-align: center; padding: 4px 8px; font-size: .85em; }
.bulk-list { list-style: none; padding: 0; margin: 0 0 14px; }
.bulk-list li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.bulk-list li label { margin: 0; flex: 1; }
.bulk-list li .nm { flex: 1; }
.bulk-list li.dim { opacity: .55; }
.switch { margin: 0; }
.sticky-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.view-as { display: flex; align-items: center; margin: 0 0 0 8px; }
.view-as label { margin: 0; display: flex; align-items: center; gap: 6px; color: #cfd8e6; font-weight: 400; font-size: .85em; white-space: nowrap; }
.view-as select { width: auto; margin: 0; padding: 4px 6px; font-size: .95em; }
.viewing-as { background: #d7e8ff; color: #0b3d80; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 860px) { .view-as { margin: 6px 4px; } }

/* ---------- Mobile polish ---------- */
[hidden] { display: none !important; }
.sm-only { display: none; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .hide-sm { display: none !important; }
  .sm-only { display: inline; }
  body { -webkit-tap-highlight-color: transparent; }
  main { padding: 12px 12px 24px; }
  h1 { font-size: 1.35rem; margin: .2em 0 .5em; }

  /* Header: brand only; the full menu becomes a sheet opened from "More" */
  .top { min-height: 48px; padding: 0 12px; padding-top: env(safe-area-inset-top); }
  body.has-tabs .menu-btn { display: none; }
  .top nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); color: var(--text);
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.35); padding: 10px 12px calc(76px + env(safe-area-inset-bottom));
    max-height: 80vh; overflow-y: auto; }
  .top nav a { color: var(--text); padding: 14px 8px; border-bottom: 1px solid var(--line); font-size: 1.05em; }
  .top nav a.active { color: var(--primary); box-shadow: none; font-weight: 600; }
  .nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
  .view-as label { color: var(--text); font-size: 1em; padding: 8px 0; }
  .sandbox { padding: 2px; font-size: .75em; }
  .acting { padding: 6px 12px; font-size: .85em; }

  /* Bottom tab bar */
  body.has-tabs { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #1b2a41;
    padding: 0 4px env(safe-area-inset-bottom); height: calc(60px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: #9fb0c8; font: 500 11px system-ui, sans-serif; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .active { color: #fff; }
  .tabbar .scan span { display: grid; place-items: center; width: 56px; height: 56px; margin-top: -22px; border-radius: 50%;
    background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.35); border: 3px solid #1b2a41; }
  .tabbar .scan svg { width: 28px; height: 28px; }

  /* Touch-friendly controls; 16px inputs stop iOS zooming in on focus */
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.small { min-height: 34px; }
  .btn.big { min-height: 52px; }
  label.check { min-height: 40px; }
  label.check input { width: 20px; height: 20px; }

  .filters { gap: 8px; }
  .filters input[type=search] { flex: 1 1 100%; }
  .filters select { flex: 1 1 40%; }
  .card { padding: 14px; border-radius: 12px; }
  .row-between .btn.primary { padding: 10px 14px; }

  /* Tool and consumable lists become stacked cards */
  table.list thead { display: none; }
  table.list, table.list tbody { display: block; }
  table.list tr { display: grid; align-items: center; gap: 2px 10px; padding: 12px 12px 12px 4px; border-bottom: 1px solid var(--line); }
  table.list td { border: 0; padding: 0; min-width: 0; }
  table.list .c-pick { grid-area: pick; align-self: stretch; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
  table.list .c-pick input { width: 22px; height: 22px; margin: 0; }
  .tool-list tr { grid-template-columns: auto 1fr auto; grid-template-areas: "pick code status" "pick name name" "pick with due"; }
  .tool-list .c-code { grid-area: code; font-weight: 700; }
  .tool-list .c-name { grid-area: name; }
  .tool-list .c-status { grid-area: status; }
  .tool-list .c-with { grid-area: with; font-size: .9em; }
  .tool-list .c-due { grid-area: due; font-size: .85em; text-align: right; }
  .tool-list .c-cat { display: none; }
  .cons-list tr { grid-template-columns: auto 1fr auto; grid-template-areas: "pick name qty" "pick code reorder" "pick loc loc"; }
  .cons-list .c-name { grid-area: name; font-weight: 600; }
  .cons-list .c-code { grid-area: code; font-size: .85em; color: var(--muted); }
  .cons-list .c-loc { grid-area: loc; font-size: .85em; color: var(--muted); }
  .cons-list .c-qty { grid-area: qty; }
  .cons-list .c-reorder { grid-area: reorder; font-size: .8em; color: var(--muted); }
  table.list td:empty { display: none; }

  /* Bulk bar floats above the tab bar, only once something is ticked */
  .sticky-actions { position: fixed; left: 8px; right: 8px; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 20;
    background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
  .sticky-actions .btn { flex: 1 1 auto; }
  .sticky-actions:not(.has-selection) { display: none; }

  /* History: each entry becomes a small card */
  table.history thead { display: none; }
  table.history, table.history tbody { display: block; }
  table.history tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.history td { border: 0; padding: 0; }
  table.history .h-action { grid-column: 1; font-weight: 600; }
  table.history .h-when { grid-column: 2; grid-row: 1; font-size: .8em; color: var(--muted); text-align: right; }
  table.history .h-item, table.history .h-note { grid-column: 1 / -1; }
  table.history .h-note { font-size: .9em; color: var(--muted); }
  table.history .h-by { display: none; }
  table.history td:empty { display: none; }

  /* Item pages */
  .item-head { gap: 14px; flex-wrap: nowrap; align-items: flex-start; }
  .item-head .qr { width: 84px; height: 84px; padding: 4px; }
  .item-head h1 { font-size: 1.2rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .facts { grid-template-columns: max-content 1fr; font-size: .92em; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; }
  .stat b { font-size: 1.7em; }
  .tabs > * { flex: 1; text-align: center; }
  .grid2.top > section h2 { margin-top: 1em; }

  /* Scan page: big camera, big input */
  .reader { max-width: none; }
  #camBtn { width: 100%; }
}
@media (max-width: 860px) {
  .nav-open .top { z-index: 35; }
  .top nav a.tab-dup { display: none; }
  .top nav::before { content: "Menu"; display: block; font-weight: 700; color: var(--muted); font-size: .8em; text-transform: uppercase; letter-spacing: .05em; padding: 4px 8px 6px; }
}
td.mono { white-space: nowrap; }
