/* ===========================================================
   MISSION CONTROL — aerospace telemetry overlay
   Loaded AFTER style.css to override the legacy aesthetic.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600;700&family=Major+Mono+Display&family=Inter+Tight:wght@400;500;600;700;800&display=swap');

:root {
  /* Mission palette */
  --void: #060912;
  --hull: #0a1422;
  --plate: #131e30;
  --rule: rgba(255, 215, 130, 0.12);
  --rule-bright: rgba(255, 215, 130, 0.32);

  --amber: #ffb547;
  --amber-hi: #ffd285;
  --amber-dim: #6a4d1c;
  --signal: #00d4ff;
  --warn: #ff5a4a;
  --okay: #4fffb0;

  --text: #f0e6d0;
  --text-mid: #c4b89c;
  --text-dim: #6a6450;
  --text-faint: #3a3a3a;

  --display: 'Major Mono Display', 'IBM Plex Mono', monospace;
  --mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  --sans: 'Inter Tight', system-ui, sans-serif;
}

/* ========== GLOBAL OVERRIDE ========== */
html { color-scheme: only light; }
html, body {
  background: var(--void) !important;
  color: var(--text) !important;
  font-family: var(--sans);
  letter-spacing: 0.005em;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  background:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(255,255,255,0.012) 2px 3px),
    radial-gradient(ellipse at 50% 0%, rgba(255,181,71,0.04), transparent 60%);
}

/* ========== LAYOUT ========== */
.layout {
  display: grid;
  grid-template-columns: 1fr 440px;
  height: 100dvh;
  background: var(--void) !important;
}

.map-panel {
  position: relative;
  background: #000;
  border-right: 1px solid var(--rule);
}
#map { background: #050a14 !important; }

/* CROSSHAIR OVERLAY — center reticle */
.map-panel::before,
.map-panel::after {
  content: '';
  position: absolute;
  z-index: 400;
  pointer-events: none;
  background: var(--amber);
  opacity: 0.42;
  mix-blend-mode: screen;
}
.map-panel::before {
  /* horizontal */
  top: 50%; left: calc(50% - 28px); width: 56px; height: 1px;
}
.map-panel::after {
  /* vertical */
  left: 50%; top: calc(50% - 28px); width: 1px; height: 56px;
}

/* Bracket corners around map */
.map-bracket {
  position: absolute;
  z-index: 401;
  pointer-events: none;
  width: 28px; height: 28px;
  border: 1px solid var(--amber);
  opacity: 0.55;
}
.map-bracket.tl { top: 14px; left: 14px; border-right: none; border-bottom: none; }
.map-bracket.tr { top: 14px; right: 14px; border-left: none; border-bottom: none; }
.map-bracket.bl { bottom: 14px; left: 14px; border-right: none; border-top: none; }
.map-bracket.br { bottom: 14px; right: 14px; border-left: none; border-top: none; }

/* Live coords HUD strip in bottom-left of map */
.coords-hud {
  position: absolute;
  bottom: 50px;
  left: 14px;
  z-index: 402;
  background: rgba(6,9,18,0.8);
  border: 1px solid var(--rule-bright);
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--amber);
  text-transform: uppercase;
  display: flex;
  gap: 14px;
  align-items: center;
  backdrop-filter: blur(6px);
}
.coords-hud .lbl { color: var(--text-dim); }

/* ========== TOP CONTROLS ========== */
.scout-controls {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 500;
  display: flex;
  gap: 4px;
  align-items: stretch;
  background: rgba(6,9,18,0.85);
  border: 1px solid var(--rule-bright);
  padding: 4px;
  backdrop-filter: blur(8px);
}
.scout-btn,
a.scout-btn {
  background: transparent !important;
  border: 1px solid transparent !important;
  color: var(--text-mid) !important;
  padding: 7px 11px !important;
  border-radius: 0 !important;
  font-family: var(--mono) !important;
  font-size: 9px !important;
  font-weight: 500 !important;
  letter-spacing: 0.18em !important;
  text-transform: uppercase !important;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.scout-btn:hover { color: var(--amber-hi) !important; background: rgba(255,181,71,0.06) !important; }
.scout-btn.active {
  color: var(--void) !important;
  background: var(--amber) !important;
  border-color: var(--amber) !important;
}

/* ========== SIDEBAR — telemetry stack ========== */
.scout-sidebar,
.sidebar {
  background: var(--hull) !important;
  border-left: 1px solid var(--rule-bright) !important;
  padding: 0 !important;
  height: 100dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-bright) transparent;
}
.scout-sidebar::-webkit-scrollbar { width: 6px; }
.scout-sidebar::-webkit-scrollbar-thumb { background: var(--rule-bright); }

/* Brand header — telemetry style */
.scout-head {
  padding: 18px 20px 14px !important;
  background: var(--void);
  border-bottom: 1px solid var(--rule-bright);
  position: relative;
}
.scout-head h1 {
  font-family: var(--display) !important;
  font-size: 14px !important;
  font-weight: 400 !important;
  letter-spacing: 0.32em !important;
  color: var(--amber) !important;
  margin: 0 0 4px !important;
  text-transform: uppercase;
}
.scout-head h1::before {
  content: '◆ ';
  color: var(--signal);
  font-family: var(--mono);
}
.scout-head p {
  font-family: var(--mono) !important;
  font-size: 9px !important;
  color: var(--text-dim) !important;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 !important;
}
.scout-head a {
  color: var(--signal) !important;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
}

/* Status line — like a comms readout */
.status-line {
  font-family: var(--mono) !important;
  font-size: 10px !important;
  letter-spacing: 0.10em !important;
  color: var(--text-dim) !important;
  padding: 12px 20px !important;
  background: var(--plate);
  border-bottom: 1px solid var(--rule);
  text-transform: uppercase;
  position: relative;
}
.status-line::before {
  content: '> ';
  color: var(--okay);
}
.status-line.working { color: var(--amber) !important; }
.status-line.working::before { color: var(--amber); content: '… '; }

/* ========== INSTRUMENT CARDS ========== */
.card {
  background: var(--plate) !important;
  border: 1px solid var(--rule) !important;
  border-radius: 0 !important;
  margin: 0 0 1px !important;
  padding: 16px 20px !important;
  position: relative;
}
.card-head {
  font-family: var(--mono) !important;
  font-size: 9px !important;
  font-weight: 600 !important;
  letter-spacing: 0.24em !important;
  color: var(--amber) !important;
  text-transform: uppercase;
  margin-bottom: 12px !important;
  padding-bottom: 8px !important;
  border-bottom: 1px dashed var(--rule) !important;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.card-head::before {
  content: '┊';
  color: var(--amber);
  margin-right: 6px;
  font-weight: 400;
}

/* Rows — instrument readouts */
.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0 !important;
  border: none !important;
  font-family: var(--mono);
  font-size: 11px;
}
.row .key {
  color: var(--text-dim) !important;
  font-size: 10px !important;
  letter-spacing: 0.12em !important;
  text-transform: uppercase;
}
.row .val {
  color: var(--text) !important;
  font-family: var(--mono) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  letter-spacing: 0.02em !important;
}
.row .val.gold { color: var(--amber) !important; }
.row .val.green { color: var(--okay) !important; }
.row .val.red { color: var(--warn) !important; }

/* Lead-score badge — like a unit insignia */
.lead-badge {
  width: 42px !important;
  height: 42px !important;
  border-radius: 0 !important;
  font-family: var(--display) !important;
  font-size: 22px !important;
  font-weight: 400 !important;
  letter-spacing: 0 !important;
  position: relative;
  border: 1px solid currentColor;
  background: transparent !important;
  color: var(--amber) !important;
}
.lead-badge::before,
.lead-badge::after {
  content: '';
  position: absolute;
  width: 6px; height: 6px;
  border: 1px solid currentColor;
}
.lead-badge::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.lead-badge::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.lead-row { gap: 14px !important; padding: 4px 0 !important; }
.lead-info .lead-score {
  font-family: var(--mono) !important;
  font-size: 13px !important;
  letter-spacing: 0.08em !important;
  color: var(--amber) !important;
}
.lead-info .lead-reasons {
  font-family: var(--mono) !important;
  font-size: 9px !important;
  letter-spacing: 0.12em !important;
  text-transform: uppercase;
  color: var(--text-dim) !important;
  margin-top: 3px;
}

/* Action buttons — stamped panel buttons */
.action-btn {
  font-family: var(--mono) !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  letter-spacing: 0.20em !important;
  text-transform: uppercase !important;
  border-radius: 0 !important;
  padding: 11px 14px !important;
  position: relative;
  border: 1px solid var(--amber) !important;
  background: transparent !important;
  color: var(--amber) !important;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
  margin-top: 6px !important;
}
.action-btn:hover {
  background: var(--amber) !important;
  color: var(--void) !important;
}
.action-btn.secondary {
  border-color: var(--rule-bright) !important;
  color: var(--text-mid) !important;
}
.action-btn.secondary:hover { color: var(--amber) !important; }

/* Placeholder before any scout */
.placeholder {
  padding: 28px 20px !important;
  font-family: var(--mono) !important;
  font-size: 10px !important;
  letter-spacing: 0.16em !important;
  text-transform: uppercase;
  color: var(--text-dim) !important;
  background: var(--plate);
  border: 1px dashed var(--rule);
  margin: 16px 18px;
  text-align: center;
  line-height: 1.8;
}

/* Leaflet popups — recon report style */
.leaflet-popup-content-wrapper {
  background: rgba(6,9,18,0.96) !important;
  border: 1px solid var(--amber) !important;
  border-radius: 0 !important;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,181,71,0.1) !important;
  backdrop-filter: blur(12px);
}
.leaflet-popup-content-wrapper::before,
.leaflet-popup-content-wrapper::after {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  border: 1px solid var(--amber);
}
.leaflet-popup-content-wrapper::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.leaflet-popup-content-wrapper::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }
.leaflet-popup-tip { background: rgba(6,9,18,0.96) !important; border-color: var(--amber) !important; }
.leaflet-popup-content { font-family: var(--mono) !important; }

.popup-scout-btn {
  font-family: var(--mono) !important;
  letter-spacing: 0.20em !important;
  text-transform: uppercase !important;
  border-radius: 0 !important;
  border: 1px solid var(--amber) !important;
}

/* Leaflet zoom controls */
.leaflet-control-zoom a {
  background: rgba(6,9,18,0.92) !important;
  border-color: var(--rule-bright) !important;
  border-radius: 0 !important;
  color: var(--amber) !important;
  font-family: var(--mono);
}
.leaflet-control-attribution {
  background: rgba(6,9,18,0.7) !important;
  color: var(--text-dim) !important;
  font-family: var(--mono);
  font-size: 9px;
}
.leaflet-control-attribution a { color: var(--amber) !important; }

/* Map cursor */
.leaflet-container { cursor: crosshair !important; }

/* ========== LEGEND PANEL ========== */
.legend {
  position: absolute;
  bottom: 50px;
  right: 14px;
  z-index: 500;
  width: 240px;
  background: rgba(6,9,18,0.92);
  border: 1px solid var(--rule-bright);
  backdrop-filter: blur(10px);
  font-family: var(--mono);
  color: var(--text-mid);
  user-select: none;
  transition: max-height 0.25s ease;
}
.legend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--plate);
  font-size: 10px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--amber);
  cursor: pointer;
}
.legend-head .toggle { transition: transform 0.2s; }
.legend.collapsed .legend-body { display: none; }
.legend.collapsed .legend-head .toggle { transform: rotate(-90deg); }
.legend-body {
  padding: 10px 14px 14px;
  max-height: 70vh;
  overflow-y: auto;
}
.legend-section { margin-bottom: 12px; }
.legend-section:last-child { margin-bottom: 0; }
.legend-title {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--amber);
  text-transform: uppercase;
  margin: 6px 0 6px;
  padding-bottom: 3px;
  border-bottom: 1px dashed var(--rule);
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px 0;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-mid);
}
.legend-row b { color: var(--amber); font-weight: 500; min-width: 8px; display: inline-block; }
.legend-row .swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border: 1px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
}
.legend-row .line {
  display: inline-block;
  width: 18px; height: 3px;
  flex-shrink: 0;
}
.legend-row .dash {
  display: inline-block;
  width: 18px; height: 0;
  border-top: 2px dashed;
  flex-shrink: 0;
}
.legend-row .dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}

/* ========== MOBILE — bottom sheet pattern ========== */
@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
  }
  .map-panel { height: 100dvh; }

  /* Sidebar becomes a draggable bottom sheet */
  .scout-sidebar {
    position: fixed !important;
    left: 0; right: 0; bottom: 0;
    height: 50dvh;
    border-left: none !important;
    border-top: 1px solid var(--amber) !important;
    border-radius: 0 !important;
    z-index: 600;
    transition: transform 0.3s cubic-bezier(.32,.72,0,1);
    transform: translateY(calc(50dvh - 64px));  /* peek 64px by default */
    box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
    will-change: transform;
  }
  .scout-sidebar.expanded {
    transform: translateY(0);
    height: 80dvh;
  }
  .scout-sidebar.full {
    transform: translateY(0);
    height: 100dvh;
  }

  /* Drag handle */
  .scout-sidebar::before {
    content: '';
    position: sticky;
    top: 0;
    left: 0; right: 0;
    height: 28px;
    background: var(--hull);
    border-bottom: 1px solid var(--rule);
    cursor: grab;
    z-index: 10;
    display: block;
  }
  .scout-sidebar::after {
    content: '';
    position: absolute;
    top: 10px; left: 50%;
    width: 48px; height: 4px;
    background: var(--amber);
    transform: translateX(-50%);
    border-radius: 2px;
    pointer-events: none;
    z-index: 11;
  }

  .scout-head { padding-top: 8px !important; }
  .scout-head h1 { font-size: 12px !important; }
  .scout-head p { font-size: 8px !important; }

  /* Map controls — wider tap targets, scroll horizontally if overflow */
  .scout-controls {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: calc(100vw - 28px);
    -webkit-overflow-scrolling: touch;
  }
  .scout-btn {
    padding: 11px 13px !important;
    font-size: 10px !important;
    flex-shrink: 0;
    min-height: 44px;
  }

  /* Action buttons — bigger taps */
  .action-btn { padding: 14px 18px !important; min-height: 48px; }
  .popup-scout-btn { padding: 12px !important; min-height: 44px; }

  /* Legend — pin to top-right, smaller */
  .legend {
    width: 180px;
    top: 14px;
    right: 14px;
    bottom: auto;
    font-size: 9px;
    max-height: 40dvh;
  }
  .legend.collapsed { max-height: 36px; }

  /* Coords HUD - smaller, top-left under controls */
  .coords-hud {
    bottom: auto;
    top: 70px;
    font-size: 9px;
    padding: 6px 10px;
    gap: 8px;
  }
}

/* Tablets */
@media (min-width: 881px) and (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 380px; }
}

/* ========== Accessibility: visible keyboard focus ========== */
:focus:not(:focus-visible) { outline: none; }
.filter-pill:focus-visible,
.nav-item:focus-visible,
.tab:focus-visible,
.toolbar-btn:focus-visible,
.action-btn:focus-visible,
.big-btn:focus-visible,
.scout-pick:focus-visible,
.view-btn:focus-visible,
th:focus-visible,
tr:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--amber, #ffb547);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(255, 181, 71, 0.25);
}
