/* Видеоархив TRASSIR: тёмная тема, mobile-first. */

:root {
  color-scheme: dark;
  --bg: #0a0c0f;
  --surface: #14181d;
  --surface-2: #1c2128;
  --surface-3: #262d36;
  --border: #2a313b;
  --text: #f4f6f8;
  --text-2: #b9c1cc;
  --text-3: #8a94a1;
  --accent: #3d8bff;
  --accent-press: #2f74db;
  --live: #ff3b3b;
  --ok: #34c77b;
  --clip: #ffb020;
  --danger: #ff6b6b;
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gutter-l: max(12px, var(--safe-l));
  --gutter-r: max(12px, var(--safe-r));

  /* Шкала времени (читается из timeline.js). */
  --tl-track: rgba(255, 255, 255, .07);
  --tl-rec: #2fbf71;
  --tl-tick: rgba(255, 255, 255, .32);
  --tl-tick-major: rgba(255, 255, 255, .75);
  --tl-label: #ccd3dc;
  --tl-day: #ffffff;
  --tl-day-line: rgba(255, 255, 255, .28);
  --tl-clip: var(--clip);
  --tl-clip-fill: rgba(255, 176, 32, .17);
  --tl-now: #ff4d4d;
  --tl-future: rgba(0, 0, 0, .4);
  --tl-future-hatch: rgba(255, 255, 255, .08);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 22px; height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color .15s, opacity .15s;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--accent-press); }
@media (hover: hover) { .btn-primary:hover:not(:disabled) { background: #5099ff; } }
.btn:disabled { cursor: default; opacity: .55; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .live-btn:focus-visible, .cam-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active:not(:disabled) { background: var(--surface-3); }
@media (hover: hover) { .icon-btn:hover:not(:disabled) { background: var(--surface-2); } }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.sm { width: 40px; height: 40px; background: var(--surface-2); }

/* ---------- Экраны, шапка ---------- */

.screen { min-height: 100vh; min-height: 100dvh; }

.boot { display: grid; place-items: center; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) max(6px, var(--safe-r)) 0 max(6px, var(--safe-l));
  background: rgba(10, 12, 15, .9);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-left: 8px;
}
.topbar-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub .dot.live { color: var(--live); }

/* ---------- Вход ---------- */

.login {
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) var(--gutter-r) calc(24px + var(--safe-b)) var(--gutter-l);
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-logo {
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  margin: 0 auto 4px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
}
.login-logo .icon { width: 34px; height: 34px; }
.login-title { font-size: 26px; }
.login-sub { margin: -6px 0 6px; color: var(--text-2); font-size: 15px; }
.field input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 17px; /* ≥16px: iOS не зумит при фокусе */
  outline: none;
  transition: border-color .15s;
}
.field input::placeholder { color: var(--text-3); }
.field input:focus { border-color: var(--accent); }
.form-error { margin: 0; color: var(--danger); font-size: 15px; font-weight: 500; }

/* ---------- Сетка камер ---------- */

.grid-main {
  padding: 10px var(--gutter-r) calc(20px + var(--safe-b)) var(--gutter-l);
}
.cam-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 640px) { .cam-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
@media (min-width: 960px) { .cam-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1360px) { .cam-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1760px) { .cam-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.cam-card {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform .12s;
}
.cam-card:active { transform: scale(.97); }
.cam-card img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.cam-card img.loaded { opacity: 1; }
.cam-card.offline img { filter: grayscale(.7) brightness(.6); }
.cam-card::after { /* затемнение под подписью */
  content: "";
  position: absolute;
  inset: 45% 0 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78));
  pointer-events: none;
}
.cam-name {
  position: absolute;
  left: 9px; right: 9px; bottom: 6px;
  z-index: 1;
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}
.cam-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-3);
  font-size: 13px;
}

.pill {
  position: absolute;
  top: 6px; left: 6px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100% - 12px);
  padding: 3px 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .66);
  font-size: 12px;
  font-weight: 650;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.pill .dot { width: 7px; height: 7px; color: var(--live); }
.pill.off { color: var(--text-2); font-weight: 550; }
.pill.off .dot { color: var(--text-3); }

.empty { color: var(--text-2); text-align: center; padding: 40px 12px; }
.grid-tip { margin: 16px 0 0; color: var(--text-3); font-size: 13px; text-align: center; }
@media (hover: hover) and (pointer: fine) { .grid-tip { display: none; } }

/* ---------- Экран камеры ---------- */

.cam-main {
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: calc(20px + var(--safe-b));
}

.player {
  position: relative;
  width: min(100%, calc((100dvh - var(--topbar-h) - var(--safe-t)) * 16 / 9));
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.player > img, .player > video, .player > canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.player-video { opacity: 0; }
.player.show-video .player-video { opacity: 1; }
.player.show-video .player-snap { display: none; }
.player-snap:not([src]) { display: none; }
.player:fullscreen { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; }
.player:-webkit-full-screen { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; }

.badge {
  position: absolute;
  top: 10px; left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .66);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.badge.live { background: var(--live); color: #fff; }
.badge.live .dot { animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.player-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(rgba(0, 0, 0, .15), rgba(0, 0, 0, .45));
  pointer-events: none;
}
.hint-circle {
  display: grid;
  place-items: center;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  border: 2px solid rgba(255, 255, 255, .85);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.hint-circle .icon { width: 26px; height: 26px; margin-left: 4px; }
.hint-text {
  padding: 4px 12px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .6);
  font-size: 15px;
  font-weight: 600;
}
.hint-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
  .hint-mouse { display: inline; }
  .hint-touch { display: none; }
}
.player-hint.pulse .hint-circle { animation: pulse .5s; }
@keyframes pulse { 40% { transform: scale(1.15); } }

.player-msg {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .75);
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  pointer-events: none;
}

.player-flash {
  position: absolute;
  left: 50%; top: 50%;
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
}
.player-flash .icon { width: 28px; height: 28px; stroke-width: 3; }
.player-flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; transform: scale(.85); } 100% { opacity: 0; transform: scale(1.2); } }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255, 255, 255, .22);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.player-spinner {
  position: absolute;
  left: 50%; top: 50%;
  margin: -18px 0 0 -18px;
}

/* Шкала времени */

.scrubber {
  padding-top: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tl-head { display: flex; justify-content: center; padding: 0 var(--gutter-r) 4px var(--gutter-l); }
.tl-time {
  position: relative;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  line-height: 28px;
}
.timeline {
  position: relative;
  height: 68px;
  background: var(--bg);
  border-block: 1px solid var(--border);
  overflow: hidden;
  cursor: grab;
  touch-action: pan-y; /* вертикальный жест — прокрутка страницы, горизонтальный — шкале */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.timeline:active { cursor: grabbing; }
.tl-canvas { display: block; }
.tl-needle {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55);
  pointer-events: none;
}
.tl-needle::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: #fff;
}

.tl-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px var(--gutter-r) 10px var(--gutter-l);
}
.zoom, .tl-actions { display: flex; align-items: center; gap: 6px; }
.zoom-label {
  min-width: 62px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.live-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border: 2px solid var(--live);
  border-radius: 10px;
  background: transparent;
  color: #ff7070;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .06em;
  cursor: pointer;
}
.live-btn .dot { color: var(--live); }
.live-btn.on { background: var(--live); color: #fff; }
.live-btn.on .dot { color: #fff; animation: blink 1.6s infinite; }
.live-btn:active { opacity: .8; }
#btn-pause.is-paused .icon { stroke-width: 0; }

/* Скачивание */

.download {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px var(--gutter-r) 0 var(--gutter-l);
}
.chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.chip {
  height: 42px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip[aria-checked="true"] {
  border-color: var(--clip);
  background: rgba(255, 176, 32, .16);
  color: #ffd27a;
}
.clip-range {
  margin: 0;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.clip-range b { color: var(--text); font-weight: 600; }
#btn-download .btn-spinner { display: none; width: 20px; height: 20px; border-width: 2px; }
#btn-download.busy .btn-spinner { display: block; }
#btn-download.busy .btn-icon { display: none; }
#btn-download.busy:disabled { opacity: .85; }

@media (min-width: 720px) {
  .cam-main { padding: 16px max(16px, var(--safe-r)) calc(24px + var(--safe-b)) max(16px, var(--safe-l)); }
  .player {
    width: min(100%, calc((100dvh - var(--topbar-h) - var(--safe-t) - 32px) * 16 / 9));
    border-radius: var(--radius);
  }
  .scrubber { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
  .download { padding: 16px 0 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .chips { flex: 1 1 360px; }
  .clip-range { order: 3; flex-basis: 100%; text-align: left; }
  #btn-download { width: auto; min-width: 220px; }
}
@media (min-width: 900px) and (min-height: 640px) {
  .player { width: min(100%, calc((100dvh - var(--topbar-h) - 300px) * 16 / 9)); }
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  transform: translate(-50%, 12px);
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .spinner { animation-duration: 1.2s !important; }
}
