* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.6; }
button, input, select { font: inherit; }
[hidden] { display: none !important; }

/* Buttons and fields: TC20 is touch-first, so nothing smaller than --touch. */
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 15px; border-radius: 8px; min-height: var(--touch); }
button:hover { background: var(--surface-2); }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 500; }
button.primary:hover { background: var(--brand-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.textbutton { border: 0; color: var(--brand-ink); background: none; padding: 9px 6px; }
input, select { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; min-height: var(--touch); max-width: 100%; }

/* Shell: sidebar on the right (216px), content on the left. */
aside { position: fixed; right: 0; top: 0; bottom: 0; width: 216px; background: var(--surface); border-left: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; z-index: 5; }
.logo { display: block; width: 150px; margin: 0 auto 8px; background: #fff; border-radius: 6px; padding: 4px 6px; }
.brandcaption { text-align: center; font-size: 12px; color: var(--ink-2); margin-bottom: 24px; }
nav button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; text-align: right; margin-bottom: 4px; padding: 10px 12px; color: var(--ink-2); background: none; }
nav button.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.navicon { width: 22px; height: 22px; flex: none; }
.sidefoot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 16px; font-size: 12px; color: var(--ink-3); }
.workspace { margin-right: 216px; }
header { min-height: 64px; padding: 8px 32px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.crumb { color: var(--ink-2); }
.headeractions { display: flex; gap: 8px; align-items: center; }
.notice { padding: 8px 32px; font-size: 12px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.notice button { margin-right: auto; font-size: 12px; min-height: 36px; padding: 4px 12px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); flex: none; }
main { padding: 26px 32px; min-height: 80vh; max-width: 1550px; margin: auto; }
footer { display: flex; justify-content: space-between; gap: 12px; padding: 16px 32px; color: var(--ink-3); font-size: 11px; border-top: 1px solid var(--line); }
#runtime-error { padding: 12px 16px; background: var(--critical-soft); color: var(--critical-ink); border: 1px solid var(--critical-line); margin: 12px; border-radius: 8px; }

/* Typography (web-* sizes from the guide). */
.pagehead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
h1 { font-size: 19px; line-height: 1.4; margin: 0 0 2px; }
.sub { font-size: 12px; color: var(--ink-2); }
h2 { font-size: 14.5px; margin: 0 0 14px; }
h2::before { content: ''; display: inline-block; background: var(--brand); width: 7px; height: 7px; border-radius: 50%; margin-left: 9px; vertical-align: middle; }
p { margin: 8px 0; }
.muted, small { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }

/* Cards and KPIs. */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--card-pad-y) var(--card-pad-x); margin-bottom: var(--card-gap); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--kpi-gap); margin-bottom: var(--card-gap); }
.kpi { margin: 0; }
.kpi .label { font-size: 11.5px; color: var(--ink-2); }
.kpi strong { display: block; font-size: 22px; line-height: 1.3; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi small { font-size: 11px; color: var(--ink-3); }
.kpi.is-critical strong { color: var(--critical-ink); }
.split { display: grid; grid-template-columns: 1.65fr 1fr; gap: var(--card-gap); }
.sectionline { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sectionline h2 { margin-bottom: 10px; }

/* Status badges always carry a word, never colour alone. */
.badge { display: inline-block; font-size: 12px; border-radius: var(--radius-pill); padding: 3px 10px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { color: var(--good-ink); background: var(--good-soft); }
.badge.warn { color: var(--warn-ink); background: var(--warn-soft); }
.badge.bad { color: var(--critical-ink); background: var(--critical-soft); }

/* Tables. */
table { width: 100%; border-collapse: collapse; text-align: right; }
th { font-size: 11px; font-weight: 500; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: var(--cell-pad-y) var(--cell-pad-x); }
td { padding: 10px var(--cell-pad-x); border-bottom: 1px solid var(--line-soft); font-size: 12.5px; font-variant-numeric: tabular-nums; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td small { display: block; font-size: 11px; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.totals { font-weight: 700; margin-top: 10px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 200px; }
.barrow { margin: 18px 0; }
.barrow > div { display: flex; justify-content: space-between; margin-bottom: 6px; }
.bar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; background: var(--brand); height: 100%; border-radius: 4px; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quick button { text-align: right; padding: 14px; display: flex; gap: 10px; align-items: flex-start; }
.quick small { display: block; margin-top: 4px; }
.particon { display: inline-flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: 9px; background: var(--surface-2); margin-left: 10px; vertical-align: middle; color: var(--ink-2); flex: none; }
.itemcell { display: flex; align-items: center; }
.empty { text-align: center; padding: 28px; color: var(--ink-2); }
.audit { padding: 12px 0; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; gap: 12px; }
.audit:last-child { border-bottom: 0; }
.stockrow { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.draftmeta { font-size: 12px; color: var(--ink-3); margin: 6px 0; }

/* Dialogs and forms. */
dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; width: 560px; max-width: 94vw; max-height: 90vh; overflow: auto; padding: 22px; }
dialog::backdrop { background: rgba(28,26,28,.4); }
.dialog-fallback { display: block; position: fixed; inset: 5vh 0 auto; margin: 0 auto; z-index: 100; box-shadow: 0 0 0 100vmax rgba(28,26,28,.4); }
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--ink-2); }
form input, form select { width: 100%; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.line-head { display: flex; justify-content: space-between; align-items: center; }
.qtyrow { display: grid; grid-template-columns: var(--touch) 1fr var(--touch); gap: 6px; }
.qtyrow input { text-align: center; }
.actions { display: flex; gap: 10px; margin-top: 18px; position: sticky; bottom: -22px; background: var(--surface); padding: 10px 0 0; }
.actions button { flex: 1; }
.error { color: var(--critical-ink); margin-top: 10px; min-height: 1em; }
#toast { position: fixed; bottom: 22px; left: 22px; right: auto; background: var(--report-ink); color: #fff; border-radius: 10px; padding: 12px 20px; z-index: 200; max-width: calc(100vw - 44px); }

/* Handheld preview. */
.phone { width: 360px; max-width: 100%; margin: auto; border: 9px solid #292529; border-radius: 30px; background: var(--surface); overflow: hidden; }
.phonehead { padding: 12px 16px; border-bottom: 2px solid var(--brand); display: flex; justify-content: space-between; }
.phonebody { padding: 16px; }
.phonebody h1 { font-size: 18px; }
.scanarea { border: 1px dashed var(--line); border-radius: 12px; text-align: center; padding: 20px 14px; margin: 14px 0; }
.scanarea svg { width: 64px; height: 44px; }
.phonegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.phonegrid button { min-height: 64px; }
.steps { display: grid; gap: 12px; }
.step { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.step b { color: var(--brand-ink); margin-left: 8px; }
.mobile, .narrow-only { display: none; }
.iconbutton { padding: 0; width: var(--touch); display: inline-flex; align-items: center; justify-content: center; }

@media (max-width: 1000px) {
  .split { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  aside { display: none; top: 0; }
  .menu aside { display: flex; overflow-y: auto; box-shadow: 0 0 0 100vmax rgba(28,26,28,.35); }
  .closemenu { align-self: flex-start; margin-bottom: 10px; }
  .workspace { margin: 0; }
  .mobile { display: inline-block; }
  header { padding: 8px var(--gutter); position: sticky; top: 0; z-index: 4; }
  .crumb { display: none; }
  main { padding: 18px var(--gutter); }
  .notice { padding: 8px var(--gutter); flex-wrap: wrap; }
  .quick { grid-template-columns: 1fr; }
  footer { padding: 14px var(--gutter); flex-direction: column; }
}
/* TC20 portrait is ~360 CSS px wide: tables become labelled blocks, dialogs go full screen. */
@media (max-width: 600px) {
  :root { --touch: 48px; }
  body { font-size: 15px; }
  .wide-only { display: none; }
  #me, .headeractions [data-action="toggleTheme"] { display: none !important; }
  .tabs { flex-wrap: wrap; overflow: visible; }
  .tabs button { flex: 1 1 auto; }
  header { gap: 6px; }
  .netbutton { padding: 4px 8px; }
  .narrow-only { display: inline; }
  .pagehead { flex-direction: column; align-items: stretch; }
  .pagehead .primary { width: 100%; }
  .kpi strong { font-size: 20px; }
  .headeractions select { max-width: 150px; }
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .rtable tr:last-child { border-bottom: 0; }
  .rtable td { border: 0; padding: 3px 0; font-size: 14px; }
  .rtable td::before { content: attr(data-label); display: inline-block; min-width: 92px; color: var(--ink-2); font-size: 12px; }
  .rtable td small { display: inline; margin-inline-start: 6px; }
  .rtable td:first-child { display: block; font-weight: 500; }
  .rtable td:first-child::before { display: none; }
  dialog { position: fixed; inset: 0; width: auto; height: auto; max-width: none; max-height: none; border-radius: 0; margin: 0; padding: 16px; }
  .actions { bottom: -16px; padding-bottom: 8px; }
  #toast { left: var(--gutter); right: var(--gutter); bottom: var(--gutter); }
}

/* ---- Components added with the role-based screens ---- */
.headbtns, .rowbtns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rowbtns button { min-height: 36px; padding: 4px 12px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { white-space: nowrap; border-radius: var(--radius-pill); }
.tabs button.active { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; font-size: 11px; text-align: center; } /* guide: brand-ink for badge numbers; a solid red dot would read as an alarm */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.taskcard { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.taskcard:last-child { border-bottom: 0; }
.taskcard small { display: block; }
.scanbig { width: 100%; display: flex; align-items: center; gap: 14px; padding: 18px; margin-bottom: var(--card-gap); text-align: right; border: 1px solid var(--brand); background: var(--brand-soft); color: var(--ink); font-size: 16px; font-weight: 700; }
.scanbig svg { width: 36px; height: 36px; color: var(--brand); }
.scanbig small { display: block; font-weight: 400; font-size: 12px; }
.biginput { width: 100%; font-size: 20px; text-align: center; letter-spacing: 1px; margin-bottom: 10px; }
.wide { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 36px; padding: 4px 10px; font-size: 12px; }
.seg button.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.scanpanel .sectionline { flex-wrap: wrap; margin-bottom: 10px; }
.qtyprompt label { flex: 1; margin: 0; }
.qtyinput { width: 96px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 label input { width: 100%; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; align-items: end; }
.formgrid label { margin: 0; }
.formgrid select, .formgrid input:not([type=checkbox]), .formgrid textarea { width: 100%; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
label.check input { min-height: 0; width: 20px; height: 20px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 12px 0; }
textarea { width: 100%; font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
label.photo { display: flex; align-items: center; gap: 10px; cursor: pointer; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; min-height: var(--touch); color: var(--brand-ink); }
label.photo input { display: none; }
label.photo img, .thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.photos img, .photoview { max-width: 160px; border-radius: 8px; border: 1px solid var(--line); }
.timeline { list-style: none; padding: 0; margin: 0 0 8px; border-right: 2px solid var(--line); }
.timeline li { position: relative; padding: 4px 16px 10px 0; }
.timeline li::before { content: ''; position: absolute; right: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline small { display: block; }
.altbtn { display: block; width: 100%; text-align: right; margin-bottom: 6px; }
.altbtn small { display: inline; }
small.critical, .critical { color: var(--critical-ink); }
.kpi.is-warn strong { color: var(--warn-ink); }
.line.pick .line-head b { font-size: 16px; }
.netbutton { min-height: 36px; padding: 4px 12px; font-size: 12px; color: var(--good-ink); border-color: var(--good); }
.netbutton.offline { color: var(--critical-ink); border-color: var(--critical); background: var(--critical-soft); }
.phone iframe { display: block; border: 0; width: 320px; height: 533px; max-width: 100%; }
#bottomnav { display: none; }
body:not(.server-mode) .server-only, body.server-mode .mock-only { display: none !important; }
.itemcode { font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .3px; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.codebox { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 6px 0 4px; }
.codebox span { color: var(--ink-2); font-size: 12px; }
.codebox b { font-size: 18px; letter-spacing: .5px; user-select: all; }
.bell { position: relative; }
.bell .count { position: absolute; top: -4px; left: -4px; }
.notiflist { display: grid; gap: 6px; }
.notif { display: flex; flex-direction: column; align-items: stretch; gap: 4px; text-align: right; width: 100%; padding: 10px 12px; }
.notif.unread { border-color: var(--brand); background: var(--brand-soft); font-weight: 500; }
.notif small { color: var(--ink-3); }
button.danger { background: var(--surface); color: var(--critical-ink); border-color: var(--critical); font-weight: 500; }
button.danger:hover { background: var(--critical-soft); }
#me { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ink-2); }
#me[hidden] { display: none; }
#me button { min-height: 36px; padding: 4px 10px; font-size: 12px; }
.acct { display: grid; gap: 2px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); color: var(--ink); }
.acct .textbutton, .sidefoot .textbutton { min-height: 36px; padding: 4px 0; text-align: right; }
body.signed-out aside, body.signed-out .headeractions, body.signed-out .mobile { display: none !important; }
body.signed-out .workspace { margin-right: 0; }
.login { max-width: 380px; margin: 6vh auto; padding: 28px 24px; border-radius: 20px; }
.login .loginlogo { display: block; width: 150px; margin: 0 auto 16px; background: #fff; border-radius: 6px; padding: 4px 6px; }
.login h1 { text-align: center; }
.login > .sub { text-align: center; }
.login input { width: 100%; }
.login .wide { margin-top: 8px; }
.temppass { font-size: 22px; font-weight: 700; letter-spacing: 2px; text-align: center; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; font-variant-numeric: tabular-nums; user-select: all; }
#print { display: none; }

/* The handheld preview frame is the app itself; keep only what a device shows. */
/* The menu button stays: it is the only way to pages outside the bottom bar (items, returns, approvals…). */
body.device:not(.menu) aside, body.device .notice, body.device footer, body.device #user { display: none !important; }

@media (max-width: 600px) {
  body.has-bottomnav #bottomnav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); }
  #bottomnav button { border: 0; border-radius: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; min-height: 56px; font-size: 11px; color: var(--ink-2); }
  #bottomnav button.active { color: var(--brand-ink); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }
  body.has-bottomnav main { padding-bottom: 80px; }
  body.has-bottomnav #toast { bottom: 72px; }
  body.has-bottomnav footer { display: none; }
  .headeractions { gap: 6px; }
  #user { max-width: 132px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .filters > * { flex: 1 1 140px; }
}

/* ---- A4 documents (brand guide: logo left 72pt, title right, red rule 1.7pt, hairlines) ---- */
@page { size: A4; margin: 32pt; }
@media print {
  body > *:not(#print) { display: none !important; }
  body.printing #print { display: block; }
  body { background: #fff; color: var(--report-ink); }
  .a4 { font-family: var(--font-sans); color: var(--report-ink); font-size: 9pt; }
  .a4-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1.7pt solid var(--report-red); padding-bottom: 8pt; box-shadow: 0 1pt 0 var(--report-hair); }
  .a4-title { font-size: 17pt; font-weight: 700; }
  .a4-sub { font-size: 7.6pt; color: var(--report-mute); }
  .a4-logo { width: 72pt; }
  .a4-section { margin-top: 16pt; break-inside: avoid; }
  .a4-sec-title { font-size: 10pt; font-weight: 700; display: flex; align-items: center; gap: 6pt; margin-bottom: 6pt; }
  .a4-disc { width: 6pt; height: 6pt; border-radius: 50%; background: var(--report-red); display: inline-block; }
  .a4-table { width: 100%; border-collapse: collapse; font-size: 7.5pt; }
  .a4-table th { font-weight: 500; text-align: right; border-bottom: 0.5pt solid var(--report-hair); padding: 3pt; color: var(--report-mute); }
  .a4-table td { border-bottom: 0.5pt solid var(--report-hair-2); padding: 3pt; font-variant-numeric: tabular-nums; }
  .a4-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16pt; }
  .a4-sign div { border-top: 0.5pt solid var(--report-ink); padding-top: 4pt; margin-top: 36pt; text-align: center; }
  .labels-sheet { page: labelsheet; display: grid; grid-template-columns: repeat(3, 70mm); grid-auto-rows: 37mm; justify-content: center; }
  .labels-sheet .plabel { border: 0; border-radius: 0; break-inside: avoid; }
  .labels-roll { page: labelroll; }
  .labels-roll .plabel { width: 50mm; height: 25mm; padding: 1.5mm 2mm; border: 0; border-radius: 0; break-after: page; }
  .labels-roll .plabel-title { font-size: 7pt; }
  .labels-roll .plabel .barcode { height: 10mm; }
  .labels-roll .plabel-code { font-size: 8pt; }
  .a4-foot { margin-top: 20pt; border-top: 0.5pt solid var(--report-hair); padding-top: 4pt; display: flex; justify-content: space-between; font-size: 6.2pt; color: var(--report-mute); }
}

/* Movements summary (system admin): an infographic page */
.mv-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.mv-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--kpi-gap); margin-bottom: var(--card-gap); }
.mv-kpi { margin: 0; border-top: 3px solid var(--line); }
.mv-kpi.is-sent { border-top-color: var(--viz-sent); }
.mv-kpi.is-received { border-top-color: var(--viz-received); }
.mv-kpi.is-critical { border-top-color: var(--critical); }
.mv-kpi.is-critical strong { color: var(--critical-ink); }
.mv-kpi .label { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.mv-kpi strong { display: block; font-size: 22px; line-height: 1.3; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.mv-kpi small { font-size: 11px; color: var(--ink-2); }
.mv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--card-gap); margin-bottom: var(--card-gap); }
.mv-grid .card { margin: 0; }
.mv-title { margin: 6px 0 12px; font-size: 16px; }

.viz { display: flex; flex-direction: column; min-height: 260px; }
.vizhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.vizhead h2 { margin: 0 0 2px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.sent { background: var(--viz-sent); }
.key.received { background: var(--viz-received); }

/* Horizontal bars: data ends rounded, anchored at the start edge (right, in Arabic). */
.hbars { display: grid; gap: 12px; }
.hb-row { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 10px; }
.hb-label { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-pair { display: grid; gap: 2px; }
.hb { display: flex; align-items: center; gap: 8px; height: 14px; }
/* The page is right-to-left: bars start at the right, so the rounded data end is on the left. */
.hb i { display: block; height: 100%; border-radius: 4px 0 0 4px; background: var(--ink-2); min-width: 0; transition: opacity .15s; }
.hb i.sent { background: var(--viz-sent); }
.hb i.received { background: var(--viz-received); }
.hb.single { height: 18px; }
.hb b { font-size: 12px; font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.hb.thin { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.hbars:hover .hb-row:not(:hover) i, .hbars:hover .hb:not(:hover) i { opacity: .45; }

/* Timeline: paired columns on a recessive grid. */
.tl { position: relative; height: 180px; margin: 4px 0 0; }
.tl-grid { position: absolute; inset: 0 0 22px 0; pointer-events: none; }
.tl-cols, .tl-grid span { inset-inline-start: 44px; }
.tl-grid span { position: absolute; inset-inline: 0; border-top: 1px solid var(--line-soft); }
.tl-grid b { position: absolute; inset-inline-start: 0; transform: translateY(-50%); font-size: 10.5px; font-weight: 400; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tl-cols { position: absolute; inset: 0; inset-inline-start: 44px; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 2px; }
.tl-col { display: flex; flex-direction: column; min-width: 0; cursor: default; }
.tl-col:hover { background: var(--surface-2); border-radius: 4px; }
.tl-bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding: 0 1px; }
.tl-bars i { display: block; width: min(10px, 40%); min-height: 0; border-radius: 3px 3px 0 0; }
.tl-bars i.sent { background: var(--viz-sent); }
.tl-bars i.received { background: var(--viz-received); }
.tl-x { height: 22px; line-height: 22px; font-size: 10.5px; color: var(--ink-2); text-align: center; white-space: nowrap; overflow: visible; }

/* Route matrix: one hue, darker = more pieces; the number is always written in the cell. */
.rm-wrap { overflow-x: auto; }
.rm { border-collapse: separate; border-spacing: 3px; width: 100%; font-variant-numeric: tabular-nums; }
.rm th { font-size: 11.5px; font-weight: 500; color: var(--ink-2); padding: 4px; text-align: center; }
.rm td { height: 34px; min-width: 40px; text-align: center; font-size: 12.5px; border-radius: 6px; color: var(--ink);
  background: color-mix(in oklab, var(--viz-sent) var(--level, 0%), var(--surface-2)); }
.rm td.rm-dark { color: #fff; font-weight: 700; }
.rm td.rm-zero { color: var(--ink-3); background: var(--surface-2); }
.rm td.rm-self { background: repeating-linear-gradient(135deg, var(--line-soft) 0 4px, transparent 4px 8px); }

.mv-stores { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--card-gap); margin-bottom: var(--card-gap); }
.mv-stores .card { margin: 0; }
.mv-store h3 { margin: 0; font-size: 15px; }
.mv-balance { margin: 10px 0 12px; }
.mv-balance strong { display: block; font-size: 22px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.mv-balance small { font-size: 11.5px; color: var(--ink-2); }
.mv-flow { display: grid; gap: 10px; padding: 12px 0; border-block: 1px solid var(--line-soft); }
.mv-flow > div { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; }
.mv-flow span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.mv-flow b { justify-self: end; font-variant-numeric: tabular-nums; }
.mv-flow .hb { grid-column: 1 / -1; }
.mv-facts { margin: 10px 0 0; display: grid; gap: 6px; }
.mv-facts div { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.mv-facts dt { color: var(--ink-2); }
.mv-facts dd { margin: 0; font-variant-numeric: tabular-nums; text-align: end; }
.totalrow td { border-top: 2px solid var(--line); font-weight: 700; }

/* Balance by governorate (dashboard and movements) */
.govs { display: grid; gap: 16px; }
.gov-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.gov-head > b { font-size: 14px; }
.gov-head small { color: var(--ink-2); font-size: 12px; margin-inline-start: 4px; }
/* A thin bar on a track, like the brand guide's balance rows. */
.gov .hb { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.gov .hb i { background: var(--brand); border-radius: 4px 0 0 4px; }
.gov-stores { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.gov-stores b { color: var(--ink); font-weight: 500; }

/* The daily report as the mail shows it (light, like most mail apps) */
.reportpreview { background: #fff; border: 1px solid var(--line); border-radius: 8px; max-height: 60vh; overflow: auto; }

/* Performance indicators */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--kpi-gap); margin-bottom: var(--card-gap); }
.kpi-tile { display: flex; flex-direction: column; gap: 2px; }
.kpi-delta { margin-top: 6px; min-height: 22px; }
.kpi-tile details { margin-top: 4px; font-size: 11.5px; }
.kpi-tile summary { cursor: pointer; color: var(--ink-2); list-style: none; }
.kpi-tile summary::-webkit-details-marker { display: none; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Barcode labels: preview on screen, and two print formats with their own page sizes */
.labelpreview { display: grid; gap: 10px; justify-items: start; }
.plabel { width: 70mm; height: 37mm; box-sizing: border-box; padding: 3mm 4mm; display: flex; flex-direction: column; justify-content: space-between; background: #fff; color: #000; border: 1px dashed var(--line); border-radius: 4px; overflow: hidden; }
.plabel-title { font-size: 9pt; font-weight: 700; line-height: 1.25; max-height: 2.5em; overflow: hidden; }
.plabel .barcode { width: 100%; height: 12mm; }
.plabel-code { font-size: 9pt; font-weight: 700; letter-spacing: .5px; display: flex; justify-content: space-between; gap: 6px; font-variant-numeric: tabular-nums; }
.plabel-code span { font-weight: 400; }
.plabel.shelf .plabel-title { font-size: 8pt; font-weight: 400; }
.plabel.shelf .plabel-code { font-size: 16pt; justify-content: center; }
@page labelsheet { size: A4; margin: 10mm 0 0 0; }
@page labelroll { size: 50mm 25mm; margin: 0; }

#viztip { position: fixed; z-index: 50; max-width: 280px; padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--surface);
  font-size: 12px; line-height: 1.5; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.18); }

@media (max-width: 1100px) { .mv-kpis { grid-template-columns: repeat(3, 1fr); } .mv-grid { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .mv-kpis { grid-template-columns: repeat(2, 1fr); } .mv-kpi:last-child { grid-column: 1 / -1; } .hb-row { grid-template-columns: 84px 1fr; } }

/* Camera scanning (core/camera-scan.js): a button beside each scan field, and a full-screen camera view. */
.scanrow { display: flex; gap: 8px; align-items: flex-start; width: 100%; }
.scanrow > input { flex: 1 1 auto; min-width: 0; }
.cambtn { flex: none; width: var(--touch); min-height: var(--touch); padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--brand-ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.biginput + .cambtn { min-height: 54px; width: 54px; }
dialog.camscan { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 16px; border: 0; border-radius: 0; background: #000; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
dialog.camscan::backdrop { background: #000; }
.camscan-view { position: relative; width: min(100%, 520px); aspect-ratio: 3 / 4; max-height: 70dvh; overflow: hidden; border-radius: 14px; background: #111; }
.camscan-view video { width: 100%; height: 100%; object-fit: cover; }
.camscan-frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
.camscan-hint, .camscan-error { margin: 0; text-align: center; font-size: 15px; max-width: 520px; }
.camscan-error { color: #ffb4b4; }
.camscan-close { min-height: var(--touch); min-width: 160px; background: #fff; color: #1f1d1b; border: 0; border-radius: 10px; font-size: 16px; }
