/*
 * styles.css — Bus Urbano Chipiona
 * Versión 2: modo claro por defecto, sin saltos en lista,
 * banner fuera de servicio, panel parada más cercana.
 */

/* ═══════════════════════════════════════════
   1. VARIABLES
   ═══════════════════════════════════════════ */
:root {
  --color-primary:       #002d72;
  --color-primary-light: #0044a7;
  --color-primary-dark:  #001a45;
  --color-accent:        #FFD700;
  --color-accent-dark:   #e6a800;

  --color-bg:            #f4f6fb;
  --color-surface:       #ffffff;
  --color-border:        #e2e8f0;
  --color-text:          #1a2340;
  --color-text-muted:    #64748b;
  --color-text-light:    #94a3b8;

  --color-success:  #22c55e;
  --color-warning:  #f59e0b;
  --color-error:    #ef4444;
  --color-info:     #3b82f6;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.12);

  --font-main:    'Inter', sans-serif;
  --font-display: 'Poppins', sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  --transition:      0.25s ease;
  --transition-slow: 0.4s ease;
  --map-height:      640px;
}

/* ═══════════════════════════════════════════
   2. RESET
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html  { scroll-behavior: smooth; }
body  { font-family: var(--font-main); background: var(--color-bg); color: var(--color-text); line-height: 1.6; min-height: 100vh; transition: background var(--transition), color var(--transition); }
a     { color: inherit; text-decoration: none; }
button{ cursor: pointer; border: none; background: none; font: inherit; }
img   { max-width: 100%; display: block; }

/* ═══════════════════════════════════════════
   3. LAYOUT
   ═══════════════════════════════════════════ */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

.main-content {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
  gap: var(--space-md);
  padding: var(--space-md);
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ═══════════════════════════════════════════
   4. HEADER
   ═══════════════════════════════════════════ */
.app-header {
  background: #ffffff;
  color: var(--color-text);
  padding: var(--space-sm) var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: background var(--transition), border-color var(--transition);
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand { display: flex; align-items: center; gap: var(--space-md); }
.header-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}
.header-controls { display: flex; align-items: center; gap: var(--space-md); }
.header-updated {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.line-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.line-selector::-webkit-scrollbar {
  display: none;
}
@media (min-width: 769px) {
  .line-selector {
    justify-content: center;
    overflow-x: visible;
  }
}

.line-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 6px 12px;
  border-radius: 100px;
  border: 1.5px solid transparent;
  font-family: var(--font-main);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition);
}

.line-badge--active {
  background: rgba(0,45,114,0.08);
  color: var(--color-primary);
  border-color: rgba(0,45,114,0.2);
}
.line-badge--active i { font-size: 0.6rem; }

.line-badge--link {
  background: var(--color-bg);
  color: var(--color-text-muted);
  border-color: var(--color-border);
  cursor: pointer;
}
.line-badge--link:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* ═══════════════════════════════════════════
   6. BANNER FUERA DE SERVICIO
   ═══════════════════════════════════════════ */
.out-of-service-banner {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  background: #fff3cd;
  border-bottom: 2px solid #e6a800;
  color: #7a5000;
  font-size: 0.9rem;
}
.out-of-service-banner i { font-size: 1.4rem; color: #e6a800; flex-shrink: 0; }
.out-of-service-banner strong { display: block; font-weight: 700; margin-bottom: 2px; }

/* ═══════════════════════════════════════════
   7. MAPA
   ═══════════════════════════════════════════ */
.map-section { grid-column: 2; grid-row: 1 / 3; display: flex; flex-direction: column; gap: var(--space-sm); }
.map-container { position: relative; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--color-border); }
#map { height: var(--map-height); width: 100%; z-index: 1; }

.stop-popup strong { display: block; color: var(--color-primary); margin-bottom: 2px; font-size: 0.88rem; }
.stop-id { font-size: 0.75rem; color: var(--color-text-light); }
.bus-marker { transition: transform 0.5s ease; filter: drop-shadow(0 3px 6px rgba(0,0,45,0.35)); }

/* ═══════════════════════════════════════════
   8. BOTONES DE CONTROL DEL MAPA
   ═══════════════════════════════════════════ */
.map-controls { display: flex; gap: var(--space-sm); justify-content: flex-end; }
.map-btn {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-sm) var(--space-md);
  display: flex; align-items: center; gap: var(--space-xs);
  font-size: 0.82rem; font-weight: 500; color: var(--color-text);
  box-shadow: var(--shadow-sm); transition: all var(--transition);
}
.map-btn:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.map-btn.btn--active { background: var(--color-primary); color: var(--color-accent); border-color: var(--color-primary); }

.btn-icon {
  width: 38px; height: 38px; border-radius: var(--radius-md);
  background: var(--color-bg); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--color-border); }

/* ═══════════════════════════════════════════
   9. PANEL LATERAL
   ═══════════════════════════════════════════ */
.info-panel { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; gap: var(--space-md); }

.info-card {
  background: var(--color-surface); border-radius: var(--radius-lg);
  padding: var(--space-lg); box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  transition: background var(--transition), border-color var(--transition);
  animation: fadeIn 0.4s ease both;
}
.info-card__title {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--color-text-muted);
  margin-bottom: var(--space-md); display: flex; align-items: center; gap: var(--space-xs);
}
.info-card__title i { color: var(--color-primary); }

.status-badge {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md); border-radius: 100px;
  font-size: 0.85rem; font-weight: 600; transition: all var(--transition);
}
.status-badge.moving   { background: rgba(34,197,94,0.12); color: #16a34a; }
.status-badge.stopped  { background: rgba(239,68,68,0.12); color: #dc2626; }
.status-badge.incident {
  background: rgba(245,158,11,0.15); color: #b45309;
  animation: pulse-incident 2s infinite;
}
@keyframes pulse-incident {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.3); }
  50%      { box-shadow: 0 0 0 5px rgba(245,158,11,0.12); }
}

/* Badge de estado en el header — más compacto */
.status-badge.header-status {
  font-size: 0.72rem;
  padding: 4px 10px;
  border: 1px solid transparent;
}
.status-badge.header-status.moving  { border-color: rgba(34,197,94,0.3); }
.status-badge.header-status.stopped { border-color: rgba(239,68,68,0.3); }
.status-badge.header-status.incident{ border-color: rgba(245,158,11,0.3); }

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric__label { font-size: 0.72rem; color: var(--color-text-muted); font-weight: 500; }
.metric__value { font-size: 1.05rem; font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums; }

/* Próxima parada — fondo azul */
.next-stop-card { background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%); color: #fff; border: none; }
.next-stop-card .info-card__title { color: rgba(255,255,255,0.7); }
.next-stop-card .info-card__title i { color: var(--color-accent); }
.next-stop-name  { font-size: 1rem; font-weight: 700; margin-bottom: var(--space-xs); }
.next-stop-eta   { font-size: 1.8rem; font-weight: 800; color: var(--color-accent); font-variant-numeric: tabular-nums; line-height: 1; }
.next-stop-label { font-size: 0.72rem; opacity: 0.7; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.next-stop-label i { font-size: 0.68rem; }

/* Parada más cercana — fondo verde suave */
.nearest-stop-card {
  background: linear-gradient(135deg, #065f46 0%, #059669 100%);
  color: #fff; border: none;
}
.nearest-stop-card .info-card__title { color: rgba(255,255,255,0.75); }
.nearest-stop-card .info-card__title i { color: #6ee7b7; }
.nearest-stop-card .next-stop-eta { color: #6ee7b7; }

/* ═══════════════════════════════════════════
   10. LISTA DE PARADAS
   ═══════════════════════════════════════════ */
.stops-section { grid-column: 1 / -1; margin-top: var(--space-sm); }
.stops-section__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-md); }
.stops-section__title { font-family: var(--font-display); font-size: 1rem; font-weight: 700; color: var(--color-primary); display: flex; align-items: center; gap: var(--space-sm); }

.stops-list { display: flex; flex-direction: column; gap: var(--space-sm); }

.stop-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: var(--space-md);
  box-shadow: var(--shadow-sm);
  /* Sin animación en la tarjeta */
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.stop-card:hover { border-color: var(--color-primary-light); box-shadow: var(--shadow-md); transform: translateX(2px); }

.stop-card--next {
  border-color: var(--color-accent-dark);
  background: rgba(255,215,0,0.06);
  box-shadow: 0 0 0 2px rgba(255,215,0,0.3), var(--shadow-md);
}

.stop-card__number {
  width:32px; height:32px; border-radius:50%;
  background: var(--color-bg); border: 2px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--color-text-muted); flex-shrink: 0;
}
.stop-card--next .stop-card__number { background: var(--color-accent); border-color: var(--color-accent-dark); color: #1a1a00; }

.stop-card__info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stop-card__name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stop-card__eta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.stop-card__eta-time { font-size: 1rem; font-weight: 800; color: var(--color-primary); font-variant-numeric: tabular-nums; }
.stop-card--next .stop-card__eta-time { color: var(--color-accent-dark); }
.stop-card__status { font-size: 0.7rem; font-weight: 500; white-space: nowrap; }

.status-at-stop    { color: var(--color-primary); }
.status-next       { color: var(--color-success);  }
.status-approaching{ color: var(--color-warning);  }
.status-pending    { color: var(--color-text-muted);}
.status-stopped    { color: var(--color-error);    }
.status-traffic    { color: var(--color-warning);  }
.status-incident   { color: #b45309; font-weight: 700; }

/* ═══════════════════════════════════════════
   11. LOADER
   ═══════════════════════════════════════════ */
#loader {
  position: fixed; inset: 0; background: var(--color-primary-dark);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; gap: var(--space-lg);
}
.loader-bus  { font-size: 4rem; animation: loader-bounce 1s ease-in-out infinite; }
.loader-text { color: rgba(255,255,255,0.85); font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.loader-dots::after { content: ''; animation: loader-dots 1.5s infinite; }
@keyframes loader-dots  { 0%{content:''} 33%{content:'.'} 66%{content:'..'} 100%{content:'...'} }
@keyframes loader-bounce{ 0%,100%{transform:translateY(0)} 50%{transform:translateY(-12px)} }

/* ═══════════════════════════════════════════
   12. TOASTS
   ═══════════════════════════════════════════ */
#toast-container {
  position: fixed; bottom: var(--space-xl); right: var(--space-xl);
  display: flex; flex-direction: column; gap: var(--space-sm);
  z-index: 9000; pointer-events: none;
}
.toast {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-sm) var(--space-md);
  display: flex; align-items: center; gap: var(--space-sm);
  font-size: 0.85rem; box-shadow: var(--shadow-lg);
  transform: translateX(120%); transition: transform var(--transition-slow);
  pointer-events: all; max-width: 340px;
}
.toast--visible  { transform: translateX(0); }
.toast--error    { border-left: 3px solid var(--color-error);   }
.toast--success  { border-left: 3px solid var(--color-success); }
.toast--info     { border-left: 3px solid var(--color-info);    }
.toast__icon     { font-size: 1rem; flex-shrink: 0; }

/* ═══════════════════════════════════════════
   13. MODO OSCURO
   ═══════════════════════════════════════════ */
.dark-mode {
  --color-bg:         #0d1117;
  --color-surface:    #161b22;
  --color-border:     #30363d;
  --color-text:       #e6edf3;
  --color-text-muted: #8b949e;
  --color-text-light: #484f58;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}
.dark-mode .stop-card--next { background: rgba(255,215,0,0.08); }
.dark-mode .leaflet-popup-content-wrapper { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.dark-mode .out-of-service-banner { background: #2d2000; border-color: #7a5000; color: #fde68a; }
.dark-mode .app-header { background: var(--color-surface); }

/* ═══════════════════════════════════════════
   14. RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 1024px) {
  .main-content { grid-template-columns: 1fr; }
  .info-panel   { grid-column: 1; grid-row: auto; }
  .map-section  { grid-column: 1; grid-row: auto; }
  .stops-section{ grid-column: 1; }
}
@media (max-width: 768px) {
  :root {
    --map-height: 80vh;
    --map-height: 80dvh;
  }
  .app-header  { padding: var(--space-sm) var(--space-md); }
  .header-logo { height: 38px; }
  .main-content    { padding: var(--space-sm); gap: var(--space-sm); }
  .out-of-service-banner { padding: var(--space-md); }
  #toast-container { bottom: var(--space-md); right: var(--space-md); left: var(--space-md); }
  .toast { max-width: 100%; }
}
@media (max-width: 480px) {
  .header-updated { display: none; }
  .next-stop-eta  { font-size: 1.4rem; }
}

/* ═══════════════════════════════════════════
   15. ANIMACIONES
   ═══════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.info-card { animation: fadeIn 0.4s ease both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}



/* Tarjeta de estado compacta (sin métricas) */
.info-card--compact {
  padding: var(--space-md) var(--space-lg);
}

/* ═══════════════════════════════════════════
   16. POPUP DE LÍNEA (imagen del recorrido)
   ═══════════════════════════════════════════ */
.line-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.line-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.line-modal__content {
  position: relative;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.25s ease both;
  display: flex;
  flex-direction: column;
}

.line-modal__content img {
  width: 100%;
  height: auto;
  max-height: 90vh;
  object-fit: contain;
  display: block;
}

.line-modal__close {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  z-index: 1;
  transition: background var(--transition);
}
.line-modal__close:hover {
  background: rgba(0,0,0,0.75);
}

.line-modal__banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 100px;
  background: rgba(0,45,114,0.88);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
.line-modal__banner i {
  color: var(--color-accent);
  font-size: 0.9rem;
}

@media (max-width: 480px) {
  .line-badge {
    font-size: 0.66rem;
    padding: 5px 10px;
  }
}
