/* Inventory frontend — mobile-first, dark-on-light */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1a1d21;
  --ink-soft: #5b6470;
  --line: #e2e5ea;
  --accent: #1f6feb;
  --accent-dark: #1857b8;
  --danger: #c92a2a;
  --danger-bg: #fdecec;
  --warn: #b7791f;
  --warn-bg: #fdf3e0;
  --ok: #1e7e34;
  --ok-bg: #e6f4ea;
  --radius: 10px;
  --tap: 48px; /* min touch target */
  --topbar-h: 56px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--ink); color: #fff;
}
#topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-badge { font-size: 13px; color: #cfd6de; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }

/* ---------- Main ---------- */
#view { max-width: 860px; margin: 0 auto; padding: 16px 14px 24px; }
.page-title { font-size: 22px; font-weight: 700; margin: 4px 0 14px; }
.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }

/* ---------- Bottom nav ---------- */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--ink-soft);
  font-size: 12px; font-weight: 600; min-height: var(--nav-h);
}
#bottomnav a .nav-icon { font-size: 20px; line-height: 1; }
#bottomnav a.active { color: var(--accent); }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { background: #f0f3f7; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row + .row { margin-top: 8px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.strong { font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.stat .label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .value.money { font-size: 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: #e7f0fd; color: var(--accent-dark); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
input[type="text"], input[type="number"], input[type="password"], input[type="tel"],
input[type="search"], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px; font-size: 16px; /* 16px avoids iOS zoom */
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.checkbox-row input[type="checkbox"] { width: 22px; height: 22px; }

.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row .field { flex: 1 1 140px; margin-bottom: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 10px 18px;
  border: 1px solid transparent; border-radius: 8px;
  font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--ink);
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { border-color: var(--line); background: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); background: #fafbfc; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Product list ---------- */
.product-row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.product-thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: #eef0f3; flex: none; }
.product-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-size: 11px; }
.product-main { flex: 1; min-width: 0; }
.product-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-sub { font-size: 13px; color: var(--ink-soft); }
.product-qoh { text-align: right; flex: none; }
.qoh-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Detail ---------- */
.detail-img { width: 100%; max-height: 320px; object-fit: contain; background: #eef0f3; border-radius: var(--radius); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 15px; }
.kv dt { color: var(--ink-soft); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.img-preview { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin-bottom: 10px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 16px); z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; border-radius: 8px; padding: 12px 14px;
  font-size: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 420px; }
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--ink-soft); }
.modal .btn-row { margin-top: 4px; }

/* ---------- Scanner ---------- */
.scanner-backdrop { position: fixed; inset: 0; z-index: 150; background: #000; display: flex; flex-direction: column; }
.scanner-backdrop video { flex: 1; width: 100%; object-fit: cover; background: #000; }
.scanner-bar { padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); background: #111; display: flex; gap: 10px; }
.scanner-bar .btn { flex: 1; }
.scanner-msg { color: #fff; text-align: center; padding: 10px; font-size: 14px; background: #111; }
.scanner-frame {
  position: absolute; left: 50%; top: 38%; width: 72%; height: 120px;
  transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.85); border-radius: 8px;
  pointer-events: none;
}

/* ---------- Labels ---------- */
.label-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.label-controls .field { flex: 1 1 150px; margin-bottom: 0; }
.label-sheet { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.label {
  border: 1px dashed #999; border-radius: 4px; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px; overflow: hidden; page-break-inside: avoid; break-inside: avoid;
  text-align: center;
}
.label.size-1x1 { width: 1in; height: 1in; }
.label.size-2x1 { width: 2in; height: 1in; }
.label.size-4x2 { width: 4in; height: 2in; }
.label .lbl-brand { font-weight: 700; line-height: 1.15; overflow: hidden; text-transform: uppercase; letter-spacing: .3px; }
.label .lbl-name { font-weight: 700; line-height: 1.15; overflow: hidden; }
.label .lbl-sub { color: #333; line-height: 1.15; }
.label.size-1x1 .lbl-brand { font-size: 7pt; max-height: 1.2em; }
.label.size-1x1 .lbl-name { font-size: 8pt; max-height: 2.3em; }
.label.size-1x1 .lbl-sub { font-size: 7pt; }
.label.size-1x1 svg { max-width: 0.92in; height: 0.34in; }
.label.size-2x1 .lbl-brand { font-size: 8pt; max-height: 1.2em; }
.label.size-2x1 .lbl-name { font-size: 9pt; max-height: 2.3em; }
.label.size-2x1 .lbl-sub { font-size: 8pt; }
.label.size-2x1 svg { max-width: 1.9in; height: 0.42in; }
.label.size-4x2 .lbl-brand { font-size: 11pt; max-height: 1.2em; }
.label.size-4x2 .lbl-name { font-size: 13pt; max-height: 2.3em; }
.label.size-4x2 .lbl-sub { font-size: 11pt; }
.label.size-4x2 svg { max-width: 3.8in; height: 0.8in; }
.label svg { display: block; }

/* ---------- Loading / empty ---------- */
.loading { text-align: center; padding: 40px 16px; color: var(--ink-soft); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 32px 16px; color: var(--ink-soft); }
.error-box { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3c2c2; border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-wrap .page-title { text-align: center; }
.pin-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.pin-alert { background: var(--warn-bg); border: 1px solid #ecd9a8; color: #7a5410; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }

/* ---------- Misc ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.pager .btn { min-width: 110px; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.menu-list .card { margin-bottom: 8px; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- Print: labels only ---------- */
@page { size: auto; margin: 6mm; }
@media print {
  body { padding: 0; background: #fff; }
  .no-print { display: none !important; }
  #view { max-width: none; padding: 0; margin: 0; }
  .label { border: none; }
  .label-sheet { gap: 4mm; }
}
