/* Variables de Tema (Claro / Oscuro) */
:root {
  --primary: #FF5B3A;
  --primary-hover: #E8492A;
  --primary-glow: rgba(255, 91, 58, 0.25);
  --success: #19C39C;
  --warning: #f59e0b;
  --danger: #ef4444;
  
  /* Tema Oscuro por defecto */
  --bg-body: #111318;
  --bg-card: #1A1D24;
  --bg-card-hover: #20242C;
  --bg-input: #23272F;
  --bg-badge: rgba(255, 255, 255, 0.06);
  --border-color: #2A2E37;
  --border-subtle: #22262E;
  
  --text-main: #F5F4EF;
  --text-muted: #A3A6AE;
  --text-faint: #6F737C;

  --chart-line: #FF5B3A;
  --chart-area: rgba(255, 91, 58, 0.14);
  --chart-uniques: #19C39C;
  --chart-grid: #2A2E37;

  --font: Satoshi, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  --bg-body: #F5F4EF;
  --bg-card: #ffffff;
  --bg-card-hover: #FBFAF7;
  --bg-input: #EEECE6;
  --bg-badge: #EAE8E1;
  --border-color: #E4E2DA;
  --border-subtle: #EEECE6;

  --text-main: #111318;
  --text-muted: #5D616B;
  --text-faint: #8E929A;

  --chart-line: #FF5B3A;
  --chart-area: rgba(255, 91, 58, 0.1);
  --chart-uniques: #13A584;
  --chart-grid: #E4E2DA;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
  padding-bottom: 3rem;
}

/* Header & Barra Superior */
.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background-color: rgba(17, 19, 24, 0.86);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
}

[data-theme="light"] .navbar {
  background-color: rgba(245, 244, 239, 0.86);
}

.nav-container {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: #FF5B3A;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  box-shadow: none;
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

/* Indicador de En Vivo */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  background: rgba(25, 195, 156, 0.12);
  border: 1px solid rgba(25, 195, 156, 0.25);
  color: #19C39C;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #19C39C;
  box-shadow: 0 0 8px #19C39C;
  animation: pulse-live 1.8s infinite;
}

@keyframes pulse-live {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(25, 195, 156, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(25, 195, 156, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(25, 195, 156, 0); }
}

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

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

/* Contenedor Principal */
.main-wrapper {
  max-width: 1280px;
  margin: 1.25rem auto;
  padding: 0 1rem;
}

/* Barra de Filtros (Sitio y Periodo) */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.select-custom {
  padding: 0.55rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.select-custom:focus {
  border-color: var(--primary);
}

.pill-group {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  overflow-x: auto;
}

.pill-btn {
  padding: 0.45rem 0.8rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.pill-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.pill-btn:hover:not(.active) {
  color: var(--text-main);
}

.btn-primary {
  padding: 0.55rem 0.9rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background-color 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  padding: 0.55rem 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

/* Tarjetas de Métricas (KPIs) */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  transition: transform 0.15s, border-color 0.15s;
}

.kpi-card:hover {
  border-color: var(--border-subtle);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.kpi-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-icon {
  font-size: 1.1rem;
  opacity: 0.8;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.4rem;
}

.kpi-footer {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
  border-radius: 4px;
  padding: 1px 4px;
}

.trend-up {
  color: #19C39C;
  background: rgba(25, 195, 156, 0.12);
}

.trend-down {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.trend-neutral {
  color: var(--text-muted);
  background: var(--bg-badge);
}

/* Gráfica de Tendencia */
.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.chart-title {
  font-size: 1rem;
  font-weight: 700;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.svg-chart-container {
  width: 100%;
  height: 240px;
  position: relative;
}

.svg-chart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Tooltip de la gráfica */
.chart-tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text-main);
  pointer-events: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  display: none;
  z-index: 10;
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

/* Rejilla de Secciones y Tablas */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.card-block {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.card-block-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Tablas Minimalistas */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table td {
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.bar-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: var(--primary-glow);
  border-radius: 4px;
  z-index: 0;
  opacity: 0.65;
}

.bar-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Embudo de Conversión */
.funnel-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.funnel-step {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  position: relative;
  overflow: hidden;
}

.funnel-bar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(255, 91, 58, 0.25), rgba(99, 102, 241, 0.25));
  z-index: 0;
}

.funnel-info {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.funnel-step-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.funnel-step-stats {
  text-align: right;
}

.funnel-step-count {
  font-weight: 800;
  font-size: 1.1rem;
}

.funnel-step-pct {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Modal y Diálogos */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.code-box {
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  color: #38bdf8;
  overflow-x: auto;
  margin: 0.5rem 0 1rem 0;
  position: relative;
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

/* Botón flotante o panel opt-out */
.optout-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.optout-text {
  font-size: 0.88rem;
}

.optout-status {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
}

.optout-active {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.optout-inactive {
  background: rgba(25, 195, 156, 0.15);
  color: #19C39C;
}

/* Responsividad para móviles / iPhone */
@media (max-width: 640px) {
  .navbar {
    padding: 0.65rem 0.75rem;
  }
  .main-wrapper {
    padding: 0 0.75rem;
    margin-top: 0.75rem;
  }
  .filters-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .pill-group {
    width: 100%;
    justify-content: space-between;
  }
  .pill-btn {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.4rem;
    font-size: 0.75rem;
  }
  .select-custom {
    width: 100%;
  }
  .kpis-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }
  .kpi-card {
    padding: 0.85rem;
  }
  .kpi-value {
    font-size: 1.45rem;
  }
  .content-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
}



/* ===== Gestzi: ajustes de marca y móvil ===== */
.brand-icon svg{width:23px;height:23px}
.brand-icon path{fill:none;stroke:#fff;stroke-width:4.5;stroke-linecap:round;stroke-linejoin:round}.brand-icon circle{fill:#fff}
.brand-title{font-weight:900;letter-spacing:-.04em;font-size:1.2rem}
.brand-title small{font-weight:500;color:var(--text-muted);letter-spacing:0;margin-left:.35rem;font-size:.85rem}
.kpi-value{font-weight:900;letter-spacing:-.04em}
.card-block-title,.kpi-title{letter-spacing:-.01em}
.pill-btn.active{background:var(--primary);color:#fff}
.live-badge{white-space:nowrap}
.content-grid>*,.kpis-grid>*{min-width:0}
.card-block{min-width:0;overflow-x:auto}
.data-table{min-width:0}
.vacio-aviso{border:1px dashed var(--border-color);border-radius:var(--radius);padding:1rem 1.15rem;margin-bottom:1.25rem;color:var(--text-muted);font-size:.9rem;line-height:1.5;background:var(--bg-card)}
.vacio-aviso b{color:var(--text-main)}
.optout-links{display:flex;flex-wrap:wrap;gap:.4rem;margin-top:.6rem}
.optout-links a{font-size:.8rem;font-weight:600;color:var(--primary);text-decoration:none;border:1px solid var(--border-color);border-radius:999px;padding:.3rem .7rem}
@media (max-width:640px){
  .nav-container{gap:.5rem}
  .nav-left{gap:.5rem;min-width:0}
  .brand-title small,.hide-mobile{display:none}
  .live-badge{padding:.25rem .5rem;font-size:.7rem}
  .btn-primary{padding:.5rem .65rem}
  .nav-actions{gap:.35rem;flex:none}
  .data-table th,.data-table td{padding-left:.45rem;padding-right:.45rem;font-size:.8rem}
  .card-block{padding:.9rem}
}
