/* ============================================================
    — Healthcare Accessibility Visualizer
   Stylesheet
   ============================================================ */

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

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

:root {
  --bg-dark: #060612;
  --bg-card: rgba(12, 12, 30, 0.88);
  --border-glass: rgba(100, 120, 255, 0.15);
  --text-primary: #e8eaff;
  --text-secondary: #8a8fb5;
  --text-dim: #555a80;
  --accent-blue: #4a9eff;
  --accent-cyan: #00d4ff;
  --accent-green: #33ff88;
  --accent-orange: #ffaa33;
  --accent-red: #ff3344;
  --accent-purple: #a855f7;
  --glow-blue: rgba(74, 158, 255, 0.4);
  --glow-cyan: rgba(0, 212, 255, 0.4);
  --glow-red: rgba(255, 51, 68, 0.5);
  --glow-green: rgba(51, 255, 136, 0.4);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
}

/* ---- Map Containers ---- */
.map-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  background: var(--bg-dark);
}

.map-container.active {
  display: block;
}

/* ---- Tab Bar ---- */
#tab-bar {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(12, 12, 30, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(100, 120, 255, 0.15);
  border-radius: 14px;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: var(--text-primary);
  background: linear-gradient(135deg, rgba(74, 158, 255, 0.2), rgba(168, 85, 247, 0.2));
  box-shadow: 0 2px 12px rgba(74, 158, 255, 0.15);
}

/* Force dark Leaflet background (no tiles in CRS.Simple) */
.leaflet-container {
  background: var(--bg-dark) !important;
}

/* Force dark Leaflet controls */
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-glass) !important;
  backdrop-filter: blur(12px);
}

.leaflet-control-zoom a:hover {
  background: rgba(30, 30, 60, 0.95) !important;
}

.leaflet-control-attribution {
  background: rgba(6, 6, 18, 0.7) !important;
  color: var(--text-dim) !important;
  font-size: 10px;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* ---- Title Overlay ---- */
#title-overlay {
  position: fixed;
  top: 72px;
  left: 24px;
  z-index: 1000;
  pointer-events: none;
}

#title-overlay h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
}

#title-overlay p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 400;
}

/* ---- Info Panel (right side) ---- */
#info-panel {
  position: fixed;
  top: 72px;
  right: 24px;
  width: 320px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 20px;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.glass-card.glow-blue {
  border-color: rgba(74, 158, 255, 0.3);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3), 0 0 40px rgba(74, 158, 255, 0.08);
}

.glass-card.glow-green {
  border-color: rgba(51, 255, 136, 0.3);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3), 0 0 40px rgba(51, 255, 136, 0.08);
}

/* ---- Stats Bar ---- */
#stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-item {
  text-align: center;
  padding: 8px 4px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-cyan);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 2px;
}

/* ---- Instruction Text ---- */
#instruction-text {
  text-align: center;
  padding: 14px 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  animation: subtlePulse 3s ease-in-out infinite;
}

#instruction-text .highlight {
  color: var(--accent-cyan);
  font-weight: 600;
}

@keyframes subtlePulse {

  0%,
  100% {
    opacity: 0.8;
  }

  50% {
    opacity: 1;
  }
}

/* ---- Path Result Card ---- */
#path-result {
  display: none;
  animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#path-result.visible {
  display: block;
}

.result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.result-header .icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: rgba(74, 158, 255, 0.15);
  flex-shrink: 0;
}

.result-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
}

.result-header .subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.result-stat {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.result-stat .label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-stat .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 2px;
}

.result-stat .value.time {
  color: var(--accent-cyan);
}

.result-stat .value.hops {
  color: var(--accent-purple);
}

.result-path-nodes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.path-node-tag {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(74, 158, 255, 0.12);
  color: var(--accent-blue);
  font-weight: 500;
}

.path-node-tag.hospital {
  background: rgba(255, 51, 68, 0.12);
  color: var(--accent-red);
}

.path-arrow {
  font-size: 0.65rem;
  color: var(--text-dim);
}

/* ---- Optimize Button ---- */
#optimize-btn {
  display: none;
  width: 100%;
  padding: 14px 20px;
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(74, 158, 255, 0.15));
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.3px;
  position: relative;
  overflow: hidden;
}

#optimize-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(74, 158, 255, 0.2));
  opacity: 0;
  transition: opacity 0.3s ease;
}

#optimize-btn:hover {
  border-color: rgba(168, 85, 247, 0.6);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.2);
}

#optimize-btn:hover::before {
  opacity: 1;
}

#optimize-btn.visible {
  display: block;
  animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#optimize-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ---- Optimization Result ---- */
#optimize-result {
  display: none;
  animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#optimize-result.visible {
  display: block;
}

.optimize-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.optimize-stat-row:last-child {
  border-bottom: none;
}

.optimize-stat-row .label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.optimize-stat-row .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  font-weight: 600;
}

.optimize-stat-row .improvement {
  color: var(--accent-green);
}

.optimize-stat-row .before {
  color: var(--accent-red);
  text-decoration: line-through;
  opacity: 0.6;
  margin-right: 8px;
}

/* ---- Reset Button ---- */
#reset-btn {
  display: none;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

#reset-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

#reset-btn.visible {
  display: block;
}

/* ---- Node Labels ---- */
.node-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

.node-label .node-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent-cyan);
  text-shadow: 0 0 6px rgba(0, 212, 255, 0.5), 0 1px 3px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.04em;
}

.node-label .node-name {
  font-family: 'Inter', sans-serif;
  font-size: 0.55rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  opacity: 0.8;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-label-intersection .node-code {
  font-size: 0.55rem;
  color: var(--text-dim);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.node-label-hospital .node-code {
  color: var(--accent-red);
  text-shadow: 0 0 6px rgba(255, 51, 68, 0.4), 0 1px 3px rgba(0, 0, 0, 0.8);
}

.node-label-hospital .node-name {
  font-size: 0.5rem;
  color: var(--text-dim);
  opacity: 0.7;
}

/* ---- Legend ---- */
#legend {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  font-size: 0.72rem;
  transition: opacity 0.4s ease;
  max-width: 520px;
}

.legend-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}

.legend-subtitle {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 0.62rem;
}

.legend-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.legend-divider {
  height: 1px;
  background: var(--border-glass);
  margin: 2px 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

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

.legend-dot.safe {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--glow-green);
}

.legend-dot.moderate {
  background: var(--accent-blue);
  box-shadow: 0 0 6px var(--glow-blue);
}

.legend-dot.warning {
  background: var(--accent-orange);
}

.legend-dot.critical {
  background: var(--accent-red);
  box-shadow: 0 0 6px var(--glow-red);
  animation: blink 1s ease-in-out infinite;
}

.legend-dot.hospital {
  background: #fff;
  border: 2px solid var(--accent-red);
  width: 8px;
  height: 8px;
}

.legend-dot.intersection {
  background: #888aaa;
  opacity: 0.7;
  width: 8px;
  height: 8px;
}

.legend-dot.new-facility {
  background: var(--accent-green);
  border: 2px solid #fff;
}

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

.legend-line.edge-fast {
  background: #33cc55;
  box-shadow: 0 0 4px rgba(51, 204, 85, 0.4);
}

.legend-line.edge-mid {
  background: #ff9933;
  box-shadow: 0 0 4px rgba(255, 153, 51, 0.3);
}

.legend-line.edge-slow {
  background: #ee3344;
  box-shadow: 0 0 4px rgba(238, 51, 68, 0.4);
  animation: blink 1s ease-in-out infinite;
}

.legend-line.edge-path {
  background: var(--accent-cyan);
  box-shadow: 0 0 6px var(--glow-cyan);
}

/* ---- Loading Overlay ---- */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(6, 6, 18, 0.7);
  backdrop-filter: blur(8px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

#loading-overlay.visible {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(168, 85, 247, 0.2);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

/* ---- Node Tooltips (Leaflet) ---- */
.village-tooltip {
  background: var(--bg-card) !important;
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass) !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  color: var(--text-primary) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.75rem !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4) !important;
}

.village-tooltip::before {
  border-top-color: var(--border-glass) !important;
}

.village-tooltip .tt-name {
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 2px;
}

.village-tooltip .tt-pop {
  color: var(--text-secondary);
  font-size: 0.7rem;
}

.village-tooltip .tt-time {
  font-family: 'JetBrains Mono', monospace;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ---- Hospital Markers ---- */
.hospital-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 51, 68, 0.9), rgba(255, 51, 68, 0.5));
  border: 2px solid rgba(255, 255, 255, 0.8);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 0 15px var(--glow-red), 0 0 30px rgba(255, 51, 68, 0.2);
  cursor: default;
}

.hospital-marker-new {
  background: radial-gradient(circle, rgba(51, 255, 136, 0.9), rgba(51, 255, 136, 0.5));
  box-shadow: 0 0 15px var(--glow-green), 0 0 30px rgba(51, 255, 136, 0.2);
  animation: facilityAppear 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes facilityAppear {
  0% {
    transform: scale(0) translateY(-20px);
    opacity: 0;
  }

  60% {
    transform: scale(1.2) translateY(0);
    opacity: 1;
  }

  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* ---- Animations ---- */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.15;
  }
}

/* Apply blink to Leaflet paths with .blink-red class */
.leaflet-interactive.blink-red {
  animation: blink 1s ease-in-out infinite;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #info-panel {
    width: calc(100% - 32px);
    left: 16px;
    right: 16px;
    top: auto;
    bottom: 16px;
    max-height: 40vh;
    overflow-y: auto;
  }

  #title-overlay {
    top: 12px;
    left: 12px;
  }

  #title-overlay h1 {
    font-size: 1.1rem;
  }

  #legend {
    bottom: auto;
    top: 60px;
    left: 12px;
    max-width: 300px;
    font-size: 0.62rem;
    padding: 10px 14px;
    gap: 6px;
  }

  .legend-row {
    gap: 8px;
  }
}