:root {
  --bg: #f4f2ee; --panel: #ffffff; --ink: #1b1d21; --muted: #6b6f78; --line: #e2ded6;
  --accent: #d9821f; --accent-ink: #fff; --ok: #2f8a4c; --warn: #c2410c; --info: #2c5f9e;
  --radius: 10px; --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161a; --panel: #1d2026; --ink: #e9e7e2; --muted: #9a9ea8; --line: #2e323a; --accent: #f2a93b; --accent-ink: #1b1d21; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); }
.pad { padding: 1rem; }
.mono { font-family: var(--mono); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  background: #14161a; color: #e9e7e2; }
.brand { font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: .5rem; letter-spacing: .02em; }
.chip { width: 16px; height: 16px; border-radius: 3px; background: #f2a93b; box-shadow: 0 0 0 3px #14161a, 0 0 0 5px #f2a93b55; }
.topbar nav { display: flex; gap: .2rem; flex: 1; }
.topbar nav a { text-decoration: none; padding: .35rem .7rem; border-radius: 6px; color: #b9bcc4; }
.topbar nav a.active { background: #2a2e36; color: #fff; }
.add-btn { white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .45rem .8rem; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--warn); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: .45rem .6rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 70px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; color: var(--muted); }
label.f.empty input, label.f.empty select { border-style: dashed; }
.check { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.check input { width: auto; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; overflow-x: auto; }
.grid { display: grid; gap: .75rem; }
.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)); }
.span2 { grid-column: span 2; } .span-all { grid-column: 1 / -1; }
@media (max-width: 720px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .topbar { gap: .4rem; padding: .5rem .6rem; } .topbar nav a { padding: .35rem .45rem; } .brand-text { display: none; } .add-btn { padding: .4rem .6rem; } }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.stats { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; text-decoration: none; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: .78rem; color: var(--muted); }
.stat.warn b { color: var(--warn); }

.filters { display: grid; grid-template-columns: 1fr 200px auto; gap: .5rem; margin-bottom: .8rem; align-items: center; }
@media (max-width: 720px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }

.items { display: flex; flex-direction: column; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item-row { display: grid; grid-template-columns: 56px 92px 1fr 90px 90px 120px; gap: .7rem; align-items: center; padding: .5rem .8rem;
  background: var(--panel); text-decoration: none; }
.item-row:hover { background: color-mix(in srgb, var(--panel) 92%, var(--accent)); }
.item-row .thumb { width: 56px; height: 44px; }
.item-row .num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .item-row { grid-template-columns: 48px 1fr auto; grid-template-areas: "t n q" "t c q"; row-gap: 0; }
  .item-row .thumb { grid-area: t; width: 48px; height: 48px; } .item-row .code { grid-area: c; } .item-row .name { grid-area: n; }
  .item-row .qty { grid-area: q; } .item-row .cost, .item-row .loc { display: none; }
}
.thumb { border-radius: 6px; background: var(--bg) center/cover no-repeat; border: 1px solid var(--line); display: grid; place-items: center;
  color: var(--muted); font-size: .7rem; }
.code { font-family: var(--mono); font-size: .82rem; color: var(--accent); font-weight: 600; }
.name b { font-weight: 600; }
.tagline { font-size: .78rem; color: var(--muted); }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); margin-left: .25rem; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.info { color: var(--info); border-color: currentColor; }

.item-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; margin-bottom: 1rem; }
.qr { width: 92px; height: 92px; background: #fff; padding: 4px; border-radius: 6px; }
.stock-box { display: flex; align-items: center; gap: .4rem; }
.stock-box .qtyv { font-size: 1.6rem; font-weight: 700; min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.gallery figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; cursor: zoom-in; background: var(--bg); }
.gallery figcaption { font-size: .78rem; padding: .3rem .4rem; display: flex; gap: .3rem; align-items: center; }
.gallery figcaption span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: .8rem; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--accent); color: var(--accent); }

table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.specs-ed .kv { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: .4rem; margin-bottom: .4rem; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button { background: none; border: none; padding: .6rem .9rem; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.preview-imgs { display: flex; gap: .4rem; overflow-x: auto; }
.preview-imgs img { height: 90px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }

.status { font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; font-weight: 600; }
.st-ordered { background: #2c5f9e22; color: var(--info); }
.st-arrived { background: #d9821f22; color: var(--accent); }
.st-verified, .st-ok { background: #2f8a4c22; color: var(--ok); }
.st-issue { background: #c2410c22; color: var(--warn); }
.st-cancelled, .st-pending { background: var(--bg); color: var(--muted); }

.lightbox { position: fixed; inset: 0; background: #000d; display: grid; place-items: center; z-index: 20; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 92vh; }
#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 30; }
#toast div { background: #1b1d21; color: #fff; padding: .6rem 1rem; border-radius: 8px; margin-top: .4rem; box-shadow: 0 4px 16px #0004; }
#toast div.err { background: var(--warn); }

.login { max-width: 360px; margin: 12vh auto; }
.history li { font-size: .85rem; margin-bottom: .3rem; }

/* printable labels */
.labels { display: grid; grid-template-columns: repeat(auto-fill, 62mm); gap: 3mm; }
.label { width: 62mm; height: 29mm; border: 1px dashed #aaa; display: grid; grid-template-columns: 25mm 1fr; gap: 2mm; padding: 2mm; background: #fff; color: #000; overflow: hidden; }
.label img { width: 25mm; height: 25mm; }
.label .lc { font-family: var(--mono); font-weight: 700; font-size: 11pt; }
.label .ln { font-size: 8pt; line-height: 1.15; max-height: 3.5em; overflow: hidden; }
.label .ll { font-size: 7pt; color: #555; }
@media print {
  .topbar, .no-print, #toast { display: none !important; }
  body { background: #fff; } main { padding: 0; max-width: none; }
  .label { border-color: #ddd; break-inside: avoid; }
}
