:root {
  --bg: #0d0f13;
  --surface: #171a21;
  --surface-2: #1f242e;
  --border: #2b313c;
  --text: #e9edf3;
  --muted: #8b95a6;
  --select: #22c55e;
  --record: #e5484d;
  --record-press: #b93b3f;
  --warn: #f5a524;
  --radius: 14px;
  --pad: 16px;
}

* { box-sizing: border-box; }

/*
 * Браузърът крие [hidden] чрез display:none в собствения си stylesheet, но всеки
 * наш `display:` от клас го бие — и елементът остава на екрана, прихващайки
 * докосванията. Тук се отнася за .pin-screen, който е display:grid.
 */
[hidden] { display: none !important; }

html {
  /* Долната лента е fixed и покрива дъното на страницата. Без това всеки
     скрол към елемент може да го остави точно под бутона ЗАПИШИ. */
  scroll-padding-bottom: 170px;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ── Вход ─────────────────────────────────────────────────────────────────── */

.pin-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--pad);
  background: var(--bg);
  z-index: 50;
}

.pin-box { width: min(360px, 100%); text-align: center; }
.pin-title { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.pin-hint { margin: 0 0 24px; color: var(--muted); font-size: 15px; }

#pin-form { display: grid; gap: 12px; }

.pin-input {
  width: 100%;
  padding: 18px;
  text-align: center;
  font-size: 28px;
  letter-spacing: 0.4em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pin-input:focus { outline: 2px solid var(--select); outline-offset: 1px; }

.pin-submit {
  padding: 16px;
  font-weight: 650;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pin-submit:active { background: var(--border); }

.pin-error { margin-top: 14px; color: var(--record); font-size: 14px; }

/* ── Заглавна лента ───────────────────────────────────────────────────────── */

main { padding: 0 var(--pad); }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 0 14px;
  background: linear-gradient(var(--bg) 78%, transparent);
}

.top-store { font-size: 17px; font-weight: 650; }
.top-sub { font-size: 13px; color: var(--muted); }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  font-size: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Секции ───────────────────────────────────────────────────────────────── */

.section { margin-bottom: 28px; }

.section-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Камери ───────────────────────────────────────────────────────────────── */

.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.camera {
  position: relative;
  padding: 0;
  overflow: hidden;
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.12s, transform 0.12s;
}
.camera:active { transform: scale(0.98); }

.camera[aria-pressed="true"] {
  border-color: var(--select);
}
.camera[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  font-size: 15px;
  font-weight: 700;
  color: #05240f;
  background: var(--select);
  border-radius: 50%;
}

.camera img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.camera .no-image {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  font-size: 30px;
  font-weight: 300;
  color: var(--muted);
  background: var(--surface-2);
}

.camera-meta { padding: 10px 12px 12px; }
.camera-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.camera-ch { font-size: 12px; color: var(--muted); }

/* ── Време назад ──────────────────────────────────────────────────────────── */

/*
 * Пренасяме на нов ред вместо хоризонтален скрол — иначе последната опция стои
 * извън екрана и служителят не подозира, че съществува. auto-fill, а не
 * auto-fit: при пет чипа последният остава с ширината на другите, вместо да се
 * разтегли през целия втори ред.
 */
.offset-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 10px;
}

.chip {
  min-height: 56px;
  font-size: 17px;
  font-weight: 650;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed="true"] {
  color: #05240f;
  background: var(--select);
  border-color: var(--select);
}

.chip .chip-tag {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}

.offset-note { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.offset-note strong { color: var(--text); }

.warning {
  margin-top: 14px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.4;
  color: #2a1c00;
  background: var(--warn);
  border-radius: 10px;
}
.warning button {
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 650;
  color: #2a1c00;
  background: rgba(0, 0, 0, 0.14);
  border: none;
  border-radius: 8px;
}

/* ── Последни записи ──────────────────────────────────────────────────────── */

.recent { margin: 0; padding: 0; list-style: none; }

.recent li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.recent li:last-child { border-bottom: none; }
.recent .dot { flex: none; font-size: 11px; }
.recent .ok { color: var(--select); }
.recent .error { color: var(--record); }
.recent .queued { color: var(--warn); }
.recent .empty { color: var(--muted); }
.recent .who { color: var(--text); }
.recent .msg {
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45%;
  text-align: right;
}

/* ── Долна лента ──────────────────────────────────────────────────────────── */

.spacer { height: 150px; }

.bottom {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 14px var(--pad) calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(transparent, var(--bg) 26%);
}

.summary {
  margin-bottom: 10px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}
.summary strong { color: var(--text); }

.record {
  width: 100%;
  min-height: 66px;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--record);
  border: none;
  border-radius: var(--radius);
  transition: transform 0.1s, background 0.15s;
}
.record:active:not(:disabled) { background: var(--record-press); transform: scale(0.985); }
.record:disabled { color: var(--muted); background: var(--surface-2); }
.record.accepted { color: #05240f; background: var(--select); }

/* ── Toast ────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  left: 50%;
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  font-size: 14px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transform: translateX(-50%);
  animation: rise 0.2s ease-out;
}
.toast.bad { color: #fff; background: var(--record); border-color: var(--record); }
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 10px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
