:root {
  --primary: #0f766e;
  --accent: #f59e0b;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17191c;
  --muted: #5f6670;
  --border: #dde1e6;
  --danger: #c2410c;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e22;
    --surface-2: #23272c;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #30353b;
    --danger: #fb923c;
    --ok: #4ade80;
    --warn: #fbbf24;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 40px; color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand img { max-height: 36px; max-width: 120px; object-fit: contain; }
.brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.brand .name { font-weight: 650; line-height: 1.2; }
.brand .tag { font-size: 11px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 14px 10px 4px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.topbar .scan { flex: 1; max-width: 520px; position: relative; }
.topbar .scan input { padding-left: 34px; }
.topbar .scan svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--muted); }
.topbar .loc { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar .menu-btn { display: none; }
.content { padding: 24px; max-width: 1400px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar .loc label { display: none; }
  .topbar .loc select { max-width: 120px; }
  .topbar .scan { min-width: 0; }
}

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid > .card { align-self: start; }
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card .card-head h2 { margin: 0; }
.card .card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.warn .value { color: var(--warn); }

/* Forms */
label { display: block; font-weight: 550; font-size: 12.5px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input, select, textarea { width: 100%; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 0; border-color: var(--primary); }
input[type='checkbox'], input[type='radio'] { width: auto; }
input[type='color'] { padding: 2px; height: 36px; width: 60px; }
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 450; }
.inline { display: flex; gap: 8px; align-items: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters > input, .filters > select { width: auto; min-width: 150px; }
.filters > input[type='search'] { flex: 1; min-width: 220px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.icon { padding: 6px 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.linkish { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 650; background: var(--surface-2); }
td input { padding: 5px 8px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.primary { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(640px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgb(0 0 0 / 0.3); }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal header h2 { margin: 0; }
.modal header button { margin-left: auto; }
.modal .body { padding: 18px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }

/* Toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: toast-in 0.15s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* Picker */
.picker { position: relative; }
.picker .results { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); max-height: 320px; overflow: auto; }
.picker .results button { display: flex; width: 100%; text-align: left; gap: 10px; padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--border); color: inherit; font: inherit; cursor: pointer; }
.picker .results button:hover, .picker .results button.hl { background: var(--surface-2); }
.picker .results .sku { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.picker .results .qty { margin-left: auto; color: var(--muted); white-space: nowrap; }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-width: 560px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .reticle { position: absolute; inset: 18%; border: 3px solid rgb(255 255 255 / 0.85); border-radius: 12px; box-shadow: 0 0 0 999px rgb(0 0 0 / 0.25); }
.scanner .status { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 12px; color: #fff; background: rgb(0 0 0 / 0.5); font-size: 12px; }
.scan-flash { animation: flash 0.4s; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--ok); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Item detail */
.item-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.qr-thumb { width: 96px; height: 96px; background: #fff; border-radius: 8px; padding: 4px; border: 1px solid var(--border); }
.attr-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.attr-list dt { color: var(--muted); }
.attr-list dd { margin: 0; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.bar-chart .bar { flex: 1; background: color-mix(in srgb, var(--primary) 70%, transparent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bar-chart .bar:hover { background: var(--primary); }

/* Setup / login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(460px, 100%); }
.auth-card .brand { justify-content: center; padding-bottom: 20px; }
.preset-opt { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; font-weight: 450; }
.preset-opt:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 6%, transparent); }

/* Labels (print) */
.label-sheet { display: flex; flex-wrap: wrap; gap: 4mm; background: #fff; color: #000; padding: 4mm; }
.qr-label { background: #fff; color: #000; border: 1px dashed #bbb; display: flex; gap: 2mm; padding: 1.5mm; overflow: hidden; break-inside: avoid; font-family: Arial, Helvetica, sans-serif; }
.qr-label img { height: 100%; aspect-ratio: 1; flex: none; }
.qr-label .txt { display: flex; flex-direction: column; min-width: 0; justify-content: center; }
.qr-label .ln1 { font-weight: 700; line-height: 1.1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.qr-label .ln2 { font-family: var(--mono); line-height: 1.1; }
.qr-label .ln3 { font-weight: 700; }
.qr-label.t-50x25 { width: 50mm; height: 25mm; font-size: 7.5pt; }
.qr-label.t-62x29 { width: 62mm; height: 29mm; font-size: 8pt; }
.qr-label.t-38x25 { width: 38mm; height: 25mm; font-size: 6.5pt; }
.qr-label.t-100x50 { width: 100mm; height: 50mm; font-size: 12pt; }
.qr-label.t-a4-3x8 { width: 63.5mm; height: 33.9mm; font-size: 9pt; }
.qr-label.t-a4-3x8 .ln1 { -webkit-line-clamp: 3; }

@media print {
  body { background: #fff; }
  .no-print, .sidebar, .topbar, #toasts, .page-head { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .label-sheet { padding: 0; gap: 0; }
  .qr-label { border: 0; page-break-inside: avoid; }
  .label-sheet.roll .qr-label { page-break-after: always; }
}
