/* P.R.T.C Inventory - styles. Mobile first, works on desktop, Android and iOS. */
:root {
  --brand: #0f4c81;
  --brand-dark: #0a365c;
  --brand-soft: #e7f0f8;
  --in: #14804a;
  --in-soft: #e3f4ea;
  --out: #c2410c;
  --out-soft: #fdeee4;
  --adj: #6d28d9;
  --adj-soft: #efe9fc;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn: #a16207;
  --warn-soft: #fdf5d9;
  --text: #1c2530;
  --muted: #5d6b7a;
  --line: #dde3ea;
  --bg: #f3f5f8;
  --card: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 236px;
  --bottom-nav: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Khmer", "Khmer UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .92em; }
.hidden { display: none !important; }
.print-only { display: none; }
.pre { white-space: pre-line; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--in); font-weight: 600; }
.neg { color: var(--out); font-weight: 600; }
.spacer { flex: 1; }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--brand-dark); color: #fff; display: flex; flex-direction: column;
  z-index: 40; overflow-y: auto;
}
.brand { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand .name { font-weight: 700; font-size: .95rem; letter-spacing: .2px; }
.brand .sub { font-size: .75rem; opacity: .75; }
.nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav button {
  display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.88);
  padding: 10px 12px; border-radius: 8px; font-size: .95rem; text-decoration: none;
  background: none; border: 0; width: 100%; text-align: left; cursor: pointer; font: inherit;
}
.nav a:hover, .nav button:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: #fff; color: var(--brand-dark); font-weight: 600; }
.nav .sep { height: 1px; background: rgba(255,255,255,.12); margin: 8px 4px; }
.nav svg { width: 20px; height: 20px; flex: none; }
.sidebar .who { margin-top: auto; padding: 12px 16px; font-size: .82rem; border-top: 1px solid rgba(255,255,255,.12); opacity: .85; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
  margin-left: var(--sidebar);
}
.topbar .title { font-weight: 600; font-size: 1rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar .user-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.topbar .menu-btn { display: none; }
.main { margin-left: var(--sidebar); padding: 20px; max-width: 1280px; }

.bottom-nav { display: none; }
.drawer-backdrop { display: none; }

@media (max-width: 899px) {
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(0,0,0,.25); width: 270px; }
  .sidebar.open { transform: none; }
  .drawer-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .topbar { margin-left: 0; padding: 0 10px; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar .user-chip .uname { display: none; }
  .main { margin-left: 0; padding: 14px 12px calc(var(--bottom-nav) + var(--safe-b) + 20px); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--card); border-top: 1px solid var(--line);
    height: calc(var(--bottom-nav) + var(--safe-b)); padding-bottom: var(--safe-b);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: .72rem; color: var(--muted); text-decoration: none; background: none; border: 0; font-family: inherit; cursor: pointer;
  }
  .bottom-nav svg { width: 24px; height: 24px; }
  .bottom-nav a.active { color: var(--brand); font-weight: 600; }
  .bottom-nav a.in svg { color: var(--in); }
  .bottom-nav a.out svg { color: var(--out); }
}

/* ---------- Page ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-head h1 { margin-right: auto; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; font-size: .9rem; }
.back svg { width: 18px; height: 18px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card > h2, .card > h3 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 14px 16px 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); color: inherit; display: block; }
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--danger); }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.quick a {
  display: flex; align-items: center; gap: 10px; padding: 16px; border-radius: var(--radius);
  color: #fff; font-weight: 600; font-size: 1.02rem; text-decoration: none; box-shadow: var(--shadow);
}
.quick a svg { width: 26px; height: 26px; flex: none; }
.quick .q-in { background: var(--in); }
.quick .q-out { background: var(--out); }
.quick .q-find { background: var(--brand); }
.quick .q-add { background: #334155; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 999px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none;
}
.btn:hover { text-decoration: none; background: #f6f8fa; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.in { background: var(--in); border-color: var(--in); color: #fff; }
.btn.out { background: var(--out); border-color: var(--out); color: #fff; }
.btn.adj { background: var(--adj); border-color: var(--adj); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: #f1c0c0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .88rem; }
.btn.big { min-height: 52px; font-size: 1.05rem; padding: 10px 22px; }
.btn.block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: #eef1f5; }
.icon-btn svg { width: 22px; height: 22px; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email], input[type=tel], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #c5ced8; border-radius: 8px;
  background: #fff; color: var(--text); font: inherit; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 76, 129, .35); border-color: var(--brand); }
.field { margin-bottom: 12px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .form-grid, .form-grid.three { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar .grow { flex: 1 1 220px; min-width: 0; }
.toolbar select, .toolbar input[type=date] { width: auto; flex: 0 1 auto; }
@media (max-width: 640px) {
  .toolbar select, .toolbar input[type=date] { flex: 1 1 45%; }
}

.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; white-space: pre-line; font-weight: 500; }
.info { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.warnbox { background: var(--warn-soft); color: #6b4705; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.t th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
table.t tbody tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f7f9fc; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfc; }
table.t tr.voided td { opacity: .55; }
.pname { font-weight: 600; }
.psub { font-size: .8rem; color: var(--muted); }

@media (max-width: 699px) {
  table.resp thead { display: none; }
  table.resp, table.resp tbody, table.resp tr, table.resp td { display: block; width: 100%; }
  table.resp tr { border-bottom: 1px solid var(--line); padding: 8px 12px; }
  table.resp td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  table.resp td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; flex: none; }
  table.resp td.main-cell { display: block; text-align: left; padding-bottom: 4px; }
  table.resp td.main-cell::before { display: none; }
  table.resp td.num { text-align: right; }
  table.resp tfoot { display: block; }
  table.resp tfoot tr { display: flex; flex-wrap: wrap; }
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.badge.ok { background: var(--in-soft); color: var(--in); }
.badge.low { background: var(--warn-soft); color: var(--warn); }
.badge.out { background: var(--danger-soft); color: var(--danger); }
.badge.t-IN, .badge.t-OPEN { background: var(--in-soft); color: var(--in); }
.badge.t-OUT { background: var(--out-soft); color: var(--out); }
.badge.t-ADJ { background: var(--adj-soft); color: var(--adj); }
.badge.t-VOID { background: #e5e7eb; color: #374151; }
.badge.gray { background: #e5e7eb; color: #374151; }
.badge.role-admin { background: #fee2e2; color: #991b1b; }
.badge.role-manager { background: var(--brand-soft); color: var(--brand); }
.badge.role-staff { background: #e5e7eb; color: #374151; }
.badge.role-viewer { background: #ecfdf5; color: #065f46; }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.more-row { padding: 12px; text-align: center; border-top: 1px solid var(--line); }
.list-meta { font-size: .85rem; color: var(--muted); padding: 8px 16px; }

/* ---------- Product detail ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 18px; }
.kv .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kv .v { font-weight: 600; word-break: break-word; }
.onhand { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.onhand .big { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Stock entry ---------- */
.stock-head { border-left: 5px solid var(--brand); }
.stock-head.IN { border-left-color: var(--in); }
.stock-head.OUT { border-left-color: var(--out); }
.stock-head.ADJ { border-left-color: var(--adj); }
.picker { position: relative; }
.picker input { padding-left: 40px; min-height: 50px; font-size: 17px; }
.picker .picker-icon { position: absolute; left: 11px; top: 14px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15);
  max-height: 340px; overflow-y: auto;
}
.picker-item { padding: 10px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #f0f2f5; }
.picker-item:last-child { border-bottom: 0; }
.picker-item.sel, .picker-item:hover { background: var(--brand-soft); }
.picker-item .grow { flex: 1; min-width: 0; }
.picker-item .pname { overflow: hidden; text-overflow: ellipsis; }
.picker-empty { padding: 12px; color: var(--muted); }

.lines { margin-top: 12px; }
.line {
  display: grid; grid-template-columns: 1fr 110px 130px 130px 44px; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #eef1f4;
}
.line.head { font-size: .78rem; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 6px 0; }
.line .onh { font-variant-numeric: tabular-nums; }
.line input { min-height: 44px; text-align: right; }
.line .diff { font-size: .85rem; }
.line.warn-line { background: var(--danger-soft); border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.line .lbl { display: none; }
@media (max-width: 760px) {
  .line { grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 12px 0; }
  .line.head { display: none; }
  .line .prod { grid-column: 1 / -1; display: flex; gap: 8px; align-items: flex-start; }
  .line .prod .grow { flex: 1; }
  .line .lbl { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
  .line .onh-cell { grid-column: 1 / -1; font-size: .88rem; color: var(--muted); }
  .line .rm-cell { display: none; }
  .line .rm-inline { display: inline-flex !important; }
}
.rm-inline { display: none !important; }
.stock-footer {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px;
}
.stock-footer .totals { margin-right: auto; color: var(--muted); }
@media (max-width: 899px) {
  .stock-footer.sticky {
    position: sticky; bottom: calc(var(--bottom-nav) + var(--safe-b)); background: var(--bg);
    padding: 10px 0; margin: 0; z-index: 5;
  }
  .stock-footer.sticky .btn { flex: 1; }
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin-right: auto; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 12px 12px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-body { flex: 1; }
  .modal-foot { border-radius: 0; padding-bottom: calc(12px + var(--safe-b)); position: sticky; bottom: 0; }
  .modal-foot .btn { flex: 1; }
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: 92vw; }
@media (max-width: 899px) { #toast-root { bottom: calc(var(--bottom-nav) + var(--safe-b) + 12px); } }
.toast { background: #1f2937; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 500; white-space: pre-line; animation: tin .18s ease-out; }
.toast.ok { background: var(--in); }
.toast.err { background: var(--danger); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, var(--brand-dark), var(--brand) 60%, #2a6fa8); }
.login-card { background: #fff; border-radius: 14px; padding: 28px 24px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card .logo { width: 56px; height: 56px; margin: 0 auto 10px; display: block; }
.login-card h1 { text-align: center; font-size: 1.15rem; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; font-size: .9rem; }

/* ---------- Document / print ---------- */
.doc-sheet .doc-company { text-align: center; margin-bottom: 12px; }
.doc-sheet .doc-company .cname { font-size: 1.2rem; font-weight: 800; }
.doc-sheet .doc-title { text-align: center; font-size: 1.1rem; font-weight: 700; letter-spacing: 1px; margin: 6px 0 14px; }
.doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 18px; margin-bottom: 14px; }
.doc-meta .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; }
.doc-meta .v { font-weight: 600; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; margin-top: 60px; }
.signs div { border-top: 1px solid #333; padding-top: 6px; text-align: center; font-size: .85rem; }
.stamp-void { display: inline-block; border: 3px solid var(--danger); color: var(--danger); font-weight: 800; padding: 4px 12px; transform: rotate(-4deg); letter-spacing: 2px; }

.url-big { font-size: 1.5rem; font-weight: 800; color: var(--brand); word-break: break-all; font-family: ui-monospace, Consolas, monospace; }
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin-bottom: 6px; }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .bottom-nav, .no-print, .page-head .actions, .back, .toolbar, .tabs, #toast-root, .drawer-backdrop { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .print-only { display: block; }
  table.t th, table.t td { padding: 5px 6px; }
  table.resp { display: table !important; }
  table.resp thead { display: table-header-group !important; }
  table.resp tbody { display: table-row-group !important; }
  table.resp tfoot { display: table-footer-group !important; }
  table.resp tr { display: table-row !important; }
  table.resp td { display: table-cell !important; text-align: left; }
  table.resp td::before { display: none !important; }
  a { color: inherit; }
}

/* ======================================================================
   QR scanning
   ====================================================================== */
.top-scan { margin-left: auto; }
.topbar .top-scan + .user-chip { margin-left: 10px; }
.quick .q-scan { background: #111827; }

.bottom-nav .scan-fab { position: relative; color: var(--brand); font-weight: 600; }
.bottom-nav .scan-fab .fab-circle {
  display: flex; align-items: center; justify-content: center; width: 54px; height: 54px; margin-top: -26px;
  border-radius: 50%; background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(15, 76, 129, .45);
  border: 4px solid var(--bg);
}
.bottom-nav .scan-fab .fab-circle svg { width: 26px; height: 26px; }
@media (max-width: 899px) {
  .bottom-nav a, .bottom-nav button { font-size: .68rem; }
  .top-scan span { display: none; }
  .top-scan { min-height: 38px; padding: 4px 10px; }
}

.picker { display: flex; gap: 8px; align-items: stretch; }
.picker input { flex: 1; min-width: 0; }
.picker-cam { min-height: 50px; flex: none; }
.picker-cam svg { width: 22px; height: 22px; }
@media (max-width: 480px) { .picker-cam span { display: none; } }

.input-btn { display: flex; gap: 6px; }
.input-btn input { flex: 1; min-width: 0; }
.input-btn .btn { flex: none; padding: 8px 12px; }

.scanner { margin: -4px 0; }
.qr-frame { position: relative; background: #0b1220; border-radius: 12px; overflow: hidden; min-height: 240px; }
#qrReader { width: 100%; }
#qrReader video { width: 100% !important; height: auto !important; display: block; object-fit: cover; }
#qrReader img { display: none; }
.qr-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.35); pointer-events: none; }
.qr-placeholder svg { width: 64px; height: 64px; }
.scan-status { margin: 10px 0; padding: 10px 12px; border-radius: 8px; background: var(--brand-soft); text-align: center; font-weight: 500; }
.scan-status.warn { background: var(--warn-soft); color: #6b4705; }
.scan-status.ok { background: var(--in-soft); color: var(--in); }
.scan-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.scan-tools .btn { flex: 1 1 130px; }
.scan-tools select { flex: 1 1 100%; }
.scan-manual { display: flex; gap: 8px; margin-top: 10px; }
.scan-manual input { flex: 1; min-width: 0; }

.qcard { display: flex; flex-direction: column; }
.qcard label { margin-top: 4px; }
.qcard-head { margin-bottom: 8px; }
.qname { font-size: 1.2rem; }
.qcard-stock { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #f6f8fb; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.qbig { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.qcard-meta { color: var(--muted); font-size: .88rem; margin: 6px 0 12px; min-height: 1px; }
.qsaved { background: var(--in-soft); color: var(--in); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-weight: 600; }
.qcard-missing { display: flex; gap: 10px; align-items: center; background: var(--warn-soft); color: #6b4705; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.qcard-missing svg { width: 28px; height: 28px; flex: none; }
.code-box { background: #f3f4f6; border-radius: 8px; padding: 10px 12px; word-break: break-all; margin-bottom: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.seg-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 54px; border-radius: 10px;
  border: 2px solid var(--line); background: #fff; font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer; color: var(--muted);
}
.seg-btn svg { width: 20px; height: 20px; }
.seg-btn.seg-in.active { border-color: var(--in); background: var(--in-soft); color: var(--in); }
.seg-btn.seg-out.active { border-color: var(--out); background: var(--out-soft); color: var(--out); }
.stepper { display: grid; grid-template-columns: 60px 1fr 60px; gap: 8px; }
.stepper .step { min-height: 54px; border-radius: 10px; border: 1px solid #c5ced8; background: #fff; font-size: 1.6rem; font-weight: 700; cursor: pointer; color: var(--text); }
.stepper .step:active { background: #eef1f5; }
.stepper input { min-height: 54px; text-align: center; font-size: 1.4rem; font-weight: 700; }
.stepper input.bad { border-color: var(--danger); color: var(--danger); }
.qwarn { margin-top: 8px; background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; font-weight: 600; white-space: pre-line; }
.qcard-foot { display: flex; gap: 8px; margin-top: 12px; }
.qcard-foot .btn { flex: 1; }
.btn.in:disabled, .btn.out:disabled { opacity: .45; }
.scan-landing { padding: 28px 16px; }

/* ======================================================================
   QR labels
   ====================================================================== */
.prod-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.prod-qr { width: 110px; flex: none; }
.prod-qr .qr-svg { width: 110px; height: 110px; display: block; }
.labels-layout { display: grid; grid-template-columns: 400px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1099px) { .labels-layout { grid-template-columns: 1fr; } }
.lb-results { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-bottom: 1px solid #f0f2f5; font-weight: 400; margin: 0; cursor: pointer; }
.lb-row:last-child { border-bottom: 0; }
.lb-row input { width: 20px; height: 20px; flex: none; }
.lb-row .grow, .lb-sel .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lb-results-actions { margin-top: 8px; }
.lb-copies-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.lb-sel { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f0f2f5; }
.lb-sel .lb-copies { width: 64px; min-height: 38px; text-align: center; }
.lb-checks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.lb-preview-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.lb-sheets { overflow-x: auto; padding-bottom: 10px; }
#lbSelected { max-height: 280px; overflow-y: auto; }
@media screen and (min-width: 1100px) {
  .labels-preview { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
}

.lb-sheet { background: #fff; box-sizing: border-box; color: #000; font-family: Arial, "Noto Sans", "Noto Sans Khmer", "Khmer UI", sans-serif; }
.lb-sheet.a4 {
  width: 210mm; height: 297mm; padding-top: var(--top); display: grid;
  grid-template-columns: repeat(var(--cols), var(--lw)); grid-auto-rows: var(--lh);
  justify-content: center; align-content: start; overflow: hidden;
}
.lb-sheet.thermal { width: var(--lw); height: var(--lh); overflow: hidden; }
.lb-label {
  width: var(--lw); height: var(--lh); box-sizing: border-box; padding: 2.5mm;
  display: flex; align-items: center; gap: 2mm; overflow: hidden;
}
.lb-label .lb-qr { width: var(--qr); height: var(--qr); flex: none; display: block; }
.lb-text { flex: 1; min-width: 0; font-size: 7.5pt; line-height: 1.2; }
.lb-company { font-size: 5.5pt; text-transform: uppercase; letter-spacing: .2px; color: #333; margin-bottom: .6mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-name { font-weight: 700; font-size: 9pt; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.lb-sku { font-family: Consolas, "Courier New", monospace; font-size: 8pt; font-weight: 700; margin-top: .8mm; word-break: break-all; }
.lb-meta { font-size: 7pt; color: #222; margin-top: .4mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-price { font-size: 10pt; font-weight: 800; margin-top: .6mm; }
.lb-label.small .lb-name { font-size: 7pt; -webkit-line-clamp: 2; }
.lb-label.small .lb-sku { font-size: 6.5pt; }
.lb-label.small .lb-meta, .lb-label.small .lb-company { font-size: 5.5pt; }
.lb-label.small .lb-price { font-size: 8pt; }
.lb-label.big { padding: 5mm; gap: 4mm; }
.lb-label.big .lb-name { font-size: 15pt; -webkit-line-clamp: 4; }
.lb-label.big .lb-sku { font-size: 12pt; }
.lb-label.big .lb-meta { font-size: 11pt; }
.lb-label.big .lb-price { font-size: 16pt; }
.lb-label.big .lb-company { font-size: 8pt; }

@media screen {
  .lb-sheet { box-shadow: 0 2px 10px rgba(0,0,0,.18); margin: 0 auto 16px; }
  .lb-label { outline: 1px dashed #d4dae2; outline-offset: -1px; }
  .lb-label.empty { background: repeating-linear-gradient(45deg, #fafafa, #fafafa 6px, #f0f0f0 6px, #f0f0f0 12px); }
}
@media screen and (max-width: 899px) {
  .lb-sheet.a4 { zoom: .42; }
  .lb-sheet.thermal { zoom: 1.4; }
}
@media print {
  .labels-layout { display: block; }
  .labels-side, .lb-preview-head { display: none !important; }
  .lb-sheets { overflow: visible; padding: 0; }
  .lb-sheet { margin: 0; box-shadow: none; zoom: 1; break-after: page; page-break-after: always; }
  .lb-sheet:last-of-type { break-after: auto; page-break-after: auto; }
  .lb-sheet.a4 { height: 296mm; }
  .lb-sheet.thermal { height: calc(var(--lh) - 0.3mm); }
  .lb-label.empty { background: none; }
  .lb-sheet, .lb-label { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media screen and (min-width: 900px) and (max-width: 1700px) { .lb-sheet.a4 { zoom: .72; } }

.stock-footer .totals.neg { color: var(--danger); font-weight: 700; cursor: pointer; text-decoration: underline; }

/* ---------- Inactivity warning ---------- */
.idle-warn { position: fixed; inset: 0; z-index: 300; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.idle-box { background: #fff; border-radius: 14px; padding: 22px 20px; max-width: 360px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.idle-box .idle-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 6px; }
.idle-box .idle-secs { font-size: 1.3rem; color: var(--danger); }
.idle-box .btn { margin-top: 16px; }

/* ======================================================================
   v1.6 - Stock In details, FIFO PO#, import
   ====================================================================== */
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .form-grid.four { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .form-grid.four { grid-template-columns: 1fr; } }

.tabs a.tab { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; text-decoration: none; }
.tabs a.tab svg { width: 18px; height: 18px; }
.tabs a.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a.tab:hover { text-decoration: none; color: var(--brand); }

.line.in-line { grid-template-columns: minmax(170px, 2fr) 86px repeat(4, minmax(78px, 1fr)) repeat(2, minmax(96px, 1.2fr)) 44px; gap: 8px; }
.line input.txt { text-align: left; }
@media (max-width: 1250px) {
  .line.in-line { grid-template-columns: repeat(3, 1fr); gap: 6px 10px; padding: 12px 0; }
  .line.in-line.head { display: none; }
  .line.in-line .prod { grid-column: 1 / -1; display: flex; gap: 8px; align-items: flex-start; }
  .line.in-line .prod .grow { flex: 1; }
  .line.in-line .lbl { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
  .line.in-line .onh-cell { grid-column: 1 / -1; font-size: .88rem; color: var(--muted); }
  .line.in-line .rm-cell { display: none; }
  .line.in-line .rm-inline { display: inline-flex !important; }
}
@media (max-width: 560px) { .line.in-line { grid-template-columns: repeat(2, 1fr); } }

.onhand-cell { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.fifo { font-size: .75rem; font-weight: 500; white-space: normal; text-align: right; padding: 1px 6px; border-radius: 6px; }
.fifo b { font-weight: 700; }
.fifo.fifo-po { background: var(--brand-soft); color: var(--brand); }
.fifo.fifo-open { background: var(--in-soft); color: var(--in); }
.fifo.fifo-none { background: #eef1f4; color: var(--muted); }
.fifo-box { margin: 8px 0 6px; padding: 8px 12px; border-radius: 8px; border-left: 4px solid var(--brand); background: var(--brand-soft); }
.fifo-box.fifo-open { border-left-color: var(--in); background: var(--in-soft); }
.fifo-box.fifo-none { border-left-color: #9aa5b1; background: #f1f3f6; }
.fifo-box b { font-size: 1.05rem; }
.qcard .fifo-box { margin: 8px 0 4px; }
.psub.block, span.block { display: block; }
tr.row-bad td { background: var(--danger-soft); }
.import-pick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.stat .stat-note { font-size: .74rem; color: var(--warn); margin-top: 4px; line-height: 1.3; }

/* ---------- Password rules checklist ---------- */
.pw-rules { list-style: none; margin: 6px 0 0; padding: 0; font-size: .82rem; color: var(--muted); display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.pw-rules li::before { content: "○ "; }
.pw-rules li.ok { color: var(--in); }
.pw-rules li.ok::before { content: "✓ "; font-weight: 700; }
@media (max-width: 480px) { .pw-rules { grid-template-columns: 1fr; } }

/* ======================================================================
   Month-end stock report (Finance)
   ====================================================================== */
.me-head { text-align: center; margin-bottom: 14px; }
.me-head h2 { margin: 2px 0; font-size: 1.25rem; text-transform: uppercase; letter-spacing: .5px; }
.me-company { font-weight: 800; font-size: 1.05rem; }
.me-period { color: var(--muted); }
.me-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; margin: 12px 0 16px; }
.me-recon { width: 100%; border-collapse: collapse; }
.me-recon td { padding: 6px 8px; border-bottom: 1px solid var(--line, #e5e7eb); }
.me-recon td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.me-recon tr.me-total td { font-weight: 800; border-top: 2px solid #333; border-bottom: 3px double #333; }
.me-kpis { display: grid; gap: 8px; align-content: start; }
.me-kpis div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 8px 12px; border: 1px solid var(--line, #e5e7eb); border-radius: 8px; }
.me-kpis span { color: var(--muted); font-size: .88rem; }
.me-kpis b { font-size: 1.05rem; white-space: nowrap; }
.me-notes { margin-top: 12px; line-height: 1.5; }
@media (max-width: 760px) { .me-grid { grid-template-columns: 1fr; } }
@media print {
  body:has(.me-report) .page-head { display: none !important; }
  .me-report { font-size: 10.5px; }
  .me-report .table-wrap { overflow: visible !important; }
  .me-table { width: 100%; font-size: 9.5px; }
  .me-table th { white-space: normal; font-size: 8.5px; vertical-align: bottom; }
  .me-table th, .me-table td { padding: 3px 4px !important; }
  .me-table th.num, .me-table td.num { text-align: right !important; white-space: nowrap; }
  .me-table td.main-cell { white-space: normal; }
  .me-recon td { padding: 4px 6px; }
  .me-kpis div { padding: 5px 8px; }
  .me-kpis span { font-size: 10px; }
  .me-kpis b { font-size: 12px; }
  .me-grid { margin: 8px 0 10px; }
  .me-table tr { break-inside: avoid; }
  .me-kpis div { border-color: #999; }
  .me-report .info { border: 1px solid #999; background: none; }
  .me-report .signs { margin-top: 40px; display: grid; }
}

/* Products list: Void / Delete buttons on each row */
td.row-actions { white-space: nowrap; text-align: right; }
td.row-actions .btn { margin-left: 4px; }
td.row-actions .btn svg { width: 16px; height: 16px; }
@media (max-width: 760px) { table.resp td.row-actions { display: flex; justify-content: flex-end; gap: 6px; padding-top: 4px; } table.resp td.row-actions .btn { margin: 0; } }
