/* =============================================================================
   DCAS Move-Up App — Main Stylesheet
   File: css/main.css
   Theme: Dark tactical operational — matches MOC screen aesthetic
   Brand: Ambulance Red #E31837 (Pantone 186C) · Ambulance Blue #005CAB (Pantone 2728C)
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. CSS CUSTOM PROPERTIES — Single source of truth for all design tokens
   ----------------------------------------------------------------------------- */
:root {
  /* Brand colours — authoritative from DCAS_color_theme.pdf */
  --dcas-red:          #E31837;
  --dcas-red-dim:      #a8112a;
  --dcas-red-glow:     rgba(227, 24, 55, 0.25);
  --dcas-blue:         #005CAB;
  --dcas-blue-dim:     #004480;
  --dcas-blue-glow:    rgba(0, 92, 171, 0.25);

  /* Operational surface palette — dark tactical */
  --bg-void:           #080c12;   /* deepest background */
  --bg-base:           #0d1117;   /* app background */
  --bg-panel:          #111820;   /* panel background */
  --bg-panel-header:   #0a1018;   /* panel header strip */
  --bg-surface:        #161e28;   /* elevated surface */
  --bg-surface-hover:  #1d2736;   /* surface hover */
  --bg-input:          #1a2230;   /* input field background */

  /* Border / separator */
  --border-subtle:     rgba(255,255,255,0.06);
  --border-mid:        rgba(255,255,255,0.12);
  --border-accent:     rgba(0, 92, 171, 0.4);

  /* Text hierarchy */
  --text-primary:      #e8edf4;
  --text-secondary:    #8a9bb0;
  --text-tertiary:     #4a5a70;
  --text-accent-red:   #E31837;
  --text-accent-blue:  #4da3ff;  /* lightened blue for readability on dark */

  /* Status semantic colours */
  --status-available:  #00c896;  /* green-teal — clear / available */
  --status-busy:       #E31837;  /* DCAS red — engaged */
  --status-transit:    #f0a500;  /* amber — in-transit */
  --status-offline:    #4a5a70;  /* grey — offline / unknown */

  /* Severity / recommendation priority */
  --sev-critical:      #E31837;
  --sev-high:          #f0a500;
  --sev-medium:        #005CAB;
  --sev-low:           #00c896;

  /* Typography */
  --font-display:      'Barlow Condensed', 'Noto Sans Arabic', sans-serif;
  --font-body:         'Barlow', 'Noto Sans Arabic', sans-serif;
  --font-mono:         'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* Layout */
  --header-h:          52px;
  --panel-left-w:      220px;
  --panel-right-w:     280px;
  --bottom-bar-h:      96px;
  --panel-border-w:    2px;

  /* Animation */
  --ease-snap:         cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-out:          cubic-bezier(0.0, 0.0, 0.2, 1.0);
  --dur-fast:          120ms;
  --dur-mid:           240ms;
  --dur-slow:          400ms;
}

/* -----------------------------------------------------------------------------
   2. RESET & BASE
   ----------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
  font-family: inherit;
}

input {
  font-family: inherit;
  color: inherit;
}

/* -----------------------------------------------------------------------------
   3. APPLICATION LAYOUT GRID
   Full-screen: header (fixed top) + workspace (fills remaining height)
   ----------------------------------------------------------------------------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 10px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border-mid);

  /* Subtle DCAS blue top accent line */
  box-shadow:
    0 1px 0 0 var(--dcas-blue-dim),
    0 4px 24px rgba(0,0,0,0.6);
}

/* Red accent rule at very top */
.app-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--dcas-red) 0%, var(--dcas-blue) 100%);
}

/* 3-column workspace below header */
.app-workspace {
  position: fixed;
  top: var(--header-h);
  bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: var(--panel-left-w) 1fr var(--panel-right-w);
  grid-template-rows: 1fr;
  overflow: hidden;
}

/* -----------------------------------------------------------------------------
   4. HEADER COMPONENTS
   ----------------------------------------------------------------------------- */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  filter: brightness(1.05);
}

.header-title-group {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.header-eyebrow {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.header-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  white-space: nowrap;
}

.header-title-accent {
  color: var(--dcas-red);
  font-weight: 400;
}

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

.header-clock {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

.clock-icon { font-size: 11px; }

.clock-time {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-accent-blue);
  letter-spacing: 0.08em;
}

.clock-tz {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
}

.data-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: rgba(0, 92, 171, 0.12);
  border: 1px solid var(--border-accent);
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-accent-blue);
}

.data-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-available);
  box-shadow: 0 0 6px var(--status-available);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--status-available); }
  50%       { opacity: 0.5; box-shadow: 0 0 2px var(--status-available); }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hdr-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease-snap),
              color var(--dur-fast) var(--ease-snap);
}

.hdr-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hdr-btn:hover {
  background: var(--bg-surface);
  color: var(--text-accent-blue);
}

.hdr-btn.active {
  background: var(--dcas-blue-glow);
  color: var(--text-accent-blue);
  border: 1px solid var(--border-accent);
}

/* -----------------------------------------------------------------------------
   5. PANELS (shared base)
   ----------------------------------------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
  position: relative;
}

.panel-left {
  border-right: var(--panel-border-w) solid var(--border-mid);
  /* Left panel: red top accent to match logo colour */
  border-top: var(--panel-border-w) solid var(--dcas-red);
}

.panel-right {
  border-left: var(--panel-border-w) solid var(--border-mid);
  /* Right panel: blue accent */
  border-top: var(--panel-border-w) solid var(--dcas-blue);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel-header-alert {
  border-bottom-color: rgba(227,24,55,0.2);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.panel-close,
.panel-menu {
  font-size: 14px;
  color: var(--text-tertiary);
  padding: 2px 6px;
  border-radius: 3px;
  transition: color var(--dur-fast);
}

.panel-close:hover,
.panel-menu:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

/* -----------------------------------------------------------------------------
   6. LEFT PANEL — Unit list & stats
   ----------------------------------------------------------------------------- */
.unit-list-header {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.unit-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}

.unit-list::-webkit-scrollbar { width: 4px; }
.unit-list::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 2px;
}

/* Stats block — fixed at bottom of left panel */
.unit-stats {
  padding: 10px 12px 8px;
  border-top: 1px solid var(--border-mid);
  background: var(--bg-panel-header);
  flex-shrink: 0;
}

.stat-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  min-width: 42px;
  color: var(--text-primary);
}

.stat-number.stat-available { color: var(--status-available); }
.stat-number.stat-busy      { color: var(--status-busy); }
.stat-number.stat-transit   { color: var(--status-transit); }

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.stat-row-response {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
  justify-content: space-between;
}

.stat-label-sm {
  font-size: 10px;
  color: var(--text-tertiary);
}

.stat-response {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--status-transit);
}

/* -----------------------------------------------------------------------------
   7. MAP CONTAINER
   ----------------------------------------------------------------------------- */
.map-container {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-void);
}

#map-view {
  position: absolute;
  top: 0; left: 0; right: 0;
  /* Leave space for bottom bar */
  bottom: var(--bottom-bar-h);
}

/* Loading overlay */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: var(--bg-void);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.map-loading.fade-out {
  opacity: 0;
  pointer-events: none;
}

.map-loading-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--dcas-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -----------------------------------------------------------------------------
   8. BOTTOM BAR (Timeline + Incident Log)
   ----------------------------------------------------------------------------- */
.map-bottom-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-bar-h);
  background: var(--bg-panel-header);
  border-top: 1px solid var(--border-mid);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.bottom-tabs {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.bottom-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}

.bottom-tab svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.bottom-tab.active {
  color: var(--text-accent-blue);
  border-bottom-color: var(--dcas-blue);
}

.bottom-tab:hover:not(.active) {
  color: var(--text-secondary);
}

.bottom-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 6px 12px;
}

.bottom-panel.hidden {
  display: none;
}

/* Timeline controls */
.timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.tl-btn {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  font-size: 16px;
  line-height: 1;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur-fast);
}

.tl-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.timeline-track {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline-label-start,
.timeline-label-end {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

.timeline-slider-wrap {
  flex: 1;
  position: relative;
}

/* Native range input styled for dark theme */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dcas-blue);
  border: 2px solid var(--text-primary);
  cursor: pointer;
  box-shadow: 0 0 6px var(--dcas-blue-glow);
  transition: transform var(--dur-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dcas-blue);
  border: 2px solid var(--text-primary);
  cursor: pointer;
}

.timeline-timestamps {
  display: flex;
  justify-content: space-around;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
}

/* Incident log */
.incident-log {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.incident-log-empty {
  color: var(--text-tertiary);
  font-size: 11px;
  font-style: italic;
}

/* -----------------------------------------------------------------------------
   9. RIGHT PANEL — Recommendations
   ----------------------------------------------------------------------------- */
.rec-subtitle {
  padding: 5px 10px;
  font-size: 10px;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.rec-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}

.rec-list::-webkit-scrollbar { width: 4px; }
.rec-list::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 2px;
}

/* Threshold config panel */
.threshold-panel {
  padding: 12px 10px;
  border-top: 1px solid var(--border-mid);
  background: var(--bg-panel-header);
  flex-shrink: 0;
  display: none; /* toggled by JS */
}

.threshold-panel.open {
  display: block;
  animation: slide-up var(--dur-mid) var(--ease-out);
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.threshold-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.threshold-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.threshold-row label {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
  flex: 1;
}

.threshold-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.thresh-btn {
  width: 22px;
  height: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.thresh-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.threshold-input-wrap input[type="number"] {
  width: 36px;
  height: 22px;
  text-align: center;
  background: var(--bg-input);
  border: 1px solid var(--border-mid);
  border-radius: 3px;
  font-size: 12px;
  font-family: var(--font-mono);
  -moz-appearance: textfield;
}

.threshold-input-wrap input[type="number"]::-webkit-inner-spin-button,
.threshold-input-wrap input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.thresh-apply {
  width: 100%;
  padding: 7px;
  background: var(--dcas-blue);
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  margin-top: 4px;
  transition: background var(--dur-fast);
}

.thresh-apply:hover {
  background: var(--dcas-blue-dim);
}

/* -----------------------------------------------------------------------------
   10. LAYER DRAWER
   ----------------------------------------------------------------------------- */
.drawer {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: 240px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-mid);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-mid) var(--ease-snap);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0,0,0,0.4);
}

.drawer-backdrop.hidden {
  display: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-mid);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.drawer-close {
  color: var(--text-tertiary);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 3px;
  transition: color var(--dur-fast);
}

.drawer-close:hover { color: var(--text-primary); }

.drawer-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.layer-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-group-label {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 0;
  transition: color var(--dur-fast);
}

.layer-toggle:hover { color: var(--text-primary); }

.layer-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--dcas-blue);
  cursor: pointer;
  flex-shrink: 0;
}

/* -----------------------------------------------------------------------------
   11. ESRI WIDGET OVERRIDES
   Ensure ArcGIS SDK widgets match dark tactical theme
   ----------------------------------------------------------------------------- */
.esri-ui-corner .esri-component {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-mid) !important;
  border-radius: 4px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
}

.esri-search__input {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

/* -----------------------------------------------------------------------------
   12. UTILITY CLASSES
   ----------------------------------------------------------------------------- */
.hidden { display: none !important; }

.fade-in {
  animation: fade-in var(--dur-mid) var(--ease-out) forwards;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
