/* Physical Inventory - stylesheet
   Colours marked "theme" are replaced per organization in base.html. */

/* Fonts are shipped with the app so it never needs the internet. */
@font-face { font-family: "Plex Sans"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-400.0ceb759015a6.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Plex Sans"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-ext-400.0e2c71ca88ef.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Plex Sans"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-500.767677e47513.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Plex Sans"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-ext-500.9e50dcc81c7e.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Plex Sans"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-600.e78568807d10.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Plex Sans"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-ext-600.4267dfb25bc2.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Plex Mono"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-mono-500.bc5ccab82723.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

:root {
  --primary: #1f6f5c;      /* theme */
  --on-primary: #ffffff;   /* theme */
  --sidebar: #15201d;      /* theme */
  --on-sidebar: #ffffff;   /* theme */

  --paper: #f3f0e8;
  --surface: #fffdf8;
  --ink: #1b1a17;
  --muted: #6a665c;
  --line: #ddd6c6;
  --line-soft: #ebe6d9;
  --danger: #a3271f;
  --danger-bg: #fbe9e6;
  --ok: #1c6b3c;
  --ok-bg: #e0f0e3;
  --warn: #8a4b06;
  --warn-bg: #fbedcf;
  --info: #1d4f91;
  --info-bg: #e2ebf6;
  --violet: #6b3a8c;
  --violet-bg: #efe5f5;

  --sans: "Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 6px;
  --sidebar-w: 248px;
  /* The stripe pattern used as the app's signature: a strip of barcode. */
  --bars: repeating-linear-gradient(90deg,
    currentColor 0 2px, transparent 2px 5px, currentColor 5px 6px, transparent 6px 8px,
    currentColor 8px 11px, transparent 11px 13px, currentColor 13px 14px, transparent 14px 18px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.5 var(--sans);
}
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
p { margin: 0 0 12px; }
a { color: var(--primary); }
.mono { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- Shell ------------------------------------------------------------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--sidebar); color: var(--on-sidebar);
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { padding: 20px 20px 16px; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: var(--radius); padding: 3px; }
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.25; overflow-wrap: anywhere; }
.brand-sub { font-size: 12px; opacity: 0.65; }
.brand-bars { height: 14px; margin-top: 16px; background: var(--bars); opacity: 0.55; }
.nav { padding: 4px 12px 16px; flex: 1; }
.nav-label { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; opacity: 0.55; padding: 16px 8px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin-bottom: 2px;
  color: inherit; text-decoration: none; border-radius: var(--radius); font-weight: 500; opacity: 0.82;
}
.nav a:hover { opacity: 1; background: color-mix(in srgb, currentColor 10%, transparent); }
.nav a.active { opacity: 1; background: var(--primary); color: var(--on-primary); }
.sidebar-foot { padding: 14px 20px 18px; border-top: 1px solid color-mix(in srgb, currentColor 16%, transparent); font-size: 13px; }
.sidebar-foot .who { font-weight: 500; overflow-wrap: anywhere; }
.linklike { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; opacity: 0.8; }
.linklike:hover { opacity: 1; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px;
  border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: 1; min-width: 0; }
.btn.menu-btn { display: none; }
.org-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.org-switch select { max-width: 220px; }
.content { padding: 24px 28px 40px; flex: 1; width: 100%; max-width: 1180px; }
.fineprint {
  padding: 12px 28px 16px; border-top: 1px solid var(--line);
  font-size: 11px; line-height: 1.45; color: var(--muted);
}
.scrim { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.18s ease; }
  .nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 17, 15, 0.45); z-index: 30; }
  .main { margin-left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .topbar h1 { font-size: 18px; }
  .org-switch { width: 100%; order: 5; }
  .org-switch select { max-width: none; flex: 1; }
  .content { padding: 16px 14px 32px; }
  .fineprint { padding: 10px 14px 14px; }
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 14px/1.2 var(--sans); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; border-color: var(--line); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { border-color: var(--primary); filter: brightness(0.92); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { border-color: var(--line); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 52px; padding: 12px 20px; font-size: 16px; }
.btn-icon { padding: 8px; min-width: 40px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: inline; }

/* --- Page head, panels ----------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head p { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel, .panel + .page-head { margin-top: 20px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 18px; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* --- Tables ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600;
  color: var(--muted); padding: 10px 18px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 18px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.actions { text-align: right; white-space: nowrap; }
.swatches { display: inline-flex; gap: 4px; vertical-align: middle; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); }
.cell-logo { width: 28px; height: 28px; object-fit: contain; border-radius: 4px; background: #fff; border: 1px solid var(--line-soft); vertical-align: middle; margin-right: 8px; }

/* --- Badges ---------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--line-soft); color: var(--muted);
}
.badge.ok, .badge.st-api-exported { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--danger-bg); color: var(--danger); }
.badge.st-inprogress { background: var(--warn-bg); color: var(--warn); }
.badge.st-submitted { background: var(--info-bg); color: var(--info); }
.badge.st-cancelled { background: var(--line-soft); color: var(--muted); }
.badge.st-ready-for-api-export { background: var(--violet-bg); color: var(--violet); }

/* --- Forms ----------------------------------------------------------------- */
.form-grid { display: grid; gap: 16px 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field label, .field .label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 5px; }
.input {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); font: 400 15px/1.3 var(--sans);
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea.input { resize: vertical; }
input[type="color"].input { padding: 3px; width: 72px; cursor: pointer; }
input[type="file"].input { padding: 6px; }
.help { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.errorlist { list-style: none; margin: 5px 0 0; padding: 0; color: var(--danger); font-size: 13px; }
.check { display: flex; gap: 9px; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.field ul:not(.errorlist), .field div[id^="id_"] { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.field div[id^="id_"] label, .field ul:not(.errorlist) label { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; cursor: pointer; }
.field div[id^="id_"] input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.section-title { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 26px 0 12px; }
.search { display: flex; gap: 8px; }
.search .input { min-width: 0; }

/* --- Messages and toasts ----------------------------------------------------- */
.alerts { margin-bottom: 16px; display: grid; gap: 8px; }
.alert { padding: 10px 14px; border-radius: var(--radius); border: 1px solid; font-size: 14px; }
.alert.success { background: var(--ok-bg); border-color: #b9dcc2; color: var(--ok); }
.alert.error { background: var(--danger-bg); border-color: #eec3bd; color: var(--danger); }
.alert.warning, .alert.info { background: var(--warn-bg); border-color: #ecd49d; color: var(--warn); }
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: var(--radius); font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
.toast.error { background: var(--danger); }

/* --- Dashboard ------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
@media (max-width: 860px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font: 500 30px/1.1 var(--mono); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.hero {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--sidebar); color: var(--on-sidebar); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px;
  position: relative; overflow: hidden;
}
.hero::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 10px; background: var(--bars); opacity: 0.35; }
.hero h2 { font-size: 20px; }
.hero p { margin: 4px 0 0; opacity: 0.75; }

/* --- Sign-in ----------------------------------------------------------------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-art { background: var(--sidebar); color: var(--on-sidebar); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art .bars { height: 96px; background: var(--bars); background-size: 54px 100%; opacity: 0.85; }
.auth-art h1 { font-size: 34px; letter-spacing: -0.02em; max-width: 12ch; }
.auth-art p { opacity: 0.7; max-width: 34ch; margin-top: 12px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h2 { font-size: 22px; margin-bottom: 4px; }
.auth-card .field { margin-top: 16px; }
.auth-card .btn { width: 100%; margin-top: 22px; }
.auth-foot { margin-top: 28px; font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-art { padding: 24px 20px; gap: 18px; }
  .auth-art .bars { height: 40px; }
  .auth-art h1 { font-size: 24px; max-width: none; }
  .auth-art p { display: none; }
  .auth-form { align-items: flex-start; }
}

/* --- Counting screen --------------------------------------------------------- */
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 500; background: var(--ok-bg); color: var(--ok); border: 0; font-family: var(--sans);
}
.sync-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sync-pill.waiting { background: var(--warn-bg); color: var(--warn); }
.sync-pill.offline { background: var(--line-soft); color: var(--muted); }
button.sync-pill { cursor: pointer; }

.session-list { display: grid; gap: 10px; }
.session-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px;
  font: inherit; color: inherit; cursor: pointer;
}
.session-card:hover { border-color: var(--ink); }
.session-code { font: 500 18px/1.2 var(--mono); }
.session-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--muted); }

.count-head { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.count-head .session-code { font-size: 22px; }
.count-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.count-grid { display: grid; gap: 16px; }
@media (min-width: 980px) { .count-grid.scanning { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; } }

.scanner { background: #0d1110; color: #fff; border-radius: var(--radius); overflow: hidden; }
.scanner-view { position: relative; aspect-ratio: 4 / 3; background: #000; }
.scanner-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle { position: absolute; inset: 22% 10%; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 10px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35); pointer-events: none; }
.reticle::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff4d3d; opacity: 0.85; }
.scanner.flash .reticle { border-color: #57e389; }
.scanner-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; font-size: 14px; background: #0d1110; }
.scanner-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; font-size: 13px; }
.scanner-bar .btn { background: #fff; color: #14110f; border-color: #fff; }

.last-scan { padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, 0.14); display: grid; grid-template-columns: 1fr auto; gap: 2px 14px; align-items: center; }
.last-scan .lbl { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; opacity: 0.6; grid-column: 1 / -1; }
.last-scan .code { font: 500 17px/1.3 var(--mono); overflow-wrap: anywhere; }
.last-scan .name { font-size: 14px; opacity: 0.85; }
.last-scan .avail { font-size: 13px; opacity: 0.65; }
.last-scan .qty { grid-row: 2 / span 3; grid-column: 2; text-align: right; }
.last-scan .qty b { display: block; font: 500 44px/1 var(--mono); color: #57e389; font-variant-numeric: tabular-nums; }
.last-scan .qty span { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; opacity: 0.6; }

.manual { display: flex; gap: 8px; padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.14); }
.manual .input { background: #1a211f; border-color: #33403c; color: #fff; font-family: var(--mono); }
.manual .input::placeholder { color: #8b9793; font-family: var(--sans); }
.manual .btn { background: transparent; color: #fff; border-color: #55635f; }

.counted { font: 500 16px/1 var(--mono); font-variant-numeric: tabular-nums; }
tr.just-scanned td { background: var(--ok-bg); }
.pending-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: 6px; vertical-align: middle; }
.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); border: 1px solid #ecd49d; margin-bottom: 14px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.notice.bad { background: var(--danger-bg); color: var(--danger); border-color: #eec3bd; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  th, td { padding-left: 12px; padding-right: 12px; }
  .count-actions .btn { flex: 1 1 46%; }
  .count-actions .btn-lg { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* --- New-count dialog ------------------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,17,15,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 18px; }
.modal-body .field + .field { margin-top: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }

/* --- In-camera quantity editor ---------------------------------------------- */
.qty-edit { grid-row: 2 / span 3; grid-column: 2; display: flex; align-items: center; gap: 6px; }
.qty-edit input { width: 68px; text-align: center; font: 500 22px/1 var(--mono); padding: 7px 4px; border-radius: 6px; border: 1px solid #33403c; background: #1a211f; color: #fff; }
.qbtn { width: 38px; height: 38px; border-radius: 6px; border: 1px solid #55635f; background: transparent; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.qbtn:hover { background: rgba(255,255,255,0.1); }

/* --- Detail rows: red unknown product, quantity edit, delete ---------------- */
tr.unknown td.bcode, tr.unknown td.pname { color: var(--danger); }
tr.unknown td.pname::after { content: " (not in products)"; font-size: 11px; color: var(--danger); }
.row-qty { width: 64px; text-align: right; font: 500 15px/1 var(--mono); padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.row-qty:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
td.seqcell { color: var(--muted); font-family: var(--mono); }
tr.gap-before td.seqcell::before { content: "⋯"; color: var(--danger); margin-right: 6px; }

/* --- Radio row (match mode) ------------------------------------------------- */
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
.radio { display: flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; }
.radio input { width: 17px; height: 17px; accent-color: var(--primary); }

/* --- Language switch + RTL --------------------------------------------------- */
.lang-switch select { max-width: 130px; }
@media (max-width: 860px) { .lang-switch { order: 6; } .lang-switch select { max-width: none; width: 100%; } }

/* Right-to-left: mirror the shell. Barcodes, numbers and times stay LTR. */
html[dir="rtl"] body { direction: rtl; }
html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
html[dir="rtl"] .main { margin-left: 0; margin-right: var(--sidebar-w); }
@media (max-width: 860px) {
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="rtl"].nav-open .sidebar { transform: none; }
  html[dir="rtl"] .main { margin-right: 0; }
}
html[dir="rtl"] .nav a.active { border-left: none; border-right: 3px solid white; }
html[dir="rtl"] th, html[dir="rtl"] td { text-align: right; }
html[dir="rtl"] td.num, html[dir="rtl"] th.num { text-align: left; }
html[dir="rtl"] .form-actions, html[dir="rtl"] .modal-footer { flex-direction: row-reverse; }
html[dir="rtl"] .page-head { flex-direction: row-reverse; }
html[dir="rtl"] .nav a, html[dir="rtl"] .check, html[dir="rtl"] .radio { flex-direction: row-reverse; }
html[dir="rtl"] .nav a { justify-content: flex-end; }
html[dir="rtl"] .back-btn svg, html[dir="rtl"] #back-btn svg { transform: scaleX(-1); }
/* Keep machine-readable values left-to-right even inside RTL text */
.mono, .session-code, .stat-value, .counted, input[type="number"], .last-scan .code, .scanner-result { direction: ltr; unicode-bidi: embed; }
html[dir="rtl"] .mono, html[dir="rtl"] .session-code { text-align: right; }
html[dir="rtl"] .brand-row, html[dir="rtl"] .sync-pill, html[dir="rtl"] .btn { flex-direction: row-reverse; }

/* --- Scan alert (barcode not found) ----------------------------------------- */
.scanner.alert .reticle { border-color: #ff4d3d; box-shadow: 0 0 0 100vmax rgba(140, 20, 10, 0.45); }
.scanner.alert .scanner-view { animation: alertpulse 0.65s ease; }
@keyframes alertpulse { 0%, 100% { background: #000; } 30% { background: #4a0f0a; } }

/* --- Selectable session cards ----------------------------------------------- */
.session-card.selectable { grid-template-columns: auto 1fr auto; cursor: pointer; }
.sc-check { display: flex; align-items: center; }
.sc-check input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.session-card.selectable .session-code { grid-column: 2; }

/* --- Keep the camera visible while the list scrolls (during scanning) -------- */
/* When the camera is open on a wide screen, the camera panel stays put (sticky)
   and the scanned-rows table scrolls inside its own box, so auto-scrolling to the
   newest row never pushes the camera out of view. */
@media (min-width: 980px) {
  .count-grid.scanning > .scanner { position: sticky; top: 70px; align-self: start; }
  .count-grid.scanning .table-wrap.rows-scroll {
    max-height: calc(100vh - 230px);
    overflow-y: auto;
  }
}
/* On phones the camera is above the list; cap the list height so the newest row
   is reachable without the whole page scrolling the camera away. */
@media (max-width: 979px) {
  .count-grid.scanning .table-wrap.rows-scroll {
    max-height: 48vh;
    overflow-y: auto;
  }
}
