:root{
  --blue:#1d4ed8; --blue-d:#1e40af; --blue-l:#eff6ff; --blue-m:#dbeafe;
  --text:#0f172a; --muted:#64748b; --line:#e2e8f0; --bg:#f1f5f9; --white:#fff;
  --red:#dc2626; --green:#16a34a; --amber:#d97706;
  --r:16px; --shadow:0 1px 3px rgba(15,23,42,.08),0 1px 2px rgba(15,23,42,.04);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;padding:0}
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;background:var(--bg);color:var(--text);font-size:16px;line-height:1.4;padding-bottom:84px}
button{font-family:inherit;font-size:inherit;cursor:pointer}
h3{margin:0 0 8px;font-size:16px}

.topbar{position:sticky;top:0;z-index:20;background:var(--blue);color:#fff;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 14px;padding-top:calc(12px + env(safe-area-inset-top))}
.store-name{font-weight:800;font-size:15px;letter-spacing:.2px}
.status{font-size:12px;opacity:.9;display:flex;align-items:center;gap:6px;margin-top:2px}
.dot{width:8px;height:8px;border-radius:50%;background:#4ade80;display:inline-block}
.btn-scan-top{background:#fff;color:var(--blue);border:0;border-radius:12px;padding:10px 12px;font-weight:700;white-space:nowrap}

main{max-width:720px;margin:0 auto;padding:12px}
.page{display:none}
.page.active{display:block}

.card{background:var(--white);border-radius:var(--r);box-shadow:var(--shadow);padding:14px;margin-bottom:12px}
.row-between{display:flex;align-items:center;justify-content:space-between}
.lbl{display:block;font-size:13px;font-weight:600;color:var(--muted);margin:10px 0 4px}
.card .lbl:first-child{margin-top:0}
.input{width:100%;min-height:48px;border:1.5px solid var(--line);border-radius:12px;padding:10px 12px;font-size:16px;background:#fff;color:var(--text)}
.input:focus{outline:none;border-color:var(--blue);box-shadow:0 0 0 3px var(--blue-m)}
.inline-form{display:flex;gap:8px}
.two-col{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.hint{font-size:13px;color:var(--muted);margin:8px 0}
.err{color:var(--red);font-size:14px;font-weight:600;min-height:0;margin:8px 0}
.err:empty{display:none}
.check{display:flex;align-items:center;gap:8px;margin:12px 0 4px;font-size:15px}
.check input{width:20px;height:20px}

.btn{border:0;border-radius:12px;min-height:48px;padding:10px 16px;font-weight:700;font-size:16px}
.btn-primary{background:var(--blue);color:#fff}
.btn-primary:active{background:var(--blue-d)}
.btn-outline{background:#fff;color:var(--blue);border:1.5px solid var(--blue)}
.btn-wa{background:#16a34a;color:#fff}
.btn-block{display:block;width:100%;margin-top:10px}
.btn-scan-big{display:block;width:100%;min-height:64px;margin-bottom:12px;border:0;border-radius:var(--r);background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;font-size:20px;font-weight:800;box-shadow:0 4px 12px rgba(29,78,216,.35)}
.card .btn-scan-big{margin-bottom:0}
.btn-link{background:none;border:0;color:var(--blue);font-weight:600;padding:6px 0}
.btn-link.danger,.danger{color:var(--red)}
.danger-outline{color:var(--red);border-color:var(--red)}
button:disabled{opacity:.5}

.seg{display:flex;background:var(--blue-l);border-radius:12px;padding:4px;margin-top:12px;gap:4px}
.seg-btn{flex:1;border:0;background:transparent;border-radius:9px;min-height:44px;font-weight:700;color:var(--blue)}
.seg-btn.active{background:var(--blue);color:#fff}

.list{display:flex;flex-direction:column;gap:8px}
.item{background:#fff;border:1px solid var(--line);border-radius:14px;padding:12px}
.card .item{background:#f8fafc}
.item-top{display:flex;justify-content:space-between;gap:10px}
.item-name{font-weight:700}
.item-meta{font-size:12.5px;color:var(--muted);margin-top:2px}
.item-price{font-weight:800;color:var(--blue);white-space:nowrap}
.item-actions{display:flex;align-items:center;gap:8px;margin-top:10px;justify-content:space-between}
.tag{display:inline-block;font-size:11px;font-weight:800;padding:2px 8px;border-radius:999px;background:var(--blue-m);color:var(--blue-d)}
.tag.g{background:#dcfce7;color:#166534}
.tag.g2{background:#fef3c7;color:#92400e}
.tag.low{background:#fee2e2;color:#991b1b}
.badge{background:var(--blue);color:#fff;border-radius:999px;font-size:12px;padding:1px 8px;margin-left:4px}
.stepper{display:flex;align-items:center;gap:6px}
.stepper button{width:40px;height:40px;border-radius:10px;border:1.5px solid var(--blue);background:#fff;color:var(--blue);font-size:20px;font-weight:700}
.stepper .q{min-width:34px;text-align:center;font-weight:800}
.del{border:0;background:#fee2e2;color:var(--red);border-radius:10px;height:40px;padding:0 12px;font-weight:700}
.small-btn{border:1.5px solid var(--blue);background:#fff;color:var(--blue);border-radius:10px;min-height:40px;padding:0 14px;font-weight:700}
.empty{text-align:center;color:var(--muted);padding:18px 0;font-size:14px}

.total-box{display:flex;justify-content:space-between;align-items:center;background:var(--blue-l);border-radius:12px;padding:14px;margin-top:12px;font-weight:700;color:var(--blue-d)}
.total-box strong{font-size:22px}
.total-box.big strong{font-size:28px}
.change-box{display:flex;justify-content:space-between;align-items:center;background:#f0fdf4;border-radius:12px;padding:12px 14px;margin-top:10px;font-weight:700;color:#166534}
.change-box strong{font-size:20px}
.change-box.bad{background:#fef2f2;color:var(--red)}
.quick{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}
.quick button{border:1px solid var(--blue);background:#fff;color:var(--blue);border-radius:999px;padding:6px 12px;font-weight:600;min-height:36px}

.stats{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:12px}
.stat{background:#fff;border-radius:var(--r);box-shadow:var(--shadow);padding:14px;display:flex;flex-direction:column;gap:4px}
.stat span{font-size:12.5px;color:var(--muted);font-weight:600}
.stat strong{font-size:20px;color:var(--blue)}
.stat.warn strong{color:var(--amber)}

.bottomnav{position:fixed;left:0;right:0;bottom:0;z-index:30;background:#fff;border-top:1px solid var(--line);display:flex;padding-bottom:env(safe-area-inset-bottom);box-shadow:0 -2px 10px rgba(15,23,42,.06)}
.nav-btn{flex:1;border:0;background:none;padding:8px 0 10px;font-size:12px;font-weight:600;color:var(--muted);display:flex;flex-direction:column;align-items:center;gap:2px}
.nav-btn span{font-size:20px}
.nav-btn.active{color:var(--blue)}

.modal{position:fixed;inset:0;z-index:50;background:rgba(15,23,42,.55);display:none;align-items:flex-end;justify-content:center}
.modal.open{display:flex}
.sheet{background:#fff;width:100%;max-width:560px;max-height:92vh;overflow-y:auto;border-radius:22px 22px 0 0;padding:16px;padding-bottom:calc(16px + env(safe-area-inset-bottom))}
@media(min-width:600px){.modal{align-items:center}.sheet{border-radius:22px}}
.sheet-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}
.sheet-head h3{margin:0;font-size:18px}
.x{border:0;background:var(--bg);width:38px;height:38px;border-radius:50%;font-size:24px;line-height:1;color:var(--muted)}
#reader{width:100%;min-height:220px;background:#0f172a;border-radius:14px;overflow:hidden}
#reader video{width:100%!important;border-radius:14px}

.pinfo{background:var(--blue-l);border-radius:14px;padding:12px}
.pname{font-weight:800;font-size:17px}
.pmeta{font-size:13px;color:var(--muted);margin-bottom:8px}
.price-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.price-grid div{background:#fff;border-radius:10px;padding:8px}
.price-grid span{display:block;font-size:11.5px;color:var(--muted)}
.price-grid strong{font-size:15px}
.qty-row{display:flex;gap:8px;align-items:center}
.qbtn{width:52px;height:52px;border-radius:12px;border:1.5px solid var(--blue);background:#fff;color:var(--blue);font-size:26px;font-weight:700}
.qty-input{text-align:center;font-size:22px;font-weight:800}
.preview{margin:12px 0 4px;padding:10px 12px;border-radius:12px;background:#f8fafc;border:1px dashed var(--blue);font-size:14.5px}
.preview.bad{border-color:var(--red);color:var(--red)}

.receipt-wrap{background:#f8fafc;border:1px solid var(--line);border-radius:12px;padding:10px;margin-bottom:10px;overflow-x:auto}
.receipt{margin:0;font-family:"Courier New",Courier,monospace;font-size:12.5px;line-height:1.35;white-space:pre;color:#000}

.toast{position:fixed;left:50%;bottom:96px;transform:translateX(-50%) translateY(20px);background:#0f172a;color:#fff;padding:10px 16px;border-radius:12px;font-size:14px;opacity:0;pointer-events:none;transition:.25s;z-index:99;max-width:90%;text-align:center}
.toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
.toast.err{background:var(--red)}

#printArea{display:none}
@media print{
  @page{margin:4mm}
  body{background:#fff;padding:0}
  body>*:not(#printArea){display:none!important}
  #printArea{display:block!important}
  #printArea pre{font-family:"Courier New",monospace;font-size:11px;line-height:1.3;margin:0;white-space:pre-wrap;width:100%;max-width:76mm;color:#000}
}

[hidden]{display:none!important}
.topbar-btns{display:flex;gap:8px}
.btn-scan-top{position:relative}
.rdot{position:absolute;top:4px;right:4px;width:9px;height:9px;border-radius:50%;background:#94a3b8;border:2px solid #fff;display:none}
.rdot.on{display:block;background:#16a34a}
.qrbox{display:flex;justify-content:center;padding:10px;min-height:20px}
.qrbox img,.qrbox canvas{max-width:220px;height:auto}
body.phone-mode{padding-bottom:0;background:#0f172a}
body.phone-mode .topbar,body.phone-mode main,body.phone-mode .bottomnav{display:none}
.phone{max-width:560px;margin:0 auto;padding:14px;color:#fff}
.ph-head{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-bottom:10px}
.ph-head span{font-size:13px;background:#1e293b;border-radius:999px;padding:4px 10px}
.ph-head span.ok{background:#166534}
.ph-head span.bad{background:#991b1b}
#phReader{width:100%;min-height:260px;background:#000;border-radius:14px;overflow:hidden}
#phReader video{width:100%!important}
.ph-last{background:#1e293b;border-radius:12px;padding:14px;margin:12px 0;font-size:16px;font-weight:600;min-height:52px}
.ph-last.ok{background:#166534}
.ph-last.bad{background:#991b1b}
