:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --border: #dcdfe4;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.subtitle { color: var(--muted); font-size: 13px; }

.badge {
  margin-left: auto;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge-wait { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-ok   { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-err  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 48px;
  align-items: start;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 22px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.panel h3 { font-size: 13px; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  background: #fafbfc;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: #eff6ff; }
.dropzone p { margin: 0 0 12px; color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.options { justify-content: flex-start; margin: 14px 0 12px; gap: 18px; }
.chk { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }

.btn {
  font: inherit;
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#runBtn { width: 100%; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #cbd5e1; border-color: #cbd5e1; cursor: not-allowed; }
.btn-ghost { background: transparent; }

.progress-wrap { margin-top: 12px; }
.progress { height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }

.canvas-wrap { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fafbfc; }
#cardCanvas { width: 100%; height: auto; display: block; border-radius: 4px; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }

.details { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.details summary { cursor: pointer; font-size: 13px; color: var(--muted); }

.roi-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-top: 12px; }
.roi-item { margin: 0; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }
.roi-img { max-width: 100%; max-height: 70px; width: auto; height: auto; display: block; margin: 0 auto; background: #fff; border-radius: 3px; }
.roi-item figcaption { font-size: 11px; margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.roi-src { color: var(--accent); font-size: 10px; }
.roi-raw { color: var(--muted); word-break: break-all; }
.roi-clean { color: var(--ok); word-break: break-all; }

.raw {
  margin-top: 10px; padding: 10px; background: #0f172a; color: #e2e8f0;
  border-radius: 6px; font-size: 12px; max-height: 260px; overflow: auto; white-space: pre-wrap;
}

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px 6px; margin: 0 0 16px; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 6px; }

.field { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 10px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; min-width: 0;
}
.field input:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
@media (max-width: 560px) { .field { grid-template-columns: 1fr; } }

.conf { font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; min-width: 46px; text-align: center; }
.conf-high { background: #dcfce7; color: #166534; }
.conf-mid  { background: #fef9c3; color: #854d0e; }
.conf-low  { background: #fee2e2; color: #991b1b; }
.conf-none { background: #f1f5f9; color: #64748b; }
.conf[data-fallback="1"]::after { content: " ·zál."; }

/* ---- ručné vyznačenie rohov ---- */
.crop { position: fixed; inset: 0; z-index: 60; background: #0f172a; display: none; flex-direction: column; }
.crop.open { display: flex; }
.crop-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; }
.crop-canvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: grab; }
.crop-hint { color: #e2e8f0; text-align: center; margin: 0 0 10px; font-size: 14px; }
.crop-bar { display: flex; gap: 12px; justify-content: center; padding: 0 16px 22px; flex-wrap: wrap; }

/* ---- snímanie cez rámik ---- */
.cam { position: fixed; inset: 0; z-index: 50; background: #000; display: none; }
.cam.open { display: block; }
.cam-video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Rámik má presný pomer strán dokladu ID-1 (85,60 × 53,98 mm). */
.cam-guide {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 86%; max-width: 640px; aspect-ratio: 85.6 / 53.98;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55);
  border-radius: 12px;
}
/* Rohy rámika zozelenajú, keď je doklad priložený správne. */
.cam-guide .c { position: absolute; width: 34px; height: 34px; border: 4px solid #fff; transition: border-color .15s; }
.cam-guide.good .c { border-color: #22c55e; }
.cam-guide.good { box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45), 0 0 24px rgba(34, 197, 94, .55); }
.cam-guide .tl { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-radius: 12px 0 0 0; }
.cam-guide .tr { top: -3px; right: -3px; border-left: 0; border-bottom: 0; border-radius: 0 12px 0 0; }
.cam-guide .bl { bottom: -3px; left: -3px; border-right: 0; border-top: 0; border-radius: 0 0 0 12px; }
.cam-guide .br { bottom: -3px; right: -3px; border-left: 0; border-top: 0; border-radius: 0 0 12px 0; }

.cam-hint {
  position: absolute; left: 0; right: 0; top: calc(50% + 28vw + 24px);
  text-align: center; color: #fff; font-size: 15px; font-weight: 600;
  margin: 0; text-shadow: 0 1px 3px #000;
}
.cam-bar { position: absolute; left: 0; right: 0; bottom: 28px; display: flex; gap: 14px; justify-content: center; }
/* Výzva na otočenie telefónu prekryje celý náhľad — fotiť sa vtedy nedá. */
.cam-rotate {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center;
  background: rgba(15, 23, 42, .92); color: #fff; z-index: 2;
}
.cam.landscape .cam-rotate { display: flex; }
.cam.landscape .cam-guide, .cam.landscape .cam-hint { visibility: hidden; }
.cam-rotate p { margin: 0; font-size: 20px; }
.cam-rotate-why { font-size: 14px; color: #cbd5e1; max-width: 34ch; }

.cam-error { position: absolute; left: 16px; right: 16px; top: 16px; margin: 0; padding: 10px 14px;
  background: #7f1d1d; color: #fff; border-radius: 8px; font-size: 13px; text-align: center; }

.debug-log { max-height: 320px; font-size: 11px; line-height: 1.45; }
#debugPanel .btn { margin-top: 8px; }

.validation { margin: 4px 0 16px; }
.msg { margin: 0 0 6px; font-size: 13px; padding: 7px 11px; border-radius: 6px; }
.msg-ok { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.msg-warn { background: #fffbeb; color: var(--warn); border: 1px solid #fde68a; }
