/* ========== GEON · Esencial GPS Platform ========== */
:root {
  /* Brand */
  --brand-blue: #1E1EE6;
  --brand-blue-600: #1818C2;
  --brand-blue-50: #EEF0FF;
  --brand-orange: #F39324;
  --brand-orange-600: #D97A12;

  /* Light theme (default) */
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --surface-2: #F0F2F8;
  --surface-3: #E6E9F2;
  --border: #E2E5EE;
  --border-strong: #CCD1DE;
  --text: #0B1020;
  --text-2: #434A60;
  --text-3: #7A8198;
  --text-inv: #FFFFFF;

  --success: #16A34A;
  --success-bg: #E8F7EE;
  --warn: #F39324;
  --warn-bg: #FEF3E4;
  --danger: #DC2626;
  --danger-bg: #FDECEC;
  --info: #1E1EE6;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(11, 16, 32, 0.06), 0 0 0 1px rgba(11, 16, 32, 0.04);
  --shadow: 0 6px 16px -6px rgba(11, 16, 32, 0.12), 0 2px 4px rgba(11, 16, 32, 0.05);
  --shadow-lg: 0 24px 48px -12px rgba(11, 16, 32, 0.22), 0 8px 16px -8px rgba(11, 16, 32, 0.10);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #0B1020;
  --surface: #151A2E;
  --surface-2: #1E233A;
  --surface-3: #262C46;
  --border: #2A3050;
  --border-strong: #3A426A;
  --text: #F1F3FA;
  --text-2: #B6BDD4;
  --text-3: #7A8198;
  --text-inv: #0B1020;

  --brand-blue-50: rgba(30, 30, 230, 0.18);
  --success-bg: rgba(22, 163, 74, 0.15);
  --warn-bg: rgba(243, 147, 36, 0.15);
  --danger-bg: rgba(220, 38, 38, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.7), 0 8px 16px -8px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-blue); color: white; }
.btn-primary:hover { background: var(--brand-blue-600); }
.btn-accent { background: var(--brand-orange); color: white; }
.btn-accent:hover { background: var(--brand-orange-600); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* ============ Inputs ============ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-2); letter-spacing: 0.02em;
  text-transform: uppercase;
}
.input {
  height: 44px; padding: 0 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
  width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px var(--brand-blue-50);
}
.input-group { position: relative; }
.input-group .input { padding-left: 42px; }
.input-group .input-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.input-group .input-trailing {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  color: var(--text-3);
  width: 32px; height: 32px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
.input-group .input-trailing:hover { background: var(--surface-2); color: var(--text); }

.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; color: var(--text-2); }
.checkbox input {
  appearance: none; width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); position: relative;
}
.checkbox input:checked {
  background: var(--brand-blue); border-color: var(--brand-blue);
}
.checkbox input:checked::after {
  content: ""; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ============ Chips / Badges ============ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.chip-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.chip-info { background: var(--brand-blue-50); color: var(--brand-blue); border-color: transparent; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.status-dot.moving { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.status-dot.idle { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.status-dot.stopped { background: var(--text-3); box-shadow: 0 0 0 3px var(--surface-2); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Utilities ============ */
.flex { display: flex; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-height: 0; min-width: 0; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 26px; }
.text-3xl { font-size: 34px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.tabular { font-variant-numeric: tabular-nums; }

/* ============ Responsive helpers ============ */
.hide-mobile { display: initial; }
.show-mobile { display: none; }
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: initial; }
  body { font-size: 14px; }
  .input { height: 46px; font-size: 16px; /* iOS no-zoom */ }
  .btn { height: 44px; min-width: 44px; }
  .btn-sm { height: 38px; }
  .btn-icon { width: 40px; height: 40px; }
}

/* Mobile bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(11,16,32,0.5); z-index: 999;
  animation: fade-in .2s ease;
}
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  background: var(--surface);
  border-top-left-radius: 18px; border-top-right-radius: 18px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.2);
  animation: slide-up .25s ease;
}
.sheet-handle {
  width: 36px; height: 4px; background: var(--border-strong); border-radius: 2px;
  margin: 10px auto 2px;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--brand-blue);
  animation: spin .7s linear infinite;
  display: inline-block; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Campana: sacudida al llegar una alerta nueva */
@keyframes bell-pulse {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-13deg); }
  30% { transform: rotate(11deg); }
  45% { transform: rotate(-8deg); }
  60% { transform: rotate(6deg); }
  75% { transform: rotate(-3deg); }
}
.bell-pulse { animation: bell-pulse .55s ease-in-out 2; transform-origin: 50% 20%; }

/* Toast de alerta: entrada deslizando desde la derecha */
@keyframes toast-in { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Popups de Leaflet acordes al tema (mapa en vivo e historial) */
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: 12px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.leaflet-popup-tip { background: var(--surface); border: 1px solid var(--border); border-top: none; border-left: none; }
.street-popup .leaflet-popup-content { margin: 8px; }
.street-popup img { background: var(--surface-2); }

/* Punto seleccionado desde el panel del historial: ANILLO que enmarca el ícono
   existente en el mapa (hueco al centro para no taparlo) + pulso. */
.route-pin-ring {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--brand-blue);
  background: rgba(30, 30, 230, 0.08);
  box-shadow: 0 0 0 0 rgba(30, 30, 230, 0.5);
  animation: routePinPulse 1.3s ease-out infinite;
}
@keyframes routePinPulse {
  0% { box-shadow: 0 0 0 0 rgba(30, 30, 230, 0.45); }
  70% { box-shadow: 0 0 0 9px rgba(30, 30, 230, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 30, 230, 0); }
}

/* Mobile nav tabs (bottom) */
.mobile-tabs {
  display: none;
  flex-shrink: 0; position: relative; z-index: 1100;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  justify-content: space-around;
}
@media (max-width: 768px) { .mobile-tabs { display: flex; } }
.mobile-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; font-size: 10px; color: var(--text-3); font-weight: 500;
  border-radius: 8px; min-width: 0;
}
.mobile-tab.active { color: var(--brand-blue); }
.mobile-tab.accent.active { color: var(--brand-orange); }

/* ============ Aura AI chat ============ */
.aura-dot {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: aura-bounce 1s infinite;
}
@keyframes aura-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}
.aura-fab {
  transition: transform .2s ease, box-shadow .2s ease;
}
.aura-fab:hover { transform: translateY(-2px) scale(1.04); }
.aura-fab:active { transform: scale(0.96); }

/* Brillo del botón cerrar del chat: se activa cuando el agente ejecutó una
   acción en la vista (que en móvil queda tapada por el chat), para invitar a
   cerrar y verla. */
@keyframes aura-close-attn {
  0%   { box-shadow: 0 0 0 0 rgba(90,120,255,.6); }
  70%  { box-shadow: 0 0 0 11px rgba(90,120,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(90,120,255,0); }
}
.aura-close-attn {
  animation: aura-close-attn 1.1s ease-out infinite;
  color: var(--brand-blue) !important;
  background: var(--brand-blue-50) !important;
  border-radius: 8px;
}
@media (max-width: 768px) {
  /* Por defecto al MEDIO del borde derecho: siempre visible, libre de la esquina
     inferior derecha (zoom del mapa), de la píldora de vehículos y de la barra
     inferior. Es arrastrable: el usuario lo mueve donde quiera. */
  .aura-fab { top: 50% !important; right: 16px !important; left: auto !important; bottom: auto !important; }
}

/* ============ Leaflet overrides ============ */
.leaflet-container { background: var(--surface-2) !important; font-family: var(--font-sans) !important; }
.leaflet-control-zoom a {
  background: var(--surface) !important; color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  font-size: 10px !important;
}
[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(11,16,32,0.85) !important; color: var(--text-2) !important;
}
[data-theme="dark"] .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }

/* Geofence tooltip */
.geo-tooltip {
  background: var(--surface) !important; color: var(--brand-orange) !important;
  border: 1px solid var(--brand-orange) !important; border-radius: 6px !important;
  font-size: 11px !important; font-weight: 700 !important;
  padding: 3px 8px !important; box-shadow: var(--shadow-sm) !important;
}
.geo-tooltip::before { border-top-color: var(--brand-orange) !important; }
