:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #10161a;
  color: #edf4f2;
  --panel: #182125;
  --line: #334044;
  --muted: #b0bfbe;
  --accent: #78e1bd;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
header {
  min-height: 4rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem max(1rem, calc((100% - 85rem) / 2));
  background: #141d21;
}
.brand { font-size: 1.125rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
main { width: min(85rem, calc(100% - 2rem)); margin: 2rem auto; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { font-size: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.view-switch { display: flex; gap: .5rem; margin-bottom: 1.25rem; }
.view-switch button { padding-inline: 1.15rem; }
.view-switch button[aria-pressed="true"] { background: #203c35; border-color: #456c60; color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.panel, .camera { background: var(--panel); border: 1px solid var(--line); border-radius: .8rem; overflow: hidden; }
.screen { position: relative; display: grid; place-items: center; overflow: hidden; background: #080e10; aspect-ratio: 16 / 9; }
.screen > video { object-fit: fill; }
.screen[data-zoomed] { cursor: grab; touch-action: none; }
.screen[data-dragging] { cursor: grabbing; }
.screen[data-expanded] { position: fixed; inset: 0; z-index: 5; }
.camera:has(.screen[data-expanded])::before { content: ""; display: block; aspect-ratio: 16 / 9; }
body:has(.screen[data-expanded]) { overflow: hidden; }
.screen:is(:fullscreen, [data-expanded]) { width: 100%; height: 100%; aspect-ratio: auto; }
.screen:is(:fullscreen, [data-expanded]) > video {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}
.live-quality {
  display: none;
  position: absolute;
  top: .55rem;
  left: .55rem;
  max-width: calc(100% - 12rem);
  padding: .4rem .6rem;
  border-radius: .5rem;
  background: #10161ae8;
  font-size: .8rem;
  pointer-events: none;
}
.screen:is(:fullscreen, [data-expanded]) > .live-quality:not(:empty) { display: block; }
.camera-tools {
  position: absolute;
  z-index: 1;
  top: .55rem;
  right: .55rem;
  display: flex;
  gap: .2rem;
  padding: .25rem;
  border-radius: .6rem;
  background: #10161ae8;
}
.camera-tools button {
  min-width: 2rem;
  min-height: 2rem;
  padding: .15rem .35rem;
  border-color: transparent;
  background: transparent;
  color: #edf4f2;
  font-variant-numeric: tabular-nums;
}
.camera-tools button:hover:not(:disabled) { background: #334044; }
.camera-tools button:disabled { cursor: default; }
.camera-tools .zoom-reset { min-width: 3.2rem; font-size: .8rem; }
video { display: block; width: 100%; height: 100%; aspect-ratio: 16 / 9; object-fit: contain; }
.camera-info { padding: .75rem .9rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.camera-info h2 { font-size: .95rem; overflow-wrap: anywhere; }
.state, #export-help { color: var(--muted); font-size: .875rem; }
.state[data-state="live"] { color: var(--accent); }
.panel { padding: 1.25rem; }
.login { max-width: 25rem; margin: 11vh auto 0; }
.login form { display: grid; gap: .9rem; margin-top: 1.25rem; }
.playback-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 19rem);
  gap: 1rem;
  margin-top: 1rem;
  align-items: start;
}
.playback-surface, .export form {
  border: 1px solid var(--line);
  border-radius: .75rem;
  min-width: 0;
}
.export form {
  display: grid;
  gap: .75rem;
  padding: .85rem;
  background: #141d21;
}
.export form a { justify-self: start; margin-top: 0; }
#playback-cameras { display: grid; gap: .25rem; border: 0; padding: 0; margin: 0; min-width: 0; }
#playback-cameras legend { margin-bottom: .35rem; font-weight: 650; font-size: .9rem; }
.recording-camera {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 2.1rem;
  padding: .3rem .45rem;
  border-radius: .35rem;
  cursor: pointer;
}
.recording-camera:has(input:checked) { background: #203c35; color: var(--accent); }
.recording-camera input { width: 1rem; height: 1rem; min-height: 0; margin: 0; accent-color: var(--accent); }
.playback-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: 68vh;
  border-radius: .75rem .75rem 0 0;
  overflow: hidden;
  background: #080e10;
}
#playback-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1rem; color: var(--muted); }
.playback-controls { display: flex; align-items: center; gap: .7rem; min-height: 3.7rem; padding: .65rem .85rem; }
#playback-status { color: var(--muted); font-size: .875rem; }
#export-options { display: grid; gap: .65rem; }
#export-options button { justify-self: start; }
.timeline { padding: .85rem; }
.timeline-heading, .timeline-legend { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.timeline-heading h2 { font-size: 1rem; }
.timeline-heading { flex-wrap: wrap; }
.timeline-zoom, #timeline-pan-controls { display: flex; align-items: center; gap: .4rem; }
.timeline-zoom { margin-left: auto; }
.timeline-zoom button, #timeline-pan-controls button { min-height: 2.15rem; min-width: 2.1rem; padding: .25rem .55rem; }
#timeline-pan-controls { margin-top: .65rem; }
#timeline-pan-controls label { flex: 1; gap: .15rem; color: var(--muted); font-size: .8rem; }
#timeline-pan {
  min-height: 1.4rem;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: grab;
}
#timeline-pan:active { cursor: grabbing; }
#timeline-time { font-variant-numeric: tabular-nums; }
#timeline-ticks { position: relative; height: 1.4rem; color: var(--muted); font-size: .75rem; margin-top: .5rem; }
#timeline-ticks span { position: absolute; transform: translateX(-50%); font-variant-numeric: tabular-nums; }
#timeline-ticks span:first-child { transform: none; }
#timeline-ticks span:last-child { transform: translateX(-100%); }
#timeline-bar { height: 1.5rem; position: relative; border-radius: .25rem; background: #29353b; }
#timeline-intervals { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; pointer-events: none; }
#timeline-intervals span { position: absolute; height: 100%; min-width: 1px; }
.timeline .regular { --recording-color: #46bf8a; }
.timeline .motion { --recording-color: #e5bc50; }
.timeline .alarm { --recording-color: #f07778; }
#timeline-intervals span { background: var(--recording-color); }
#timeline-intervals .motion, #timeline-intervals .alarm { z-index: 1; }
#timeline-input {
  position: absolute; z-index: 2; inset: 0;
  appearance: none; padding: 0; margin: 0; min-height: 0; height: 100%;
  border: 0; background: transparent; cursor: pointer;
}
#timeline-input::-webkit-slider-thumb { appearance: none; width: 3px; height: 1.7rem; background: #fff; border-radius: 1px; }
#timeline-input::-moz-range-thumb { width: 3px; height: 1.7rem; border: 0; background: #fff; border-radius: 1px; }
#timeline-input.cursor-outside::-webkit-slider-thumb { background: transparent; }
#timeline-input.cursor-outside::-moz-range-thumb { background: transparent; }
#timeline-input:disabled { visibility: hidden; }
.timeline-legend { justify-content: flex-start; flex-wrap: wrap; margin-top: .65rem; font-size: .83rem; }
.timeline-legend span::before { content: ""; display: inline-block; width: .65rem; height: .65rem; margin-right: .35rem; border-radius: .15rem; background: var(--recording-color); }
#timeline-status:not(:empty) { margin-top: .65rem; color: var(--muted); font-size: .85rem; }
.recording-actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.recording-actions button { min-height: 2.7rem; }
#recording { margin: 0; width: 100%; }
#gallery-recording { margin: 1rem 0 0; }
#recording-caption, #gallery-caption { color: var(--muted); margin-bottom: .5rem; overflow-wrap: anywhere; }
#recording-caption {
  min-height: 2.5rem;
  margin: 0;
  padding: .55rem .75rem;
  line-height: 1.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#recording-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#gallery-player {
  width: 100%;
  height: auto;
  max-height: 68vh;
  background: #080e10;
  border: 1px solid var(--line);
  border-radius: .65rem;
}
.gallery-help, .clip-range, .clip-details { color: var(--muted); font-size: .875rem; }
.gallery-list { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .65rem; }
.gallery-clip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: .8rem;
  gap: .8rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
}
.gallery-clip h2 { font-size: 1rem; margin-bottom: .25rem; }
.clip-actions { display: flex; gap: .5rem; align-items: stretch; }
.clip-actions a { margin-top: 0; }
#gallery-status:not(:empty) { margin-top: .7rem; }
label { display: grid; gap: .45rem; font-size: .9rem; font-weight: 650; min-width: 0; }
input, select, button, .button {
  font: inherit;
  min-height: 2.7rem;
  min-width: 0;
  padding: .5rem .75rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  color: inherit;
}
input, select { background: #10191c; width: 100%; }
button, .button { background: var(--accent); color: #10201a; cursor: pointer; font-weight: 700; border-color: transparent; }
.button { display: inline-flex; align-items: center; text-decoration: none; margin-top: .65rem; }
button:disabled { opacity: .6; cursor: wait; }
.quiet { background: transparent; color: #e0eae8; border-color: var(--line); min-height: 2.3rem; font-size: .9rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#export-status:not(:empty) { margin-top: .65rem; }
#login-status:empty { display: none; }
@media (max-width: 58rem) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .playback-layout { grid-template-columns: minmax(0, 1fr); }
  .playback-surface { grid-row: 2; }
  #playback-cameras { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 35rem) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  #timeline-ticks span:not(:nth-child(3n+1)) { visibility: hidden; }
  main { margin-top: 1.25rem; }
}
