/* Shelf-stock app — phone-first, works fine on desktop. */
/* STOCKT brand palette: deep navy ground, vivid blue accent, white type.
   Status colours (red/green/amber) stay semantic — they mean stock state, not brand. */
:root {
  --navy: #041632;   /* sampled from the STOCKT master artwork — header blends seamlessly */
  --navy-2: #0a2450;
  --accent: #2e7bf0;
  --blue: #2e7bf0;
  --bg: #f3f4f6;
  --card: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

.boot-splash { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- header + nav ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  padding: 10px 14px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
/* The STOCKT artwork is navy-on-navy, so it sits seamlessly on the bar — no white plate. */
.topbar .brand img { height: 38px; max-width: 170px; object-fit: contain; }
.topbar .brand .name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { font-size: 12.5px; opacity: 0.85; text-align: right; line-height: 1.25; }
.topbar .who a { color: #6ea8ff; text-decoration: none; font-weight: 600; }
/* Wordmark styling when no logo image is set: bold italic, like the STOCKT mark */
.wordmark { font-style: italic; font-weight: 800; letter-spacing: 0.04em; }
.tagline { font-size: 10.5px; letter-spacing: 0.28em; text-transform: uppercase; opacity: 0.75; font-weight: 600; }

.tabbar {
  background: var(--navy-2);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top: calc(50px + env(safe-area-inset-top));
  z-index: 29;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar a {
  color: #cdd5e4;
  text-decoration: none;
  padding: 11px 14px;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tabbar a.active { color: #fff; border-bottom-color: var(--accent); }

main { padding: 14px; max-width: 1080px; margin: 0 auto; padding-bottom: 60px; }

h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }

/* ---------- cards, tables ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card .card-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .n { font-size: 26px; font-weight: 800; }
.tile .lbl { font-size: 13px; color: var(--muted); }
.tile.warn .n { color: var(--red); }

/* Sticky-header tables: border-collapse SEPARATE (collapse silently breaks sticky),
   single scroll container, borders via border-bottom only. */
.table-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14.5px; }
thead th {
  position: sticky; top: 0; z-index: 5;
  background: #f9fafb; text-align: left; font-size: 13px; color: var(--muted);
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f8faff; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.low { background: var(--red-bg); color: var(--red); }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.warn { background: var(--amber-bg); color: var(--amber); }
.badge.role { background: #e0e7ff; color: #3730a3; text-transform: capitalize; }
.badge.type { background: #f3f4f6; color: var(--muted); text-transform: capitalize; }

/* ---------- buttons & forms ---------- */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 600; font-size: 15px;
  text-decoration: none; display: inline-block;
}
button:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--blue); padding: 6px 8px; }
.btn-danger { color: var(--red); }
.btn-big { padding: 14px 18px; font-size: 17px; border-radius: 12px; }
button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit; padding: 10px 11px; border: 1px solid #d1d5db; border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
label.fld { display: block; margin-bottom: 10px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
label.fld > input, label.fld > select, label.fld > textarea { margin-top: 4px; font-weight: 400; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 130px; }
.row > .fix { flex: 0 0 auto; min-width: 0; }
.muted { color: var(--muted); font-size: 13.5px; }
.error-text { color: var(--red); font-size: 14px; margin-top: 6px; }

input.cell { padding: 6px 8px; width: 76px; text-align: right; }
select.cell { padding: 6px 8px; width: auto; }

/* ---------- scan view ---------- */
.loc-picker { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.loc-picker select { flex: 1; font-weight: 600; }

#scan-viewport {
  width: 100%; border-radius: var(--radius); overflow: hidden; background: #0b1222;
  min-height: 90px; position: relative;
}
#scan-viewport video { width: 100% !important; border-radius: var(--radius); }
.scan-idle { color: #93a3c4; text-align: center; padding: 30px 14px; font-size: 14.5px; }

.scan-actions { display: flex; gap: 10px; margin-top: 10px; }
.scan-actions .btn-big { flex: 1; }

.manual-entry { display: flex; gap: 8px; margin-top: 10px; }
.manual-entry input { flex: 1; font-size: 16px; }

.result-card { border-left: 5px solid var(--blue); }
.result-card .pname { font-size: 19px; font-weight: 800; }
.result-card .pmeta { color: var(--muted); font-size: 13.5px; margin-bottom: 6px; }
.result-card .shelfqty { font-size: 16px; margin: 8px 0; }
.result-card .shelfqty b { font-size: 24px; }
.low-banner { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 8px 12px; font-weight: 700; margin-top: 8px; font-size: 14.5px; }

.qty-stepper { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.qty-stepper button { width: 52px; height: 52px; font-size: 24px; border-radius: 12px; }
.qty-stepper input { width: 90px; height: 52px; text-align: center; font-size: 22px; font-weight: 700; }

.move-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.move-buttons .take { background: var(--navy); border-color: var(--navy); color: #fff; }
.move-buttons .putback { background: #fff; }
.move-buttons .restock { background: var(--green-bg); border-color: var(--green-bg); color: var(--green); }
.move-buttons .setcount { background: var(--amber-bg); border-color: var(--amber-bg); color: var(--amber); }
.move-buttons .writeoff { background: var(--red-bg); border-color: var(--red-bg); color: var(--red); }
.writeoff-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.writeoff-row select { flex: 1; }
.writeoff-row .btn-danger { border-color: var(--red); }

/* Viewfinder flashes green whenever a code is read — instant "got it" feedback. */
#scan-viewport { transition: box-shadow 0.15s ease-out; }
#scan-viewport.scan-hit { box-shadow: 0 0 0 4px #22c55e; }

.recent-scans { margin-top: 14px; }
.recent-scans .item { display: flex; justify-content: space-between; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.recent-scans .item:last-child { border-bottom: none; }

/* ---------- login ---------- */
.auth-wrap { max-width: 400px; margin: 8vh auto 0; padding: 0 16px; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo img { max-height: 130px; max-width: min(340px, 90%); object-fit: contain; border-radius: 12px; }
.auth-logo .name { font-size: 30px; font-weight: 800; font-style: italic; letter-spacing: 0.04em; color: var(--navy); }
.auth-logo .name .s-mark { color: var(--accent); }
.auth-logo .tagline { color: var(--muted); margin-top: 2px; }

/* ---------- lists ---------- */
.list-item { padding: 10px 2px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13.5px; cursor: pointer; user-select: none; background: #fff; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- toast ---------- */
#toast-holder { position: fixed; bottom: 18px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14.5px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in 0.18s ease-out; max-width: 90vw;
}
.toast.err { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- desktop tweaks ---------- */
@media (min-width: 760px) {
  .topbar { padding-left: 20px; padding-right: 20px; }
  main { padding: 20px; }
  .move-buttons { grid-template-columns: repeat(4, 1fr); }
  .scan-cols { display: grid; grid-template-columns: 420px 1fr; gap: 14px; align-items: start; }
}
