:root {
  --ink: #10231a;
  --line: #cad8ce;
  --paper: #f8faf7;
  --green: #0d5c3a;
  --danger: #a1271f;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
body { margin: 0; min-width: 320px; color: var(--ink); font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.scanner-app { position: relative; width: 100%; height: 100svh; overflow: hidden; background: #000; }
.camera-section, .camera-view, .reader, .reader video, #fallback-reader { position: absolute; inset: 0; width: 100%; height: 100%; }
.camera-view, #fallback-reader { overflow: hidden; background: #000; }
.reader video, #fallback-reader video { display: block; object-fit: cover; }
.scan-frame { position: absolute; top: 50%; left: 50%; width: min(78vw, 340px); height: min(34vh, 190px); border: 2px solid rgba(255,255,255,.9); transform: translate(-50%, -50%); pointer-events: none; }

.camera-status { position: absolute; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); left: 16px; margin: 0; color: #fff; font-size: 16px; font-weight: 600; letter-spacing: -.01em; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .85); pointer-events: none; }
.camera-switch-button, .flash-button { position: absolute; top: calc(16px + env(safe-area-inset-top)); min-width: 46px; min-height: 46px; padding: 0 13px; border: 1px solid rgba(255,255,255,.75); border-radius: 0; background: rgba(0,0,0,.34); color: #fff; font-size: 14px; font-weight: 700; }
.camera-switch-button { left: 16px; }
.flash-button { right: 16px; }

.app-footer { position: absolute; z-index: 2; right: 0; bottom: calc(55px + env(safe-area-inset-bottom)); left: 0; display: flex; justify-content: center; gap: 18px; padding: 0 16px; }
.text-button { min-height: 44px; padding: 8px 12px; border: 0; background: rgba(0,0,0,.34); color: #fff; font-size: 14px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.65); }

.manual-section { position: absolute; z-index: 3; right: 0; bottom: 0; left: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
.manual-section label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; }
.manual-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.manual-row input { min-width: 0; min-height: 50px; padding: 0 12px; border: 1px solid var(--line); border-radius: 0; font-size: 16px; }

.result-section { position: absolute; z-index: 5; inset: 0; overflow-y: auto; padding: calc(28px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); background: var(--paper); }
.result-section[hidden] { display: none; }
.eyebrow { margin: 0 0 6px; color: #5e6e64; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h2 { margin: 0 0 10px; font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 500; letter-spacing: -.035em; line-height: 1.04; }
.result-detail { max-width: 42ch; margin: 0 0 16px; color: #5e6e64; font-size: 15px; line-height: 1.45; }
.result-detail:empty { display: none; }
.result-detail strong { color: var(--ink); }
.product-information:empty { display: none; }
.product-information { margin: 0 0 22px; border-top: 1px solid var(--line); }
.product-information-title { margin: 14px 0 8px; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 20px; font-weight: 500; letter-spacing: -.02em; line-height: 1.15; }
.product-fields { margin: 0; }
.product-fields > div { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.product-fields dt { color: #5e6e64; font-size: 13px; font-weight: 700; }
.product-fields dd { min-width: 0; margin: 0; color: var(--ink); font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.result-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.template-selection { display: grid; grid-column: 1 / -1; gap: 7px; margin-bottom: 5px; color: #34483b; font-size: 13px; font-weight: 700; }
.template-select { width: 100%; min-height: 50px; padding: 0 12px; border: 1px solid var(--line); border-radius: 0; background: #fff; color: var(--ink); font: inherit; font-weight: 500; }
.configuration-form { display: grid; grid-column: 1 / -1; gap: 14px; }
.configuration-field { display: grid; gap: 7px; color: #34483b; font-size: 13px; font-weight: 700; }
.configuration-field input { width: 100%; min-height: 50px; padding: 0 12px; border: 1px solid var(--line); border-radius: 0; background: #fff; color: var(--ink); font-size: 16px; }
.configuration-submit { margin-top: 4px; }
.button { width: 100%; min-height: 62px; padding: 10px 12px; border: 1px solid var(--green); border-radius: 0; font-size: 14px; font-weight: 700; line-height: 1.2; text-align: left; }
.button-primary { background: var(--green); color: #fff; }
.button-secondary { background: #fff; color: var(--green); }
.button-danger { border-color: var(--danger); background: transparent; color: var(--danger); }
.button:disabled { opacity: .5; cursor: wait; }
.manual-row .button { width: auto; min-height: 50px; }

@media (min-width: 700px) {
  .scanner-app { max-width: 540px; margin: 0 auto; }
}
