:root {
  color-scheme: dark;
  font-family: Arial, Helvetica, sans-serif;
  background: #090b0d;
  color: #f4f6f8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090b0d;
}

button {
  min-height: 44px;
  border: 1px solid #343a40;
  border-radius: 6px;
  padding: 0 15px;
  background: #181c20;
  color: #f4f6f8;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid #56a8ff;
  outline-offset: 2px;
}

.pairing {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #090b0d;
}

.pairing[hidden] {
  display: none;
}

.pairing-panel {
  width: min(440px, 100%);
  text-align: center;
}

.pairing-panel h1 {
  margin: 0 0 18px;
  font-size: 28px;
}

.pairing-panel p {
  margin: 16px 0 8px;
  color: #c1c8ce;
}

.pairing-qr {
  width: min(280px, 70vw);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 8px solid #fff;
  border-radius: 6px;
  background: #fff;
}

.pairing-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.pairing-code {
  display: block;
  min-height: 24px;
  margin-bottom: 18px;
  font-size: 18px;
}

.viewer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  min-height: 480px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 66px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid #282d32;
  background: #111417;
}

.identity {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.identity strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 19px;
}

.connection {
  flex: 0 0 auto;
  color: #9ca6af;
  font-size: 13px;
}

.connection[data-state="online"] {
  color: #5bd68a;
}

.connection[data-state="error"] {
  color: #ffbd66;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 300px;
  padding: 3px;
  border: 1px solid #343a40;
  border-radius: 7px;
  background: #090b0d;
}

.mode-switch button {
  min-height: 38px;
  border: 0;
  background: transparent;
}

.mode-switch button.active {
  background: #245f9c;
  color: white;
}

.commands {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.commands button.active {
  border-color: #56a8ff;
  background: #173f67;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

#video,
#snapshot {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

#snapshot {
  display: none;
}

.viewer[data-mode="snapshot"] #video {
  display: none;
}

.viewer[data-mode="snapshot"] #snapshot {
  display: block;
}

.viewer[data-mode="snapshot"] #audio-toggle {
  visibility: hidden;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #090b0d;
  color: #d5dbe0;
}

.empty-state[hidden] {
  display: none;
}

.stream-stats {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 230px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid #343a40;
  border-radius: 6px;
  background: rgb(9 11 13 / 88%);
  color: #dce2e7;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.stream-stats[hidden] {
  display: none;
}

.stream-stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stream-stats dt {
  color: #9ca6af;
}

.stream-stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.camera-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(130px, 1fr);
  gap: 7px;
  overflow-x: auto;
  padding: 9px 12px max(9px, env(safe-area-inset-bottom));
  border-top: 1px solid #282d32;
  background: #111417;
  scrollbar-width: thin;
}

.camera-button {
  position: relative;
  min-width: 130px;
  height: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-name-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-button[data-event]:not([data-event=""]) .camera-name-label {
  transform: translateY(-6px);
}

.camera-event {
  position: absolute;
  left: 50%;
  bottom: 3px;
  max-width: calc(100% - 14px);
  transform: translateX(-50%);
  overflow: hidden;
  padding: 1px 5px;
  border-radius: 4px;
  background: #d74343;
  color: #fff;
  font-size: 10px;
  line-height: 14px;
  text-overflow: ellipsis;
}

.camera-button[data-event="vehicle"] .camera-event {
  background: #2879ba;
}

.camera-button[data-event="motion"] .camera-event {
  background: #a36b19;
}

.camera-button.active {
  border-color: #56a8ff;
  background: #173f67;
}

.camera-button.offline::after {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e4a548;
  content: "";
}

@media (max-width: 760px) {
  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .identity {
    grid-column: 1;
    grid-row: 1;
  }

  .commands {
    grid-column: 2;
    grid-row: 1;
  }

  .mode-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .commands button {
    width: 48px;
    min-width: 48px;
    overflow: hidden;
    padding: 0 6px;
    font-size: 0;
  }

  #audio-toggle::after {
    content: "A";
    font-size: 16px;
  }

  #fullscreen::after {
    content: "F";
    font-size: 16px;
  }

  #stats-toggle::after {
    content: "S";
    font-size: 16px;
  }

  .stream-stats {
    left: 8px;
    bottom: 8px;
  }
}
