/* Skaner dokumentów AI-CARGO — część wizualna (Hostinger).
   Jedna czcionka aplikacji (Inter) ładowana systemowo: moduł jest samodzielny
   (bez next/font), więc stack = Inter jeśli zainstalowany + system-ui fallback. */

:root {
  --bg: #0a0a0a;
  --fg: #fafafa;
  --dim: #a1a1aa;
  --ok: #4ade80;
  --warn: #fbbf24;
  --accent: #e4e4e7;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
}
.brand { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.order { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ═══ Start ═══ */
.start-body { flex: 1; display: flex; flex-direction: column; padding: 8px 22px calc(env(safe-area-inset-bottom, 0px) + 22px); gap: 14px; }
.start-body h1 { font-size: 26px; font-weight: 700; margin-top: 8px; }
.hint { font-size: 14px; line-height: 1.55; color: var(--dim); }
.cat-label { margin-top: 10px; font-size: 10px; font-weight: 600; letter-spacing: 0.16em; color: var(--dim); }
.cats { display: flex; flex-wrap: wrap; gap: 8px; }
.cat {
  padding: 9px 14px; border: 1px solid #3f3f46; border-radius: 999px;
  background: transparent; color: var(--fg); font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em; transition: all .18s ease;
}
.cat.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.btn {
  display: block; width: 100%; padding: 15px 16px; border-radius: var(--radius);
  border: 1px solid #3f3f46; background: transparent; color: var(--fg);
  font-family: inherit; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; text-align: center;
  text-decoration: none; cursor: pointer; transition: transform .12s ease, opacity .18s ease;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); margin-top: auto; }
.btn-ghost { color: var(--dim); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.error { color: #f87171; font-size: 13px; text-align: center; }

/* ═══ Kamera ═══ */
#screen-camera { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

.flash {
  position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none;
}
.flash.on { animation: flash .32s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

.scanline {
  position: absolute; left: 6%; right: 6%; height: 2px; top: 0;
  background: linear-gradient(90deg, transparent, var(--ok) 30%, var(--ok) 70%, transparent);
  box-shadow: 0 0 14px 3px rgba(74, 222, 128, .55);
  animation: scanline 0.9s ease-in-out;
  pointer-events: none;
}
@keyframes scanline { 0% { top: 8%; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { top: 88%; opacity: 0; } }

/* Prowadzenie: pierścień postępu + komunikat (Face-ID-like) */
.guide {
  position: absolute; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 118px);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  pointer-events: none;
}
.ring { width: 40px; height: 40px; flex: 0 0 auto; }
.ring circle { fill: none; stroke-width: 5; }
.ring-bg { stroke: rgba(255, 255, 255, .22); }
.ring-fg {
  stroke: var(--ok); stroke-linecap: round;
  stroke-dasharray: 150.8; stroke-dashoffset: 150.8;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset .12s linear;
}
.msg-wrap { position: relative; min-width: 200px; height: 44px; display: flex; align-items: center; }
.msg {
  position: absolute; left: 0; right: 0;
  font-size: 17px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--fg); text-shadow: 0 1px 8px rgba(0,0,0,.85);
  opacity: 0; transition: opacity .22s ease;
}
.msg.show { opacity: 1; }
.msg.ok { color: var(--ok); }
.msg.warn { color: var(--warn); }

.btn-cam-cancel {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 10px); left: 12px;
  width: auto; padding: 9px 16px; background: rgba(0,0,0,.45); border-color: rgba(255,255,255,.25);
  color: var(--fg); backdrop-filter: blur(6px); border-radius: 999px;
}
.shutter {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  width: 66px; height: 66px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.9); background: rgba(255,255,255,.28);
  cursor: pointer; transition: transform .12s ease;
}
.shutter:active { transform: translateX(-50%) scale(.92); }

/* ═══ Przetwarzanie ═══ */
#screen-processing { align-items: center; justify-content: center; }
.proc-box { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.proc-doc {
  width: 92px; height: 122px; border: 2px solid #52525b; border-radius: 8px;
  position: relative; overflow: hidden;
}
.proc-line {
  position: absolute; left: 8%; right: 8%; height: 2px;
  background: var(--ok); box-shadow: 0 0 10px 2px rgba(74,222,128,.6);
  animation: procline 1.1s ease-in-out infinite alternate;
}
@keyframes procline { from { top: 10%; } to { top: 88%; } }
.proc-text { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; color: var(--dim); }

/* ═══ Podgląd ═══ */
.review-body { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 4px 18px calc(env(safe-area-inset-bottom, 0px) + 18px); min-height: 0; }
.review-canvas-wrap {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); overflow: hidden; background: #18181b;
}
#review-canvas { max-width: 100%; max-height: 100%; box-shadow: 0 8px 40px rgba(0,0,0,.6); animation: reviewIn .32s ease; }
@keyframes reviewIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

.seg { display: flex; border: 1px solid #3f3f46; border-radius: 10px; overflow: hidden; align-self: center; }
.seg-btn {
  padding: 8px 22px; background: transparent; border: 0; color: var(--dim);
  font-family: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; cursor: pointer;
}
.seg-btn.active { background: var(--fg); color: var(--bg); }
.review-actions { display: flex; gap: 10px; }
.review-actions .btn { flex: 1; padding: 12px; }

/* ═══ Korekta narożników ═══ */
.corners-body { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 4px 18px calc(env(safe-area-inset-bottom, 0px) + 18px); min-height: 0; }
.corners-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#corners-canvas { max-width: 100%; max-height: 100%; }
#corners-quad { position: absolute; pointer-events: none; overflow: visible; }
#corners-quad polygon { fill: rgba(74, 222, 128, .12); stroke: var(--ok); stroke-width: 2; }
.handle {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 3px solid var(--ok); background: rgba(10,10,10,.5);
  touch-action: none; cursor: grab;
}
.handle::after {
  content: ''; position: absolute; inset: 11px; border-radius: 50%; background: var(--ok);
}

/* ═══ Done ═══ */
.done-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 22px; }
.done-icon svg { width: 84px; height: 84px; }
.done-icon circle { fill: none; stroke: var(--ok); stroke-width: 3; stroke-dasharray: 151; stroke-dashoffset: 151; }
.done-icon path { fill: none; stroke: var(--ok); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 40; stroke-dashoffset: 40; }
.done-icon.play circle { animation: draw .5s ease forwards; }
.done-icon.play path { animation: draw .35s ease .4s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.done-icon.spin svg { animation: spin 1.1s linear infinite; }
.done-icon.spin circle { stroke: #52525b; stroke-dashoffset: 110; }
.done-icon.spin path { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.done-text { font-size: 16px; font-weight: 700; letter-spacing: 0.1em; }
.done-sub { font-size: 13px; color: var(--dim); text-align: center; line-height: 1.5; }
.done-body .btn { max-width: 340px; }
