body.map-page {
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

body.map-page nav {
  flex-shrink: 0;
}

/* Faction Gate */
#faction-gate, #taclink-blocked {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
}

.faction-box {
  width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 32px;
  text-align: center;
}

.faction-box h2 {
  font-size: 18px;
  letter-spacing: 4px;
  color: var(--accent);
  margin-bottom: 8px;
}

.faction-box p {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 24px;
  line-height: 1.6;
}

.faction-buttons {
  display: flex;
  gap: 12px;
}

.faction-btn {
  flex: 1;
  padding: 20px 16px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  background: #1a2332;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.faction-btn.blue { border-color: rgba(66, 165, 245, 0.3); }
.faction-btn.blue:hover { background: rgba(66, 165, 245, 0.15); border-color: #42a5f5; }
.faction-btn.blue .faction-btn-label { color: #42a5f5; }

.faction-btn.red { border-color: rgba(239, 83, 80, 0.3); }
.faction-btn.red:hover { background: rgba(239, 83, 80, 0.15); border-color: #ef5350; }
.faction-btn.red .faction-btn-label { color: #ef5350; }

.faction-btn-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
}

.faction-btn-sub {
  font-size: 11px;
  color: var(--text-muted);
}

#cgi-password-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.faction-error {
  background: rgba(244, 67, 54, 0.12);
  color: var(--red);
  border: 1px solid rgba(244, 67, 54, 0.3);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}

.faction-ind {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 1px;
}

.faction-ind.blue {
  background: rgba(66, 165, 245, 0.15);
  color: #42a5f5;
  border: 1px solid rgba(66, 165, 245, 0.3);
}

.faction-ind.red {
  background: rgba(239, 83, 80, 0.15);
  color: #ef5350;
  border: 1px solid rgba(239, 83, 80, 0.3);
}

/* CGI Role Bar */
.cgi-role-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 4px 0;
}

.cgi-role {
  font-size: 9px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 1px;
}

.cgi-role.own {
  background: rgba(66, 165, 245, 0.15);
  color: #42a5f5;
}

.cgi-role.enemy {
  background: rgba(239, 83, 80, 0.15);
  color: #ef5350;
}

.cgi-type-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 2px;
}

#map-content {
  flex: 1;
  min-height: 0;
}

.map-layout {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#sidebar {
  width: 320px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  flex-shrink: 0;
  position: relative;
  transition: margin-left 0.25s ease;
}

#sidebar.collapsed {
  margin-left: -320px;
}

#sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -24px;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 0;
  transition: color 0.15s;
}

#sidebar-toggle:hover {
  color: var(--accent);
}

#sidebar.collapsed #sidebar-toggle svg {
  transform: rotate(180deg);
}

#time-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #0b1018;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

#mission-time {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--mono);
}

#ref-time-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* Filter Bar */
#filter-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#filter-search {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

#filter-search:focus {
  border-color: var(--accent);
}

#filter-search::placeholder {
  color: var(--text-muted);
}

#filter-types {
  display: flex;
  gap: 4px;
}

.filter-type-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  background: #1a2332;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-type-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.filter-type-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(79,195,247,0.3);
}

#filter-player-btn.active {
  background: rgba(76,175,80,0.12);
  color: var(--green);
  border-color: rgba(76,175,80,0.3);
}

#unit-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.unit-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}

.unit-entry:hover {
  background: var(--accent-dim);
}

.unit-entry.selected {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
}

.unit-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.unit-dot.blue { background: var(--blue); }
.unit-dot.red { background: var(--red); }
.unit-dot.neutral { background: #bdbdbd; }

.unit-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-type {
  font-size: 10px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

.player-badge {
  font-size: 9px;
  font-weight: 700;
  color: var(--green);
  background: rgba(76,175,80,0.15);
  border: 1px solid rgba(76,175,80,0.3);
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.5px;
}

.unit-alt {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: right;
}

#info-panel {
  border-top: 1px solid var(--border);
  padding: 16px;
  min-height: 140px;
  background: var(--bg-card);
}

#info-content {
  font-size: 13px;
  color: var(--text-dim);
}

#info-content .label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 8px;
}

#info-content .value {
  color: var(--text);
  margin-bottom: 4px;
}

/* Map */
#map {
  flex: 1;
  background: var(--bg-dark);
}

/* Timeline */
#timeline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  background: rgba(13, 17, 23, 0.95);
  border-top: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.tl-btn {
  background: #1a2332;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.15s;
}

.tl-btn.active {
  background: var(--green-dim);
  color: var(--green);
  border-color: rgba(76, 175, 80, 0.4);
}

.tl-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 60px;
}

.tl-end { text-align: right; }

#tl-time-current {
  color: var(--accent);
  font-weight: 600;
}

#tl-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#tl-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 6px rgba(79, 195, 247, 0.4);
}

#tl-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-panel);
}

/* Leaflet overrides */
.leaflet-container { background: var(--bg-dark); }
.leaflet-control-zoom a {
  background: #1a2332 !important;
  color: var(--accent) !important;
  border-color: var(--border) !important;
}
.leaflet-control-attribution {
  background: rgba(13, 17, 23, 0.8) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

.unit-marker { transition: transform 0.3s linear; }

.leaflet-tooltip {
  background: rgba(13, 17, 23, 0.95) !important;
  background-color: rgba(13, 17, 23, 0.95) !important;
  color: #e0e0e0 !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 4px !important;
  font-size: 12px !important;
  font-family: var(--font) !important;
  white-space: nowrap !important;
  padding: 4px 10px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6) !important;
}

.leaflet-tooltip::before {
  border-top-color: transparent !important;
  border-bottom-color: transparent !important;
  border-left-color: rgba(13, 17, 23, 0.95) !important;
  border-right-color: rgba(13, 17, 23, 0.95) !important;
}

.model-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--text-dim);
  font-size: 10px;
  font-family: var(--mono);
  white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 6px #000;
  pointer-events: none;
}

#unit-list::-webkit-scrollbar { width: 6px; }
#unit-list::-webkit-scrollbar-track { background: transparent; }
#unit-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === CGI TOOLS === */
#cgi-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.cgi-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  background: #1a2332;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  letter-spacing: 0.5px;
}

.cgi-toggle-btn:hover { background: #243040; color: var(--text); }

.cgi-toggle-btn.active {
  background: rgba(255, 235, 59, 0.12);
  color: #ffeb3b;
  border-color: rgba(255, 235, 59, 0.35);
}

.cgi-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: #1a2332;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.cgi-clear-btn:hover { color: var(--red); border-color: var(--red); }

#cgi-panel {
  border-bottom: 1px solid var(--border);
  background: rgba(255, 235, 59, 0.02);
  max-height: 400px;
  overflow-y: auto;
}

#cgi-content {
  padding: 12px;
}

.cgi-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px;
  font-style: italic;
}

.cgi-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.cgi-vs {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 1px;
}

.cgi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cgi-metric {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.cgi-metric-large {
  grid-column: 1 / -1;
  text-align: center;
  padding: 12px;
}

.cgi-metric-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.cgi-metric-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--mono);
}

.cgi-metric-large .cgi-metric-value {
  font-size: 24px;
  color: #ffeb3b;
}

.cgi-metric-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.cgi-metric-value small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
}

.cgi-aspect-badge {
  display: inline-block;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 700;
  letter-spacing: 1px;
  vertical-align: middle;
}

.cgi-aspect-badge.hot {
  background: rgba(244, 67, 54, 0.2);
  color: #ef5350;
}

.cgi-aspect-badge.flanking {
  background: rgba(255, 183, 77, 0.2);
  color: #ffb74d;
}

.cgi-aspect-badge.beaming {
  background: rgba(79, 195, 247, 0.2);
  color: #4fc3f7;
}

.cgi-aspect-badge.cold {
  background: rgba(76, 175, 80, 0.2);
  color: #66bb6a;
}

/* CGI selected unit in sidebar */
.unit-entry.cgi-selected {
  background: rgba(255, 235, 59, 0.08);
  border-left: 2px solid #ffeb3b;
}

/* CGI distance label on map */
.cgi-dist-label {
  background: rgba(255, 235, 59, 0.9) !important;
  color: #000 !important;
  border: none !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  font-family: var(--mono) !important;
  text-align: center;
  padding: 2px 8px !important;
  border-radius: 4px !important;
  white-space: nowrap;
  pointer-events: none;
}

/* CGI pulse animation for selected markers */
@keyframes cgiPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

#cgi-panel::-webkit-scrollbar { width: 4px; }
#cgi-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Keyboard Toast */
#kb-toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 17, 23, 0.92);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  pointer-events: none;
  opacity: 0;
  z-index: 9000;
  white-space: nowrap;
}

.kb-toast-fade {
  animation: toastFade 1.8s ease forwards;
}

@keyframes toastFade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Help Overlay */
#kb-help-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.kb-help-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 420px;
  width: 90%;
}

.kb-help-box h3 {
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 18px;
  text-align: center;
}

.kb-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  align-items: center;
}

.kb-grid kbd {
  background: #1a2332;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 700;
  text-align: center;
  min-width: 36px;
}

.kb-grid span {
  font-size: 13px;
  color: var(--text-dim);
}

.kb-close-hint {
  text-align: center;
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-muted);
}

.kb-close-hint kbd {
  background: #1a2332;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: var(--mono);
}

/* Range Ring Labels */
.range-ring-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--mono);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 0 3px #000, 0 0 6px #000;
}

/* === MOBILE === */
@media (max-width: 768px) {
  body.map-page nav { height: 48px; }

  .faction-box { width: 90%; padding: 28px 20px; }
  .faction-box h2 { font-size: 15px; }

  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 1001;
  }

  #sidebar.collapsed {
    margin-left: -280px;
  }

  #sidebar-toggle {
    right: -28px;
    width: 28px;
    height: 52px;
  }

  #time-bar { padding: 8px 12px; }
  #mission-time { font-size: 15px; }

  #cgi-toolbar { padding: 6px 8px; gap: 3px; }
  .cgi-toggle-btn { font-size: 11px; padding: 5px 8px; }

  .cgi-metric-value { font-size: 14px; }
  .cgi-metric-large .cgi-metric-value { font-size: 18px; }

  #filter-bar { padding: 6px 8px; gap: 4px; }
  #filter-search { font-size: 16px; padding: 8px 10px; }
  .filter-type-btn { padding: 6px; }

  #info-panel { padding: 10px; min-height: 100px; }

  #timeline { padding: 0 8px; gap: 6px; height: 38px; }
  .tl-btn { font-size: 10px; padding: 3px 8px; }
  .tl-label { font-size: 11px; min-width: 50px; }

  .kb-help-box { padding: 20px; max-width: 90%; }
}

/* ==================== AIRFIELD LAYER ==================== */

.airfield-marker {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.airfield-label-marker {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.airfield-label {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.95), 0 0 6px rgba(0,0,0,0.9);
  pointer-events: none;
  letter-spacing: 0.3px;
}

#filter-airfield-btn.active {
  background: rgba(158, 158, 158, 0.15);
  color: #9e9e9e;
  border-color: rgba(158, 158, 158, 0.3);
}

.airfield-popup .leaflet-popup-content-wrapper {
  background: rgba(13, 17, 23, 0.97);
  color: #e0e0e0;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}

.airfield-popup .leaflet-popup-tip {
  background: rgba(13, 17, 23, 0.97);
}

.airfield-popup .leaflet-popup-close-button {
  color: #999 !important;
}

.airfield-popup-content {
  font-size: 12px;
  line-height: 1.6;
}

.af-name {
  font-size: 14px;
  font-weight: 700;
  color: #4fc3f7;
  margin-bottom: 2px;
}

.af-icao {
  font-size: 11px;
  color: #888;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.af-detail {
  font-size: 11px;
  color: #aaa;
  margin-top: 4px;
}

.af-section {
  margin-top: 8px;
  font-size: 11px;
  color: #aaa;
}

.af-section b {
  color: #e0e0e0;
}

/* ==================== MEASURE TOOL ==================== */

#btn-measure.active {
  background: rgba(0, 230, 118, 0.15);
  color: #00e676;
  border-color: rgba(0, 230, 118, 0.3);
}

.measure-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.measure-label span {
  background: rgba(0, 0, 0, 0.75);
  color: #00e676;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid rgba(0, 230, 118, 0.3);
}
