/* ==============================================================================
   GSTec TRACK - Dashboard de Monitoreo en Tiempo Real
   Diseño: Tema Oscuro Premium / Glassmorphism / Responsive
   ============================================================================== */

:root {
  --bg-main: #0a0e14;
  --bg-surface: #111722;
  --bg-card: rgba(19, 27, 39, 0.85);
  --bg-card-hover: rgba(28, 40, 58, 0.95);
  --bg-header: rgba(14, 20, 30, 0.92);
  --bg-modal: #131c28;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(0, 230, 153, 0.25);
  --border-focus: #00e699;

  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --color-active: #00e699;       /* Verde neón / En movimiento */
  --color-active-glow: rgba(0, 230, 153, 0.35);
  --color-stopped: #38bdf8;      /* Azul cielo / Detenido encendido */
  --color-stopped-glow: rgba(56, 189, 248, 0.35);
  --color-offline: #f43f5e;      /* Rojo suave / Desconectado */
  --color-offline-glow: rgba(244, 63, 94, 0.35);
  --color-warning: #fbbf24;      /* Ámbar para alertas */

  --primary-gradient: linear-gradient(135deg, #00e699 0%, #00b4d8 100%);
  --surface-blur: blur(14px);

  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-subtle);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar estilizado */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ==============================================================================
   HEADER PRINCIPAL
   ============================================================================== */
.app-header {
  height: 64px;
  background: var(--bg-header);
  backdrop-filter: var(--surface-blur);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px var(--color-active-glow);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-title span {
  color: var(--color-active);
  font-weight: 800;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 30px;
  font-size: 0.82rem;
  font-weight: 600;
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.stat-dot.total { background: var(--text-secondary); }
.stat-dot.active { background: var(--color-active); box-shadow: 0 0 8px var(--color-active); }
.stat-dot.stopped { background: var(--color-stopped); box-shadow: 0 0 8px var(--color-stopped); }
.stat-dot.offline { background: var(--color-offline); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-active);
  background: rgba(0, 230, 153, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(0, 230, 153, 0.2);
}

.pulse-ring {
  width: 8px;
  height: 8px;
  background: var(--color-active);
  border-radius: 50%;
  position: relative;
}
.pulse-ring::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 2px solid var(--color-active);
  border-radius: 50%;
  animation: ripple 1.8s infinite cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes ripple {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.badge-counter {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--color-offline);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-header);
}

/* ==============================================================================
   CONTENEDOR PRINCIPAL
   ============================================================================== */
.main-layout {
  flex: 1;
  position: relative;
  display: flex;
  overflow: hidden;
}

/* Mapa en pantalla completa */
#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  background: #080d14;
}

/* ==============================================================================
   PANEL LATERAL (SIDEBAR FLOTANTE)
   ============================================================================== */
.sidebar {
  position: absolute;
  top: 20px;
  left: 20px;
  bottom: 20px;
  width: 380px;
  background: var(--bg-card);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-main);
  z-index: 10;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar.collapsed {
  transform: translateX(-410px);
}

.sidebar-toggle-btn {
  position: absolute;
  right: -42px;
  top: 15px;
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--border-subtle);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
}

/* Pestañas del sidebar */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 12px 0 12px;
  gap: 6px;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--color-active);
  border-bottom-color: var(--color-active);
}

/* Buscador y filtros */
.search-filter-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-bar input:focus {
  border-color: var(--color-active);
  box-shadow: 0 0 0 2px rgba(0, 230, 153, 0.15);
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chip-btn {
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chip-btn.active {
  background: rgba(0, 230, 153, 0.15);
  border-color: var(--color-active);
  color: var(--color-active);
  font-weight: 600;
}

/* Lista de vehículos */
.vehicles-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vehicle-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.vehicle-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.vehicle-card.selected {
  border-color: var(--color-active);
  background: rgba(0, 230, 153, 0.05);
  box-shadow: 0 0 0 1px var(--color-active), 0 6px 20px rgba(0, 230, 153, 0.15);
}

.vehicle-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.vehicle-name-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.vehicle-status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.vehicle-status-indicator.active {
  background: var(--color-active);
  box-shadow: 0 0 8px var(--color-active);
}
.vehicle-status-indicator.stopped {
  background: var(--color-stopped);
  box-shadow: 0 0 8px var(--color-stopped);
}
.vehicle-status-indicator.offline {
  background: var(--color-offline);
}

.vehicle-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.vehicle-status-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 6px;
}
.vehicle-status-tag.active {
  color: var(--color-active);
  background: rgba(0, 230, 153, 0.12);
}
.vehicle-status-tag.stopped {
  color: var(--color-stopped);
  background: rgba(56, 189, 248, 0.12);
}
.vehicle-status-tag.offline {
  color: var(--color-offline);
  background: rgba(244, 63, 94, 0.12);
}

.vehicle-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.telemetry-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.telemetry-item b {
  color: var(--text-primary);
}

.vehicle-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 8px;
}

.card-actions {
  display: flex;
  gap: 6px;
}

.action-chip-btn {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-chip-btn:hover {
  background: var(--color-active);
  color: #000;
  border-color: var(--color-active);
}

/* Estado de lista vacía */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ==============================================================================
   CONTROLES FLOTANTES SOBRE EL MAPA
   ============================================================================== */
.map-floating-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-control-card {
  background: var(--bg-card);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px;
  box-shadow: var(--shadow-main);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-action-btn {
  width: 38px;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.map-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-active);
}

.map-action-btn.active {
  background: var(--color-active);
  color: #000;
}

/* Pill de modo seguimiento */
.follow-pill {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--color-active);
  box-shadow: 0 4px 20px var(--color-active-glow);
  padding: 8px 18px;
  border-radius: 30px;
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 10;
}

.follow-pill.visible {
  display: flex;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.btn-stop-follow {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-stop-follow:hover {
  background: var(--color-offline);
}

/* ==============================================================================
   MARCADORES EN EL MAPA
   ============================================================================== */
.custom-vehicle-marker {
  position: relative;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: transform 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}

.leaflet-vehicle-icon-wrapper {
  background: transparent !important;
  border: none !important;
}

.marker-beacon {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.marker-beacon.active {
  background: rgba(0, 230, 153, 0.2);
  border: 2px solid var(--color-active);
  box-shadow: 0 0 16px var(--color-active);
}

.marker-beacon.stopped {
  background: rgba(56, 189, 248, 0.2);
  border: 2px solid var(--color-stopped);
  box-shadow: 0 0 16px var(--color-stopped);
}

.marker-beacon.offline {
  background: rgba(244, 63, 94, 0.2);
  border: 2px solid var(--color-offline);
}

.marker-icon-container {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  bottom: 6px;
  background: #0f172a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.3s ease;
}

.marker-arrow {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid var(--color-active);
}

/* ==============================================================================
   MODALES (AJUSTES, HISTORIAL, ALERTAS)
   ============================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-window {
  background: var(--bg-modal);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  animation: popIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}
.btn-close-modal:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select {
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--color-active);
  box-shadow: 0 0 0 2px rgba(0, 230, 153, 0.2);
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: var(--color-active);
  color: #000;
}
.btn-primary:hover {
  box-shadow: 0 0 16px var(--color-active-glow);
  transform: translateY(-1px);
}

/* Notificaciones Toast flotantes */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  color: var(--text-primary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-main);
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 280px;
}

.toast.success { border-left: 4px solid var(--color-active); }
.toast.error { border-left: 4px solid var(--color-offline); }
.toast.warning { border-left: 4px solid var(--color-warning); }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==============================================================================
   RESPONSIVE (MÓVIL Y TABLETS)
   ============================================================================== */
@media (max-width: 768px) {
  .app-header {
    padding: 0 14px;
  }
  .header-stats {
    display: none;
  }
  .sidebar {
    top: 10px;
    left: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
    max-width: 360px;
  }
}

/* Filtro elegante para modo oscuro de OpenStreetMap sin marcas de agua */
.map-tiles-dark {
  filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7) !important;
}

