:root {
  --panel-bg: #1b1d21;
  --panel-border: #33363b;
  --text: #e8e8ea;
  --accent: #4da6ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0f1012;
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}

#app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#video-panel {
  flex: 1 1 55%;
  border-right: 1px solid var(--panel-border);
}

#map-panel {
  flex: 1 1 45%;
  position: relative;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
}

.toolbar button, .toolbar select {
  background: #2a2d32;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

.toolbar button:hover { background: #363a40; }

.toolbar button:disabled, .toolbar select:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

#loading-indicator {
  font-size: 12px;
  color: var(--accent);
}

#file-name, #file-datetime {
  font-size: 12px;
  color: #9aa0a6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.toolbar-secondary {
  padding-top: 4px;
  padding-bottom: 4px;
  background: #16171a;
}

.video-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.video-stage {
  flex: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.video-stage video, .video-stage img {
  max-width: 100%;
  max-height: 100%;
}

#inner-divider {
  width: 6px;
  cursor: col-resize;
  background: var(--panel-border);
  flex: 0 0 auto;
}

#inner-divider:hover {
  background: var(--accent);
}

#inner-divider[hidden] {
  display: none;
}

#map {
  width: 100%;
  height: 100%;
}

#map-info {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 5;
  background: rgba(15, 16, 18, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  max-width: 280px;
}

#map-info .label { color: #9aa0a6; }

/* Scale bar — ported from SAK26 (via the sibling `hunt` project): deliberately
   a fixed-width bar whose LABEL updates to the real-world distance, rather
   than a library scale control that picks its own "nice number" width. */
#map-scale-bar {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 5;
  background: transparent;
  border: none;
  padding: 4px 8px 6px;
  box-sizing: border-box;
  pointer-events: none;
}

#map-scale-bar-label {
  font-size: 11px;
  text-align: center;
  color: var(--text);
  margin-bottom: 2px;
  line-height: 1;
  /* No background chip behind this anymore, so give the text its own
     contrast against whatever basemap is underneath. */
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 2px #000;
}

.map-scale-bar-line {
  width: 100px;
  height: 6px;
  border-left: 2px solid var(--text);
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  filter: drop-shadow(0 0 2px #000);
}

.drone-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  box-shadow: 0 0 6px rgba(77, 166, 255, 0.8);
}

#drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #9aa0a6;
  font-size: 14px;
  padding: 20px;
}

@media (max-width: 860px) {
  #app { flex-direction: column; }
  #video-panel, #map-panel { flex: 1 1 50%; border-right: none; }
  #video-panel { border-bottom: 1px solid var(--panel-border); }
  #divider { display: none; }
}

#camera-tabs {
  display: flex;
  gap: 2px;
  margin-right: 6px;
}

.cam-tab {
  opacity: 0.4;
}

.cam-tab.loaded {
  opacity: 1;
}

.cam-tab.active {
  border-color: var(--accent) !important;
  color: var(--accent);
}

#divider {
  width: 6px;
  cursor: col-resize;
  background: var(--panel-border);
  flex: 0 0 auto;
}

#divider:hover {
  background: var(--accent);
}

#layer-control {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  background: rgba(15, 16, 18, 0.9);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
}

#layer-control label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.my-layers-row {
  border-top: 1px solid var(--panel-border);
  padding-top: 6px;
}

.my-layers-row button {
  width: 100%;
}

.layer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.layer-row label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-layer {
  background: transparent;
  border: none;
  color: #9aa0a6;
  cursor: pointer;
  font-size: 13px;
  padding: 0 4px;
}

.remove-layer:hover {
  color: #ff6b6b;
}

#pip-toggle {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 5;
  background: #2a2d32;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

#flights-panel {
  display: none;
  flex-direction: column;
  width: 220px;
  flex: 0 0 220px;
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  background: #16171a;
}

#flights-panel.has-flights {
  display: flex;
}

.flight-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  cursor: pointer;
  font-size: 12px;
}

.flight-row .flight-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.remove-flight {
  background: transparent;
  border: none;
  color: #9aa0a6;
  cursor: pointer;
  font-size: 13px;
  padding: 0 4px;
  flex: 0 0 auto;
}

.remove-flight:hover {
  color: #ff6b6b;
}

.flight-row:hover {
  background: #21242a;
}

.flight-row.active {
  background: #262b33;
  border-left: 3px solid var(--accent);
}

.flight-row .flight-time {
  color: var(--text);
}

.flight-row .flight-cams {
  color: #9aa0a6;
  font-size: 11px;
}

#second-video-panel {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--panel-border);
  min-width: 0;
}

#second-video-panel[hidden] {
  display: none;
}

#second-video-panel #camera-tabs-2 {
  display: flex;
  gap: 2px;
}

#second-video-panel .toolbar {
  justify-content: space-between;
}

/* Picture-in-picture: map floats small over the full-width video, with every
   other map control hidden — just the bare map and the toggle itself. */
#app.pip-mode #layer-control,
#app.pip-mode #map-info {
  display: none;
}

#app.pip-mode {
  position: relative;
}

#app.pip-mode #video-panel {
  flex: 1 1 100%;
  border-right: none;
}

#app.pip-mode #divider {
  display: none;
}

#app.pip-mode #map-panel {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 300px;
  height: 220px;
  min-width: 180px;
  min-height: 140px;
  flex: none;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

#pip-drag-handle {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 18px;
  z-index: 11;
  cursor: move;
  background: linear-gradient(rgba(0, 0, 0, 0.45), transparent);
}

#app.pip-mode #pip-drag-handle {
  display: block;
}

#pip-resize-handle {
  display: none;
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  z-index: 11;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 0 50%, rgba(255, 255, 255, 0.5) 50% 60%, transparent 60% 70%, rgba(255, 255, 255, 0.5) 70% 80%, transparent 80%);
}

#app.pip-mode #pip-resize-handle {
  display: block;
}
