:root {
  --bg: #0B0B0D; --surface: #161719; --surface-alt: #202229; --border: #2A2C33;
  --text: #F5F6F8; --muted: #9A9DA6; --accent: #E6A817; --green: #3BB273; --red: #E5534B;
  --purple: #9b6cf0; --blue: #4a90e2; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body { min-height: 100%; margin: 0; overflow-x: hidden; overscroll-behavior-y: none; -webkit-overflow-scrolling: touch; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }

/* iOS standalone (home-screen) bug: with viewport-fit=cover the layout viewport
   boots SHORT on first launch, so the bottom bar floats with a gap below it.
   100vh/100dvh/innerHeight/position:fixed all just fill that wrong height — only a
   reflow/scroll makes WebKit expand to the true screen height. So: (1) body::after
   is a 1px-taller invisible sentinel that keeps a hair of scrollability, which stops
   iOS from collapsing the standalone viewport; (2) app.js nudges a scroll on launch
   to force the expand, then pins .app to the measured innerHeight via --app-h and
   re-measures on every signal. The product window then flexes to its maximum size. */
body::after { content: ''; display: block; width: 1px; height: calc(var(--app-h, 100dvh) + 1px); pointer-events: none; }
.app { position: fixed; top: 0; left: 0; right: 0; height: var(--app-h, 100dvh); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }

.pager { flex: 1 1 auto; min-height: 0; display: flex; align-items: stretch; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-behavior: smooth; }
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; width: 100%; height: 100%; scroll-snap-align: start; display: flex; flex-direction: column; overflow: hidden; padding: 10px 12px 12px; gap: 10px; }

/* Preview */
.preview { position: relative; flex: 0 0 auto; height: 34dvh; min-height: 200px; max-height: 300px; border-radius: 18px; overflow: hidden; background: #000; }
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 68%; height: 48%; border: 3px solid rgba(255,255,255,0.92); border-radius: 14px; box-shadow: 0 0 0 2000px rgba(0,0,0,0.22); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.box-msg { display: none; font-size: 13px; font-weight: 700; padding: 7px 12px; border-radius: 8px; text-align: center; max-width: 90%; background: rgba(0,0,0,0.62); color: #fff; }
.box-msg.show { display: block; }
.box-msg.load { background: var(--accent); color: #1A1206; }
.box-msg.err { background: var(--red); color: #fff; }
.flash-num { position: absolute; font-family: var(--mono); font-size: 17px; font-weight: 700; letter-spacing: 1px; color: #fff; background: rgba(0,0,0,0.66); padding: 5px 10px; border-radius: 8px; opacity: 0; transition: opacity 0.1s; }
.flash-num.show { opacity: 1; }
.focus-ring { position: absolute; width: 62px; height: 62px; border: 2px solid #fff; border-radius: 8px; transform: translate(-50%,-50%); opacity: 0; pointer-events: none; }
.focus-ring.show { opacity: 1; transition: opacity .15s; }

/* Info bar */
.infobar { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 14px; padding: 6px 6px 6px 14px; }
.status { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.ok { color: var(--green); } .status.bad { color: var(--red); }
.status.perf { color: var(--red); font-weight: 800; } .status.eff { color: var(--accent); font-weight: 800; }
.controls { display: flex; gap: 0; flex: none; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: none; background: transparent; color: var(--text); display: flex; align-items: center; justify-content: center; }
.icon-btn:active { background: var(--surface-alt); }
.icon-btn.active { background: var(--accent); color: #1A1206; }
#perfBtn { color: #fff; }
#perfBtn.on { color: var(--red); background: rgba(229,83,75,0.16); }
/* Tint the (transparent-bg) PNG to an exact colour via mask: white = efficient,
   red = performance. */
#perfBtn .perf-icon { width: 23px; height: 23px; display: block; background-color: #fff; -webkit-mask: url(/icons/perf-icon.png) center / contain no-repeat; mask: url(/icons/perf-icon.png) center / contain no-repeat; }
#perfBtn.on .perf-icon { background-color: var(--red); }

/* Details */
.details-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.refresh-corner { position: absolute; top: 10px; right: 10px; z-index: 4; width: 34px; height: 34px; border-radius: 9px; border: none; background: var(--surface-alt); color: var(--muted); display: flex; align-items: center; justify-content: center; }
.refresh-corner.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.details { flex: 1 1 auto; min-height: 0; overflow-y: auto; background: var(--surface); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; }
.detail-empty { color: var(--muted); text-align: center; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-size: 15px; }
.detail-loading { color: var(--muted); text-align: center; padding: 28px 0; flex: 1; display: flex; align-items: center; justify-content: center; }
.big-btn { background: var(--accent); color: #1A1206; border: none; font-size: 17px; font-weight: 800; padding: 15px 32px; border-radius: 14px; }
.d-name { font-size: 20px; font-weight: 800; line-height: 1.25; margin: 0 6px 4px 0; flex: none; }
.d-price { color: var(--accent); font-size: 26px; font-weight: 900; margin: 0 0 12px; flex: none; }
.d-rows { display: flex; flex-direction: column; gap: 8px; flex: none; }
.d-row { display: flex; align-items: baseline; gap: 10px; }
.d-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1px; width: 96px; flex: none; }
.d-value { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; word-break: break-word; }
.d-value.mono { font-family: var(--mono); font-weight: 500; }
.d-photo { flex: 1 1 auto; min-height: 140px; width: 100%; object-fit: contain; border-radius: 12px; margin-top: 14px; display: block; }
.d-error { color: var(--red); font-weight: 700; }

/* Logs */
.logs-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 2px 4px; }
.logs-title { font-size: 16px; font-weight: 800; }
.logs-actions { display: flex; align-items: center; gap: 12px; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 14px; font-weight: 700; padding: 4px 2px; }
.log-head { flex: 0 0 auto; display: flex; padding: 8px 4px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 700; }
#log-rows { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.log-row { display: flex; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-row:active { background: var(--surface-alt); }
.col-barcode { width: 108px; flex: none; font-family: var(--mono); color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-name { flex: 1; padding-right: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-qty { width: 50px; flex: none; text-align: center; color: var(--muted); }
.col-price { width: 96px; flex: none; text-align: right; font-weight: 700; color: var(--accent); }
.log-empty { color: var(--muted); text-align: center; padding: 24px 0; }
.log-footer { flex: 0 0 auto; padding: 10px 4px 2px; color: var(--muted); font-size: 13px; font-weight: 600; text-align: center; border-top: 1px solid var(--border); }

/* Bottom bar */
.bottombar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; background: var(--surface); padding: 5px 12px calc(env(safe-area-inset-bottom) + 5px); border-top: 1px solid var(--border); }
.conn { flex: 1 1 0; display: flex; align-items: center; min-width: 0; }
.conn-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 800; padding: 5px 11px; border-radius: 999px; max-width: 100%; color: var(--muted); background: var(--surface-alt); }
.conn-pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.conn.online .conn-pill { color: var(--green); background: rgba(59,178,115,0.16); }
.conn.offline .conn-pill { color: var(--red); background: rgba(229,83,75,0.16); }
.conn.local .conn-pill { color: var(--purple); background: rgba(155,108,240,0.18); }
.conn.sync .conn-pill { color: var(--blue); background: rgba(74,144,226,0.18); }
.dots-nav { flex: none; display: flex; gap: 9px; justify-content: center; align-items: center; }
.pd { width: 9px; height: 9px; border-radius: 50%; border: none; background: var(--border); padding: 0; }
.pd.active { background: var(--accent); width: 24px; border-radius: 5px; }
.brand-slot { flex: 1 1 0; min-width: 0; display: flex; justify-content: flex-end; align-items: center; }
.brand-logo { height: 30px; max-width: 100%; width: auto; object-fit: contain; border-radius: 7px; display: block; }

/* Passcode */
.passcode { height: var(--app-h, 100dvh); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.brand { color: var(--accent); font-size: 32px; font-weight: 900; margin: 0; }
.passcode-sub { color: var(--muted); margin: 8px 0 30px; }
.dots { display: flex; gap: 14px; min-height: 16px; margin-bottom: 32px; }
.dots .d { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border); }
.dots .d.filled { background: var(--accent); border-color: var(--accent); }
.pad { display: grid; grid-template-columns: repeat(3, 84px); gap: 14px; }
.key { width: 84px; height: 84px; border-radius: 50%; border: none; background: var(--surface); color: var(--text); font-size: 28px; font-weight: 600; }
.key:active { background: var(--surface-alt); }
.key-ok { font-size: 19px; font-weight: 800; color: var(--accent); }
.passcode-err { color: var(--red); min-height: 20px; margin-top: 12px; font-weight: 600; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: calc(env(safe-area-inset-top) + 50px) 16px 16px; }
.overlay.sheet-bottom { align-items: flex-end; padding: 0; }
.sheet, .menu { width: 100%; max-width: 480px; background: var(--surface-alt); border-radius: 16px; padding: 16px; border: 1px solid var(--border); }
/* Bottom sheets: flex column capped to the visible viewport so a long list scrolls
   inside the sheet instead of bleeding past the notch / off the screen. */
.overlay.sheet-bottom .menu { max-width: 600px; border-radius: 18px 18px 0 0; border-bottom: none; padding-bottom: calc(env(safe-area-inset-bottom) + 14px); display: flex; flex-direction: column; max-height: calc(var(--app-h, 100dvh) - env(safe-area-inset-top) - 8px); }
.menu-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-title, .menu-title { font-size: 16px; font-weight: 800; margin-bottom: 12px; flex: none; }
.search-input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 17px; padding: 14px; border-radius: 12px; outline: none; }
.search-input:focus { border-color: var(--accent); }
.results { margin-top: 8px; max-height: 46dvh; overflow-y: auto; }
.result { padding: 12px 8px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.result:active { background: var(--surface); }
.result-top { display: flex; justify-content: space-between; gap: 8px; }
.result-name { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-price { color: var(--accent); font-weight: 700; flex: none; }
.result-sub { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.results-empty { color: var(--muted); padding: 16px 4px; font-size: 14px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; align-items: center; }
.btn-ghost { background: transparent; color: var(--muted); border: none; font-size: 15px; font-weight: 700; padding: 12px 16px; }
.btn-primary { background: var(--accent); color: #1A1206; border: none; font-size: 15px; font-weight: 800; padding: 12px 22px; border-radius: 12px; }
.menu-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; font-size: 16px; border-bottom: 1px solid var(--border); gap: 12px; }
.menu-row small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.menu-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.menu-action { width: 100%; text-align: left; background: transparent; border: none; color: var(--text); font-size: 15px; font-weight: 600; padding: 14px 4px; border-bottom: 1px solid var(--border); }
.menu-action:active { color: var(--accent); }
.menu-close { width: 100%; margin-top: 14px; background: var(--surface); color: var(--text); border: none; font-size: 15px; font-weight: 700; padding: 13px; border-radius: 12px; flex: none; }
.menu-action.danger { color: var(--red); font-weight: 700; }
.menu-row.last, .astat.last { border-bottom: none; }
.storage-info { padding-bottom: 6px; }
/* Catalogue summary + sync / info buttons in Settings */
.cat-summary { background: var(--surface); border-radius: 12px; padding: 2px 12px; margin: 12px 0 10px; }
.cat-actions { display: flex; gap: 10px; margin-bottom: 6px; }
.cat-btn { flex: 1; border: none; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 800; }
.cat-btn.sync { background: var(--accent); color: #1A1206; }
.cat-btn.sync.done { background: var(--green); color: #062012; }
.cat-btn.info { background: var(--blue); color: #fff; }

/* Admin / stats */
.astat-group { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 12px 2px 4px; }
.admin-stats { max-height: 52dvh; overflow-y: auto; }
.astat { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.astat .k { color: var(--muted); } .astat .v { font-weight: 700; font-family: var(--mono); text-align: right; }
.astat .v.good { color: var(--green); } .astat .v.bad { color: var(--red); }

/* Fullscreen photo */
.img-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.96); z-index: 50; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.img-loading { position: absolute; color: var(--muted); font-size: 15px; }
.img-full { max-width: 100%; max-height: 100%; touch-action: none; will-change: transform; }
.img-close { position: absolute; top: calc(env(safe-area-inset-top) + 14px); right: 18px; z-index: 51; width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,0.15); color: #fff; font-size: 22px; font-weight: 700; }
