:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --muted: #667085;
  --line: #e2e6ec;
  --primary: #1f3b63;
  --primary-text: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e5f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --error: #b42318;
  --error-bg: #fde8e6;
  --info-bg: #e6eefb;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

.page { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(16px + var(--safe-bottom)); }
.page.with-footer { padding-bottom: calc(88px + var(--safe-bottom)); }
.page.center { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(24px + var(--safe-top)) 16px 24px; }
.brand { font-size: 26px; font-weight: 700; color: var(--primary); text-align: center; padding: calc(20px + var(--safe-top)) 0 8px; }
.page.center .brand { padding-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center-text { text-align: center; }
.pad { padding: 8px 16px; }
.pre { white-space: pre-line; }
.error { color: var(--error); }
.stack { display: flex; flex-direction: column; gap: 10px; }
h2 { font-size: 19px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 12px 0 4px; color: var(--muted); font-weight: 600; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: var(--primary); color: var(--primary-text);
  padding: calc(8px + var(--safe-top)) 8px 8px; min-height: 52px; }
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-title b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title small { opacity: .8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { display: flex; gap: 6px; align-items: center; }
.icon { background: transparent; border: 0; color: inherit; font-size: 26px; width: 40px; height: 40px; border-radius: 10px; line-height: 1; }
.icon:active { background: rgba(255,255,255,.15); }
.icon-space { width: 8px; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; min-height: 44px; font-weight: 600; }
.btn:active { filter: brightness(.95); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.bar .btn.small { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.3); color: #fff; }
.btn:disabled { opacity: .45; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; color: var(--primary); font-weight: 600; padding: 4px 0; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 16px; box-shadow: 0 1px 2px rgba(16,24,40,.06); }
.form { width: 100%; max-width: 420px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .search input, .scanbar input { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; min-height: 44px; font-size: 17px; width: 100%; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 14px; }

.operators { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 8px 16px; }
.operator { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 10px; min-height: 64px; text-align: left; display: flex; flex-direction: column; justify-content: center; }
.operator small { color: var(--muted); font-size: 12px; }
.operator.last { border-color: var(--primary); border-width: 2px; }
.pin { width: 100%; max-width: 360px; text-align: center; }
.pin-name { font-size: 19px; font-weight: 700; margin: 4px 0 12px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 10px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--primary); }
.pin-dots i.on { background: var(--primary); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.pinpad button { min-height: 60px; font-size: 24px; border-radius: 14px; border: 1px solid var(--line); background: #fff; }
.pinpad button.ghost { font-size: 16px; background: transparent; border-color: transparent; color: var(--primary); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--info-bg); color: var(--primary); vertical-align: middle; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

.banner { display: block; width: calc(100% - 32px); margin: 10px 16px 0; padding: 10px 12px; border-radius: 12px; border: 0; text-align: left; font-size: 14px; font-weight: 600; }
.banner.info { background: var(--info-bg); color: var(--primary); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.error { background: var(--error-bg); color: var(--error); }

.toolbar { padding: 10px 16px 0; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 7px 12px; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.search { display: flex; gap: 8px; }

.orders, .lines, .cards { list-style: none; margin: 8px 0 0; padding: 0; }
.order { display: flex; margin: 8px 16px; background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,.06); border-left: 5px solid var(--line); }
.order.work { border-left-color: #3b82f6; }
.order.partial { border-left-color: #f59e0b; }
.order.done { border-left-color: var(--ok); }
.order.closed { border-left-color: #98a2b3; opacity: .8; }
.order-main { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 12px; }
.order-more { width: 48px; background: none; border: 0; border-left: 1px solid var(--line); font-size: 22px; color: var(--muted); }
.order-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.order-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { color: var(--muted); font-size: 13px; white-space: nowrap; }
.order-sub { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; font-size: 13px; }
.order-qty { margin-top: 4px; font-size: 13px; color: var(--muted); }
.state { font-weight: 600; font-size: 13px; }
.state.work { color: #1d4ed8; } .state.partial { color: var(--warn); } .state.done { color: var(--ok); }
.state.closed, .state.new { color: var(--muted); } .state.error { color: var(--error); }
.who { color: var(--text); }

.progress { height: 6px; background: var(--line); margin: 10px 16px 0; border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; background: var(--ok); }
.scanbar { display: flex; gap: 8px; padding: 10px 16px 0; }
.scanbar input { flex: 1; min-width: 0; }
.camera { position: relative; margin: 10px 16px 0; border-radius: 14px; overflow: hidden; background: #000; }
.camera video { width: 100%; height: 34vh; object-fit: cover; display: block; }
.camera-frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px; pointer-events: none; }
.camera-error { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; padding: 16px; text-align: center; }
.camera-close { position: absolute; right: 8px; bottom: 8px; min-height: 36px; padding: 6px 10px; }
.last { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.last > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.last b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last-buttons { display: flex; gap: 6px; }
.last-buttons .btn { min-width: 48px; }
.lines-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 0; color: var(--muted); font-size: 14px; }
.line { display: flex; justify-content: space-between; gap: 10px; align-items: center; background: var(--card); margin: 6px 16px; padding: 12px; border-radius: 12px; border-left: 4px solid transparent; }
.line.done { background: var(--ok-bg); border-left-color: var(--ok); }
.line.over { background: var(--warn-bg); border-left-color: var(--warn); }
.line.extra { border-left-color: var(--warn); }
.line.short { border-left-color: var(--error); }
.line-name { flex: 1; min-width: 0; }
.line-qty { white-space: nowrap; text-align: right; }
.line-qty b { font-size: 18px; }
.footer { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + var(--safe-bottom)); background: rgba(243,245,248,.96); border-top: 1px solid var(--line); }
.footer .btn { min-height: 52px; font-size: 17px; }
.result.ok { border-left: 6px solid var(--ok); }
.result.error { border-left: 6px solid var(--error); }
.result.info { border-left: 6px solid #3b82f6; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ro { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ro:last-child { border-bottom: 0; }
.ro span { color: var(--muted); }
.ro b { text-align: right; word-break: break-word; font-weight: 600; }

.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.dialog { background: #fff; width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + var(--safe-bottom)); }
@media (min-width: 600px) { .overlay { align-items: center; } .dialog { border-radius: 18px; } }
.dialog-buttons { display: flex; gap: 8px; margin-top: 14px; }
.dialog-buttons .btn { flex: 1; }
.choice { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.choice-item { text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; }
.choice-item small { color: var(--muted); font-size: 12px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(96px + var(--safe-bottom)); z-index: 30; background: #17202b; color: #fff; padding: 12px 14px; border-radius: 12px; font-size: 14px; white-space: pre-line; }
.toast.error { background: var(--error); }
