/* ============================================================
   style.css — Estilos compartidos
   ============================================================ */

:root {
  --primary: #2c3e50;
  --primary-dark: #1f2f3d;
  --accent: #3498db;
  --accent-dark: #2980b9;
  --bg: #f4f6f8;
  --white: #ffffff;
  --border: #dfe4e8;
  --muted: #7f8c8d;
  --success: #27ae60;
  --danger: #e74c3c;
  --warn: #f39c12;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.2;
  transition: background var(--transition), color var(--transition),
              transform var(--transition), box-shadow var(--transition),
              border-color var(--transition);
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(44, 62, 80, 0.28); }

.btn-secondary { background: #eef2f5; color: var(--primary); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8ed; }

.btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.45); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.16); }

.btn-logout { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.45); }
.btn-logout:hover { background: rgba(231, 76, 60, 0.9); border-color: transparent; }

.btn-block { width: 100%; }

/* ============================================================
   LOGIN / REGISTRO
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  padding: 28px 26px 22px;
  animation: cardIn 0.3s ease;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.auth-header { text-align: center; }
.auth-header h1 { margin: 0; font-size: 26px; letter-spacing: 0.4px; color: var(--primary); }
.auth-sub { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

.tabs {
  display: flex;
  background: #eef2f5;
  border-radius: 10px;
  padding: 4px;
  margin: 18px 0 20px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  transition: all var(--transition);
}
.tab:hover { color: var(--primary); }
.tab.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(44, 62, 80, 0.12); }

.form { animation: fadeIn 0.2s ease; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field .opt { font-style: normal; font-weight: 400; opacity: 0.8; }
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.field input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15); }

.msg { min-height: 18px; margin: 12px 0 0; font-size: 13px; text-align: center; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--success); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   PÁGINA DEL MAPA
   ============================================================ */
.map-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  position: relative;
  z-index: 1400;
  flex: 0 0 60px;
  height: 60px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; white-space: nowrap; }
.user-name { font-size: 13.5px; opacity: 0.92; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#map { flex: 1 1 auto; width: 100%; background: #e8ecef; }

.fab {
  position: fixed;
  left: 16px;
  bottom: 24px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition), box-shadow var(--transition), color var(--transition);
}
.fab:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3); color: var(--accent-dark); }
.fab:active { transform: scale(0.94); }

/* ============================================================
   PANEL ADMIN
   ============================================================ */
.admin-panel {
  position: fixed;
  top: 60px;
  left: 0;
  bottom: 0;
  width: 340px;
  max-width: 86vw;
  background: #fff;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.18);
  transform: translateX(-105%);
  transition: transform var(--transition);
  z-index: 1200;
  display: flex;
  flex-direction: column;
}
.admin-panel.open { transform: translateX(0); }

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
}
.panel-head h2 { margin: 0; font-size: 14px; letter-spacing: 0.6px; }

.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--transition), transform var(--transition);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.18); transform: rotate(90deg); }

.panel-body { flex: 1 1 auto; overflow-y: auto; }

.acc { border-bottom: 1px solid var(--border); }
.acc-head {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.7px;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
}
.acc-head:hover { background: #f5f8fa; }
.chev { display: inline-block; font-size: 11px; color: var(--accent); transition: transform var(--transition); }
.acc.open .chev { transform: rotate(90deg); }
.acc-body { display: none; padding: 4px 16px 16px; }
.acc.open .acc-body { display: block; animation: fadeIn 0.2s ease; }

.list { list-style: none; margin: 10px 0 0; padding: 0; }
.gf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
}
.gf-item:hover { background: #f2f6f9; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06); }
.gf-name { flex: 1 1 auto; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gf-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.gf-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 5px;
  border-radius: 6px;
  transition: background var(--transition), transform var(--transition);
}
.gf-actions button:hover { background: #e3ebf1; transform: scale(1.15); }

.empty { list-style: none; font-size: 12.5px; color: var(--muted); padding: 10px 4px; text-align: center; }

.sub-label {
  margin: 14px 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.sub-label:first-child { margin-top: 6px; }

.user-list { list-style: none; margin: 0; padding: 0; }
.user-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  transition: background var(--transition);
}
.user-row:hover { background: #f2f6f9; }
.user-row-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.status-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.18); }
.status-dot.off { background: #b0b8bd; }

.badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #eaf4fb;
  color: var(--accent-dark);
  padding: 2px 7px;
  border-radius: 20px;
  flex: 0 0 auto;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  font-size: 13.5px;
  cursor: pointer;
}
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #cfd8de;
  border-radius: 24px;
  transition: background var(--transition);
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.date-row { display: flex; gap: 10px; margin-bottom: 12px; }
.field-sm { flex: 1; display: block; }
.field-sm span { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field-sm input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field-sm input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15); }

#histExport { margin-top: 10px; }

.event-list { list-style: none; margin: 12px 0 0; padding: 0; }
.event-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid #eef2f5;
  font-size: 13px;
}
.event-row:last-child { border-bottom: none; }
.ev-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  color: #fff;
  flex: 0 0 auto;
}
.ev-in { background: var(--success); }
.ev-out { background: var(--danger); }
.ev-user { font-weight: 600; flex: 0 0 auto; }
.ev-gf { color: var(--muted); flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-time { color: var(--muted); font-size: 11.5px; white-space: nowrap; flex: 0 0 auto; }

/* ============================================================
   TOOLBAR DE DIBUJO
   ============================================================ */
.draw-toolbar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px));
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
  z-index: 1300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: toolbarIn 0.2s ease;
}
@keyframes toolbarIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.dt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#gfName {
  flex: 1 1 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#gfName:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15); }
#gfName:disabled { background: #f0f4f7; color: var(--muted); }
.dt-counter {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-dark);
  background: #eaf4fb;
  padding: 5px 11px;
  border-radius: 20px;
  white-space: nowrap;
}
.palette { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform var(--transition), box-shadow var(--transition);
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--primary); }
.dt-actions { display: flex; gap: 8px; margin-left: auto; }
.dt-hint { margin: 0; font-size: 12px; color: var(--muted); }

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--primary);
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  max-width: 320px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity var(--transition), transform var(--transition);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warn { background: var(--warn); }

/* ============================================================
   ELEMENTOS LEAFLET
   ============================================================ */
.vertex-icon { background: transparent; border: none; }
.vertex-dot {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}
.vertex-icon:hover .vertex-dot { transform: scale(1.2); }

.gf-tooltip {
  background: rgba(255, 255, 255, 0.92);
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
}
.gf-tooltip::before { display: none; }

.me-tooltip {
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
}
.me-tooltip::before { display: none; }

/* ============================================================
   NUEVO: Tooltip permanente de usuarios (nombre debajo)
   ============================================================ */
.user-tooltip {
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.user-tooltip::before { display: none; }

/* ============================================================
   NUEVO: Panel flotante de notificaciones
   ============================================================ */
.notif-panel {
  position: fixed;
  top: 76px;
  right: 16px;
  width: 340px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
  z-index: 1250;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: notifIn 0.2s ease;
}
@keyframes notifIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--primary);
  color: #fff;
  cursor: move;
  user-select: none;
  touch-action: none;
}
.notif-head h3 { margin: 0; font-size: 13px; letter-spacing: 0.5px; font-weight: 700; }
.notif-head-actions { display: flex; gap: 2px; }
.notif-head-actions .icon-btn { font-size: 12px; padding: 4px 6px; color: #fff; transform: none !important; }
.notif-head-actions .icon-btn:hover { background: rgba(255, 255, 255, 0.2); transform: none !important; }

.notif-body { flex: 1 1 auto; overflow-y: auto; max-height: 60vh; }
.notif-list { list-style: none; margin: 0; padding: 6px; }

.notif-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  border-radius: 8px;
  font-size: 12.5px;
  transition: background var(--transition);
  animation: fadeIn 0.25s ease;
}
.notif-item:hover { background: #f2f6f9; }

.notif-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.notif-user { font-weight: 700; color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-gf { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-time { color: var(--muted); font-size: 11px; white-space: nowrap; flex: 0 0 auto; }

.notif-collapsed-msg {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  background: #f7f9fb;
  border-top: 1px solid var(--border);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  .brand { font-size: 16px; }
  .user-name { display: none; }
  .admin-panel { width: 86vw; }
  .draw-toolbar { bottom: 88px; padding: 12px; }
  .dt-actions { margin-left: 0; width: 100%; }
  .dt-actions .btn { flex: 1; }
  .fab { width: 44px; height: 44px; font-size: 20px; bottom: 16px; left: 12px; }
  .toast-container { top: 68px; right: 10px; left: 10px; align-items: stretch; }
  .toast { max-width: none; }
  .notif-panel { top: 70px; right: 8px; left: 8px; width: auto; max-width: none; }
  .notif-body { max-height: 50vh; }
}