/* ═══════════════════════════════════════════════════════════════
   Strait of Hormuz Crisis Dashboard — Stylesheet
   Ahmad Ghozlan · aghozlan.github.io/hormuz-dashboard
   Design: Reuters/Bloomberg dark intelligence aesthetic
═══════════════════════════════════════════════════════════════ */

/* ── Reset & Tokens ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0a0a0f;
  --bg-panel:     #12121a;
  --bg-panel-alt: #16161f;
  --bg-hover:     #1a1a26;
  --border:       #1e1e2e;
  --border-light: #2a2a3e;

  --gold:         #D4AF37;
  --gold-dim:     #a8892a;
  --gold-glow:    rgba(212,175,55,0.15);

  --text-primary: #e8e8f0;
  --text-secondary:#9898b0;
  --text-muted:   #5a5a72;

  --red:          #e05252;
  --orange:       #e07820;
  --yellow:       #e0c820;
  --green:        #52c878;
  --blue:         #4a9eff;
  --cyan:         #52d0e0;

  --red-dim:      rgba(224,82,82,0.15);
  --orange-dim:   rgba(224,120,32,0.15);
  --yellow-dim:   rgba(224,200,32,0.15);
  --green-dim:    rgba(82,200,120,0.15);

  --font-mono:    'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --font-sans:    'Inter', 'Segoe UI', system-ui, sans-serif;

  --radius:       6px;
  --radius-lg:    10px;
  --shadow:       0 4px 24px rgba(0,0,0,0.6);
  --shadow-gold:  0 0 20px rgba(212,175,55,0.2);

  --transition:   0.25s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }

/* ── Loading Screen ── */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg-base);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}
#loading-screen.fade-out { opacity: 0; pointer-events: none; }

.loader-wordmark {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--gold);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  margin-bottom: 2rem;
  opacity: 0.8;
}

.loader-ring {
  width: 48px; height: 48px;
  border: 2px solid var(--border-light);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-status {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1.2rem;
  letter-spacing: 0.1em;
}

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

/* ── Header ── */
#header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-wordmark {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-subtitle {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 1px;
}

.header-divider {
  width: 1px;
  height: 32px;
  background: var(--border-light);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid;
  transition: all var(--transition);
  cursor: default;
}

.status-badge.closed   { background: var(--red-dim);    color: var(--red);    border-color: rgba(224,82,82,0.4); }
.status-badge.severe   { background: var(--orange-dim); color: var(--orange); border-color: rgba(224,120,32,0.4); }
.status-badge.partial  { background: var(--yellow-dim); color: var(--yellow); border-color: rgba(224,200,32,0.4); }
.status-badge.normal   { background: var(--green-dim);  color: var(--green);  border-color: rgba(82,200,120,0.4); }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

.header-center {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.live-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.live-counter-value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
  transition: all var(--transition);
}

.live-counter-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
}

.conn-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.conn-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}

.conn-dot.connected    { background: var(--green); animation: pulse-dot 1.5s ease-in-out infinite; }
.conn-dot.connecting   { background: var(--yellow); animation: pulse-dot 0.8s ease-in-out infinite; }
.conn-dot.disconnected { background: var(--red); }

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.byline {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
}

.timestamp {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto auto auto;
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 64px);
}

.panel {
  background: var(--bg-panel);
  padding: 1.25rem;
  position: relative;
}

.panel-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 12px;
  background: var(--gold);
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Metrics Cards ── */
#metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  grid-column: 1 / -1;
}

.metric-card {
  background: var(--bg-panel);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: background var(--transition);
  position: relative;
  overflow: hidden;
}

.metric-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gold);
  opacity: 0.4;
  transform: scaleX(0);
  transition: transform var(--transition);
}

.metric-card:hover::after { transform: scaleX(1); }
.metric-card:hover { background: var(--bg-hover); }

.metric-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  transition: color var(--transition);
}

.metric-value.danger  { color: var(--red); }
.metric-value.warning { color: var(--orange); }
.metric-value.gold    { color: var(--gold); }
.metric-value.good    { color: var(--green); }

.metric-sub {
  font-size: 0.68rem;
  color: var(--text-secondary);
}

.metric-delta {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  width: fit-content;
}

.metric-delta.up   { background: var(--red-dim);   color: var(--red); }
.metric-delta.down { background: var(--green-dim);  color: var(--green); }

/* ── Map Panel ── */
#map-panel {
  grid-column: 1;
  grid-row: 2;
  padding: 0;
  display: flex;
  flex-direction: column;
}

#map-header {
  padding: 0.9rem 1.25rem 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

#map-container {
  flex: 1;
  min-height: 480px;
  position: relative;
}

#map { width: 100%; height: 100%; min-height: 480px; }

.map-controls {
  display: flex;
  gap: 0.5rem;
}

.map-btn {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.35rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.map-btn:hover  { border-color: var(--gold-dim); color: var(--gold); }
.map-btn.active { border-color: var(--gold); color: var(--gold); background: var(--gold-glow); }

/* ── Map Legend ── */
.map-legend {
  background: rgba(18,18,26,0.92) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius) !important;
  padding: 0.6rem 0.8rem !important;
  box-shadow: var(--shadow) !important;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

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

.legend-line {
  width: 20px; height: 2px;
  flex-shrink: 0;
  border-radius: 1px;
}

/* ── Custom Leaflet Popups ── */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  font-family: var(--font-sans) !important;
}

.leaflet-popup-tip { background: var(--bg-panel) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

.ship-popup { min-width: 180px; }
.ship-popup-name {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.ship-popup-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}
.ship-popup-row span:last-child { color: var(--text-primary); font-family: var(--font-mono); }

/* ── Right Sidebar ── */
#sidebar {
  grid-column: 2;
  grid-row: 2 / 4;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
}

/* ── Charts Panel ── */
#charts-panel {
  grid-column: 1;
  grid-row: 3;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-event-marker {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--gold-dim);
  pointer-events: none;
}

/* ── Donut Chart ── */
#donut-wrap {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

#donut-chart-container {
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}

.donut-legend { flex: 1; }

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.donut-legend-swatch {
  width: 8px; height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.donut-legend-name { flex: 1; }
.donut-legend-pct { font-family: var(--font-mono); color: var(--text-primary); }

/* ── Stats Panel ── */
#stats-panel .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

#stats-panel .stat-row:last-child { border-bottom: none; }

.stat-key { color: var(--text-secondary); }
.stat-val {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-primary);
  text-align: right;
}

.stat-val.highlight { color: var(--gold); }
.stat-val.danger    { color: var(--red); }
.stat-val.positive  { color: var(--green); }

.correlation-bar {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-panel-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}

.corr-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.corr-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--red);
  line-height: 1;
}

.corr-desc {
  font-size: 0.67rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.forecast-box {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--gold-glow);
  border: 1px solid rgba(212,175,55,0.3);
  border-radius: var(--radius);
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.forecast-box strong { color: var(--gold); }

/* ── Calculator Panel ── */
#calc-panel .calc-slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.calc-slider-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 80px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(212,175,55,0.4);
}

.calc-result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.calc-result-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
}

.calc-result-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
}

.calc-result-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

.calc-result-unit {
  font-size: 0.62rem;
  color: var(--text-muted);
}

/* ── Carrier Table ── */
#carrier-panel .carrier-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}

.carrier-table th {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.carrier-table td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

.carrier-table tr:last-child td { border-bottom: none; }
.carrier-table tr:hover td { background: var(--bg-hover); color: var(--text-primary); }

.carrier-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.75rem;
}

.carrier-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.carrier-badge.suspended { background: var(--red-dim);    color: var(--red); }
.carrier-badge.limited   { background: var(--orange-dim); color: var(--orange); }
.carrier-badge.operating { background: var(--green-dim);  color: var(--green); }

/* ── Timeline ── */
#timeline-panel .timeline {
  position: relative;
  padding-left: 1.25rem;
}

#timeline-panel .timeline::before {
  content: '';
  position: absolute;
  left: 5px; top: 0; bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, var(--gold-dim) 0%, var(--border-light) 80%, transparent 100%);
}

.timeline-item {
  position: relative;
  padding-bottom: 1.1rem;
  cursor: default;
}

.timeline-dot {
  position: absolute;
  left: -1.25rem;
  top: 5px;
  width: 11px; height: 11px;
  border-radius: 50%;
  border: 2px solid;
  background: var(--bg-panel);
  transition: transform var(--transition);
}

.timeline-item:hover .timeline-dot { transform: scale(1.3); }

.timeline-dot.critical { border-color: var(--red);    box-shadow: 0 0 6px rgba(224,82,82,0.4); }
.timeline-dot.high     { border-color: var(--orange); box-shadow: 0 0 6px rgba(224,120,32,0.3); }
.timeline-dot.medium   { border-color: var(--yellow); }
.timeline-dot.normal   { border-color: var(--green);  }
.timeline-dot.today    { border-color: var(--gold);   box-shadow: 0 0 8px rgba(212,175,55,0.5); }

.timeline-date {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--gold-dim);
  margin-bottom: 0.15rem;
  letter-spacing: 0.05em;
}

.timeline-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.15rem;
}

.timeline-detail {
  font-size: 0.68rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* ── Footer ── */
#footer {
  grid-column: 1 / -1;
  background: var(--bg-panel);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
}

.footer-sources {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-sources a { color: var(--gold-dim); text-decoration: none; }
.footer-sources a:hover { color: var(--gold); }

.footer-caveat {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: rgba(224,200,32,0.05);
  border: 1px solid rgba(224,200,32,0.2);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  line-height: 1.5;
  max-width: 420px;
}

.footer-caveat strong { color: var(--yellow); }

/* ── Regression chart container ── */
#regression-wrap {
  height: 130px;
  margin-top: 0.75rem;
  position: relative;
}

/* ── Utility ── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.text-mono { font-family: var(--font-mono); }
.text-gold  { color: var(--gold); }
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.72rem; }

/* ── Number flash animation ── */
@keyframes flash-gold {
  0%   { color: var(--gold); text-shadow: 0 0 12px rgba(212,175,55,0.7); }
  100% { color: var(--text-primary); text-shadow: none; }
}

.flash { animation: flash-gold 0.8s ease-out forwards; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  #metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }

  #map-panel, #charts-panel {
    grid-column: 1;
  }

  #sidebar {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 640px) {
  #header {
    height: auto;
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #metrics-row {
    grid-template-columns: 1fr 1fr;
  }

  .metric-value { font-size: 1.5rem; }

  .header-center { display: none; }

  #map-container { min-height: 300px; }
  #map { min-height: 300px; }
}

/* ── AIS Vessel markers custom icons ── */
.ais-pulse {
  animation: ais-pulse 2s ease-in-out infinite;
}

@keyframes ais-pulse {
  0%, 100% { opacity: 0.9; }
  50%       { opacity: 0.5; }
}

/* ── Heatmap overlay layer toggle ── */
.leaflet-heatmap-layer { transition: opacity 0.5s ease; }

/* ── Tooltip override ── */
.leaflet-tooltip {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius) !important;
  font-family: var(--font-mono) !important;
  font-size: 0.68rem !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-tooltip::before { border-right-color: var(--border-light) !important; }

/* ── Sample count badge ── */
.sample-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
}

/* ── Section headers for right sidebar panels ── */
.sidebar-panel {
  background: var(--bg-panel);
  padding: 1.1rem 1.1rem;
  flex: 0 0 auto;
}

/* ── Scrollable sidebar ── */
#sidebar {
  overflow-y: auto;
  max-height: calc(100vh - 64px - 50px);
}
