/* =============================================
   GPS FLEET TRACKER - Modern UI
   ============================================= */

:root {
  --bg-dark: #0b1120;
  --bg-sidebar: #111827;
  --bg-card: #1e2d45;
  --bg-card-hover: #263650;
  --border: #2a3f5f;
  --text-primary: #f0f4ff;
  --text-secondary: #8ca0c0;
  --text-muted: #5a7294;
  --accent: #3b82f6;
  --accent-glow: rgba(59,130,246,0.25);
  --moving: #22c55e;
  --moving-bg: rgba(34,197,94,0.15);
  --stopped: #f97316;
  --stopped-bg: rgba(249,115,22,0.15);
  --offline: #64748b;
  --offline-bg: rgba(100,116,139,0.15);
  --bg-input: #162032;
  --sidebar-width: 340px;
  --topbar-h: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.25s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* =============================================
   LOGIN PAGE
   ============================================= */
.login-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 30%, #1a3a6b 0%, #0b1120 60%);
}

.login-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow), 0 0 80px rgba(59,130,246,0.1);
  animation: fadeUp 0.5s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo img {
  max-width: 160px;
  max-height: 70px;
  object-fit: contain;
}

.login-logo .brand-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 12px;
  letter-spacing: -0.3px;
}

.login-logo .brand-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.login-field {
  position: relative;
  margin-bottom: 16px;
}

.login-field i {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
}

.login-field input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  padding: 14px 16px 14px 44px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.login-field input::placeholder { color: var(--text-muted); }

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-btn {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  cursor: pointer;
  margin-top: 8px;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.login-btn:hover {
  background: #2563eb;
  box-shadow: 0 4px 20px rgba(59,130,246,0.4);
  transform: translateY(-1px);
}

.login-btn:active { transform: translateY(0); }

.login-error {
  color: #f87171;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  margin-top: 16px;
  text-align: center;
}

.login-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 28px;
}

/* =============================================
   MAIN LAYOUT
   ============================================= */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.topbar-brand img {
  height: 32px;
  object-fit: contain;
}

.topbar-brand .brand-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.topbar-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: transform var(--transition);
  cursor: default;
}

.stat-chip:hover { transform: scale(1.05); }

.stat-chip.total    { background: rgba(59,130,246,0.15);  border-color: rgba(59,130,246,0.3);  color: #93c5fd; }
.stat-chip.moving   { background: var(--moving-bg);        border-color: rgba(34,197,94,0.3);   color: #86efac; }
.stat-chip.stopped  { background: var(--stopped-bg);       border-color: rgba(249,115,22,0.3);  color: #fdba74; }
.stat-chip.offline  { background: var(--offline-bg);       border-color: rgba(100,116,139,0.3); color: #94a3b8; }

.stat-chip .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-chip.total .dot    { background: #3b82f6; }
.stat-chip.moving .dot   { background: var(--moving); animation: pulse-dot 1.5s infinite; }
.stat-chip.stopped .dot  { background: var(--stopped); }
.stat-chip.offline .dot  { background: var(--offline); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

.topbar-logout {
  flex-shrink: 0;
  margin-left: 8px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-user i { color: var(--accent); font-size: 18px; flex-shrink: 0; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  text-decoration: none;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.icon-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---- BODY AREA ---- */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto auto 1fr;
  flex-shrink: 0;
  min-height: 0;
  overflow: hidden;
  transition: transform var(--transition), width var(--transition);
  z-index: 50;
}

/* Desktop: colapsar sidebar ocultando su ancho */
.sidebar.collapsed {
  width: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar-search {
  padding: 12px 12px 0;
  flex-shrink: 0;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px 9px 36px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input-wrap input::placeholder { color: var(--text-muted); }
.search-input-wrap input:focus { border-color: var(--accent); }

.sidebar-controls {
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-toggle {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all var(--transition);
  white-space: nowrap;
}

.ctrl-toggle i { font-size: 13px; }
.ctrl-toggle:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.ctrl-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.vehicle-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px;
  min-height: 0;
}

.vehicle-list .vehicle-card {
  margin-bottom: 8px;
}

/* ---- VEHICLE CARD ---- */
.vehicle-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}
.vehicle-card:hover  { background: var(--bg-card-hover); border-color: var(--accent); }
.vehicle-card.active-card { border-color: var(--accent); background: rgba(59,130,246,0.08); }

/* ---- CARD COMPACT ROW ---- */
.card-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  min-height: 0;
}

.card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 5px currentColor;
}

.card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.card-plate {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.card-speed-sm {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
  min-width: 52px;
}
.card-speed-sm small {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}

.card-time-sm {
  font-size: 11px;
  color: #ffffff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 12px;
  touch-action: manipulation;
  transition: all var(--transition);
}
.card-icon-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- CARD ROWS ---- */
.card-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 6px;
}

.plate-badge {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  white-space: nowrap;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.status-badge.moving  { background: var(--moving-bg);  color: #86efac; }
.status-badge.stopped { background: var(--stopped-bg); color: #fdba74; }
.status-badge.offline { background: var(--offline-bg); color: #94a3b8; }

.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-badge.moving .dot  { background: var(--moving); animation: pulse-dot 1.5s infinite; }
.status-badge.stopped .dot { background: var(--stopped); }
.status-badge.offline .dot { background: var(--offline); }

/* fila velocidad + dirección + hora */
.card-row-mid {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
}

.card-speed {
  display: flex;
  align-items: baseline;
  gap: 2px;
  min-width: 52px;
}

.speed-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}

.speed-unit {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.card-dir {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.dir-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-time {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
}

.card-time span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-divider {
  flex: 1;
  height: 1px;
  background: var(--border);
  display: none;
}

.card-address {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  line-height: 1.4;
}

.card-address i {
  color: var(--accent);
  font-size: 11px;
  margin-top: 1px;
  flex-shrink: 0;
}

.card-time {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-time i { font-size: 11px; }

.card-actions {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.card-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 6px;
  min-height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.card-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--accent); }
.card-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.card-btn.primary:hover { background: #2563eb; }

/* ---- MAP AREA ---- */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* Map overlay buttons */
.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1000;
}

.map-btn {
  width: 40px; height: 40px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all var(--transition);
  text-decoration: none;
}

.map-btn:hover  { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--accent); }
.map-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Refresh timer */
.refresh-indicator {
  position: absolute;
  bottom: 30px;
  right: 12px;
  z-index: 1000;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 7px;
  box-shadow: var(--shadow);
}

.refresh-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--moving);
  animation: pulse-dot 1.5s infinite;
}

/* Leaflet custom popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-sidebar) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  color: var(--text-primary) !important;
}

.leaflet-popup-tip { background: var(--bg-sidebar) !important; }

.popup-content { min-width: 200px; }

.popup-plate {
  font-size: 16px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.popup-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.popup-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.popup-row i { color: var(--accent); font-size: 12px; width: 14px; }
.popup-row b { color: var(--text-primary); }

.popup-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
}

/* ---- MOBILE OVERLAY SIDEBAR ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  backdrop-filter: blur(2px);
}

/* ---- MOBILE BOTTOM DRAWER ---- */
.mobile-drawer {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  z-index: 500;
  max-height: 65vh;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  transform: translateY(calc(100% - 56px));
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
}

.mobile-drawer.open { transform: translateY(0); }

.drawer-handle {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  cursor: pointer;
  user-select: none;
}

.drawer-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 10px;
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
}

.drawer-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-mini-stats {
  display: flex;
  gap: 6px;
}

.mini-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
}

.mini-chip.total   { background: rgba(99,102,241,.2); color: #a5b4fc; }
.mini-chip.moving  { background: var(--moving-bg);  color: #86efac; }
.mini-chip.stopped { background: var(--stopped-bg); color: #fdba74; }
.mini-chip.offline { background: var(--offline-bg); color: #94a3b8; }

.drawer-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 16px;
}

.drawer-content .vehicle-card {
  margin-bottom: 8px;
}

/* Mobile toggle sidebar btn */
.mobile-menu-btn {
  display: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 32px;
  margin-bottom: 12px;
  display: block;
  color: var(--border);
}

.empty-state p { font-size: 13px; }

/* ---- LOADING OVERLAY ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11,17,32,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.loading-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* =============================================
   ROUTE HISTORY MODAL
   ============================================= */
.route-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  backdrop-filter: blur(2px);
}
.route-modal-overlay.visible { display: block; }

.route-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 2001;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  width: min(420px, 94vw);
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  pointer-events: none;
}
.route-modal.visible {
  display: flex;
  flex-direction: column;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: all;
}

.route-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.route-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.route-modal-title i { color: var(--accent); font-size: 16px; }

.route-modal-body { padding: 16px; }

.route-date-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.route-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.route-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.route-field input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
  touch-action: manipulation;
  color-scheme: dark;
}
.route-field input:focus { border-color: var(--accent); }

.route-submit-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
  transition: background var(--transition);
}
.route-submit-btn:hover { background: #2563eb; }
.route-submit-btn:disabled { background: var(--border); cursor: not-allowed; }

.route-stats {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.route-stat {
  flex: 1;
  min-width: 80px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.route-stat i { color: var(--accent); font-size: 14px; }
.route-stat span { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.route-stat small { font-size: 10px; color: var(--text-muted); }

.route-msg {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  min-height: 20px;
}
.route-msg.error { color: #f87171; }

/* ---- LEAFLET CUSTOM MARKERS ---- */
.custom-marker,
.leaflet-marker-icon.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible !important;
  background: none !important;
  border: none !important;
}
.custom-marker svg {
  overflow: visible;
  display: block;
}

/* ---- MARKER ANIMATIONS ---- */
.marker-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pulso de actualización al recibir nueva posición */
@keyframes markerUpdatePulse {
  0%   { filter: drop-shadow(0 0 0px rgba(99,102,241,0)); transform: scale(1); }
  30%  { filter: drop-shadow(0 0 8px rgba(99,102,241,0.9)); transform: scale(1.25); }
  100% { filter: drop-shadow(0 0 0px rgba(99,102,241,0)); transform: scale(1); }
}
.marker-update-pulse {
  animation: markerUpdatePulse 0.8s ease-out forwards;
}

/* Etiqueta de placa sobre el marcador */
.marker-label {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 17, 32, 0.88);
  color: #f0f4ff;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 5px;
}

.marker-label-speed {
  font-size: 11px;
  font-weight: 600;
  color: #f0f4ff;
  display: flex;
  align-items: baseline;
  gap: 1px;
}
.marker-label-speed small {
  font-size: 9px;
  font-weight: 400;
  opacity: 0.75;
}

/* Anillo que se expande y desvanece */
.marker-ping {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  pointer-events: none;
}
.marker-ping.green {
  background: rgba(34, 197, 94, 0.45);
  animation: ping-green 1.8s ease-out infinite;
}
.marker-ping.red {
  background: rgba(239, 68, 68, 0.45);
  animation: ping-red 2.4s ease-out infinite;
}

/* Flecha que pulsa suavemente */
.marker-arrow-svg {
  animation: arrow-pulse 2s ease-in-out infinite;
}

@keyframes ping-green {
  0%   { transform: scale(0.85); opacity: 0.8; }
  100% { transform: scale(2.4);  opacity: 0; }
}
@keyframes ping-red {
  0%   { transform: scale(0.85); opacity: 0.7; }
  60%  { transform: scale(2.0);  opacity: 0.3; }
  100% { transform: scale(2.0);  opacity: 0; }
}
@keyframes arrow-pulse {
  0%   { filter: drop-shadow(0 0 3px rgba(34,197,94,0.6)); }
  50%  { filter: drop-shadow(0 0 9px rgba(34,197,94,1));   }
  100% { filter: drop-shadow(0 0 3px rgba(34,197,94,0.6)); }
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes pulse-dot {
  0%   { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70%  { opacity: 0.85; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

/* =============================================
   RESPONSIVE — MOBILE FIRST
   Breakpoints:
     móvil   < 640px
     tablet  640px – 1024px
     laptop  1024px – 1280px
     desktop > 1280px
   ============================================= */

/* ---- LAPTOP (< 1280px) ---- */
@media (max-width: 1280px) {
  :root { --sidebar-width: 300px; }
}

/* ---- TABLET + LAPTOP: sidebar pasa a overlay (< 1024px) ---- */
@media (max-width: 1024px) {
  :root { --sidebar-width: 300px; }

  /* El app-body no recorta el sidebar fijo */
  .app-body { overflow: visible; }

  /* Stats en topbar: ocultar en tablet */
  .topbar-stats { display: none; }

  /* Sidebar como panel deslizante */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 300;
    width: 72vw;
    max-width: 320px;
    transform: translateX(-100%);
    padding-top: var(--topbar-h);
    display: grid;
    grid-template-rows: auto auto 1fr;
    overflow: hidden;
    transition: transform 0.3s ease;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,0.6);
  }

  .sidebar .vehicle-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 16px;
  }

  .sidebar-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar-overlay.visible { opacity: 1; pointer-events: all; }

  .mobile-menu-btn { display: flex; }
  .mobile-drawer   { display: flex; }

  /* Leaflet controles por encima del drawer */
  .leaflet-control-zoom { z-index: 400 !important; }
  .map-controls { top: 8px; right: 8px; z-index: 400; }
  .mobile-drawer { z-index: 500; }

  /* Touch targets */
  .vehicle-card  { touch-action: manipulation; }
  .card-icon-btn { touch-action: manipulation; min-height: 36px; min-width: 36px; }

  /* Sidebar controls más compactos */
  .sidebar-controls { padding: 8px 10px; gap: 6px; }
  .ctrl-toggle { font-size: 11px; padding: 6px 4px; }

  /* Route modal: centrado */
  .route-modal { width: min(460px, 92vw); }
}

/* ---- TABLET (640px – 1024px) ---- */
@media (min-width: 640px) and (max-width: 1024px) {
  :root { --topbar-h: 54px; }

  .topbar-user { max-width: 140px; font-size: 13px; }
  .sidebar { width: 65vw; max-width: 320px; }

  /* Drawer altura cómoda en tablet */
  .mobile-drawer { max-height: 55vh; }
}

/* ---- MÓVIL (< 640px) ---- */
@media (max-width: 640px) {
  :root { --topbar-h: 50px; }

  /* Topbar compacto */
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-user { display: none; }
  .topbar-brand .brand-text { font-size: 14px; }
  .topbar-actions { gap: 6px; }
  .icon-btn { width: 34px; height: 34px; font-size: 14px; }

  /* Sidebar más ancho en móvil */
  .sidebar { width: 88vw; max-width: 360px; }

  /* Sidebar controls: 2 columnas */
  .sidebar-controls { flex-wrap: wrap; gap: 5px; }
  .ctrl-toggle { flex: 1 1 calc(50% - 5px); min-width: 0; font-size: 11px; }

  /* Drawer ocupa más espacio en pantalla pequeña */
  .mobile-drawer { max-height: 72vh; }

  /* Map buttons más pequeños */
  .map-controls { top: 6px; right: 6px; gap: 4px; }
  .map-btn { width: 36px; height: 36px; font-size: 14px; }

  /* Route modal: hoja inferior full width */
  .route-modal {
    width: 100vw;
    max-width: 100vw;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }
  .route-modal.visible { transform: none; }
  .route-modal-overlay.visible { display: block; }

  /* Date row apilado verticalmente */
  .route-date-row { flex-direction: column; gap: 8px; }
  .route-field { flex-direction: row; align-items: center; justify-content: space-between; }
  .route-field label { min-width: 50px; }
  .route-field input { flex: 1; }

  /* Stats de ruta en 2x2 */
  .route-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Login pantalla completa */
  .login-card {
    padding: 28px 18px;
    border-radius: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Drawer mini stats más compactos */
  .mini-chip { font-size: 11px; padding: 2px 8px; }
  .drawer-title { font-size: 13px; }

  /* Card compacta en móvil */
  .card-plate { font-size: 12px; }
  .card-time-sm { font-size: 10px; }
  .card-speed-sm { font-size: 12px; min-width: 44px; }
}

/* ===================== PWA INSTALL BANNER ===================== */
.pwa-banner {
  display: none;
  position: fixed;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: var(--bg-sidebar);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  padding: 12px 14px;
  z-index: 2000;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: slideUpBanner 0.4s cubic-bezier(0.4,0,0.2,1);
}
.pwa-banner.visible { display: flex; }

@keyframes slideUpBanner {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.pwa-banner-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}
.pwa-banner-info i {
  font-size: 24px;
  color: var(--accent);
  flex-shrink: 0;
}
.pwa-banner-info strong {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}
.pwa-banner-info span {
  font-size: 12px;
  color: var(--text-muted);
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.pwa-btn-install {
  padding: 7px 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}
.pwa-btn-install:hover { opacity: .85; }
.pwa-btn-close {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all var(--transition);
}
.pwa-btn-close:hover { border-color: var(--accent); color: var(--text-primary); }


/* ===================== REPORT MODAL ===================== */
.rpt-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1100;
  backdrop-filter: blur(2px);
}
.rpt-overlay.visible { display: block; }

.rpt-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, 94vw);
  max-height: 88vh;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  z-index: 1200;
  flex-direction: column;
  overflow: hidden;
}
.rpt-modal.open { display: flex; }

.rpt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rpt-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.rpt-title i { color: var(--accent); font-size: 16px; }

.rpt-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Tipo de reporte */
.rpt-type-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.rpt-type-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.rpt-type-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.rpt-type-btn.active {
  background: rgba(99,102,241,.15);
  border-color: var(--accent);
  color: var(--accent);
}
.rpt-type-btn i { font-size: 14px; }

/* Filtros */
.rpt-filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 10px;
  align-items: end;
}
.rpt-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rpt-field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.rpt-field input,
.rpt-field select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
  color-scheme: dark;
}
.rpt-field input:focus,
.rpt-field select:focus { border-color: var(--accent); }
.rpt-field select option {
  background: #162032;
  color: #f0f4ff;
}

.rpt-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.rpt-submit-btn,
.rpt-download-btn {
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: opacity var(--transition);
}
.rpt-submit-btn   { background: var(--accent); }
.rpt-download-btn { background: #16a34a; }
.rpt-submit-btn:hover,
.rpt-download-btn:hover   { opacity: .85; }
.rpt-submit-btn:disabled  { opacity: .5; cursor: not-allowed; }

/* Resultados */
.rpt-results { flex: 1; }

.rpt-summary {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.rpt-summary strong { color: var(--text-primary); }

.rpt-empty,
.rpt-error {
  text-align: center;
  padding: 30px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.rpt-error { color: #f87171; }

.rpt-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.rpt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.rpt-table thead th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.rpt-table tbody tr { border-bottom: 1px solid var(--border); }
.rpt-table tbody tr:last-child { border-bottom: none; }
.rpt-table tbody tr:hover { background: var(--bg-card-hover); }
.rpt-table tbody td {
  padding: 8px 12px;
  color: var(--text-secondary);
  vertical-align: top;
}
.rpt-table tbody td strong { color: var(--text-primary); }
.addr-cell { max-width: 240px; font-size: 12px; }

.dur-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(99,102,241,.15);
  color: #a5b4fc;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.spd-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(239,68,68,.15);
  color: #fca5a5;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.spd-moving { color: #86efac; font-weight: 600; }
.spd-zero   { color: var(--text-muted); }

.km-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(34,197,94,.15);
  color: #86efac;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.rpt-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.rpt-dot.moving  { background: var(--moving); }
.rpt-dot.stopped { background: var(--stopped); }

/* Responsive */
@media (max-width: 1024px) {
  .rpt-modal { width: min(640px, 96vw); }
}
@media (max-width: 640px) {
  .rpt-modal {
    top: auto; left: 0; right: 0; bottom: 0;
    transform: none;
    width: 100vw;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }
  .rpt-filters {
    grid-template-columns: 1fr 1fr;
  }
}

/* Leaflet default overrides */
/* Control de capas integrado en .map-controls */
/* El control de capas ocupa solo el espacio del botón (40×40).
   El panel expandido sale fuera del flujo para no desplazar otros botones. */
.map-controls .leaflet-control-layers {
  position: relative !important;
  width: 40px !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  margin: 0 !important;
  float: none !important;
  clear: both !important;
  padding: 0 !important;
}

.map-controls .leaflet-control-layers-toggle {
  width: 40px !important;
  height: 40px !important;
  background: var(--bg-sidebar) !important;
  background-image: none !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all var(--transition) !important;
}
.map-controls .leaflet-control-layers-toggle:hover {
  background: var(--bg-card-hover) !important;
  border-color: var(--accent) !important;
}

.map-controls .leaflet-control-layers-toggle::after {
  content: '\f279';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 15px;
  color: var(--text-secondary);
  pointer-events: none;
}
.map-controls .leaflet-control-layers-toggle:hover::after {
  color: var(--text-primary);
}

/* Panel expandido: absoluto para no desplazar los demás botones */
.map-controls .leaflet-control-layers-expanded {
  width: 40px !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}
.map-controls .leaflet-control-layers-list {
  position: absolute !important;
  right: 48px !important;
  top: 0 !important;
  background: var(--bg-sidebar) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  padding: 10px 14px !important;
  min-width: 170px !important;
  z-index: 9999 !important;
}

.map-controls .leaflet-control-layers label {
  color: var(--text-secondary) !important;
  font-size: 13px !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 4px 0 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
}
.map-controls .leaflet-control-layers label:hover {
  color: var(--text-primary) !important;
}

.map-controls .leaflet-control-layers input[type=radio] {
  accent-color: var(--accent) !important;
}

@media (max-width: 640px) {
  .map-controls .leaflet-control-layers,
  .map-controls .leaflet-control-layers-toggle {
    width: 36px !important;
    height: 36px !important;
  }
}
