/* INVENTARIS – stock count app */
:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dde3ea;
  --brand: #0f2240;
  --brand-2: #16305a;
  --accent: #f26b1d;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --grey: #6b7280;
  --grey-bg: #e5e7eb;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.4; }
a { color: var(--info); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
p { margin: .3rem 0 .6rem; }
small, .muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 12px; background: var(--brand); color: #fff; padding: 0 14px; height: 54px; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 5px; background: linear-gradient(90deg, #fff 0 18%, transparent 18% 28%, #fff 28% 36%, transparent 36% 44%, var(--accent) 44% 66%, transparent 66% 74%, #fff 74% 82%, transparent 82% 88%, #fff 88%); }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: var(--brand-2); color: #fff; }
.nav a.active { color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
.net { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; flex: none; }
.net.off { background: var(--bad); box-shadow: 0 0 0 4px rgba(220,38,38,.3); }
.net.pending { background: var(--warn); }
@media (max-width: 640px) {
  .brand-name { display: none; }
  .nav a { padding: 8px 9px; font-size: 14px; }
}

/* layout */
.view { max-width: 1400px; margin: 0 auto; padding: 14px; }
.view.narrow { max-width: 820px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.card.tight { padding: 10px 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 10px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.pagehead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.pagehead h1 { margin: 0; }
.pagehead .spacer { flex: 1; }

/* fields */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, label.lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
input, select, textarea, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); font-size: 16px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(242,107,29,.45); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; min-height: 44px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #e05f14; }
.btn.dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 10px 14px; font-weight: 700; cursor: pointer; min-height: 44px; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.seg button.on.recount { background: var(--warn); }
.setup { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 10px; align-items: end; }
@media (max-width: 720px) { .setup { grid-template-columns: 1fr 1fr; } .setup .field:last-child { grid-column: 1 / -1; } }

/* scan box */
.scanbox { border: 3px solid var(--line); transition: border-color .15s, box-shadow .15s; }
.scanbox.flash-ok { border-color: var(--ok); box-shadow: 0 0 0 4px rgba(21,128,61,.2); }
.scanbox.flash-bad { border-color: var(--bad); box-shadow: 0 0 0 4px rgba(220,38,38,.2); }
.scanbox.flash-warn { border-color: var(--warn); box-shadow: 0 0 0 4px rgba(217,119,6,.25); }
.scanbox.flash-grey { border-color: var(--grey); }
.scanbox.recount { border-color: var(--warn); }
.scanrow { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; }
@media (max-width: 520px) { .scanrow { grid-template-columns: 1fr 90px; } .scanrow .btn { grid-column: 1 / -1; } }
#scan { font-size: 22px; min-height: 58px; font-family: var(--mono); font-weight: 600; letter-spacing: .02em; }
#qty { font-size: 20px; min-height: 58px; text-align: center; }
.scanrow .btn { min-height: 58px; font-size: 18px; }
.feedback { margin-top: 10px; border-radius: 10px; padding: 12px 14px; min-height: 64px; display: flex; align-items: center; gap: 12px; background: #f8fafc; color: var(--muted); border-left: 8px solid var(--line); }
.feedback .fb-icon { font-size: 28px; line-height: 1; font-weight: 900; flex: none; width: 34px; text-align: center; }
.feedback .fb-main { font-size: 18px; font-weight: 800; }
.feedback .fb-sub { font-size: 14px; }
.feedback.ok { background: var(--ok-bg); color: #14532d; border-left-color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: #7f1d1d; border-left-color: var(--bad); }
.feedback.warn { background: var(--warn-bg); color: #78350f; border-left-color: var(--warn); }
.feedback.grey { background: var(--grey-bg); color: #1f2937; border-left-color: var(--grey); }
.feedback.info { background: var(--info-bg); color: #1e3a8a; border-left-color: var(--info); }
.feedback .fb-qty { margin-left: auto; font-size: 26px; font-weight: 900; white-space: nowrap; }
.rules { background: var(--warn-bg); border-left: 6px solid var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; color: #78350f; }
.rules ul { margin: 4px 0 0 18px; padding: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); min-width: 0; }
.stat .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; overflow-wrap: anywhere; }
.stat .val.small { font-size: 16px; }
.stat.ok .val { color: var(--ok); }
.stat.bad .val { color: var(--bad); }
.stat.warn .val { color: var(--warn); }
.stat.grey .val { color: var(--grey); }
.stat.accent { background: var(--brand); color: #fff; }
.stat.accent .lbl { color: #cbd5e1; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--grey-bg); color: #374151; }
.badge.ok, .badge.OK, .badge.DONE { background: var(--ok-bg); color: var(--ok); }
.badge.bad, .badge.NOT_FOUND, .badge.RECOUNT { background: var(--bad-bg); color: var(--bad); }
.badge.warn, .badge.CHECK, .badge.CHECK_QTY, .badge.TO_DO, .badge.NO_CODE { background: var(--warn-bg); color: #92400e; }
.badge.grey, .badge.ARCHIVED, .badge.Below_threshold { background: var(--grey-bg); color: #374151; }
.badge.info, .badge.recount { background: var(--info-bg); color: #1e40af; }
.badge.first { background: #e0e7ff; color: #3730a3; }

/* tables */
.wrap { overflow: auto; max-width: 100%; -webkit-overflow-scrolling: touch; border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
.tbl th, .tbl td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: #f1f5f9; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tr.clickable { cursor: pointer; }
.tbl td.code { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.tbl td.desc { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl td.actions { white-space: nowrap; text-align: right; }
.tbl tr.deleted td { color: var(--muted); text-decoration: line-through; }
.tbl tr.deleted td.actions { text-decoration: none; }
.tbl tr.pending td { color: var(--info); font-style: italic; }
.tbl tr.todo td { background: #fffbeb; }
.tbl .sticky-col { position: sticky; left: 0; background: #fff; z-index: 2; }
.tbl th.sticky-col { z-index: 3; background: #f1f5f9; }
.tbl.compact td, .tbl.compact th { padding: 5px 7px; font-size: 13px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.more { text-align: center; padding: 10px; }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input, .filters select { width: auto; min-width: 140px; flex: 1 1 160px; max-width: 320px; }
.filters .search { flex: 2 1 220px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--accent); }

/* location cards */
.loccards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.loccard { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; border-left: 6px solid var(--line); text-decoration: none; color: inherit; display: block; }
.loccard.active { border-left-color: var(--ok); }
.loccard.recount { border-left-color: var(--warn); }
.loccard:hover { box-shadow: 0 6px 18px rgba(15,23,42,.12); }
.loccard .name { font-weight: 800; font-size: 15px; margin-bottom: 6px; }
.loccard .big { font-size: 26px; font-weight: 900; line-height: 1; }
.loccard .sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.loccard .names { font-size: 12px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: min(520px, calc(100% - 24px)); }
.toast { background: var(--brand); color: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); display: flex; align-items: center; gap: 10px; animation: pop .15s ease-out; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.toast.warn { background: var(--warn); }
.toast .btn { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.3); color: #fff; margin-left: auto; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 150; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal[hidden] { display: none; }
.modal .box { background: #fff; border-radius: 14px; width: min(760px, 100%); max-height: calc(100vh - 28px); overflow: auto; padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal .box.small { width: min(420px, 100%); }
.modal .box h2 { margin-bottom: 10px; }
.modal .mbtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

/* gate */
.gate { position: fixed; inset: 0; background: var(--brand); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate[hidden] { display: none; }
.gate-box { background: #fff; border-radius: 14px; padding: 24px; width: min(380px, 100%); }
.gate-title { font-weight: 900; font-size: 20px; margin-bottom: 4px; }
.gate-box input { margin: 10px 0; font-size: 20px; text-align: center; letter-spacing: .1em; }
.gate-err { color: var(--bad); font-weight: 600; min-height: 1.4em; margin-top: 8px; text-align: center; }

/* admin */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.admin-grid .card { margin: 0; }
.admin-grid .card.span { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.loclist { display: flex; flex-direction: column; gap: 6px; }
.loclist .item { display: flex; gap: 6px; align-items: center; }
.loclist .item input { flex: 1; }
.loclist .item .btn { padding: 6px 9px; min-height: 36px; }
.mapping { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.notice { padding: 10px 12px; border-radius: 9px; background: var(--info-bg); color: #1e3a8a; margin: 8px 0; }
.notice.warn { background: var(--warn-bg); color: #78350f; }
.notice.bad { background: var(--bad-bg); color: #7f1d1d; }
.notice.ok { background: var(--ok-bg); color: #14532d; }
code { font-family: var(--mono); background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.pendingbar { background: var(--info-bg); color: #1e3a8a; padding: 8px 12px; border-radius: 9px; margin-bottom: 10px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.pendingbar.off { background: var(--bad-bg); color: #7f1d1d; }

/* suggestions while typing */
.codewrap { position: relative; min-width: 0; }
.sugg { position: absolute; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 0; list-style: none; background: #fff; border: 2px solid var(--accent); border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.22); z-index: 40; max-height: 340px; overflow-y: auto; }
.sugg li { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 15px; }
.sugg li:last-child { border-bottom: 0; }
.sugg li b { display: block; font-family: var(--mono); }
.sugg li small { color: var(--muted); }
.sugg li.act, .sugg li:hover { background: #fff3e8; }
.sugg li.nohit { cursor: default; }
.sugg mark { background: #ffe58a; padding: 0; }
.sugg.hidden { display: none; }

/* large qty confirmation */
.confirm { background: var(--warn-bg); border: 3px solid var(--warn); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.confirm .big { font-size: 20px; font-weight: 800; color: #78350f; }
.confirm .sub { margin: 6px 0 12px; color: #78350f; }
.confirm .row .btn { flex: 1; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin-top: 10px; cursor: pointer; }
.chk input { width: 20px; height: 20px; min-height: 0; margin: 0; }
.done { color: var(--ok); font-weight: 800; }
.badge.typed { background: #e0e7ff; color: #3730a3; }
.badge.um { background: #ede9fe; color: #5b21b6; }
.tbl tr.replaced td { color: var(--muted); }
.bar { height: 8px; background: var(--grey-bg); border-radius: 4px; overflow: hidden; min-width: 60px; margin: 6px 0 2px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.qrbox { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qrbox img { border-radius: 8px; background: #fff; }
.url { font-size: 18px; font-weight: 800; color: var(--brand); word-break: break-all; }
.bcform { display: grid; grid-template-columns: 1fr 1.6fr auto auto; gap: 10px; align-items: end; }
@media (max-width: 800px) { .bcform { grid-template-columns: 1fr; } }

/* print */
@media print {
  .topbar, .filters, .btn, .toasts, .modal, .tabs, .noprint, .setup, .scanbox { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .view { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; }
  .wrap { overflow: visible; }
  .tbl th { position: static; }
  .tbl td.desc { white-space: normal; max-width: none; }
  .stats { grid-template-columns: repeat(6, 1fr); }
}
