/* Gabit Rack Scanner — Mini App
   Kierunek: przyrzad terenowy, nie aplikacja. Slownictwo etykiet spedycyjnych
   i celownikow skanera. Baza kolorystyczna z motywu Telegrama, do tego dwa
   kolory sygnalowe na przeciwne kierunki ruchu stojaka. */

:root {
  --bg:       var(--tg-theme-bg-color, #17212b);
  --surface:  var(--tg-theme-secondary-bg-color, #232e3c);
  --text:     var(--tg-theme-text-color, #f2f5f7);
  --muted:    var(--tg-theme-hint-color, #8b9aa8);
  --accent:   var(--tg-theme-button-color, #3d9ae8);

  /* kierunki ruchu stojaka */
  --out:      #24a45c;   /* dostarczenie — stojak zostaje u klienta */
  --in:       #e08a2b;   /* odbior — stojak wraca */
  --stop:     #e0524d;

  --line:     color-mix(in srgb, var(--muted) 26%, transparent);
  --r-lg:     18px;
  --r-md:     13px;
  --pad:      16px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* --- rusztowanie ---------------------------------------------------------
   Pelna wysokosc bez skakania przy chowaniu paska adresu: dvh z odwrotem
   na vh, plus zmienna ustawiana z JS na podstawie viewportu Telegrama. */

.app {
  height: 100vh;
  height: 100dvh;
  height: var(--app-h, 100dvh);
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 10px)
    calc(env(safe-area-inset-right) + var(--pad))
    calc(env(safe-area-inset-bottom) + 12px)
    calc(env(safe-area-inset-left) + var(--pad));
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view--center {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

.view--scan { gap: 12px; }

.spacer { flex: 1; min-height: 8px; }

.is-hidden { display: none !important; }

/* --- pasek gorny --------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.bar__mark { font-weight: 700; color: var(--text); letter-spacing: .16em; }
.bar__sep { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }
.bar__title { font-weight: 500; }

.bar__user {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- celownik ------------------------------------------------------------ */

.finder {
  position: relative;
  flex: 1;
  min-height: 220px;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #000;
}

#reader { width: 100%; height: 100%; }

#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}

/* html5-qrcode dokleja wlasne UI — chowamy, mamy swoj celownik */
#reader img,
#reader__dashboard,
#reader__status_span,
#reader__scan_region > img { display: none !important; }

.finder__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.finder__corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2.5px solid #fff;
  opacity: .92;
}

.finder__corner--tl { top: 14px; left: 14px;  border-right: 0; border-bottom: 0; border-radius: 7px 0 0 0; }
.finder__corner--tr { top: 14px; right: 14px; border-left: 0;  border-bottom: 0; border-radius: 0 7px 0 0; }
.finder__corner--bl { bottom: 14px; left: 14px;  border-right: 0; border-top: 0; border-radius: 0 0 0 7px; }
.finder__corner--br { bottom: 14px; right: 14px; border-left: 0;  border-top: 0; border-radius: 0 0 7px 0; }

/* jedyny ruch w calym interfejsie — procenty w `top` licza sie od wysokosci
   celownika, wiec linia jedzie od gornej do dolnej ramki niezaleznie od ekranu */
.finder__beam {
  position: absolute;
  left: 14px;
  right: 14px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, #fff 22%, #fff 78%, transparent);
  opacity: .7;
  animation: sweep 2.8s ease-in-out infinite alternate;
}

@keyframes sweep {
  from { top: 16px; }
  to   { top: calc(100% - 18px); }
}

/* --- etykieta stojaka (element sygnaturowy) ------------------------------
   Karta udajaca naklejke spedycyjna: prazkowana krawedz jak nadruk kodu. */

.tag {
  position: relative;
  flex: 0 0 auto;
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 18px 18px 20px;
  overflow: hidden;
}

.tag::before,
.tag::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--muted) 0 2px,
    transparent 2px 6px
  );
  opacity: .35;
}

.tag::before { top: 0; }
.tag::after  { bottom: 0; }

.tag__eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}

.tag__code {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: clamp(26px, 8.5vw, 40px);
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.15;
  word-break: break-all;
}

.tag__meta {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-line;
}

/* pieczec statusu na ekranie potwierdzenia */
.tag__stamp {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 11px;
  border: 2px solid currentColor;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.tag--out .tag__stamp { color: var(--out); }
.tag--in  .tag__stamp { color: var(--in); }

/* --- przyciski akcji ----------------------------------------------------- */

.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.act {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform .07s ease, opacity .15s ease;
}

.act--out  { background: var(--out); }
.act--in   { background: var(--in); }
.act--next { background: var(--accent); color: var(--tg-theme-button-text-color, #fff); }

.act:active:not(:disabled) { transform: scale(.983); }
.act:disabled { opacity: .45; cursor: default; }

.act__glyph {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  opacity: .95;
}

.act__glyph svg { width: 100%; height: 100%; display: block; }

.act__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.act__title { font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; }
.act__sub { font-size: 12.5px; font-weight: 400; opacity: .82; }

/* --- przyciski drugorzedne ----------------------------------------------- */

.btn {
  width: 100%;
  min-height: 46px;
  padding: 11px 16px;
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.btn--quiet {
  background: transparent;
  color: var(--muted);
}

.btn--quiet:active { color: var(--text); }

/* --- komunikaty ---------------------------------------------------------- */

.view__title { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }

.note { margin: 0; font-size: 14.5px; color: var(--muted); max-width: 34ch; }
.note--hint { text-align: center; align-self: center; }

.error {
  flex: 0 0 auto;
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--stop) 15%, transparent);
  color: var(--stop);
  font-size: 14px;
}

.idchip {
  margin: 0;
  padding: 9px 16px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  user-select: all;
}

.mark {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.mark svg { width: 30px; height: 30px; }
.mark--stop { background: color-mix(in srgb, var(--stop) 18%, transparent); color: var(--stop); }

/* --- spinner i naklada --------------------------------------------------- */

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(2px);
  font-size: 15px;
  color: var(--muted);
}

/* --- dostepnosc ---------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .finder__beam { animation: none; opacity: 0; }
  .spinner { animation-duration: 2s; }
  .act:active { transform: none; }
}

/* telefony o niskich ekranach — oddajemy przestrzen celownikowi */
@media (max-height: 640px) {
  .app { gap: 10px; }
  .tag { padding: 14px 15px 16px; }
  .act { min-height: 58px; }
  .finder__corner { width: 24px; height: 24px; }
}
