:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #13201d;
  --muted: #64706d;
  --brand: #0f766e;
  --brand-2: #115e59;
  --danger: #b42318;
  --border: #dde3e1;
  --price: #0f766e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1413;
    --card: #16201e;
    --text: #e8efed;
    --muted: #93a19d;
    --border: #2a3634;
    --price: #5eead4;
    --danger: #f97066;
  }
}
* { box-sizing: border-box; }
/* Atribut hidden harus selalu menang atas display:flex/grid di aturan lain —
   tanpa ini, lapisan "Mulai Scan" tetap menutupi kamera setelah disembunyikan. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--brand); color: #fff;
}
.brand { font-weight: 700; font-size: 18px; }
.hint { font-size: 13px; opacity: .85; }
main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px); }

.camera {
  position: relative; border-radius: 16px; overflow: hidden;
  background: #000; aspect-ratio: 4 / 3; width: 100%;
}
#reader { width: 100%; height: 100%; }
#reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
#reader img[alt="Info icon"] { display: none; }
.cam-idle {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; color: #fff; text-align: center; padding: 16px;
}
.cam-idle .muted { color: #cfd8d6; }
.scanline {
  position: absolute; left: 10%; right: 10%; top: 50%; height: 2px;
  background: #ef4444; box-shadow: 0 0 8px #ef4444; pointer-events: none;
}

.focus-ring {
  position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border: 2px solid #facc15; border-radius: 10px; pointer-events: none; opacity: 0;
}
.focus-ring.show { animation: focus 1s ease-out; }
@keyframes focus {
  0% { transform: scale(1.4); opacity: 1; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}
.zoom-bar {
  position: absolute; z-index: 5; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; background: rgba(0,0,0,.45); padding: 4px; border-radius: 999px;
}
.zoom-bar button {
  appearance: none; border: none; background: transparent; color: #fff; font: inherit;
  font-size: 13px; font-weight: 700; min-width: 40px; height: 32px; border-radius: 999px; cursor: pointer;
}
.zoom-bar button.on { background: #fff; color: #000; }
.camera { cursor: crosshair; }

.result {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px 16px; min-height: 160px; display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.result .barcode { font-family: ui-monospace, Menlo, monospace; color: var(--muted); font-size: 13px; }
.result .name { font-size: 22px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.result .price { font-size: 40px; font-weight: 800; color: var(--price); letter-spacing: -.5px; }
.result .noprice { font-size: 18px; color: var(--muted); font-style: italic; }
.result .notfound { font-size: 20px; font-weight: 600; color: var(--danger); }
.result .row { margin-top: 10px; }
.result.flash { animation: flash .35s ease-out; }
@keyframes flash { from { transform: scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }

.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 12px; cursor: pointer; min-height: 48px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-2); }
.btn.big { font-size: 18px; padding: 14px 28px; }
.btn:disabled { opacity: .6; }

dialog {
  border: none; border-radius: 16px; padding: 0; width: min(92vw, 420px);
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 20px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
input {
  font: inherit; font-size: 17px; font-weight: 400; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%;
}
input[readonly] { color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
input:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.req { color: var(--danger); }
.error { color: var(--danger); margin: 0; font-size: 14px; }
