/* ============================================================
   Terrain Link — Field Client Styles
   Dark theme matching DAMOCLES aesthetic
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
}

/* --- Status Bar --- */
#status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 36px;
  background: rgba(16, 16, 32, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 1000;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: #f59e0b;
  transition: background 0.3s;
}

#status-indicator.connected { background: #22c55e; }
#status-indicator.disconnected { background: #ef4444; }
#status-indicator.connecting { background: #f59e0b; animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#status-text {
  margin-right: 12px;
  opacity: 0.7;
}

#channel-name {
  font-weight: 600;
  color: #60a5fa;
}

/* --- Map --- */
#map {
  position: fixed;
  top: 36px;
  left: 0;
  right: 0;
  bottom: 0;
}

/* --- Leaflet Popup Overrides --- */
.leaflet-popup-content-wrapper {
  background: rgba(16, 16, 32, 0.95);
  color: #e0e0e0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-tip {
  background: rgba(16, 16, 32, 0.95);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  max-height: 250px;
  overflow-y: auto;
}

.leaflet-popup-content .entity-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
  color: #ffffff;
}

.leaflet-popup-content .entity-type {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #60a5fa;
  margin-bottom: 8px;
}

.leaflet-popup-content .entity-field {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leaflet-popup-content .entity-field-label {
  color: #888;
  font-size: 12px;
}

.leaflet-popup-content .entity-field-value {
  color: #e0e0e0;
  font-size: 12px;
  text-align: right;
  max-width: 60%;
}

/* Close button on popups */
.leaflet-popup-close-button {
  color: #888 !important;
  font-size: 18px !important;
}
.leaflet-popup-close-button:hover {
  color: #fff !important;
}

/* --- Entity Detail Overlay --- */
#entity-detail {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  background: rgba(16, 16, 32, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1001;
  overflow-y: auto;
  padding: 16px;
  transition: transform 0.3s ease;
}

#entity-detail.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

#entity-detail-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
}
#entity-detail-close:hover { color: #fff; }

/* --- Actor Markers --- */
.actor-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* --- Zone polygons --- */
/* Styled via Leaflet options, not CSS */

/* --- Connection lines --- */
/* Styled via Leaflet options, not CSS */

/* --- Mobile adjustments --- */
@media (max-width: 768px) {
  #status-bar { height: 32px; font-size: 12px; }
  #map { top: 32px; }
  .leaflet-popup-content { font-size: 12px; }
}

/* --- Offline/Commander disconnected overlay --- */
#commander-offline {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(239, 68, 68, 0.9);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  z-index: 1002;
  display: none;
}

/* --- Operator Toolbar --- */
#operator-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(16, 16, 32, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1001;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#operator-toolbar button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#operator-toolbar button:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

#operator-toolbar button.active {
  background: rgba(59, 130, 246, 0.4);
  border-color: #3B82F6;
}

#operator-toolbar button.toggle-btn.active {
  background: rgba(34, 197, 94, 0.4);
  border-color: #22C55E;
  animation: pulse-gps 2s infinite;
}

@keyframes pulse-gps {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

/* --- Dialogs --- */
#pin-dialog,
#report-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-content {
  background: rgba(16, 16, 32, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  width: 90%;
  max-width: 360px;
}

.dialog-content h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  color: #ffffff;
}

.category-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.cat-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: #e0e0e0;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.cat-btn.selected {
  border-color: #60a5fa;
  background: rgba(96, 165, 250, 0.2);
}

.cat-btn.cat-blue.selected { border-color: #3B82F6; background: rgba(59, 130, 246, 0.2); }
.cat-btn.cat-yellow.selected { border-color: #F59E0B; background: rgba(245, 158, 11, 0.2); }
.cat-btn.cat-red.selected { border-color: #EF4444; background: rgba(239, 68, 68, 0.2); }
.cat-btn.cat-green.selected { border-color: #22C55E; background: rgba(34, 197, 94, 0.2); }
.cat-btn.cat-gray.selected { border-color: #6B7280; background: rgba(107, 114, 128, 0.2); }

.dialog-content textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #e0e0e0;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 12px;
}

.dialog-content textarea:focus {
  outline: none;
  border-color: #60a5fa;
}

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

.dialog-actions button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}

#pin-cancel,
#report-cancel {
  background: rgba(255, 255, 255, 0.1);
  color: #888;
}

#pin-submit,
#report-submit {
  background: #3B82F6;
  color: #ffffff;
}

/* Adjust map bottom when toolbar is visible */
body.has-operator-toolbar #map {
  bottom: 56px;
}

@media (max-width: 768px) {
  body.has-operator-toolbar #map {
    top: 32px;
  }
}

/* --- Phase 3: live video (operator_plus) --- */
#operator-toolbar #btn-live.active {
  background: rgba(239, 68, 68, 0.45);
  border-color: #ef4444;
  animation: pulse-live 1.8s infinite;
}

@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

#video-live-panel {
  position: fixed;
  right: 12px;
  bottom: 68px;
  width: min(42vw, 220px);
  max-width: calc(100vw - 24px);
  z-index: 1005;
  background: rgba(16, 16, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

#video-preview {
  display: block;
  width: 100%;
  height: auto;
  max-height: 40vh;
  object-fit: cover;
  background: #0f0f1a;
  vertical-align: middle;
}

.video-live-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.25);
}

.video-live-controls button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.video-live-controls button:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
}

.video-live-controls button.muted {
  background: rgba(239, 68, 68, 0.35);
  border-color: #f87171;
}

.video-live-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
  padding: 0 8px 8px;
  min-height: 14px;
}

@media (max-width: 768px) {
  #video-live-panel {
    bottom: 64px;
    width: min(55vw, 200px);
  }
}
