/* Created with AI assistance */
:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1b1f24; --muted: #5b6470; --line: #d5d9df;
  --accent: #1f5fbf; --red: #d22f2f; --yellow: #e0a800; --green: #1f9d55;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171b; --card: #1e2329; --text: #e8eaed; --muted: #9aa3ad; --line: #363d46; --accent: #6ea8ff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, sans-serif; }
[hidden] { display: none !important; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.spacer { flex: 1; }
main { max-width: 720px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 12px; }
h1 { font-size: 1.2rem; margin: 0; }
label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
input, select, button { font: inherit; }
input:not([type=checkbox]):not([type=file]), select {
  padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%;
}
button { padding: 12px 18px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
button.quiet { background: transparent; color: var(--accent); border: 1px solid var(--line); padding: 6px 12px; font-weight: 500; }
button:disabled { opacity: 0.5; cursor: default; }
.error { color: var(--red); margin: 0; }
.hint { color: var(--muted); margin: 8px 0; min-height: 1.4em; }
.note { color: var(--muted); font-size: 0.9rem; margin: 0; padding-left: 18px; }
p.note { padding-left: 0; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 0.85rem; margin: 0; width: fit-content; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 12px 0; }

/* camera picture with the scan frame on top: the stage has the shape of the label plus a small margin,
   the video fills it ("cover") and is scaled for digital zoom */
#stage { position: relative; width: 100%; margin: 0 auto; background: #000; border-radius: 10px; overflow: hidden; line-height: 0; aspect-ratio: 3 / 1; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 50% 50%; }
#frame { position: absolute; border: 3px solid var(--red); border-radius: 4px; box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.3); box-sizing: border-box; }
#frame.yellow { border-color: var(--yellow); }
#frame.green { border-color: var(--green); }
#elements { position: absolute; inset: 0; }
/* positions really found: blue while searching, green once read */
#detected { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#detected polygon { fill: rgba(47, 128, 237, 0.12); stroke: #2f80ed; stroke-width: 2; vector-effect: non-scaling-stroke; }
#detected polygon.read { fill: rgba(31, 157, 85, 0.16); stroke: var(--green); }
#elements svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#elements polygon { fill: none; stroke: #4dd0ff; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
#elements polygon.line { stroke: #ffd84d; stroke-width: 1.5; stroke-dasharray: none; }
#elements span { position: absolute; color: #4dd0ff; font: 600 11px/1 system-ui, sans-serif; padding: 1px 2px; text-shadow: 0 0 2px #000; }
/* status line below the picture: barcode and texts (not found / found / read / confirmed) */
.status-line { display: grid; gap: 2px; margin-top: 8px; }
.code-state { display: flex; align-items: center; gap: 8px; margin: 0; font: 600 0.9rem/1.3 ui-monospace, monospace; color: var(--muted); overflow-wrap: anywhere; }
.code-state.found::before { background: #2f80ed; }
.code-state::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.code-state.seen { color: var(--text); }
.code-state.seen::before { background: var(--yellow); }
.code-state.ok { color: var(--green); }
.code-state.ok::before { background: var(--green); }
.stats { font: 0.8rem/1.4 ui-monospace, monospace; white-space: pre-line; }
.camera-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
.camera-tools .zoom { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 160px; }
.camera-tools .zoom input { flex: 1; }
.camera-tools select { width: auto; max-width: 100%; padding: 6px 10px; }
button.quiet[aria-pressed="true"] { background: var(--yellow); color: #000; border-color: var(--yellow); }

/* imported photo with the frame drawn by the user */
#mark-area { position: relative; touch-action: none; user-select: none; line-height: 0; cursor: crosshair; }
#mark-canvas { width: 100%; border-radius: 6px; background: #000; }
#mark-rect { position: absolute; border: 3px dashed var(--accent); background: rgba(31, 95, 191, 0.15); box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.35); pointer-events: none; }
#mark-area { overflow: hidden; border-radius: 6px; }

/* live values while aiming: one row per entry of the form layout, the boxes of a row share its width */
.live { display: grid; gap: 6px; }
.form-row { display: flex; gap: 6px; min-width: 0; }
.form-row > * { flex: 1 1 0; min-width: 0; }
.live .form-row > div { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 0.85rem; overflow: hidden; }
.live .form-row > div.ok { border-color: var(--green); }
.live .form-row > div.known { border-style: dashed; color: var(--muted, #666); }
.live small { display: block; color: var(--muted); }

/* result */
#result-image { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#fields { display: grid; gap: 8px; }
#fields .form-row { gap: 8px; }
#fields .field-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
#fields .state { font-size: 0.72rem; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
#fields .state.confirmed { border-color: var(--green); color: var(--green); }
#fields .state.conflict, #fields .state.invalid, #fields .state.missing, #fields .state.unreadable { border-color: var(--red); color: var(--red); }
#fields .state.plausible, #fields .state.reconstructed { border-color: var(--yellow); color: var(--yellow); }
pre { overflow: auto; max-height: 50vh; font-size: 0.75rem; background: var(--bg); padding: 8px; border-radius: 6px; margin: 0; }

/* camera switched off after a while without scanning */
.camera-off { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.72); line-height: 1.4; }

/* settings */
#view-settings { display: grid; gap: 16px; }
.grid { display: grid; gap: 10px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.actions.tight { margin: 0; gap: 8px; }
.segmented { display: flex; gap: 0; }
.segmented button { flex: 1; background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 0; padding: 8px; font-weight: 500; }
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.panel { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 10px; }
.panel textarea { width: 100%; min-height: 90px; font: 0.8rem/1.4 ui-monospace, monospace; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
#ed-area { position: relative; touch-action: none; user-select: none; line-height: 0; }
#ed-canvas { width: 100%; border-radius: 6px; background: #fff; cursor: crosshair; }
.probe { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.done { margin: 0; padding: 10px 12px; border-radius: 8px; background: rgba(31, 157, 85, 0.14); color: var(--green); font-weight: 600; }

/* progress while the server works on the photo */
.progress { display: grid; gap: 6px; }
.progress-track { height: 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.progress-step { margin: 0; font-size: 0.95rem; }
.server-load { font: 0.8rem/1.4 ui-monospace, monospace; color: var(--muted); }

/* footer: server load and the small settings button */
.footer { max-width: 720px; margin: 0 auto; padding: 4px 16px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.footer .server-load { flex: 1; }
.footer .credit { flex-basis: 100%; color: var(--muted); font-size: 0.8rem; }
button.small { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 4px 10px; font-size: 0.8rem; font-weight: 500; }
