/* Inventory Lab - one stylesheet, no framework. Colours live in the variables below. */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e4e8f0;
  --text: #1c2434;
  --muted: #667085;
  --brand: #4f46e5;
  --brand-2: #0ea5a4;
  --brand-soft: #eef2ff;
  --side: #111827;
  --side-2: #1f2937;
  --side-text: #c7cdd8;
  --ok: #12a150;      --ok-soft: #e7f7ee;
  --warn: #c27803;    --warn-soft: #fff6e0;
  --bad: #d92d20;     --bad-soft: #fdecea;
  --info: #2563eb;    --info-soft: #e8f0fe;
  --violet: #7c3aed;  --violet-soft: #f1eafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Thai", sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
code, .mono { font-family: "Cascadia Code", Consolas, "SFMono-Regular", monospace; font-size: 12.5px; }
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand-logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 6px 16px rgba(79, 70, 229, .45); }
.brand-logo .icon { color: #fff; }
.brand b { font-size: 15px; display: block; }
.brand small { color: #8b93a3; font-size: 11.5px; }
.nav-group { margin: 14px 0 4px; padding: 0 10px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #6b7384; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-text); font-size: 13.5px; }
.nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav a.active { background: linear-gradient(90deg, rgba(79, 70, 229, .35), rgba(79, 70, 229, .12)); color: #fff; }
.nav a .no { margin-left: auto; font-size: 10.5px; color: #6b7384; font-family: Consolas, monospace; }
.nav a.active .no { color: #c7d2fe; }
.nav .badge-count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 460px; position: relative; }
.topbar .search input { width: 100%; padding-left: 36px; }
.topbar .search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.menu-btn { display: none; }

.page { padding: 24px 28px 48px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .lead { color: var(--muted); margin-top: 4px; max-width: 760px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.feature-no { display: inline-block; font-family: Consolas, monospace; font-size: 11.5px; background: var(--brand-soft); color: var(--brand); padding: 2px 8px; border-radius: 99px; margin-right: 6px; vertical-align: middle; font-weight: 600; }

/* ---------- cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head .more { margin-left: auto; font-size: 13px; }
.card-body { padding: 16px 18px; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.kpi .kpi-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.kpi .kpi-icon .icon { width: 21px; height: 21px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.tone-brand { background: var(--brand-soft); color: var(--brand); }
.tone-ok { background: var(--ok-soft); color: var(--ok); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:hover { background: #fafbff; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
table.data td.sku { font-family: Consolas, monospace; font-size: 12.5px; white-space: nowrap; }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
.dim { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 34px 12px !important; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-gray { background: #eef0f4; color: #505a6b; }
.b-RECEIPT, .b-IN, .b-ADJUST_IN { background: var(--ok-soft); color: var(--ok); }
.b-ISSUE, .b-OUT, .b-ADJUST_OUT { background: var(--bad-soft); color: var(--bad); }
.b-TRANSFER, .b-TRANSFER_IN, .b-TRANSFER_OUT { background: var(--info-soft); color: var(--info); }
.b-ADJUSTMENT { background: var(--violet-soft); color: var(--violet); }

/* ---------- forms ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input:not([type]), select, textarea {
  border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
textarea { resize: vertical; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #344054; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.field .err, .err { color: var(--bad); font-size: 12px; margin-top: 4px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid #d0d5dd;
  background: #fff; cursor: pointer; font-weight: 600; font-size: 13.5px; color: #344054; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: #f9fafb; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3); }
.btn-primary:hover { background: #4338ca; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #0f8a44; }
.btn-danger { color: var(--bad); border-color: #f5c2bd; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; }
.inline { display: inline; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar .f { min-width: 150px; }
.toolbar .f.grow { flex: 1; min-width: 220px; }
.toolbar label { font-size: 11.5px; color: var(--muted); }
.tabs { display: inline-flex; background: #eef0f4; padding: 3px; border-radius: 9px; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: #505a6b; font-weight: 600; font-size: 13px; }
.tabs a.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; }

/* ---------- alerts / flash ---------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b7e4c7; color: #0b6b35; }
.flash.bad { background: var(--bad-soft); border-color: #f5c2bd; color: #a3241a; }
.flash.info { background: var(--info-soft); border-color: #c4d7fb; color: #1d4ed8; }
.flash.warn { background: var(--warn-soft); border-color: #f6dd9b; color: #8a5300; }

/* ---------- bars & charts ---------- */
.bar { height: 8px; background: #eef0f4; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.bar.ok > span { background: var(--ok); } .bar.warn > span { background: #f5a524; } .bar.bad > span { background: var(--bad); } .bar.info > span { background: var(--info); }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 8px; }
.chart .day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart .pair { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.chart .pair span { width: 10px; border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .in { background: var(--ok); } .chart .out { background: #f97066; }
.chart .lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; }

/* ---------- document form lines ---------- */
.lines td { vertical-align: top; }
.lines td input, .lines td select, .lines td textarea { font-size: 13px; padding: 6px 8px; }
.lines .col-product { min-width: 240px; }
.lines .col-qty { width: 92px; }
.lines .col-cost { width: 120px; }
.lines .stack > * + * { margin-top: 6px; }
.lines .meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.serial-picks { display: flex; flex-wrap: wrap; gap: 4px; max-height: 92px; overflow-y: auto; }
.serial-picks label { display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px;
  font: 12px Consolas, monospace; margin: 0; cursor: pointer; color: var(--text); }
.serial-picks label:has(input:checked) { background: var(--brand-soft); border-color: #c7d2fe; }
.serial-picks input { width: auto; margin: 0; }
.type-banner { display: flex; gap: 14px; align-items: center; padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px; color: #fff; }
.type-banner .icon { width: 26px; height: 26px; }
.type-RECEIPT { background: linear-gradient(120deg, #0f9f6e, #12b981); }
.type-ISSUE { background: linear-gradient(120deg, #dc4c3f, #f97066); }
.type-TRANSFER { background: linear-gradient(120deg, #2563eb, #4f8df7); }
.type-ADJUSTMENT { background: linear-gradient(120deg, #6d28d9, #9061f9); }
.type-banner p { margin: 2px 0 0; opacity: .9; font-size: 13px; }

/* ---------- bins grid ---------- */
.bins { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.bin { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); position: relative; }
.bin .code { font: 600 13px Consolas, monospace; }
.bin .type { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.bin.off { opacity: .5; }
.bin .bar { margin-top: 8px; }
.zone-title { margin: 18px 0 8px; font-weight: 650; color: #344054; }

/* ---------- labels ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.label-card { border: 1px dashed #c5cbd6; border-radius: 10px; padding: 12px; text-align: center; background: #fff; break-inside: avoid; }
.label-card .name { font-weight: 600; font-size: 12.5px; margin: 4px 0; min-height: 34px; }
.label-card img.code128 { width: 100%; height: 64px; object-fit: contain; }
.label-card .row { display: flex; gap: 10px; align-items: center; justify-content: center; }
.label-card img.qr { width: 84px; height: 84px; }

/* ---------- learn ---------- */
.learn-table td:first-child { white-space: nowrap; }
.callout { border-left: 4px solid var(--brand); background: var(--brand-soft); padding: 12px 16px; border-radius: 8px; }
pre.sql { background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 12.5px; margin: 8px 0 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(circle at 20% 20%, #6366f1, transparent 55%), radial-gradient(circle at 80% 70%, #14b8a6, transparent 50%), #111827;
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h1 { font-size: 34px; margin-top: 18px; }
.login-art p { color: #cbd5e1; max-width: 460px; font-size: 15px; }
.login-art .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; max-width: 520px; }
.login-art .chips span { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .15); padding: 4px 10px; border-radius: 99px; font-size: 12.5px; }
.login-form { display: grid; place-items: center; padding: 40px; background: var(--surface); }
.login-form form { width: 100%; max-width: 360px; }
.demo-users { margin-top: 18px; font-size: 13px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.demo-users button { margin-top: 6px; }

.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -270px; width: 252px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-flex; }
  .g2 { grid-template-columns: 1fr; }
  .page { padding: 18px 16px 40px; }
  .topbar { padding: 10px 16px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; }
  .card { border: 0; box-shadow: none; }
  body { background: #fff; }
}
.lines select[data-f=locationId], .lines select[data-f=toLocationId], .lines select[data-f=lotId], .lines select[data-f=dir] { min-width: 150px; }
.lines input[data-f=lotNo] { min-width: 170px; }
