/* ==========================================================================
   TFI 77A Live Bus Tracker & Dual-Key Engine - Premium Vanilla CSS
   ========================================================================== */

:root {
  /* Curated Dark-Mode Obsidian Palette */
  --bg-main: #0a0e17;
  --bg-surface: rgba(22, 29, 44, 0.75);
  --bg-surface-hover: rgba(30, 41, 62, 0.9);
  --bg-surface-card: rgba(18, 25, 38, 0.85);

  /* Dublin Bus Accent Neons */
  --accent-yellow: #ffca28;
  --accent-yellow-glow: rgba(255, 202, 40, 0.35);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.35);
  --accent-cyan: #38bdf8;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;

  /* Text & Border Tokens */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(255, 202, 40, 0.25);

  /* Typography */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Shadows */
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  --shadow-neon: 0 0 20px rgba(255, 202, 40, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 10% 20%, rgba(255, 202, 40, 0.05) 0px, transparent 50%),
    radial-gradient(at 90% 80%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glass);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.route-badge {
  background: linear-gradient(135deg, var(--accent-yellow), #f59e0b);
  color: #090d16;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 10px;
  box-shadow: 0 0 15px var(--accent-yellow-glow);
  letter-spacing: 0.5px;
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.nav-telemetry {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.telemetry-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.telemetry-label {
  color: var(--text-muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.75rem;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

.mono-timer {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.1);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-refresh:hover:not(:disabled) {
  background: rgba(255, 202, 40, 0.15);
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
  transform: translateY(-1px);
}

.btn-refresh:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-refresh .refresh-icon {
  transition: transform 0.4s ease;
}

.btn-refresh.spinning .refresh-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Hero Visual Banner Section
   ========================================================================== */
.hero-banner {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border-glass);
  background: var(--bg-surface);
  min-height: 280px;
  display: flex;
  align-items: center;
  padding: 2.5rem 2rem;
}

.banner-image-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.banner-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.28;
  filter: saturate(1.2) contrast(1.1);
}

.banner-gradient-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(10, 14, 23, 0.95) 0%,
    rgba(10, 14, 23, 0.75) 55%,
    rgba(10, 14, 23, 0.95) 100%
  );
}

.banner-content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3rem;
  flex-wrap: wrap;
}

.banner-route-header {
  flex: 1;
  min-width: 320px;
}

.tag-live {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: #090d16;
  background: var(--accent-yellow);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  letter-spacing: 1px;
  margin-bottom: 0.75rem;
}

.banner-route-header h2 {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 0.75rem;
}

.accent-text {
  color: var(--accent-yellow);
  text-shadow: 0 0 15px var(--accent-yellow-glow);
}

.banner-description {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 600px;
  line-height: 1.6;
}

.btn-hero-alert {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.25), rgba(220, 38, 38, 0.15));
  border: 1px solid rgba(239, 68, 68, 0.6);
  color: #f8fafc;
  padding: 0.65rem 1.25rem;
  border-radius: 99px;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.25);
}

.btn-hero-alert:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.4), rgba(220, 38, 38, 0.3));
  border-color: #ef4444;
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.4);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  min-width: 380px;
  width: 100%;
}

.stat-card {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  padding: 1rem 1.25rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
}

.stat-card:hover {
  border-color: rgba(255, 202, 40, 0.3);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-value.text-emerald {
  color: var(--accent-emerald);
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* ==========================================================================
   Dual-Key Rate-Limit Monitor Section
   ========================================================================== */
.key-monitor-section {
  max-width: 1400px;
  width: 100%;
  margin: 1.5rem auto 0;
  padding: 0 2rem;
}

.monitor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.monitor-title-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.monitor-title-group h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
}

.info-tooltip {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: help;
  border-bottom: 1px dotted var(--text-dim);
}

.pool-status-text {
  font-size: 0.8rem;
  color: var(--accent-emerald);
  font-weight: 600;
}

.keys-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.key-card {
  background: var(--bg-surface-card);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.key-card.key-active-cooldown {
  border-color: rgba(245, 158, 11, 0.4);
}

.key-card.key-ready {
  border-color: rgba(16, 185, 129, 0.4);
}

.key-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.key-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.key-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
}

.key-indicator.cooldown {
  background-color: var(--accent-amber);
}

.key-mask {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.key-status-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.key-status-badge.cooldown {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--accent-cyan));
  border-radius: 999px;
  transition: width 1s linear, background-color 0.3s ease;
}

.progress-bar-fill.cooldown {
  background: linear-gradient(90deg, var(--accent-amber), var(--accent-yellow));
}

.key-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Main Workspace (Map & Fleet List)
   ========================================================================== */
.main-workspace {
  max-width: 1400px;
  width: 100%;
  margin: 1.5rem auto 2.5rem;
  padding: 0 2rem;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.5rem;
}

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar-title h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
}

.toolbar-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.filter-group {
  display: flex;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  padding: 0.2rem;
  gap: 0.2rem;
}

.filter-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  color: var(--text-main);
}

.filter-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent-yellow);
}

.btn-icon {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 202, 40, 0.15);
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

/* Map Element */
.map-section {
  background: var(--bg-surface-card);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.map-container-wrapper {
  position: relative;
  flex: 1;
  min-height: 520px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.map-element {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.map-legend {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-outbound {
  background-color: var(--accent-yellow);
  box-shadow: 0 0 6px var(--accent-yellow);
}

.dot-inbound {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 6px var(--accent-emerald);
}

/* Custom Bus Leaflet Markers */
.custom-bus-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-badge {
  background: #0f172a;
  color: var(--text-main);
  border: 2px solid var(--accent-yellow);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.75rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: transform 0.2s ease;
}

.marker-badge:hover {
  transform: scale(1.1);
  z-index: 1000;
}

.marker-badge.inbound {
  border-color: var(--accent-emerald);
}

/* Fleet List Section */
.fleet-section {
  background: var(--bg-surface-card);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.toolbar-search {
  flex: 1;
  max-width: 220px;
}

.search-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.8rem;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-input:focus {
  border-color: var(--accent-yellow);
}

.fleet-list-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 540px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

/* Scrollbar styling */
.fleet-list-container::-webkit-scrollbar {
  width: 6px;
}
.fleet-list-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}
.fleet-list-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Bus Card */
.bus-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 1rem;
  transition: all 0.2s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bus-card:hover {
  border-color: rgba(255, 202, 40, 0.35);
  transform: translateX(4px);
  background: var(--bg-surface-hover);
}

.bus-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bus-number-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bus-id-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  background: rgba(255, 202, 40, 0.15);
  color: var(--accent-yellow);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 202, 40, 0.3);
}

.bus-id-badge.inbound {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border-color: rgba(16, 185, 129, 0.3);
}

.bus-trip-id {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.delay-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.delay-badge.late {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.delay-badge.ontime {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.bus-card-mid {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.direction-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.direction-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.bus-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.btn-locate {
  background: transparent;
  border: none;
  color: var(--accent-yellow);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: transform 0.2s ease;
}

.btn-locate:hover {
  transform: translateX(2px);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  gap: 1rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-yellow);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Footer */
.app-footer {
  background: rgba(10, 14, 23, 0.95);
  border-top: 1px solid var(--border-glass);
  padding: 1.5rem 2rem;
  margin-top: auto;
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-legal {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.status-badge-footer {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.75rem;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1024px) {
  .main-workspace {
    grid-template-columns: 1fr;
  }
  .banner-content {
    flex-direction: column;
    align-items: flex-start;
  }
  .stats-grid {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .keys-grid {
    grid-template-columns: 1fr;
  }
  .top-nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
