/* ---------- токены ---------- */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --err: #dc2626;
  --err-soft: #fef2f2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --tabbar-h: 0px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- шапка ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none; letter-spacing: -.2px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background:
  linear-gradient(90deg, #fff 0 3px, transparent 3px 5px, #fff 5px 6px, transparent 6px 9px, #fff 9px 12px, transparent 12px 13px, #fff 13px 14px, transparent 14px) 8px 8px / 14px 14px no-repeat, var(--accent); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.nav a:hover { background: #f1f5f9; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg.i { width: 18px; height: 18px; }
.user { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.user-name { display: flex; align-items: center; gap: 7px; padding: 0 12px; height: 36px; border-radius: 999px; background: #f1f5f9; font-weight: 600; font-size: 14px; white-space: nowrap; max-width: 220px; }
.user-name span { overflow: hidden; text-overflow: ellipsis; }
.user-name svg.i { width: 16px; height: 16px; color: var(--muted); }

/* экран входа: без меню */
body.auth .top, body.auth .tabbar { display: none; }
body.auth main { padding-bottom: 40px; }
.login { min-height: calc(100vh - 80px); display: grid; place-content: center; gap: 20px; padding: 24px 0; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 800; font-size: 22px; }
.login-brand .brand-mark { width: 38px; height: 38px; background-position: 12px 12px; }
.login-card { width: min(380px, calc(100vw - 32px)); display: grid; gap: 16px; padding: 28px; margin: 0; }
.login-card h1 { margin: 0; font-size: 24px; }
.pw { display: flex; position: relative; }
.pw .f { flex: 1; padding-right: 96px; }
.pw .btn { position: absolute; right: 4px; top: 4px; height: 36px; }

/* сотрудники */
.creds { margin-bottom: 16px; }
.creds-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; align-items: baseline; }
.creds-list dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.creds-list dd { margin: 0; overflow-wrap: anywhere; }
.badge.role-admin { --c: #0d9488; }
.badge.role-user { --c: #64748b; }
.btn.confirm { background: var(--err); border-color: var(--err); color: #fff; }
.btn.confirm:hover { background: #b91c1c; border-color: #b91c1c; }

/* нижнее меню — только на телефоне */
.tabbar { display: none; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 40px; }

/* ---------- заголовки ---------- */
.page-head { margin-bottom: 18px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 26px; letter-spacing: -.4px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -.2px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }

/* ---------- раскладка ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid2.even { grid-template-columns: 1fr 1fr; }
.scroll-x { overflow-x: auto; }

/* ---------- кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s, transform .05s; }
.btn:hover { background: #f8fafc; border-color: #94a3b8; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #bfdbfe; outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, .25); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f5f9; color: var(--text); }
.btn.danger { color: var(--err); border-color: #fecaca; }
.btn.danger:hover { background: var(--err-soft); border-color: #fca5a5; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn.lg { height: 56px; padding: 0 22px; font-size: 17px; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled=true] { background: #f1f5f9; border-color: var(--line); color: #94a3b8; box-shadow: none; cursor: default; transform: none; }

/* ---------- поля ---------- */
.f { height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; min-width: 0; }
.f:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px #dbeafe; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field .f { color: var(--text); font-weight: 400; font-size: 15px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
input[type=file].f { padding: 9px 12px; height: auto; }

/* степпер количества */
.qty { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; height: 44px; }
.qty button { width: 44px; border: 0; background: #f8fafc; font-size: 20px; cursor: pointer; }
.qty button:hover { background: #eef2f7; }
.qty input { width: 70px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font-weight: 700; font-size: 16px; -moz-appearance: textfield; }
.qty input::-webkit-inner-spin-button { -webkit-appearance: none; }
.qty input:focus { outline: 0; background: var(--accent-soft); }

/* сегменты (размер этикетки) */
.seg { display: inline-flex; padding: 3px; background: #f1f5f9; border-radius: 11px; gap: 2px; }
.seg button { height: 36px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- поле сканера ---------- */
.scanbox { display: flex; gap: 10px; }
.scan-wrap { position: relative; flex: 1; min-width: 0; }
.scan-wrap svg.i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; color: var(--accent); pointer-events: none; }
.scan { width: 100%; height: 64px; padding: 0 16px 0 54px; font: 600 24px var(--mono); letter-spacing: .5px; border: 2px solid var(--accent); border-radius: var(--radius); background: #fff; }
.scan::placeholder { font: 500 18px system-ui, sans-serif; color: #94a3b8; letter-spacing: 0; }
.scan:focus { outline: 0; box-shadow: 0 0 0 4px #dbeafe; }
.cam-btn { height: 64px; padding: 0 20px; border-radius: var(--radius); flex: none; }
.cam-btn svg.i { width: 24px; height: 24px; }
.cam-btn.on { background: var(--text); border-color: var(--text); color: #fff; }
.scan-hint { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.scan-hint .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px #dcfce7; }

.cam { position: relative; margin-top: 12px; border-radius: var(--radius); overflow: hidden; background: #000; outline: 4px solid transparent; outline-offset: -4px; }
.cam video { display: block; width: 100%; height: min(40vh, 340px); object-fit: cover; }
.cam-aim { position: absolute; inset: 22% 10%; border: 2px solid rgba(255, 255, 255, .8); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); pointer-events: none; }
.cam-aim::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.cam-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; justify-content: flex-end; padding: 10px; }
.cam-bar .btn { background: rgba(255, 255, 255, .95); border: 0; }
.cam.hit { animation: hit .5s; }
@keyframes hit { from { outline-color: #22c55e; } to { outline-color: transparent; } }

/* ---------- результат скана ---------- */
.result { border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.result-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; font-weight: 700; font-size: 16px; }
.result-head .ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; flex: none; }
.result-head .ic svg.i { width: 20px; height: 20px; stroke-width: 2.5; }
.result.ok { border-color: #bbf7d0; } .result.ok .result-head { background: var(--ok-soft); color: #166534; } .result.ok .ic { background: var(--ok); }
.result.wait { border-color: #fde68a; } .result.wait .result-head { background: var(--warn-soft); color: #92400e; } .result.wait .ic { background: var(--warn); }
.result.err { border-color: #fecaca; } .result.err .result-head { background: var(--err-soft); color: #991b1b; } .result.err .ic { background: var(--err); }
.result-body { padding: 14px 18px 16px; }
.result-body:empty { display: none; }
.empty-state { display: grid; place-items: center; gap: 8px; padding: 36px 20px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .5); }
.empty-state svg.i { width: 36px; height: 36px; color: #94a3b8; }

.code { font-family: var(--mono); font-weight: 700; }
.code-lg { font: 700 24px var(--mono); letter-spacing: .3px; }
.item-title { margin-top: 2px; font-size: 15px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv a { text-decoration: none; }

/* ---------- статусы ---------- */
.st-new { --c: #16a34a; } .st-opened { --c: #2563eb; } .st-defect { --c: #dc2626; } .st-substitution { --c: #ea580c; }
.st-service { --c: #d97706; } .st-returned { --c: #7c3aed; } .st-sold { --c: #64748b; } .st-written_off { --c: #475569; } .st-pending { --c: #94a3b8; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: var(--c, #475569);
  background: color-mix(in srgb, var(--c, #64748b) 12%, white); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain { --c: #64748b; }
.badge.plain::before { display: none; }

.statuses { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.st-btn { position: relative; display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 14px 10px 18px; border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; font-weight: 700; font-size: 16px; text-align: left; cursor: pointer; overflow: hidden; transition: background .12s, border-color .12s; }
.st-btn::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.st-btn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.st-btn kbd { margin-left: auto; }
.st-btn:hover:not(:disabled) { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, white); }
.st-btn:disabled { cursor: default; color: #94a3b8; background: #f8fafc; }
.st-btn:disabled::before, .st-btn:disabled .dot { background: #cbd5e1; }
.st-btn.current { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.st-btn.current::after { content: "сейчас"; margin-left: auto; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--c); }
.st-btn.current kbd { display: none; }
.repeat { margin-top: 10px; }
kbd { font: 600 11px var(--mono); background: #f1f5f9; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; color: #475569; }
.btn.primary kbd { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .35); color: #fff; }

/* ---------- шаги ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 999px; background: #f1f5f9; color: var(--muted); font-weight: 600; font-size: 14px; }
.step .n { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 1px solid var(--line-strong); font-size: 13px; }
.step.active { background: var(--accent-soft); color: var(--accent); }
.step.active .n { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.done { background: var(--ok-soft); color: #166534; }
.step.done .n { background: var(--ok); border-color: var(--ok); color: #fff; }
.step .opt { font-weight: 500; opacity: .7; }

.ctx { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.ctx .ic { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); flex: none; }
.ctx .ic svg.i { width: 24px; height: 24px; }
.ctx .meta { flex: 1; min-width: 0; }
.ctx .label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ctx.idle { border-style: dashed; box-shadow: none; background: transparent; }
.ctx.idle .ic { background: #f1f5f9; color: #94a3b8; }

/* ---------- лента сканов ---------- */
.feed { list-style: none; margin: 0; padding: 0; max-height: 440px; overflow: auto; }
.feed li { display: flex; gap: 12px; align-items: center; padding: 10px 2px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.feed li:last-child { border-bottom: 0; }
.feed li .fi { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); flex: none; }
.feed li .fi svg.i { width: 14px; height: 14px; stroke-width: 3; }
.feed li.err .fi { background: var(--err-soft); color: var(--err); }
.feed li.err { color: #991b1b; }
.feed li > span { flex: 1; min-width: 0; }
.feed time { color: #94a3b8; font-size: 12px; font-variant-numeric: tabular-nums; }
.feed:empty::before { content: "Пока пусто"; display: block; padding: 12px 0; color: #94a3b8; }

/* ---------- таблицы ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
th { background: #f8fafc; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td a { text-decoration: none; }

/* ---------- цифры ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .k { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .k::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, transparent); }
.stat b { display: block; margin-top: 2px; font-size: 24px; letter-spacing: -.5px; }
.stat.hero { background: var(--ok-soft); border-color: #bbf7d0; }
.stat.hero b { color: #166534; }

/* ---------- главная ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 26px; }
.tile { display: flex; gap: 14px; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); text-decoration: none; transition: border-color .12s, box-shadow .12s, transform .12s; }
.tile:hover { border-color: var(--accent); box-shadow: 0 6px 18px rgba(37, 99, 235, .1); transform: translateY(-1px); }
.tile .ic { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; flex: none; background: color-mix(in srgb, var(--c) 12%, white); color: var(--c); }
.tile .ic svg.i { width: 24px; height: 24px; }
.tile b { display: block; font-size: 16px; margin-bottom: 2px; }
.tile span { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.section-title { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }

/* раскрывающиеся блоки */
details.panel > summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; font-weight: 700; font-size: 16px; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary .ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
details.panel > summary .sub { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
details.panel > summary::after { content: ""; margin-left: auto; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
details.panel[open] > summary::after { transform: rotate(-135deg); }
details.panel[open] > summary { margin-bottom: 16px; }

.notice { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.notice.ok { background: var(--ok-soft); color: #166534; }
.notice.err { background: var(--err-soft); color: #991b1b; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--tabbar-h)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: min(92vw, 560px); padding: 12px 18px; border-radius: 12px; background: var(--text); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(15, 23, 42, .25); z-index: 30; }
.toast.err { background: var(--err); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); }

/* ---------- планшет ---------- */
@media (max-width: 960px) {
  .grid2, .grid2.even { grid-template-columns: 1fr; }
  .nav a span { display: none; }
  .nav a { padding: 9px; }
}

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  :root { --tabbar-h: 68px; }
  body { font-size: 16px; }
  .top { padding: 10px 14px; gap: 10px; }
  .top .nav { display: none; }
  .user-name { max-width: 150px; padding: 0 10px; }
  .user .btn span { display: none; }
  main { padding: 16px 14px calc(var(--tabbar-h) + 24px); }
  .page-head h1 { font-size: 22px; }
  .page-head p { font-size: 14px; }
  .panel { padding: 14px; border-radius: 12px; }
  .scan { height: 58px; font-size: 20px; padding-left: 48px; }
  .scan::placeholder { font-size: 16px; }
  .scan-wrap svg.i { left: 14px; width: 22px; height: 22px; }
  .cam-btn { height: 58px; padding: 0 16px; }
  .cam-btn span { display: none; }
  .st-btn { min-height: 60px; font-size: 15px; }
  .st-btn kbd, .desktop-only { display: none; }
  .tiles { grid-template-columns: 1fr; gap: 10px; }
  .tile { padding: 14px; }
  .code-lg { font-size: 20px; }
  th, td { padding: 9px 8px; }
  .f, .qty input { font-size: 16px; } /* iOS не зумит поле при фокусе */
  .feed { max-height: none; }

  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
  .tabbar a svg.i { width: 24px; height: 24px; }
  .tabbar a.active { color: var(--accent); }
}
