/* ============================================================
   PUBLIGEO – Estilos Principales (Mobile First)
   ============================================================ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:        #0f1117;
  --c-surface:   #1a1d27;
  --c-surface2:  #232736;
  --c-border:    #2e3347;
  --c-accent:    #3b82f6;
  --c-accent-h:  #2563eb;
  --c-success:   #22c55e;
  --c-danger:    #ef4444;
  --c-warn:      #f59e0b;
  --c-text:      #e2e8f0;
  --c-muted:     #8b95a8;
  --c-white:     #ffffff;

  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', monospace;

  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  16px;

  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Tipografía ────────────────────────────────────────────── */
h1 { font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem;   font-weight: 600; }

/* ── Layout Raíz ───────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 56px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--c-white);
}

.topbar-brand .dot {
  width: 10px; height: 10px;
  background: var(--c-accent);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.4); opacity: 0.6; }
}

.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.topbar-user {
  font-size: 0.8rem;
  color: var(--c-muted);
  display: none;
}

@media (min-width: 480px) { .topbar-user { display: block; } }

/* ── Nav ───────────────────────────────────────────────────── */
.nav {
  display: flex;
  background: var(--c-surface2);
  border-bottom: 1px solid var(--c-border);
}

.nav-btn {
  flex: 1;
  padding: 0.65rem 0.5rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--c-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.nav-btn.active,
.nav-btn:hover {
  color: var(--c-text);
  border-bottom-color: var(--c-accent);
}

.nav-btn.active { color: var(--c-accent); }

/* ── Contenido Principal ───────────────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
}

.view { display: none; height: 100%; }
.view.active { display: flex; flex-direction: column; }

/* ── Tarjetas / Paneles ────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 1.25rem;
}

/* ── Botones ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary  { background: var(--c-accent);  color: #fff; }
.btn-primary:hover  { background: var(--c-accent-h); }
.btn-success  { background: var(--c-success); color: #fff; }
.btn-danger   { background: var(--c-danger);  color: #fff; }
.btn-warn     { background: var(--c-warn);    color: #000; }
.btn-ghost    { background: transparent; border: 1px solid var(--c-border); color: var(--c-text); }
.btn-ghost:hover { background: var(--c-surface2); }
.btn-sm       { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-icon     { padding: 0.4rem; }

/* ── Formularios ───────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--c-accent);
}

select.form-control { appearance: none; cursor: pointer; }

/* ── Grilla / Tabla ────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--c-surface2);
  padding: 0.7rem 0.9rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-muted);
  white-space: nowrap;
}

tbody tr {
  border-top: 1px solid var(--c-border);
  transition: background var(--transition);
}

tbody tr:hover { background: var(--c-surface2); }

tbody td {
  padding: 0.65rem 0.9rem;
  vertical-align: middle;
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-active   { background: rgba(34,197,94,0.15);  color: var(--c-success); }
.badge-inactive { background: rgba(239,68,68,0.15);  color: var(--c-danger);  }

/* ── Toolbar de tabla ──────────────────────────────────────── */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--c-border);
}

.table-title { font-weight: 600; font-size: 0.95rem; }

/* ── Modal / Drawer ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slide-up 0.2s ease;
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

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

.modal-body    { padding: 1.25rem; }
.modal-footer  { padding: 1rem 1.25rem; border-top: 1px solid var(--c-border); display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Popup publigeo (pantalla usuario) ─────────────────────── */
.publigeo-popup {
  position: fixed;
  inset: 5%;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  z-index: 500;
  display: none;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.publigeo-popup.open { display: flex; }

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--c-border);
  font-weight: 600;
}

.popup-body {
  flex: 1;
  overflow: hidden;
}

.popup-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Layout pantalla usuario ───────────────────────────────── */
#view-usuario {
  flex-direction: row;
  height: calc(100vh - 56px - 44px);
}

.map-col {
  flex: 1 1 70%;
  position: relative;
  overflow: hidden;
}

#mapa { width: 100%; height: 100%; }

.sidebar-col {
  flex: 0 0 30%;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 1rem;
}

.sidebar-col h3 {
  margin-bottom: 0.75rem;
  color: var(--c-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lugar-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--c-border);
}

.lugar-item:last-child { border: none; }

.lugar-info { flex: 1; }
.lugar-name { font-size: 0.85rem; font-weight: 500; }
.lugar-empresa { font-size: 0.72rem; color: var(--c-muted); }

/* ── Toggle switch ─────────────────────────────────────────── */
.toggle {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--c-border);
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--c-accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Login ─────────────────────────────────────────────────── */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .dot-big {
  width: 48px; height: 48px;
  background: var(--c-accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.65rem 1.1rem;
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: slide-up 0.2s ease;
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--c-success); }
.toast.error   { border-left: 3px solid var(--c-danger);  }
.toast.info    { border-left: 3px solid var(--c-accent);  }

/* ── Admin sub-nav ─────────────────────────────────────────── */
.sub-nav {
  display: flex;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  overflow-x: auto;
}

.sub-nav-btn {
  padding: 0.55rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--c-muted);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.sub-nav-btn.active { color: var(--c-accent); border-bottom-color: var(--c-accent); }
.sub-nav-btn:hover  { color: var(--c-text); }

/* ── Geo button ────────────────────────────────────────────── */
.geo-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.geo-coords {
  font-size: 0.75rem;
  color: var(--c-success);
  font-family: var(--font-mono);
}

/* ── Responsive: móvil pantalla usuario ───────────────────── */
@media (max-width: 640px) {
  #view-usuario { flex-direction: column; }
  .map-col  { flex: 0 0 60vh; }
  .sidebar-col { flex: 1; border-left: none; border-top: 1px solid var(--c-border); }
}

/* ── Blinking marker ───────────────────────────────────────── */
.blink-marker {
  width: 14px; height: 14px;
  background: var(--c-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  animation: blink 1.2s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(59,130,246,0.4); }
  50% { opacity: 0.6; box-shadow: 0 0 0 8px rgba(59,130,246,0); }
}

/* ── Loading ───────────────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ─────────────────────────────────────────────── */
.flex        { display: flex; }
.items-center{ align-items: center; }
.gap-2       { gap: 0.5rem; }
.gap-3       { gap: 0.75rem; }
.mt-1        { margin-top: 0.25rem; }
.mt-2        { margin-top: 0.5rem; }
.mt-4        { margin-top: 1rem; }
.mb-1        { margin-bottom: 0.25rem; }
.p-4         { padding: 1rem; }
.p-6         { padding: 1.5rem; }
.text-muted  { color: var(--c-muted); }
.text-sm     { font-size: 0.85rem; }
.text-xs     { font-size: 0.75rem; }
.text-center { text-align: center; }
.hidden      { display: none !important; }
.w-full      { width: 100%; }
