:root {
  --bg: #f3f5f8; --card: #fff; --text: #1b2430; --muted: #5d6b7c; --line: #dfe4ea;
  --accent: #1f5fa8; --accent-ink: #fff; --ok: #1d8a4a; --warn: #b7791f; --bad: #c0392b;
  --ok-bg: #e5f5ec; --warn-bg: #fdf4e3; --bad-bg: #fbe8e6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --card: #1a2129; --text: #e6ebf1; --muted: #9aa8b8; --line: #2b3541;
    --accent: #4d8fe0; --ok: #3cc178; --warn: #e3a948; --bad: #ef6b5c;
    --ok-bg: #16301f; --warn-bg: #33280f; --bad-bg: #3a1814; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding: max(8px, env(safe-area-inset-top)) 16px 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
nav { display: flex; gap: 4px; margin-top: 6px; overflow-x: auto; }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 8px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
main { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 10px; }
fieldset.mode { border: 0; padding: 0; margin: 12px 0 0; }
fieldset.mode legend { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
label.radio { flex-direction: row; align-items: center; gap: 8px; color: var(--text); padding: 4px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: #c0392b; border-color: #c0392b; }
.danger-row { margin-top: 12px; justify-content: flex-end; }
.btn.big { padding: 16px; font-size: 18px; flex: 1; }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .hint { flex-basis: 100%; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 0; }
.status { display: flex; align-items: center; gap: 12px; }
.status.error { background: var(--bad-bg); border-color: var(--bad); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.headline { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.label { color: var(--muted); font-size: 14px; }
.big-num { font-size: 44px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.verdict { padding: 10px 14px; border-radius: 10px; font-weight: 700; text-align: right; }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.warn { background: var(--warn-bg); color: var(--warn); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 8px; margin: 12px 0; }
.kv div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.kv b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); font-size: 13px; }
ul.warn { margin: 8px 0; padding-left: 20px; color: var(--warn); }
ul.warn:empty { display: none; }
.canvas-wrap { width: 100%; margin: 8px 0; border-radius: 8px; overflow: hidden; background: #000; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; touch-action: manipulation; }
.canvas-wrap.tap canvas { cursor: crosshair; }
.strip canvas { aspect-ratio: 4 / 1; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--warn); color: #fff; font-size: 12px; }
.hrow { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.hrow img { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.hrow .m { font-size: 14px; color: var(--muted); }
.hrow .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.q { background: var(--bg); color: var(--muted); }
h3 { margin: 16px 0 4px; font-size: 16px; }
a { color: var(--accent); }

/* вход и смяна на парола */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.gate-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.gate-card h2 { margin: 0; font-size: 20px; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 6px; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; margin: 4px 0; }
.err:empty { display: none; }
.who { margin-left: auto; font-weight: 500; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical; }
.inline { display: flex; gap: 6px; } .inline input { flex: 1; }
.btn.small { padding: 6px 10px; font-size: 14px; }
code { font-size: 0.95em; }
/* администрация */
.users { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 12px; }
.users th, .users td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.users tr.off td { opacity: .6; }
.users td.acts { white-space: nowrap; }
.users td.acts .btn + .btn { margin-left: 6px; }
.users .m { color: var(--muted); font-size: 12px; }
.userform { border-top: 1px solid var(--line); padding-top: 12px; }
@media (max-width: 560px) { .users th:nth-child(3), .users td:nth-child(3) { display: none; } }

/* доставка, бележка, таблица */
.delivery { border-color: var(--accent); }
.delivery b { font-size: 18px; }
.delivery .m, .m { color: var(--muted); font-size: 13px; }
.big-num.small { font-size: 24px; }
.canvas-wrap.doc { background: var(--bg); }
.canvas-wrap.doc img { display: block; width: 100%; height: auto; max-height: 55vh; object-fit: contain; }
.ocr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 10px 0; }
.ocr #ocrState { grid-column: 1 / -1; }
.ocr label { display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 420px) { .ocr { grid-template-columns: 1fr; } }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 10px; }
.tablecard { padding: 0; overflow-x: auto; }
table.rec { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rec th, table.rec td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.rec th { position: sticky; top: 0; background: var(--card); font-weight: 600; color: var(--muted); }
table.rec td.n, table.rec th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.rec tbody tr { cursor: pointer; }
table.rec tbody tr:hover { background: var(--bg); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 10px; margin-top: 10px; }
.gallery .ph { background: var(--bg); border-radius: 8px; min-height: 120px; padding: 6px; font-size: 13px; color: var(--muted); }
.gallery img { width: 100%; height: auto; border-radius: 6px; display: block; }
.small-text { font-size: 12px; font-weight: 400; word-break: break-all; white-space: normal; }
.preview { background: var(--bg); border-radius: 8px; padding: 10px; font-size: 13px; line-height: 1.6; word-break: break-all; }

/* серия от ъгли */
.series { display: flex; gap: 8px; overflow-x: auto; margin: 8px 0; padding-bottom: 4px; }
.series .v { flex: none; width: 92px; font-size: 12px; text-align: center; color: var(--muted); }
.series .v img { width: 92px; height: 69px; object-fit: cover; border-radius: 6px; display: block; margin-bottom: 2px; border: 2px solid transparent; }
.series .v.rep img { border-color: var(--accent); }
.series .v.off { opacity: .45; }
/* камера в приложението */
.camview { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; align-items: center; justify-content: center; }
.camview video { width: 100%; height: 100%; object-fit: contain; }
.cam-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: center; color: #fff; font-size: 13px; text-shadow: 0 1px 2px #000; }
.cam-msg { position: absolute; top: 60px; left: 10px; right: 10px; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }
.cam-bottom { position: absolute; bottom: max(20px, env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; justify-content: space-around; align-items: center; }
.cam-count { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.35); cursor: pointer; }
.shutter:active { background: #fff; }
.shutter:disabled { opacity: .4; }

/* нивелир в камерата */
.cam-level { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.cam-level .ring { width: 96px; height: 96px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); position: relative; background: rgba(0,0,0,.15); }
.cam-level .ring::after { content: ''; position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.8); }
.cam-level .dot { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px; border-radius: 50%; background: #e74c3c; transition: transform .1s linear; }
.cam-level.ok .dot { background: #2ecc71; } .cam-level.warn .dot { background: #f1c40f; }
.cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-hint { position: absolute; left: 12px; right: 12px; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 118px); margin: 0 auto; max-width: 520px; padding: 10px 14px; border-radius: 12px; text-align: center; font-weight: 700; font-size: 17px; color: #fff; background: rgba(0,0,0,.6); pointer-events: none; }
.cam-hint.ok { background: rgba(39,174,96,.85); } .cam-hint.warn { background: rgba(241,196,15,.9); color: #222; } .cam-hint.bad { background: rgba(231,76,60,.88); }
.cam-checks { position: absolute; left: 8px; right: 8px; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 80px); display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; pointer-events: none; }
.cam-checks span { font-size: 12px; padding: 2px 8px; border-radius: 10px; color: #fff; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.25); }
.cam-checks .ok { border-color: #2ecc71; } .cam-checks .warn { border-color: #f1c40f; color: #f1c40f; } .cam-checks .bad { border-color: #e74c3c; color: #ff8a80; }
.cam-level span { color: #fff; font-weight: 700; font-size: 18px; text-shadow: 0 1px 3px #000; }
.series .v.off img { border-color: var(--bad); }

/* ===== v0.6: опростен интерфейс ===== */
.top .brand { min-height: 44px; padding-bottom: 6px; }
.top .title { font-size: 18px; }
.btn.back { margin-right: 4px; }
a.btn { text-decoration: none; }
.upbar { margin: 0 -16px; padding: 6px 16px; background: var(--warn-bg); color: var(--warn); font-size: 14px; font-weight: 600; }
.upbar.err { background: var(--bad-bg); color: var(--bad); }
.home { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
@media (min-width: 640px) { .home { grid-template-columns: repeat(3, 1fr); } }
.home.small { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.tile { display: flex; align-items: center; gap: 14px; font: inherit; font-size: 20px; font-weight: 700; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 18px; cursor: pointer; text-align: left; }
.tile span { font-size: 30px; }
.tile.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.home.small .tile { font-size: 16px; padding: 14px; } .home.small .tile span { font-size: 22px; }
.resume { width: 100%; margin-bottom: 12px; padding: 16px; font-size: 16px; background: var(--ok-bg); color: var(--ok); border-color: var(--ok); text-align: left; }
.meters { font-size: 64px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; margin: 4px 0 8px; }
.meters span { font-size: inherit; }
.delstats { display: flex; gap: 10px; margin-top: 8px; }
.delstats div { flex: 1; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.delstats span { display: block; color: var(--muted); font-size: 13px; }
.delstats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.step h3 { margin-top: 0; font-size: 20px; }
.step .actions { margin: 10px 0; }
.btn.linklike { background: none; border: 0; color: var(--accent); padding: 10px 0; font-weight: 600; }
details.more { grid-column: 1 / -1; color: var(--muted); }
details.more summary { cursor: pointer; padding: 6px 0; }
details.more label { margin-top: 8px; }
.saved { font-size: 22px; margin-bottom: 12px; }
.saved b { font-size: 30px; }
.upstate { display: block; font-size: 14px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.result .row .btn.big { flex: 1; }
.kv.big b { font-size: 22px; }
/* доставки днес */
.dcard { padding: 12px 14px; }
.dhead { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 4px; }
.dtotal { text-align: right; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.roll { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.roll:last-of-type { border-bottom: 0; }
.roll b { font-size: 22px; font-variant-numeric: tabular-nums; }
b.mt { font-size: 16px; }
