/* ═══════════════════════════════════════════════════════════
   AMPS Monitoring Platform — Shared Styles
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #f5f7fa;
  --white: #ffffff;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f0f1f3;
  /* Whitelabel: --brand-accent es escrito por js/branding.js desde el API.
     Fallback al default AMPS si el loader no corrió o no hay brand custom. */
  --brand-accent: #2563eb;
  --accent: var(--brand-accent);
  --accent-light: #eff6ff;
  --accent-hover: #1d4ed8;
  --green: #10b981;
  --green-light: #ecfdf5;
  --red: #ef4444;
  --red-light: #fef2f2;
  --yellow: #f59e0b;
  --yellow-light: #fffbeb;
  --blue-moving: #3b82f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Common icons ────────────────────────────────────── */
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-md { width: 20px; height: 20px; }
.icon-lg { width: 24px; height: 24px; }

/* ─── Topbar (shared across admin views) ──────────────── */
.topbar {
  height: 60px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { height: 28px; }
.topbar-logo img { height: 100%; width: auto; }

.topbar-right { display: flex; align-items: center; gap: 20px; }
.topbar-notif {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
  color: var(--text-secondary);
}
.topbar-notif-dot {
  position: absolute; top: 7px; right: 7px;
  width: 7px; height: 7px;
  background: var(--red);
  border-radius: 50%;
  border: 2px solid var(--white);
}
.topbar-user { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 600;
}
.topbar-user-info { line-height: 1.2; }
.topbar-user-name { font-size: 13px; font-weight: 600; }
.topbar-user-role { font-size: 11px; color: var(--text-muted); }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  border: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-blue { background: var(--accent-light); color: var(--accent); }
.badge-purple { background: #f5f3ff; color: #8b5cf6; }

/* ─── Toast notifications ─────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 14px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s;
  box-shadow: var(--shadow-lg);
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--accent); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ─── Loading spinner ─────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile ≤ 768px
   Estos estilos NO afectan desktop (≥ 769px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ─── Topbar compact ─── */
  .topbar { padding: 0 14px; height: 52px; }
  .topbar-logo { height: 22px; }
  .topbar-right { gap: 10px; }
  .topbar-user-info { display: none; }
  .topbar-avatar { width: 30px; height: 30px; font-size: 11px; }
  .topbar-notif { width: 30px; height: 30px; border-radius: 8px; }
  .logout-btn { padding: 5px 10px; font-size: 11px; }

  /* ─── Page body ─── */
  .page-body { padding: 16px !important; }
  .page-inner { max-width: 100% !important; }

  /* ─── Page header stacked ─── */
  .page-header { flex-direction: column; align-items: flex-start !important; gap: 12px; }
  .page-title { font-size: 18px !important; }

  /* ─── Search bars full width ─── */
  .search-bar { min-width: unset !important; width: 100%; }

  /* ─── Tables responsive ─── */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  th, td { padding: 10px 12px !important; font-size: 12px !important; }

  /* ─── Modals full-width ─── */
  .modal { width: calc(100vw - 32px) !important; max-width: 100% !important; }

  /* Forms */
  .form-row { grid-template-columns: 1fr !important; }

  /* Buttons */
  .btn { padding: 8px 14px; font-size: 12px; }

  /* Toast */
  .toast { left: 16px; right: 16px; top: 12px; text-align: center; }
}

/* === Password Toggle (Sprint 11) === */
[data-password-input] {
  position: relative;
}
[data-password-input] > input {
  padding-right: 40px;
}
.password-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  line-height: 0;
}
.password-toggle-btn:hover { color: rgba(59, 130, 246, 1); }
.password-toggle-btn:focus { outline: none; box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3); }
.password-toggle-btn.showing { color: rgba(16, 185, 129, 1); }

/* Login (index.html) usa tema oscuro con input claro — ojo más visible. */
.login-form [data-password-input] .password-toggle-btn { color: rgba(156, 163, 175, 1); }
.login-form [data-password-input] .password-toggle-btn:hover { color: rgba(59, 130, 246, 1); }

/* ───────────────────────────────────────────────────────────
   Sprint 17 — Tag permanente con nombre al lado del marker
   Leaflet tooltip con className `.device-label-tooltip`.
   ─────────────────────────────────────────────────────────── */
.leaflet-tooltip.device-label-tooltip {
  background: rgba(15, 23, 42, 0.82);
  color: #e2e8f0;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid rgba(59, 130, 246, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  pointer-events: none;
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
}
.leaflet-tooltip.device-label-tooltip::before { display: none; }

/* ───────────────────────────────────────────────────────────
   Sprint 17 — Replay con ícono de vehículo rotable (history.html)
   ─────────────────────────────────────────────────────────── */
.replay-vehicle-icon { pointer-events: none; background: transparent; border: none; }
.replay-vehicle-wrapper {
  width: 32px;
  height: 32px;
  transition: transform 0.3s ease-out;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Botón toggle activo (tanto desktop .panel-icon-btn como mobile .m-fab) */
.panel-icon-btn.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}
.m-fab.active {
  background: var(--accent);
  color: #fff;
}

/* En mobile, esconder labels cuando el zoom es muy bajo (evita saturación) */
@media (max-width: 768px) {
  .leaflet-container .leaflet-tooltip.device-label-tooltip {
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Sprint 33.1 — Street View modal (desktop)
   Embed API iframe en modal centrado. Botón Street View clona
   .detail-action-btn / .drawer-action visual (heredan).
   ═══════════════════════════════════════════════════════════════ */

.btn-street-view svg { stroke: #8b5cf6; }
.btn-street-view:hover { border-color: #8b5cf6; color: #8b5cf6; background: rgba(139,92,246,0.08); }

.street-view-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease-out;
}
.street-view-overlay.active { opacity: 1; pointer-events: auto; }

.street-view-modal {
  background: var(--white, #fff);
  width: min(900px, 92vw);
  height: min(640px, 85vh);
  border-radius: 12px;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.45);
  overflow: hidden;
  transform: translateY(16px);
  transition: transform 0.22s ease-out;
}
.street-view-overlay.active .street-view-modal { transform: translateY(0); }

.street-view-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--bg-card, #f9fafb);
}
.street-view-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text, #111827);
}
.street-view-title svg { stroke: #8b5cf6; }
.street-view-close {
  width: 28px; height: 28px;
  border: 1px solid var(--border, #e5e7eb);
  background: transparent;
  border-radius: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text, #374151);
}
.street-view-close:hover { background: var(--accent-light, #eff6ff); border-color: var(--accent, #2563eb); color: var(--accent, #2563eb); }
.street-view-iframe {
  flex: 1; width: 100%; border: 0; display: block;
}

@media (max-width: 640px) {
  .street-view-modal {
    width: 100%; height: 80vh;
    border-radius: 12px 12px 0 0;
    align-self: flex-end;
  }
  .street-view-overlay { align-items: flex-end; }
  .street-view-overlay .street-view-modal { transform: translateY(100%); }
  .street-view-overlay.active .street-view-modal { transform: translateY(0); }
}
