/* Веб-клиент /ui/: пульт диспетчера. Главный элемент — шкала записи:
   три состояния разными цветами и фактурой (ожидание — штриховка), указатель
   архива поверх. Шрифты системные: страница не ходит за шрифтами наружу
   (CSP font-src 'none', установка без интернета). */

:root {
  color-scheme: dark light;
  --ground: #19212c;
  --panel: #212b38;
  --panel-raised: #283444;
  --line: #34414f;
  --text: #e2e8ef;
  --muted: #95a2b3;
  --accent: #7fb2ff;
  --recorded: #3aa184;
  --gap: #d9505a;
  --pending: #d8a23b;
  --warn: #e6b450;
  --radius-control: 6px;
  --radius-panel: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --step: 0.5rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --ground: #edf0f4;
    --panel: #ffffff;
    --panel-raised: #f5f7fa;
    --line: #cdd5df;
    --text: #1a2330;
    --muted: #5b6878;
    --accent: #2563c9;
    --recorded: #1f8a6c;
    --gap: #c43a44;
    --pending: #b7801a;
    --warn: #9a6a00;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
}

h1 {
  font-size: 1.15rem;
}

h2 {
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1rem;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 0.3rem 0.8rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.quiet {
  background: transparent;
}

button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ground);
}

input[type="password"],
input[type="search"] {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 0.3rem 0.6rem;
  min-width: 0;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--step) calc(var(--step) * 3);
  padding: calc(var(--step) * 1.5) calc(var(--step) * 3);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.token {
  display: flex;
  gap: var(--step);
  flex: 1 1 28rem;
}

.token input {
  flex: 1;
}

.token-info {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.token-info[data-state="expired"],
.token-info[data-state="invalid"] {
  color: var(--gap);
}

.messages {
  margin: 0;
  padding: var(--step) calc(var(--step) * 3);
  background: var(--panel-raised);
  border-bottom: 1px solid var(--line);
}

.messages.error,
.error {
  color: var(--gap);
}

.layout {
  display: grid;
  grid-template-columns: minmax(15rem, 19rem) 1fr;
  min-height: calc(100vh - 4rem);
}

.cameras {
  border-right: 1px solid var(--line);
  padding: calc(var(--step) * 2);
  overflow-y: auto;
  max-height: calc(100vh - 4rem);
}

.cameras-head {
  display: flex;
  gap: var(--step);
}

.cameras-head input {
  flex: 1;
}

.summary {
  color: var(--muted);
  font-size: 0.85rem;
  margin: var(--step) 0;
}

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

.camera {
  display: grid;
  grid-template-columns: 0.75rem 1fr;
  column-gap: var(--step);
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  padding: 0.35rem 0.5rem;
}

.camera[aria-current="true"] {
  background: var(--panel-raised);
  box-shadow: inset 3px 0 0 var(--accent);
}

.camera .dot {
  grid-row: span 2;
  align-self: center;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
}

.camera-id {
  font-weight: 600;
}

.camera-sub {
  color: var(--muted);
  font-size: 0.8rem;
}

.rec-yes.dot {
  background: var(--recorded);
}

.rec-no.dot,
.rec-suspended.dot {
  background: var(--gap);
}

dd.rec-yes {
  color: var(--recorded);
}

dd.rec-no,
dd.rec-suspended,
dd.warn {
  color: var(--warn);
}

.camera-view {
  padding: calc(var(--step) * 3);
  display: flex;
  flex-direction: column;
  gap: calc(var(--step) * 3);
  min-width: 0;
}

.camera-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--step) calc(var(--step) * 4);
}

.camera-head h2 {
  flex: 0 0 100%;
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  row-gap: 0.15rem;
  column-gap: calc(var(--step) * 2);
  margin: 0;
  font-size: 0.9rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
}

.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: calc(var(--step) * 2);
}

.live-grid:empty {
  display: none;
}

.tile {
  margin: 0;
  background: #000;
  border-radius: var(--radius-panel);
  overflow: hidden;
}

.tile video,
.archive video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.tile figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--step);
  padding: 0.35rem 0.6rem;
  background: var(--panel);
  font-size: 0.85rem;
}

.tile-camera {
  font-weight: 600;
}

.tile-status {
  color: var(--muted);
  flex: 1;
}

.tile[data-status="error"] .tile-status,
.tile[data-status="stalled"] .tile-status {
  color: var(--warn);
}

.clock {
  color: var(--muted);
  font-size: 0.85rem;
}

.timeline {
  background: var(--panel);
  border-radius: var(--radius-panel);
  padding: calc(var(--step) * 2);
}

.timeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--step) * 2);
  margin-bottom: calc(var(--step) * 1.5);
}

.timeline-head h3 {
  flex: 1;
}

.segmented {
  display: inline-flex;
}

.segmented button {
  border-radius: 0;
}

.segmented button:first-child {
  border-radius: var(--radius-control) 0 0 var(--radius-control);
}

.segmented button:last-child {
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
}

.segmented button + button {
  border-left-width: 0;
}

.timeline-bar {
  position: relative;
  height: 3.25rem;
  background: var(--ground);
  border-radius: var(--radius-control);
  cursor: crosshair;
  overflow: hidden;
}

.segments {
  position: absolute;
  inset: 0;
}

.seg {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 1px;
}

.seg.recorded {
  background: var(--recorded);
}

.seg.gap {
  background: var(--gap);
}

.seg.pending {
  background: repeating-linear-gradient(135deg, var(--pending) 0 6px, transparent 6px 12px);
  opacity: 0.85;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  box-shadow: 0 0 0 1px var(--ground);
  pointer-events: none;
}

.cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px dashed var(--text);
  padding: 0 0.3rem;
  font-size: 0.75rem;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
}

.axis {
  position: relative;
  height: 1.3rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.axis span {
  position: absolute;
  top: 0.2rem;
  transform: translateX(-50%);
}

.axis span:first-child {
  transform: none;
}

.axis span:last-child {
  transform: translateX(-100%);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--step) * 3);
  list-style: none;
  margin: var(--step) 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  display: inline-block;
  width: 1.2rem;
  height: 0.7rem;
  border-radius: 2px;
}

.swatch.recorded {
  background: var(--recorded);
}

.swatch.gap {
  background: var(--gap);
}

.swatch.pending {
  background: repeating-linear-gradient(135deg, var(--pending) 0 3px, transparent 3px 6px);
}

.lower {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(16rem, 2fr);
  gap: calc(var(--step) * 3);
}

.archive-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--step);
}

.archive video {
  border-radius: var(--radius-panel);
}

.archive-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--step) * 2);
  margin-top: var(--step);
  font-size: 0.9rem;
}

.archive-tools a {
  color: var(--accent);
}

.check {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

.explain {
  background: var(--panel);
  border-radius: var(--radius-panel);
  padding: calc(var(--step) * 2);
}

.explain h3 {
  margin-bottom: var(--step);
}

.verdict {
  font-weight: 600;
  margin: 0 0 var(--step);
  padding-left: 0.6rem;
  border-left: 4px solid var(--muted);
}

.verdict.recorded {
  border-color: var(--recorded);
}

.verdict.gap {
  border-color: var(--gap);
}

.verdict.pending {
  border-color: var(--pending);
}

.empty {
  padding: calc(var(--step) * 6);
  color: var(--muted);
  max-width: 40rem;
}

code {
  font-size: 0.9em;
}

@media (max-width: 52rem) {
  .layout,
  .lower {
    grid-template-columns: 1fr;
  }

  .cameras {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 16rem;
  }
}
