: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;
}

/* ── Моите записи ─────────────────────────────────────────────────────────── */

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

.clip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: background 0.12s, transform 0.12s;
}
.clip:active { background: var(--surface-2); transform: scale(0.99); }

.clip-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.clip-cam {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-sub { font-size: 12px; color: var(--muted); }

.clip-play {
  flex: none;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  font-size: 15px;
  color: var(--select);
  background: var(--surface-2);
  border-radius: 50%;
}

/* ── Плейър ───────────────────────────────────────────────────────────────── */

.player {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
  background: rgba(0, 0, 0, 0.85);
}

.player-box {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-box video {
  width: 100%;
  max-height: 62vh;
  background: #000;
  border-radius: var(--radius);
}

.player-meta { font-size: 14px; color: var(--text); text-align: center; }

.player-actions { display: flex; gap: 10px; }
.player-actions button {
  flex: 1;
  min-height: 54px;
  font-size: 16px;
  font-weight: 650;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.btn-close { background: var(--surface-2); }
.btn-close:active { background: var(--border); }
.btn-delete { color: var(--record); background: var(--surface); border-color: var(--record); }
.btn-delete.confirm { color: #fff; background: var(--record); }
.btn-delete:active { background: var(--record-press); }

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

.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; }
}

/* ── Метаданни след запис („Кой краде?" / „Каква кражба?") ────────────────── */

.meta-box { max-width: 420px; padding: var(--pad); }

.meta-title {
  margin: 6px 0 10px;
  font-size: 17px;
  font-weight: 700;
}
.meta-title + .chip-row { margin-bottom: 16px; }
.meta-hint { font-size: 12px; font-weight: 500; color: var(--muted); }

.chip-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.chip-row .chip { min-height: 48px; font-size: 15px; padding: 6px 8px; }

.btn-save {
  flex: 1;
  padding: 14px;
  font-weight: 700;
  color: #05240f;
  background: var(--select);
  border: none;
  border-radius: var(--radius);
}
.btn-save:disabled { color: var(--muted); background: var(--surface-2); }

/* ── Избор на магазин ─────────────────────────────────────────────────────── */

.top-actions { display: flex; align-items: center; gap: 10px; }

.store-select {
  max-width: 150px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Прогрес по квотите ───────────────────────────────────────────────────── */

.stats-summary { cursor: pointer; list-style: none; }
.stats-summary::before { content: '▸ '; }
.stats[open] .stats-summary::before { content: '▾ '; }

.stats-body { font-size: 14px; }

.stats-total { margin: 4px 0 14px; font-size: 15px; }
.stats-total strong { font-size: 22px; }

.stats-group { margin: 0 0 14px; }
.stats-group h4 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.stat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-count { flex: none; font-variant-numeric: tabular-nums; color: var(--muted); }

.stat-bar {
  flex: none;
  width: 90px;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.stat-bar i {
  display: block;
  height: 100%;
  background: var(--select);
  border-radius: 999px;
}
.stat-bar.hot i { background: var(--warn); }

.stats-refresh {
  margin-top: 4px;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
