/* ==================================================================
   STOCKTAKE — design tokens
   Brand palette: Dark Blue 01 #002664 · Supplementary Blue 02 #146cfd
   Light Blue 04 #cbedfd · Accent Red 02 #d7153a · Light Red 04 #ffe6ea
   Display: Barlow Condensed · Body: Barlow · Data: IBM Plex Mono
   ================================================================== */
:root {
  --paper:      #f2f7fb;   /* cool paper, tinted toward Light Blue 04 */
  --panel:      #ffffff;
  --ink:        #002664;   /* Brand Dark Blue 01 — text, headers, sidebar */
  --ink-2:      #495054;   /* Grey 02 */
  --ink-3:      #7c848b;
  --line:       #dbe3ea;
  --brand:      #146cfd;   /* Brand Supplementary Blue 02 */
  --brand-dark: #002664;   /* Brand Dark Blue 01 */
  --brand-soft: #cbedfd;   /* Brand Light Blue 04 */
  --ok:         #004000;   /* Green 01 */
  --ok-soft:    #dbfadf;   /* Green 04 */
  --warn:       #941b00;   /* Orange 01 */
  --warn-soft:  #fdeddf;   /* Orange 04 */
  --bad:        #d7153a;   /* Brand Accent Red 02 */
  --bad-soft:   #ffe6ea;   /* Brand Accent Light Red 04 */
  --radius:     6px;
  --shadow:     0 1px 2px rgba(0,38,100,.06), 0 4px 16px rgba(0,38,100,.06);
  --font-body: 'Barlow', system-ui, sans-serif;
  --font-display: 'Barlow Condensed', 'Barlow', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Navigation surfaces get their own tokens so a theme can restyle the
     sidebar without every rule hard-coding a colour. */
  --side-bg:        #002664;
  --side-text:      #c2cdda;
  --side-text-on:   #ffffff;   /* text sitting ON the active gradient pill */
  --side-strong:    #ffffff;   /* bright text on the sidebar background itself */
  --side-hover:     rgba(255,255,255,.07);
  --side-active-a:  #146cfd;   /* active pill gradient, start */
  --side-active-b:  #0b3f9e;   /* active pill gradient, end */
  --logo-accent:    #8ce0ff;   /* the "TAKE" half of the wordmark */
  --sheet-bg:       rgba(0, 20, 54, .55);
  --sheet-panel:    rgba(0, 26, 68, .82);
  --side-shadow:    0 2px 10px rgba(0,0,0,.18);
  --card-top:       var(--ink);
}

/* ---------- duck theme: warm cream and rubber-duck yellow ---------- */
[data-theme="duck"] {
  --paper:      #ffffea;
  --panel:      #ffffff;
  --ink:        #2f2610;
  --ink-2:      #6b5c33;
  --ink-3:      #9a8a63;
  --line:       #ece2c6;
  --brand:      #b8860b;        /* readable amber for text and borders */
  --brand-dark: #7a5a00;
  --brand-soft: #fff3c9;
  --ok:         #3f6212;
  --ok-soft:    #e9f3d6;        /* pale wash, matches every other theme's chips */
  --warn:       #92400e;
  --warn-soft:  #fdecd2;
  --bad:        #b3261e;
  --bad-soft:   #fdeae8;
  --shadow:     0 1px 2px rgba(70,52,0,.07), 0 4px 16px rgba(70,52,0,.08);
  --side-bg:        #2f2610;
  --side-text:      #ddd0a8;
  --side-text-on:   #2f2610;    /* dark text on the yellow pill */
  --side-strong:    #ffd84d;    /* readable on the dark brown sidebar */
  --side-hover:     rgba(240,196,25,.14);
  --side-active-a:  #f0c419;    /* duck yellow */
  --side-active-b:  #d9a400;
  --logo-accent:    #f0c419;
  --sheet-bg:       rgba(47, 38, 16, .55);
  --sheet-panel:    rgba(47, 38, 16, .88);
  --side-shadow:    0 2px 10px rgba(0,0,0,.18);
  --card-top:       var(--ink);
}

/* ---------- health theme: brand red leading, brand blues supporting ---------- */
[data-theme="health"] {
  --paper:      #f5f8fd;
  --panel:      #ffffff;
  --ink:        #002664;
  --ink-2:      #4a5568;
  --ink-3:      #7b8494;
  --line:       #dde5f0;
  --brand:      #d7153a;        /* red leads */
  --brand-dark: #a4102c;
  --brand-soft: #ffe6ea;
  --ok:         #004000;
  --ok-soft:    #dbfadf;
  --warn:       #941b00;
  --warn-soft:  #fdeddf;
  --bad:        #d7153a;
  --bad-soft:   #ffe6ea;
  --shadow:     0 1px 2px rgba(0,38,100,.07), 0 4px 16px rgba(0,38,100,.07);
  --side-bg:        #002664;
  --side-text:      #bacbe6;
  --side-text-on:   #ffffff;
  --side-strong:    #ffffff;
  --side-hover:     rgba(215,21,58,.16);
  --side-active-a:  #d7153a;    /* red fading out */
  --side-active-b:  rgba(215,21,58,0);
  --side-shadow:    none;
  --logo-accent:    #d7153a;
  --card-top:       #d7153a;
  --sheet-bg:       rgba(0, 20, 54, .55);
  --sheet-panel:    rgba(0, 26, 68, .85);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* ensure hidden always wins over display:flex/grid rules */
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 17px;              /* was 14.5 — bumped ~20% for readability */
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
.mono { font-family: var(--font-mono); font-size: .92em; }
input, select, textarea, button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input.mono, select.mono, textarea.mono { font-size: 16.5px; }
.muted { color: var(--ink-3); }

/* ---------- loader ---------- */
.loader {
  height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; color: var(--ink-2);
}
.loader-bars {
  width: 120px; height: 44px;
  background: repeating-linear-gradient(90deg,
    var(--brand) 0 3px, transparent 3px 7px, var(--brand) 7px 12px, transparent 12px 15px,
    var(--brand) 15px 17px, transparent 17px 23px);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 258px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--side-bg); color: var(--side-strong);
  display: flex; flex-direction: column; gap: 1px; padding: 0 0 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 12px; }
.brand img { width: 46px; height: auto; border-radius: 5px; display: block; }
.brand h1 {
  margin: 0; font-family: var(--font-display); font-weight: 700;
  font-size: 27px; letter-spacing: .06em; line-height: 1;
}
.brand h1 span { color: var(--logo-accent); }

.nav-btn {
  appearance: none; background: none; border: 0; color: var(--side-text);
  text-align: left; padding: 8px 14px; margin: 0 10px; cursor: pointer;
  border-radius: 8px; min-height: 46px;
  font: 600 21px/1 var(--font-display); letter-spacing: .07em; text-transform: uppercase;
  transition: color .14s, background .14s, transform .06s;
}
.nav-btn:hover { color: var(--side-strong); background: var(--side-hover); }
.nav-btn:active { transform: translateY(1px); }
.nav-btn.active {
  color: var(--side-text-on);
  background: linear-gradient(to right, var(--side-active-a), var(--side-active-b));
  box-shadow: var(--side-shadow);
}
.nav-btn:focus-visible, .btn:focus-visible, .input:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.sidebar-foot {
  margin-top: auto; padding: 12px 20px 0; display: flex; flex-direction: column; gap: 10px;
  font-size: 13px; color: var(--ink-3); word-break: break-all;
}

.main { padding: 0 28px 48px; max-width: 1280px; }

/* ---------- scan bar (signature element) ---------- */
.scanbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border-bottom: 2px solid var(--ink);
  margin: 0 -28px; padding: 12px 28px;
  overflow: hidden;
}
.scanbar-label {
  font: 700 18px/1 var(--font-display); letter-spacing: .18em; color: var(--brand);
}
.scan-input {
  flex: 1; border: 1.5px dashed var(--ink-3); border-radius: var(--radius);
  padding: 11px 12px; font-size: 18px; background: var(--paper); color: var(--ink);
  min-width: 0;
}
.scan-input:focus { border-style: solid; border-color: var(--brand); outline: none; background: #fff; }
.scanline {
  position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: var(--brand); box-shadow: 0 0 12px 2px rgba(20,108,253,.6);
  transform: translateY(-4px); opacity: 0;
}
.scanline.fire { animation: sweep .45s ease-out; }
@keyframes sweep { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(62px); } }
@media (prefers-reduced-motion: reduce) {
  .scanline.fire { animation: none; }
  .loader-bars { animation: none; }
}

/* ---------- views ---------- */
.view { padding-top: 26px; }
.view-head { display: flex; align-items: baseline; gap: 18px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head h2 {
  margin: 0; font-family: var(--font-display); font-weight: 700;
  font-size: 36px; letter-spacing: .04em; text-transform: uppercase;
}
.view-sub { margin: 0; color: var(--ink-3); }
.head-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.eyebrow {
  display: block; font: 600 14px/1 var(--font-display); letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px;
}

/* ---------- cards / panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* working-location chips */
.loc-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.loc-chips button {
  appearance: none; border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--ink-2); cursor: pointer;
  font: 600 15px/1 var(--font-display); letter-spacing: .06em; text-transform: uppercase;
  padding: 9px 16px; min-height: 38px; touch-action: manipulation;
}
.loc-chips button:hover { border-color: var(--brand); color: var(--brand); }
.loc-chips button.active { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

/* per-location stock editor */
.stock-row { display: grid; grid-template-columns: 1fr 110px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }
.stock-row .rm {
  appearance: none; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--bad); cursor: pointer; font-size: 18px; min-height: 44px;
}
.stock-row .rm:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  border-top: 3px solid var(--card-top); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-card.alert { border-top-color: var(--brand); }
.stat-card.clickable { cursor: pointer; transition: transform .06s, box-shadow .12s; }
.stat-card.clickable:hover { box-shadow: 0 4px 18px rgba(20,108,253,.22); transform: translateY(-1px); }
.stat-card .num { font: 600 34px/1.1 var(--font-mono); margin: 4px 0 2px; }
.stat-card .sub { font-size: 14px; color: var(--ink-3); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel h3 {
  margin: 0 0 12px; font-family: var(--font-display); font-size: 22px;
  letter-spacing: .06em; text-transform: uppercase;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th {
  text-align: left; font: 600 14px/1.2 var(--font-display); letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-2);
  border-bottom: 2px solid var(--ink); padding: 9px 10px; white-space: nowrap;
}
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
td.sel, th.sel { width: 34px; text-align: center; padding-left: 4px; padding-right: 4px; }
.selbox { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; }
.empty { padding: 22px 10px; color: var(--ink-3); font-size: 16px; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 3px;
  font: 500 14px/1.5 var(--font-mono); white-space: nowrap;
}
.chip.ok   { background: var(--ok-soft); color: var(--ok); }
.chip.bad  { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.dim  { background: #e6eef5; color: var(--ink-3); }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--panel); color: var(--ink); padding: 10px 18px; cursor: pointer;
  font: 600 17px/1.1 var(--font-display); letter-spacing: .07em; text-transform: uppercase;
  transition: transform .06s, background .12s, color .12s;
  min-height: 44px;
}
.btn:hover { background: var(--ink); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn-ghost { border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--paper); color: var(--ink); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-warn { border-color: var(--warn); color: var(--warn); }
.btn-warn:hover { background: var(--warn); color: #fff; }
.btn-sm { padding: 7px 11px; font-size: 14px; min-height: 36px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.perm-hidden { display: none !important; }

.input {
  border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff;
  padding: 10px 11px; font: 400 17px/1.3 var(--font-body); color: var(--ink); width: 100%;
  min-height: 44px;
}
.input:focus { border-color: var(--brand); outline: none; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }

/* ---------- card grids (suppliers / locations / reports) ---------- */
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.entity-card, .report-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.entity-card { cursor: pointer; border-left: 3px solid var(--ink); transition: border-color .12s; }
.entity-card:hover { border-left-color: var(--brand); }
.entity-card h4, .report-card h4 {
  margin: 0; font-family: var(--font-display); font-size: 20px;
  letter-spacing: .05em; text-transform: uppercase;
}
.entity-card p, .report-card p { margin: 0; font-size: 15px; color: var(--ink-2); }
.entity-card .meta { font-size: 14px; color: var(--ink-3); }
.report-card .btn, .report-card .input { margin-top: auto; }
.report-card { gap: 10px; }

/* ---------- stocktake ---------- */
.session-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  background: var(--side-bg); color: var(--side-strong); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px; flex-wrap: wrap;
}
.session-banner .eyebrow { color: #9fb3d4; margin-bottom: 2px; }
.session-banner strong { font-size: 19px; }
.session-progress { flex: 1; min-width: 220px; max-width: 420px; text-align: right; font-size: 15px; color: #c9d7ee; }
.progress { height: 6px; background: rgba(255,255,255,.18); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--brand); transition: width .3s; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,38,100,.5); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px;
}
.modal {
  background: var(--panel); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.28);
  width: 100%; max-width: 640px; padding: 22px 24px; position: relative;
  border-top: 4px solid var(--brand); max-height: 86vh; overflow-y: auto;
}
.modal h3 {
  margin: 0 0 14px; font-family: var(--font-display); font-size: 29px;
  letter-spacing: .04em; text-transform: uppercase;
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 15px; font-weight: 600; color: var(--ink-2); }
.form-grid .span-2 { grid-column: span 2; }

/* barcode modal */
.modal-barcode { max-width: 500px; }
.barcode-preview {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; text-align: center;
}
.barcode-preview svg { max-width: 100%; height: auto; }
.bc-name { font-weight: 600; font-size: 18px; margin-top: 4px; word-break: break-word; }

/* item photos */
.photo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.item-photo {
  width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper); flex: 0 0 auto;
}
.item-photo.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); font-size: 13px;
}
.photo-btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.count-photo {
  width: 132px; height: 132px; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--line); display: block; margin: 6px auto 10px;
}

/* count modal */
.modal-count { max-width: 460px; text-align: center; }
.modal-count h3 { margin-bottom: 4px; }
.count-scan-flash {
  position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--brand);
  box-shadow: 0 0 14px 2px rgba(20,108,253,.6);
}
.count-row { display: flex; gap: 10px; justify-content: center; align-items: stretch; margin: 18px 0 8px; }
.count-input {
  width: 160px; text-align: center; font-size: 40px; font-weight: 600;
  border: 2px solid var(--ink); border-radius: var(--radius); padding: 8px;
}
.count-input:focus { border-color: var(--brand); outline: none; }
.btn-step { font-size: 28px; width: 60px; padding: 0; }

/* admin access editor */
.group-label { display: block; font-size: 15px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.check-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 12px; }
.check-grid label, .check-inline {
  display: flex; align-items: center; gap: 8px;
  font-size: 15.5px; font-weight: 400; color: var(--ink); cursor: pointer;
}
.check-grid label.opt-all { font-weight: 600; }
th.sel.wide { width: 56px; }
.selall-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  font: 600 11px/1 var(--font-display); letter-spacing: .08em; }
@media (max-width: 600px) { .check-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; left: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 90; align-items: flex-end; }
.toast {
  background: var(--ink); color: #fff; border-left: 4px solid var(--ok);
  border-radius: 4px; padding: 12px 16px; font-size: 16px; box-shadow: var(--shadow);
  animation: toast-in .18s ease-out; max-width: 480px;
}
.toast.err { border-left-color: var(--bad); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ==================================================================
   RESPONSIVE — laptop ▸ tablet ▸ phone
   ================================================================== */
@media (max-width: 1150px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet & phone: sidebar becomes a sticky top bar with scrollable nav */
@media (max-width: 900px) {
  /* auto+1fr rows: without this, the grid's spare viewport height is shared
     between both rows, leaving a large dead band under the top bar */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-content: start; }
  .sidebar {
    position: sticky; top: 0; z-index: 30;
    height: 58px; min-height: 58px; max-height: 58px;   /* fixed — the bar can never grow */
    flex-direction: row; flex-wrap: nowrap; align-items: stretch; padding: 0;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0 12px 0 14px; flex: 0 0 auto; display: flex; align-items: center; }
  .brand img { width: 34px; }
  .brand h1 { font-size: 22px; }
  .nav-btn {
    flex: 0 0 auto; white-space: nowrap;
    display: inline-flex; align-items: center;
    padding: 0 14px; font-size: 16px;
    border-left: 0;
    border-top: 3px solid transparent;                  /* balances the bottom border */
    border-bottom: 3px solid transparent;               /* so text stays centred */
  }
  .nav-btn.active { border-bottom-color: var(--brand); }
  .nav-btn:focus-visible { outline-offset: -2px; }      /* keep outline inside the bar */
  .sidebar-foot { display: none; }
  .main { padding: 0 14px 90px; }
  .scanbar { position: static; margin: 12px 0 0; padding: 10px 12px; border: 2px solid var(--ink); border-radius: var(--radius); }
  .scanbar-label { display: none; }
  .view { padding-top: 18px; }
  .view-head h2 { font-size: 30px; }
  .grid-2, .filters { grid-template-columns: 1fr; }
  .head-actions { margin-left: 0; width: 100%; }
  .head-actions .btn { flex: 1; }
  .modal-backdrop { padding: 3vh 10px 10px; }
  .modal { padding: 18px 16px; }
}

@media (max-width: 600px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card .num { font-size: 27px; }
  .card-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .session-banner { flex-direction: column; align-items: stretch; }
  .session-progress { text-align: left; max-width: none; }
  .count-input { width: 130px; font-size: 34px; }
  .toasts { align-items: stretch; }
  .toast { max-width: none; }
}

/* ==================================================================
   PocketBase edition additions
   ================================================================== */

/* login screen */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--paper);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  border-top: 4px solid var(--brand); box-shadow: var(--shadow);
  width: 100%; max-width: 400px; padding: 28px 26px;
}
.login-card .brand { padding: 0 0 18px; display: flex; align-items: center; gap: 12px; }
.login-card .brand img { width: 48px; border-radius: 5px; }
.login-card h1 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 28px; letter-spacing: .06em; }
.login-card h1 span { color: var(--brand); }
.login-card label { display: block; font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
.login-card .btn { width: 100%; margin-top: 18px; }
.login-err { color: var(--bad); font-size: 14.5px; margin: 10px 0 0; min-height: 1.2em; }

/* camera scanner */
.scan-cam-btn {
  appearance: none; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); cursor: pointer; font-size: 20px; padding: 8px 12px;
  min-height: 44px; touch-action: manipulation;
}
.scan-cam-btn:hover { border-color: var(--brand); }
#cameraReader { width: 100%; border-radius: var(--radius); overflow: hidden; }
.modal-camera { max-width: 480px; }


/* barcode lookup panel */
.lookup-panel {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px; background: var(--paper);
}
.lookup-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lookup-head span { font-size: 14.5px; }
.lookup-imgs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.lookup-imgs img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 4px;
  border: 2px solid var(--line); cursor: pointer; background: #fff;
}
.lookup-imgs img.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(20,108,253,.25); }

/* ==================================================================
   Lots, expiry and departments
   ================================================================== */

/* per-department stock editor: a department block owns its lot rows */
.dept-block {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 10px 8px; margin-bottom: 10px; background: var(--paper);
}
.dept-block .stock-row { margin-bottom: 0; }
.dept-block .lot-list:not(:empty) { margin: 10px 0 8px; display: flex; flex-direction: column; gap: 6px; }
.lot-row {
  display: grid; grid-template-columns: 1.2fr 1.1fr .7fr auto 40px;
  gap: 6px; align-items: center;
}
.lot-row .input { min-height: 40px; padding: 7px 9px; font-size: 15.5px; }
.lot-row .rm {
  appearance: none; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--bad); cursor: pointer; font-size: 17px; min-height: 40px;
}
.lot-row .rm:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.lot-status { text-align: center; }
.st-qty.derived { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--ink); font-weight: 600; }

/* decoded GS1 label banner in the item editor */
.gs1-panel {
  border-left: 3px solid var(--brand); border-radius: var(--radius);
  background: var(--brand-soft); padding: 10px 14px; margin-bottom: 14px;
}
.gs1-panel .eyebrow { color: var(--brand-dark); margin-bottom: 6px; }
.gs1-fields { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.gs1-field { font-size: 14.5px; color: var(--ink-2); }
.gs1-field b {
  font: 600 12.5px/1 var(--font-display); letter-spacing: .1em;
  text-transform: uppercase; color: var(--brand-dark); margin-right: 4px;
}

/* lot picker in the count modal */
.count-lot { margin: 14px auto 0; max-width: 320px; text-align: left; }
.count-lot-label {
  display: block; font: 600 13px/1 var(--font-display); letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 5px;
}
.count-lot-new { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* expiry view */
.expiry-panel { display: flex; flex-direction: column; }
.expiry-panel .table-wrap { max-height: 62vh; overflow-y: auto; }
.expiry-panel h3 { display: flex; align-items: center; gap: 8px; }
.count-badge {
  font: 600 13px/1 var(--font-mono); letter-spacing: 0;
  background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 999px; padding: 3px 9px; text-transform: none;
}
.count-badge:empty { display: none; }
.sub-line { display: block; font-size: 13.5px; color: var(--ink-3); }
tr.row-expired td { background: var(--bad-soft); }
tr.row-expired.rowlink:hover td { background: #ffd4dc; }
.chip.info { background: var(--brand-soft); color: var(--brand-dark); }

@media (max-width: 900px) {
  .lot-row { grid-template-columns: 1fr 1fr; gap: 6px; }
  .lot-row .lot-qty { grid-column: 1; }
  .lot-row .lot-status { grid-column: 2; text-align: left; }
  .lot-row .rm { grid-column: 2; justify-self: end; width: 44px; }
  .expiry-panel .table-wrap { max-height: none; }
  .count-lot { max-width: none; }
}

/* filter feedback on the expiry screen */
.filter-hint { margin: -6px 0 14px; font-size: 14.5px; color: var(--ink-3); }
.linkish {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--brand); font: inherit; text-decoration: underline; text-underline-offset: 2px;
}
.linkish:hover { color: var(--brand-dark); }

/* sortable table headers (items list) */
th.sortable { cursor: pointer; user-select: none; transition: color .12s; }
th.sortable:hover { color: var(--brand); }
th.sortable .sort-ind { margin-left: 5px; font-size: 10px; opacity: .3; }
th.sortable:hover .sort-ind { opacity: .7; }
th.sortable.sorted { color: var(--brand); border-bottom-color: var(--brand); }
th.sortable.sorted .sort-ind { opacity: 1; font-size: 9px; }

/* ==================================================================
   Overflow guards
   Grid and flex children default to min-width:auto, so a single wide
   descendant — a many-column table, a long email — stretches its parent
   past the viewport and takes the whole page with it. Allowing these to
   shrink keeps the scroll inside .table-wrap where it belongs.
   ================================================================== */
.app, .main, .sidebar, .scanbar, .view, .view-head, .panel, .stat-card,
.cards, .grid-2, .card-grid, .filters, .entity-card, .report-card,
.session-banner, .table-wrap, .lot-row, .stock-row, .dept-block { min-width: 0; }
.main { max-width: 100%; }
.table-wrap { max-width: 100%; }

/* long unbroken strings (emails, barcodes, lot numbers) wrap instead of pushing */
.view-sub, .stat-card .sub, .filter-hint, .gs1-fields, .session-banner strong { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .main { max-width: 100vw; }
  /* tables stay readable while scrolling within their own box */
  .table-wrap table { min-width: 480px; }
  .expiry-panel .table-wrap table { min-width: 420px; }
}

@media (max-width: 600px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .cards { gap: 8px; }
  .stat-card { padding: 12px 12px; }
  .scan-input { font-size: 16px; }
  .scanbar { gap: 8px; padding: 8px 10px; }
  .scan-cam-btn { padding: 8px 10px; font-size: 18px; }
}

/* account menu */
.acct-email { font-size: 21px !important; text-transform: none !important;
  letter-spacing: 0 !important; overflow-wrap: anywhere; }
.acct-actions { display: flex; flex-direction: column; gap: 8px; }
.acct-actions .btn { width: 100%; }

/* sidebar email is the way into the account menu on desktop */
.sidebar-acct { color: var(--side-text); text-align: left; }
.sidebar-acct:hover { color: var(--side-strong); }

/* ==================================================================
   ICONS + MOBILE NAVIGATION
   ================================================================== */
.icon-sprite { display: none; }
.ico {
  width: 22px; height: 22px; flex: 0 0 auto;
  fill: currentColor; color: inherit; pointer-events: none;
}

/* icons inside the desktop sidebar */
.nav-btn { display: flex; align-items: center; gap: 15px; }
.nav-btn .ico { width: 27px; height: 27px; opacity: .8; }
.nav-btn.active .ico, .nav-btn:hover .ico { opacity: 1; }

/* ---------- bottom tab bar + sheet (mobile only) ---------- */
.tabbar, .nav-sheet { display: none; }

@media (max-width: 900px) {
  /* the top bar is replaced by the bottom bar */
  .sidebar { display: none; }
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .main { padding-top: 8px; padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; align-items: stretch;
    background: var(--side-bg); color: var(--side-strong);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 14px rgba(0,38,100,.28);
  }
  .tab-btn {
    flex: 1 1 0; min-width: 0;
    appearance: none; background: none; border: 0; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 9px 2px 8px; color: var(--side-text);
    border-top: 3px solid transparent;
    font: 600 11px/1.1 var(--font-display); letter-spacing: .08em; text-transform: uppercase;
    transition: color .12s;
  }
  .tab-btn span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tab-btn .ico { width: 25px; height: 25px; }
  .tab-btn.active { color: var(--side-strong); border-top-color: var(--side-active-a); }
  .tab-btn:active { background: rgba(255,255,255,.08); }
  .tab-btn[hidden] { display: none; }

  /* the "more" button swaps its glyph for a cross while the sheet is open */
  .tab-more .ico { transition: transform .18s; }
  .tab-more .ico:nth-of-type(2) { display: none; }
  .tab-more.open .ico:nth-of-type(1) { display: none; }
  .tab-more.open .ico:nth-of-type(2) { display: block; }
  .tab-more.open { color: var(--side-strong); }
  /* the label follows the glyph: More -> Close */
  .tab-more .lbl-close { display: none; }
  .tab-more.open .lbl-more { display: none; }
  .tab-more.open .lbl-close { display: inline; }

  /* ---------- "more" sheet ---------- */
  .nav-sheet {
    position: fixed; inset: 0; z-index: 55;
    display: flex; flex-direction: column; justify-content: flex-end;   /* mobile only */
    background: var(--sheet-bg);
    -webkit-backdrop-filter: blur(7px) saturate(115%);
    backdrop-filter: blur(7px) saturate(115%);
    animation: sheet-fade .16s ease-out;
  }
  .nav-sheet-panel {
    background: var(--sheet-panel);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    border-top: 3px solid var(--brand);
    padding: 14px 10px calc(84px + env(safe-area-inset-bottom, 0px));
    max-height: 82vh; overflow-y: auto;
    animation: sheet-rise .2s cubic-bezier(.22,.8,.3,1);
  }
  .nav-sheet-title { color: var(--side-text); padding: 2px 14px 8px; }
  .sheet-btn {
    display: flex; align-items: center; gap: 15px; width: 100%;
    appearance: none; background: none; border: 0; cursor: pointer;
    color: var(--side-text); text-align: left;
    padding: 14px; border-radius: var(--radius); min-height: 54px;
    font: 600 18px/1 var(--font-display); letter-spacing: .07em; text-transform: uppercase;
  }
  .sheet-btn .ico { width: 24px; height: 24px; }
  .sheet-btn.active {
    background: linear-gradient(to bottom right, var(--side-active-a), var(--side-active-b));
    color: var(--side-text-on);
  }
  .sheet-btn:active { background: rgba(255,255,255,.12); }
  .sheet-btn[hidden] { display: none; }

  body.sheet-open { overflow: hidden; }
  /* toasts clear the tab bar */
  .toasts { bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }
}

@keyframes sheet-fade { from { opacity: 0; } }
@keyframes sheet-rise { from { transform: translateY(14px); opacity: .4; } }

@media (prefers-reduced-motion: reduce) {
  .nav-sheet, .nav-sheet-panel { animation: none; }
}

/* no backdrop-filter (older Android WebView): fall back to solid panels */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .nav-sheet { background: rgba(0, 20, 54, .82); }
  .nav-sheet-panel { background: #001a44; }
}

/* Outline icons carry fill="none" on a wrapper <g> inside their symbol.
   Never set fill on .ico descendants (.ico *, .ico path, .ico use) — a
   declaration on those elements beats the wrapper and the outline icons
   collapse back into solid blobs. Styling .ico itself is what works: the
   wrapper's fill="none" overrides the inherited value. */

/* clickable stat cards are <button>, so reset the browser's button styling */
button.stat-card {
  appearance: none; display: block; width: 100%;
  font: inherit; color: inherit; text-align: left;
}
.stat-card.clickable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Microsoft sign-in */
.login-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0 12px; color: var(--ink-3); font-size: 14px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}
.ms-btn {
  width: 100%; display: flex; align-items: center; justify-content: center;
  gap: 10px; text-transform: none; letter-spacing: 0;
  font: 600 16px/1.1 var(--font-body);
}
.ms-btn:hover { background: var(--paper); color: var(--ink); }
.ms-logo { width: 18px; height: 18px; flex: 0 0 auto; }

/* resume-a-session picker */
.resume-row { display: flex; gap: 10px; flex-wrap: wrap; }
.resume-row .input { flex: 1; min-width: 220px; }
@media (max-width: 600px) {
  .resume-row { flex-direction: column; }
  .resume-row .btn { width: 100%; }
}

/* theme picker in the account menu */
.theme-picker { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.theme-opt {
  display: flex; align-items: center; gap: 12px; width: 100%;
  appearance: none; cursor: pointer; text-align: left;
  background: var(--panel); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; min-height: 48px;
  font: 600 16px/1.1 var(--font-body);
}
.theme-opt:hover { border-color: var(--brand); }
.theme-opt.active { border-color: var(--brand); background: var(--brand-soft); }
.theme-opt.active::after { content: '✓'; margin-left: auto; color: var(--brand); font-weight: 700; }
.theme-swatch { display: flex; flex: 0 0 auto; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.theme-swatch i { display: block; width: 15px; height: 22px; }
