/* =========================================================================
   Kuala Lumpur Integrated Operations Centre (KL IOC · kl.nonarkara.org)
   Axiom Design Core — Brutalist Instrument Mode
   Zero border-radius · Zero box-shadows · Zero backdrop blurs · Mono telemetry
   ========================================================================= */

:root {
  --kl-bg: #090d14;
  --kl-bg-subtle: #0f1622;
  --kl-panel: #131b29;
  --kl-panel-border: #1e293b;
  --kl-border-strong: #334155;
  --kl-text: #f1f5f9;
  --kl-text-muted: #94a3b8;
  --kl-text-dim: #64748b;
  
  /* Signal Accents */
  --kl-lime: #c9ff38;       /* Primary Signal / Nominal */
  --kl-danger: #ff3838;     /* Danger / Flood / Accident */
  --kl-alert: #ff9900;      /* Alert / Warning */
  --kl-cyan: #38c9ff;       /* Hydrology / Aviation / Water */
  --kl-amber: #facc15;      /* Caution / Moderate */
  --kl-blue: #3b82f6;       /* Law Enforcement / Police */
  
  --kl-font-mono: "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, monospace;
  --kl-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  --top-height: 48px;
  --ticker-height: 28px;
  --lens-height: 32px;
  --corridor-height: 28px;
  --hud-height: 32px;
}

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

body.kl-ioc-body {
  background-color: var(--kl-bg);
  color: var(--kl-text);
  font-family: var(--kl-font-sans);
  font-size: 13px;
  line-height: 1.4;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.num {
  font-family: var(--kl-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* =========================================================================
   1. Header Bar
   ========================================================================= */
.kl-top {
  height: var(--top-height);
  background: var(--kl-bg-subtle);
  border-bottom: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  flex-shrink: 0;
  /* The header is a fixed-height row. Without these, a wrapping <h1> or a long
     button label overflows the box and paints over the ticker below it. */
  overflow: hidden;
  gap: 12px;
}

.kl-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Allow the brand block to shrink so the title can ellipsis rather than
     wrapping out of the fixed-height header. */
  min-width: 0;
  flex: 0 1 auto;
}

.kl-back {
  font-family: var(--kl-font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--kl-lime);
  text-decoration: none;
  padding: 4px 8px;
  background: rgba(201, 255, 56, 0.08);
  border: 1px solid rgba(201, 255, 56, 0.3);
}

.kl-back:hover {
  background: var(--kl-lime);
  color: #000;
}

.kl-plate-tag {
  font-family: var(--kl-font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--kl-text);
  background: #1e293b;
  padding: 2px 6px;
  border: 1px solid var(--kl-border-strong);
}

.kl-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.kl-clock {
  font-size: 12px;
  color: var(--kl-lime);
  font-weight: 600;
  white-space: nowrap;
}

.kl-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Controls keep their intrinsic width and never compress into each other. */
  flex-shrink: 0;
  min-width: 0;
}

/* Brutalist Buttons */
.btn {
  font-family: var(--kl-font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 0;
  border: 1px solid var(--kl-border-strong);
  background: #1e293b;
  color: var(--kl-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: none;
}

.btn:hover {
  background: #334155;
  color: #ffffff;
}

.btn-action {
  background: var(--kl-lime);
  color: #000000;
  border-color: var(--kl-lime);
}

.btn-action:hover {
  background: #d8ff66;
  color: #000000;
}

.btn-cyan {
  background: var(--kl-cyan);
  color: #000000;
  border-color: var(--kl-cyan);
}

.btn-cyan:hover {
  background: #66d8ff;
  color: #000000;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 10px;
}

.basemap-group {
  display: flex;
  border: 1px solid var(--kl-border-strong);
}

.bm-btn {
  font-family: var(--kl-font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 5px 8px;
  border: none;
  background: #131b29;
  color: var(--kl-text-muted);
  cursor: pointer;
}

.bm-btn.active {
  background: var(--kl-lime);
  color: #000;
}

/* =========================================================================
   2. Threat & Situation Ticker Bar
   ========================================================================= */
.kl-ticker-bar {
  height: var(--ticker-height);
  background: #0b111a;
  border-bottom: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 11px;
  overflow-x: auto;
  gap: 16px;
  flex-shrink: 0;
  white-space: nowrap;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ticker-label {
  color: var(--kl-text-dim);
  font-size: 10px;
}

.badge-nominal {
  color: var(--kl-lime);
  background: rgba(201, 255, 56, 0.1);
  padding: 1px 6px;
  border: 1px solid rgba(201, 255, 56, 0.3);
}

.badge-alert {
  color: var(--kl-alert);
  background: rgba(255, 153, 0, 0.1);
  padding: 1px 6px;
  border: 1px solid rgba(255, 153, 0, 0.3);
}

.badge-danger {
  color: var(--kl-danger);
  background: rgba(255, 56, 56, 0.15);
  padding: 1px 6px;
  border: 1px solid rgba(255, 56, 56, 0.4);
}

.badge-warn {
  color: var(--kl-amber);
  background: rgba(250, 204, 21, 0.1);
  padding: 1px 6px;
  border: 1px solid rgba(250, 204, 21, 0.3);
}

/* =========================================================================
   3. 9-Lens Navigation Bar
   ========================================================================= */
.kl-lens-bar {
  height: var(--lens-height);
  background: #0f1724;
  border-bottom: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: stretch;
  padding: 0;
  overflow-x: auto;
  flex-shrink: 0;
}

.lens-tab {
  font-family: var(--kl-font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 0 12px;
  background: transparent;
  color: var(--kl-text-muted);
  border: none;
  border-right: 1px solid var(--kl-panel-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.lens-tab:hover {
  background: #1e293b;
  color: var(--kl-text);
}

.lens-tab.active {
  background: #1e293b;
  color: var(--kl-lime);
  border-bottom: 2px solid var(--kl-lime);
}

.lens-key {
  font-size: 9px;
  color: var(--kl-text-dim);
  border: 1px solid var(--kl-border-strong);
  padding: 0 3px;
}

/* =========================================================================
   4. Corridor Fast-Jump Strip
   ========================================================================= */
.corridor-strip {
  height: var(--corridor-height);
  background: #0a0e17;
  border-bottom: 1px solid var(--kl-panel-border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  flex-shrink: 0;
}

.corridor-cell {
  background: transparent;
  border: none;
  border-right: 1px solid var(--kl-panel-border);
  color: var(--kl-text-dim);
  font-family: var(--kl-font-mono);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.corridor-cell:last-child {
  border-right: none;
}

.corridor-cell:hover {
  background: #162032;
  color: var(--kl-text);
}

.corridor-cell.active {
  background: #1e293b;
  color: var(--kl-cyan);
  font-weight: 700;
}

/* =========================================================================
   5. Main Operational Stage (Briefing Rail | Map Hero | Inspector)
   ========================================================================= */
.kl-main-stage {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  overflow: hidden;
  position: relative;
}

/* Left Briefing Rail */
.kl-brief-rail {
  background: var(--kl-panel);
  border-right: 1px solid var(--kl-panel-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rail-section {
  background: var(--kl-bg-subtle);
  border-bottom: 1px solid var(--kl-panel-border);
  padding: 10px 12px;
}

.rail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.rail-section-title {
  font-family: var(--kl-font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--kl-lime);
  letter-spacing: 0.04em;
}

.rail-metric-box {
  background: #090d14;
  border: 1px solid var(--kl-border-strong);
  padding: 8px;
  margin-bottom: 8px;
}

.rail-metric-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--kl-text);
}

.rail-metric-sub {
  font-size: 10px;
  color: var(--kl-text-dim);
}

/* Map Hero */
.kl-map-hero {
  position: relative;
  width: 100%;
  height: 100%;
  background: #05080c;
}

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

/* Chapter Ribbon for Flyover */
.chapter-ribbon {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  background: rgba(13, 17, 23, 0.95);
  border: 1px solid var(--kl-lime);
  padding: 8px 12px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chapter-tag {
  color: var(--kl-lime);
  font-size: 10px;
  font-weight: 800;
}

.chapter-title {
  font-size: 13px;
  font-weight: 700;
}

.chapter-desc {
  font-size: 11px;
  color: var(--kl-text-muted);
}

/* Right Inspection Rail */
.kl-inspect-rail {
  background: var(--kl-panel);
  border-left: 1px solid var(--kl-panel-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.insp-head {
  padding: 12px;
  border-bottom: 1px solid var(--kl-panel-border);
  background: #0b111a;
}

.insp-tag {
  font-size: 10px;
  font-weight: 800;
  color: var(--kl-lime);
}

.insp-name {
  font-size: 16px;
  font-weight: 800;
  margin-top: 2px;
  color: var(--kl-text);
}

.insp-style {
  font-size: 11px;
  color: var(--kl-text-dim);
  margin-top: 2px;
}

.insp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--kl-panel-border);
  border-bottom: 1px solid var(--kl-panel-border);
}

.insp-cell {
  background: var(--kl-bg-subtle);
  padding: 8px 12px;
}

.insp-cell-k {
  font-size: 9px;
  color: var(--kl-text-dim);
  font-weight: 700;
}

.insp-cell-v {
  font-size: 14px;
  font-weight: 700;
  color: var(--kl-text);
  margin-top: 2px;
}

.insp-body {
  padding: 12px;
  flex: 1;
}

.insp-subhead {
  font-size: 10px;
  font-weight: 800;
  color: var(--kl-text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  margin-top: 10px;
}

.insp-subhead:first-child {
  margin-top: 0;
}

.insp-desc {
  font-size: 11px;
  color: var(--kl-text-muted);
  line-height: 1.5;
}

.insp-media-wrap {
  margin-bottom: 12px;
}

.insp-media {
  position: relative;
  background: #090d14;
  border: 1px solid var(--kl-border-strong);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.insp-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.insp-media:hover img {
  transform: scale(1.03);
}

.insp-media-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(9, 13, 20, 0.88);
  border-top: 1px solid var(--kl-border-strong);
  padding: 3px 6px;
  font-size: 9px;
  font-weight: 700;
  color: var(--kl-cyan);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.voxel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.voxel-chip {
  font-size: 10px;
  background: #1e293b;
  border: 1px solid var(--kl-border-strong);
  padding: 2px 6px;
  color: var(--kl-lime);
}

.tp-box {
  background: #090d14;
  border: 1px solid var(--kl-border-strong);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.tp-cmd {
  font-size: 11px;
  color: var(--kl-lime);
}

/* =========================================================================
   6. Docked Telemetry HUD
   ========================================================================= */
.kl-hud {
  height: var(--hud-height);
  background: #090d14;
  border-top: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  flex-shrink: 0;
  font-size: 11px;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-k {
  color: var(--kl-text-dim);
  font-size: 10px;
}

.hud-v {
  color: var(--kl-text);
  font-weight: 600;
}

/* =========================================================================
   7. CCTV Wall Modal Matrix
   ========================================================================= */
dialog.cctv-wall-modal {
  width: 90vw;
  max-width: 1400px;
  height: 85vh;
  background: var(--kl-bg);
  border: 1px solid var(--kl-lime);
  color: var(--kl-text);
  margin: auto;
  padding: 0;
}

dialog.cctv-wall-modal:not([open]) {
  display: none !important;
}

dialog.cctv-wall-modal[open] {
  display: flex !important;
  flex-direction: column;
}

dialog.cctv-wall-modal::backdrop {
  background: rgba(0, 0, 0, 0.85);
}

.cctv-wall-head {
  height: 48px;
  background: #0f1622;
  border-bottom: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.cctv-wall-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--kl-lime);
}

.cctv-filter-toolbar {
  height: 36px;
  background: #0b111a;
  border-bottom: 1px solid var(--kl-panel-border);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}

.cctv-filter-btn {
  font-family: var(--kl-font-mono);
  font-size: 10px;
  font-weight: 700;
  background: transparent;
  border: 1px solid var(--kl-border-strong);
  color: var(--kl-text-muted);
  padding: 4px 8px;
  cursor: pointer;
}

.cctv-filter-btn.active {
  background: var(--kl-lime);
  color: #000;
  border-color: var(--kl-lime);
}

.cctv-wall-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  padding: 16px;
  background: #090d14;
}

.cctv-card {
  background: #0f1622;
  border: 1px solid var(--kl-border-strong);
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.cctv-card:hover {
  border-color: var(--kl-lime);
}

.cctv-card.status-water_suspected {
  border-color: var(--kl-danger);
}

.cctv-card.status-traffic_heavy {
  border-color: var(--kl-alert);
}

.cctv-card-head {
  padding: 6px 8px;
  background: #141c2b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
}

.cctv-id {
  color: var(--kl-text-muted);
  font-weight: 700;
}

.cctv-feed-frame {
  height: 140px;
  background: #000;
  position: relative;
  overflow: hidden;
}

.cctv-stream-sim {
  width: 100%;
  height: 100%;
  position: relative;
}

.cctv-canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cctv-scanline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(201, 255, 56, 0.4);
  animation: scanline 4s linear infinite;
  pointer-events: none;
}

@keyframes scanline {
  0% { top: 0; }
  100% { top: 100%; }
}

.cctv-cam-tag {
  position: absolute;
  bottom: 4px;
  left: 6px;
  font-size: 9px;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  padding: 1px 4px;
}

.cctv-fps {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 9px;
  color: var(--kl-lime);
  background: rgba(0, 0, 0, 0.7);
  padding: 1px 4px;
}

.cctv-card-meta {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cctv-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--kl-text);
}

.cctv-metrics {
  display: flex;
  gap: 8px;
  font-size: 10px;
  color: var(--kl-text-dim);
}

.cctv-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.cctv-agency {
  font-size: 9px;
  color: var(--kl-text-muted);
}

/* =========================================================================
   8. Responsive Layout Tweaks
   ========================================================================= */
@media (max-width: 1100px) {
  .kl-main-stage {
    grid-template-columns: 280px 1fr;
  }
  .kl-inspect-rail {
    display: none;
  }
  /* The masthead is already carried by the MALAYSIA back-link and the
     KL_IOC // COMMAND plate. Dropping the spelled-out title buys the action
     buttons room instead of letting both wrap inside a 48 px header. */
  .kl-title {
    display: none;
  }
  .kl-clock {
    display: none;
  }
}

@media (max-width: 860px) {
  /* Shrink the gaps and padding so the five action controls still fit. */
  .kl-top {
    padding: 0 8px;
    gap: 8px;
  }
  .kl-brand {
    gap: 8px;
  }
  .kl-actions {
    gap: 6px;
  }
  .btn {
    padding: 6px 8px;
    font-size: 10px;
  }
  .kl-plate-tag {
    display: none;
  }
}

@media (max-width: 768px) {
  .kl-main-stage {
    grid-template-columns: 1fr;
  }
  .kl-brief-rail {
    display: none;
  }
  .corridor-strip {
    display: none;
  }
  /* Nothing else fits at this width. The commands remain on their hotkeys and
     on the mission menu, so they are removed rather than allowed to overlap. */
  #toggleViewModeBtn,
  #flyoverBtn {
    display: none;
  }
}
