:root {
  color-scheme: dark;
  --panel: #101010;
  --panel-2: #181818;
  --text: #f2f5f8;
  --muted: #a8b0b8;
  --line: rgba(255, 255, 255, 0.14);
  --blue: #2f86ff;
  --video: #26b96f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background: #05070a;
  color: var(--text);
}

.app-shell,
#map {
  position: fixed;
  inset: 0;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.topbar > *,
.stats,
.camera-window {
  pointer-events: auto;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 4px #000;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-shadow: 0 1px 4px #000;
}

.map-controls {
  display: flex;
  gap: 8px;
  max-width: min(700px, calc(100vw - 300px));
}

button,
input,
select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(16, 16, 16, 0.94);
  color: var(--text);
  font: inherit;
}

button {
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(47, 134, 255, 0.9);
}

input,
select {
  min-width: 0;
  padding: 0 10px;
}

input {
  width: 260px;
}

select {
  width: 128px;
}

.stats {
  position: absolute;
  left: 14px;
  bottom: 28px;
  z-index: 5;
  display: flex;
  gap: 8px;
}

.stats span,
.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(16, 16, 16, 0.9);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

.badge.video {
  color: #07120d;
  background: var(--video);
  border-color: rgba(255, 255, 255, 0.4);
}

.camera-window {
  position: absolute;
  z-index: 10;
  left: 90px;
  top: 78px;
  width: min(760px, calc(100vw - 40px));
  min-width: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.camera-window.hidden {
  display: none;
}

.camera-window-head {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 16, 16, 0.98);
  cursor: move;
  user-select: none;
}

.camera-window-head h2 {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.window-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.window-actions button {
  height: 30px;
  padding: 0 9px;
}

.details {
  max-height: calc(100vh - 138px);
  overflow: auto;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.viewer {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 180px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
}

.viewer video,
.viewer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.viewer-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.field-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  padding: 8px 10px 10px;
  background: var(--panel);
}

.camera-log {
  min-height: 24px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12px;
}

.field {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.03);
}

.field b {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.field span {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.mapboxgl-popup-content {
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.mapboxgl-popup-tip {
  border-top-color: var(--panel) !important;
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
  }

  .map-controls {
    max-width: calc(100vw - 28px);
    width: 100%;
  }

  input {
    flex: 1 1 auto;
    width: auto;
  }

  select {
    width: 92px;
  }

  .camera-window {
    left: 10px;
    top: 96px;
    width: calc(100vw - 20px);
  }

  .camera-window-head {
    height: 46px;
  }
}
