@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Rajdhani:wght@300;400;600;700&display=swap');

:root {
  --bg: #050a0f;
  --panel: #0b1520;
  --border: #1a3a55;
  --accent: #00d4ff;
  --accent2: #ff6b35;
  --text: #c8e8ff;
  --muted: #4a7a99;
  --success: #00ff9d;
  --warn: #ffcc00;
  --danger: #ff3b5c;
  --glow: 0 0 20px rgba(0,212,255,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Rajdhani', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  flex-shrink: 0;
}

.header-brand {
  flex-shrink: 0;
  text-align: left;
}

.logo {
  font-family: 'Space Mono', monospace;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 3px;
  text-transform: uppercase;
  white-space: nowrap;
  font-weight: 700;
}
.logo-icon {
  font-size: 1.2em;
  margin-right: 4px;
  vertical-align: middle;
}
.logo span { color: var(--accent2); }

.subtitle {
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  letter-spacing: 1px;
}

.app-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

.app-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.header-nav {
  display: flex;
  gap: 16px;
}

.status-bar {
  display: flex;
  gap: 20px;
  justify-content: flex-end;
  font-size: 12px;
  font-family: 'Space Mono', monospace;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.status-item .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.status-item.live .dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 1.5s infinite;
}
.status-item.live { color: var(--success); }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── TABS ── */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  background: #03080d;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.nav-group {
  padding: 14px 20px 5px;
  color: var(--accent);
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.nav-item {
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: var(--muted);
  padding: 10px 20px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}
.nav-item.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--panel);
}
.sidebar-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.mission-brief {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(0, 212, 255, 0.12), transparent 48%),
    #08121c;
}

.mission-eyebrow,
.mission-powered {
  font-family: 'Space Mono', monospace;
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.mission-brief h1 {
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.05;
  color: var(--text);
  font-weight: 700;
}

.mission-brief p {
  margin-top: 8px;
  color: #9fc4d8;
  font-size: 13px;
  line-height: 1.35;
}

.mission-powered {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── LAYOUT ── */
.main {
  display: block;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
  margin-top: 10px;
}
label:first-of-type { margin-top: 0; }

input, select {
  width: 100%;
  padding: 8px 10px;
  background: #0d1e2e;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  outline: none;
  transition: border-color .2s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,212,255,0.1);
}
select option { background: #0d1e2e; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 3px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .2s;
  margin-top: 12px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 700;
}
.btn-primary:hover { background: #00b8e0; box-shadow: var(--glow); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

.btn-accent {
  background: var(--accent2);
  color: #fff;
  font-weight: 700;
}
.btn-accent:hover {
  background: #e05a2a;
}
.btn-accent:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}
.btn-secondary {
  background: transparent;
  color: var(--accent2);
  border: 1px solid var(--accent2);
}
.btn-secondary:hover { background: rgba(255,107,53,0.1); }

/* ── RESULTS ── */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-card {
  background: #0d1e2e;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.result-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: scaleY(0);
  transition: transform .2s;
}
.result-card:hover { border-color: var(--accent); }
.result-card:hover::before { transform: scaleY(1); }
.result-card.active { border-color: var(--accent); background: #0f2438; }
.result-card.active::before { transform: scaleY(1); }

.card-id {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  margin-bottom: 4px;
}
.card-date {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.card-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 2px;
  font-size: 10px;
  font-family: 'Space Mono', monospace;
}
.badge-cloud { background: rgba(255,204,0,0.15); color: var(--warn); border: 1px solid rgba(255,204,0,0.3); }
.badge-res { background: rgba(0,212,255,0.1); color: var(--accent); border: 1px solid rgba(0,212,255,0.2); }

/* ── CONSOLE LOG ── */
.console {
  background: #03080d;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  max-height: 140px;
  overflow-y: auto;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  flex-shrink: 0;
}
.console::-webkit-scrollbar { width: 3px; }
.console::-webkit-scrollbar-thumb { background: var(--border); }

.log-line {
  line-height: 1.7;
  display: flex;
  gap: 8px;
}
.log-time { color: var(--muted); }
.log-info { color: var(--accent); }
.log-ok { color: var(--success); }
.log-warn { color: var(--warn); }
.log-err { color: var(--danger); }

/* ── MAP ── */
#map {
  flex: 1;
  position: relative;
  background: #020810;
}

.leaflet-container { background: #020810; }

/* Custom Leaflet dark theme */
.leaflet-tile { filter: brightness(0.85) saturate(0.7) hue-rotate(180deg) invert(1) hue-rotate(180deg); }

.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--accent) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--border) !important; }

.leaflet-control-attribution {
  background: rgba(5,10,15,0.8) !important;
  color: var(--muted) !important;
  font-size: 9px !important;
}

/* ── LEAFLET LAYERS CONTROL STYLING ── */
/* Position below the .map-hud (12px top + approx 34px height + 8px gap) */
.leaflet-top.leaflet-right {
  top: 54px !important; 
  right: 12px !important;
}

.leaflet-control-layers {
  background: rgba(11,21,32,0.92) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  padding: 8px 12px !important;
  font-family: 'Space Mono', monospace !important;
  font-size: 10px !important;
  color: var(--muted) !important;
  backdrop-filter: blur(4px);
  box-shadow: none !important;
  margin: 0 !important;
}

.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
  width: 200px !important;
  max-width: 200px !important;
}

.leaflet-control-layers label {
  display: flex !important;
  align-items: center;
  margin-bottom: 4px !important;
}

.leaflet-control-layers label span {
  color: var(--accent) !important;
}

/* Truncate layer names */
.leaflet-control-layers label span span,
.leaflet-control-layers label input + span {
  display: inline-block;
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* Scrollable section */
.leaflet-control-layers-list {
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px; /* Space for scrollbar */
}

.leaflet-control-layers-selector {
  margin-top: 0 !important;
  accent-color: var(--accent);
}

/* ── MAP OVERLAY ── */
.map-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.map-title {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
  padding: 4px 8px;
  background: rgba(11,21,32,0.92);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.hud-box {
  background: rgba(11,21,32,0.92);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  backdrop-filter: blur(4px);
}
.hud-box .val { color: var(--accent); font-size: 11px; }

/* Loading spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}
.empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.4; }

/* Image overlay panel */
.img-panel {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 900;
  background: rgba(11,21,32,0.95);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 10px;
  width: 220px;
  display: none;
  backdrop-filter: blur(6px);
  box-shadow: var(--glow);
}
.img-panel.visible { display: block; }
.img-panel img {
  width: 100%;
  border-radius: 3px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.img-panel .img-title {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 1px;
}
.img-panel .img-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.img-panel .close-btn {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.close-btn:hover { color: var(--danger); }

/* Token input */
.token-wrap {
  position: relative;
}
.token-wrap input { padding-right: 70px; }
.token-toggle {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  padding: 2px 6px;
  cursor: pointer;
  letter-spacing: 1px;
}
.token-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* Draw bbox hint */
.draw-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 800;
  background: rgba(5,10,15,0.85);
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 20px 30px;
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  display: none;
}
.draw-hint.show { display: block; }
.draw-hint .big { font-size: 24px; color: var(--accent); margin-bottom: 6px; }

/* Crosshair cursor while drawing */
#map.drawing { cursor: crosshair !important; }

/* Bbox rect style */
.bbox-rect {
  stroke: var(--accent);
  stroke-width: 2;
  fill: rgba(0,212,255,0.08);
  stroke-dasharray: 6 3;
}

/* Tender Zone Tooltip */
.tender-zone-tooltip {
    background: rgba(11,21,32,0.9) !important;
    border: 1px solid var(--warn) !important;
    color: var(--text) !important;
    font-family: 'Space Mono', monospace;
    font-size: 10px;
}

/* ── MISSION MONITORING ── */
.mission-card {
  background: #0f1823;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 10px;
  margin-bottom: 10px;
  font-family: 'Space Mono', monospace;
}
.mission-card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
}
.mission-id { color: var(--accent); }
.mission-zone { color: var(--text); font-weight: normal; font-size: 10px; }

.progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}
.progress-fill.failed { background: var(--danger); }
.progress-fill.completed { background: var(--success); }

.mission-status-line {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 8px;
}

.mission-details-toggle {
  font-size: 10px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  margin-bottom: 6px;
  display: inline-block;
}

.mission-logs-container {
  background: #000;
  border: 1px solid #333;
  padding: 6px;
  height: 120px;
  overflow-y: auto;
  font-size: 9px;
  margin-bottom: 8px;
  display: none; /* hidden by default */
}
.mission-logs-container.visible { display: block; }

.mission-log-entry { margin-bottom: 2px; line-height: 1.4; color: #ccc; }
.mission-log-entry .ts { color: #666; margin-right: 4px; }
.mission-log-entry.INFO { color: #ccc; }
.mission-log-entry.WARNING { color: var(--warn); }
.mission-log-entry.ERROR { color: var(--danger); }
.mission-log-entry.DEBUG { color: #555; }

.mission-files-container {
  display: none; /* hidden until files arrive */
  border-top: 1px solid var(--border);
  padding-top: 6px;
  margin-top: 6px;
}
.mission-file-link {
  display: block;
  font-size: 10px;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mission-file-link:hover { text-decoration: underline; }
.mission-file-note { color: #666; font-size: 9px; margin-left: 4px; }

.badge-count { background: var(--danger); color: white; padding: 1px 4px; border-radius: 3px; font-size: 9px; display: none; margin-left: 4px; }

/* Agent Panel */
.agent-panel {
  padding: 16px;
  border-top: 1px solid var(--border);
  margin-top: auto; /* Pushes to bottom */
}
.agent-list {
  list-style: none;
  font-size: 11px;
  font-family: 'Space Mono', monospace;
}
.agent-list li {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  line-height: 1.35;
}
.agent-list .status-icon {
  color: var(--success);
  font-weight: 700;
}

.agent-list .status-icon.muted {
  color: var(--muted);
}

.agent-state {
  display: block;
  grid-column: 2;
  color: #7fa8bd;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.agent-graph-container {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: pre;
}

/* ── FOOTER ── */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #03080d;
  border-top: 1px solid var(--border);
  font-size: 10px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  flex-shrink: 0;
}
.footer-brand {
  font-size: 12px;
}
.footer-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.footer-nav {
  display: flex;
  gap: 16px;
  font-size: 12px;
}
.footer-brand strong {
  color: var(--text);
  font-weight: 700;
}
.footer-brand span {
  display: block;
  font-size: 9px;
  opacity: 0.7;
}
.footer-core {
  text-align: right;
  font-size: 9px;
}
.footer-core span {
  display: block;
}
