html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #0b0f19;
}

/* Fullscreen Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #090d16;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.55s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.55s ease, transform 0.55s ease;
  opacity: 1;
  visibility: visible;
}

.loading-overlay.loaded {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(1.02);
}

.loader-card {
  background: rgba(18, 24, 38, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #f1f5f9;
}

.loader-icon-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  color: #60a5fa;
}

.loader-train-icon {
  width: 32px;
  height: 32px;
  z-index: 2;
  animation: trainBob 2s ease-in-out infinite;
}

.loader-pulse-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(96, 165, 250, 0.4);
  animation: pulseRing 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulseRing {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 0.2; }
  100% { transform: scale(1.3); opacity: 0; }
}

@keyframes trainBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.loader-title {
  margin: 0 0 6px 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #f8fafc;
}

.loader-subtitle {
  margin: 0 0 22px 0;
  font-size: 12.5px;
  color: #94a3b8;
  line-height: 1.45;
}

.loader-progress-wrap {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}

.loader-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa, #93c5fd);
  border-radius: 999px;
  transition: width 0.12s ease-out;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}

.loader-stats {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  font-variant-numeric: tabular-nums;
}

#loaderCountText {
  color: #cbd5e1;
}

#loaderPctText {
  color: #60a5fa;
  font-weight: 700;
}

#map {
  position: absolute;
  inset: 0;
}

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  background: rgba(20, 20, 25, 0.9);
  color: #f2f2f2;
  padding: 14px 16px;
  border-radius: 10px;
  width: 300px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  transition: width 0.18s ease, padding 0.18s ease;
}

#panel.collapsed {
  width: auto;
  max-height: none;
  overflow: visible;
  padding: 8px 10px;
}

#panel.collapsed > *:not(.panel-header) {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

#panel.collapsed .panel-header {
  margin-bottom: 0;
}

#panel h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
}

#panelToggle {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid #555;
  background: #2a2a30;
  color: #ddd;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
}

#panel.collapsed #panelToggle {
  transform: rotate(180deg);
}

.loading-status {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: #9ad;
  margin-top: 2px;
}

.ka-row-more {
  font-size: 11px;
  color: #888;
  font-style: italic;
  padding: 4px 0;
}

.clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 10px 0;
}

.clock {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#liveBtn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #333;
  color: #999;
  border: 1px solid #555;
  border-radius: 14px;
  padding: 5px 10px 5px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}

#liveBtn .live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #555;
}

#liveBtn.active {
  background: #7a1414;
  color: #fff;
  border-color: #b91c1c;
}

#liveBtn.active .live-dot {
  background: #ff4d4d;
  animation: live-pulse 1.4s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

#playBtn,
#dirBtn {
  background: #3b82f6;
  border: none;
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}

#dirBtn {
  background: #555;
}

#speedSel {
  background: #333;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  font-size: 12px;
  padding: 3px 4px;
}

#slider {
  flex: 1;
}

#legend {
  font-size: 11px;
  color: #999;
  margin-top: 10px;
  border-top: 1px solid #3a3a3a;
  padding-top: 8px;
}

.maplibregl-popup-content {
  background: #1c1c22;
  color: #f2f2f2;
  font-size: 12px;
  border-radius: 6px;
}

/* --- Card bawah: detail KA saat diklik --- */
#trainCard {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  max-width: 640px;
  margin: 0 auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

#trainCard.visible {
  display: flex;
}

.tc-badge {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #1e3a8a;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tc-main {
  flex: 1;
  min-width: 0;
}

.tc-name {
  font-weight: 700;
  font-size: 14px;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-route {
  font-size: 11px;
  color: #666;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-status {
  font-size: 12px;
  color: #16a34a;
  margin-top: 2px;
}

.tc-status b { color: #111; }

.tc-progress-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.tc-progress-track {
  flex: 1;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.tc-progress-bar {
  height: 100%;
  background: #16a34a;
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s linear;
}

.tc-progress-pct {
  font-size: 11px;
  color: #888;
  width: 32px;
  text-align: right;
}

.tc-sub {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  display: flex;
  gap: 10px;
}

.tc-right {
  flex-shrink: 0;
  text-align: right;
}

.tc-clock {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #111;
}

.tc-btns {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.tc-btns button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #ddd;
  background: #fafafa;
  cursor: pointer;
  font-size: 13px;
  color: #555;
}

/* --- Responsive Mobile Optimization --- */
@media (max-width: 640px) {
  #panel {
    top: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    padding: 10px 12px;
  }

  #panel.collapsed {
    left: 8px;
    right: auto;
    width: auto;
  }

  .clock {
    font-size: 22px;
  }

  #controls {
    gap: 6px;
  }

  #playBtn,
  #dirBtn {
    width: 36px;
    height: 36px;
  }

  #trainCard {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 10px 12px;
    gap: 8px;
  }

  .tc-badge {
    width: 34px;
    height: 34px;
    font-size: 11px;
  }

  .tc-name {
    font-size: 13px;
  }

  .tc-clock {
    font-size: 13px;
  }

  .tc-btns button {
    width: 32px;
    height: 32px;
  }
}

button, input[type="range"], select {
  touch-action: manipulation;
}

