:root {
  --bg: #0a0b0f;
  --bg-soft: #11131a;
  --surface: #14161f;
  --surface-2: #1a1d28;
  --border: #232633;
  --border-soft: #1c1f2a;
  --text: #e9ecf3;
  --text-dim: #9aa3b5;
  --text-faint: #5f6678;
  --accent: #7c5cff;
  --accent-2: #ff4d8d;
  --google: #4285f4;
  --meta: #ff5a8a;
  --green: #2dd4a7;
  --red: #ff6b6b;
  --amber: #f5b454;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.10), transparent 60%),
              radial-gradient(900px 500px at -10% 0%, rgba(255, 77, 141, 0.07), transparent 55%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 20px; padding: 14px 24px; flex-wrap: nowrap;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(20, 22, 31, 0.7), rgba(10, 11, 15, 0));
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px);
  overflow-x: auto;
}
.brand { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.logo-img { height: 30px; width: auto; display: block; }
.logo {
  font-family: 'Montserrat', 'Inter', sans-serif;
  font-weight: 800; font-size: 26px; line-height: 1; letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo-w {
  background: linear-gradient(95deg, #f7941e 0%, #f6682f 35%, #ee3d77 70%, #ed2a8f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-lab { color: #fff; }
.brand-divider { width: 1px; height: 30px; background: var(--border); }
.brand-titles h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.brand-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; flex-shrink: 0; }

/* Segmented control (plataforma) */
.platform-switch { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 11px; border: 1px solid var(--border); }
.platform-switch button {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 8px 13px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; font-family: inherit; white-space: nowrap;
}
.platform-switch button:hover { color: var(--text); }

/* Desplegable de rango */
.range-select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  padding: 9px 32px 9px 13px; border-radius: 11px; color-scheme: dark;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa3b5' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.range-select:hover { border-color: var(--accent); }
.range-select:focus { outline: none; border-color: var(--accent); }

.platform-switch button { display: flex; align-items: center; gap: 6px; }
.platform-switch button.active { color: #fff; }
.platform-switch button[data-platform="both"].active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.platform-switch button[data-platform="meta"].active { background: var(--meta); }
.platform-switch button[data-platform="google"].active { background: var(--google); }

/* Rango de fechas: un solo control "desde → hasta" */
.daterange { display: flex; align-items: stretch; gap: 8px; }
.dr-fields {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  padding: 4px 10px;
}
.dr-field { display: flex; flex-direction: column; gap: 1px; cursor: pointer; }
.dr-cap { font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); padding-left: 2px; }
.dr-fields input[type="date"] {
  background: transparent; border: 0; color: var(--text);
  font-size: 13px; font-weight: 600; font-family: inherit; color-scheme: dark;
  padding: 1px 2px;
}
.dr-fields input[type="date"]:focus { outline: none; }
.dr-arrow { color: var(--accent); font-size: 15px; padding: 0 6px; align-self: center; }
.btn-apply {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0; color: #fff; padding: 0 18px; border-radius: 11px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-apply:hover { filter: brightness(1.08); }

.status-bar { display: flex; gap: 16px; align-items: center; padding: 12px 28px; }
.status { font-size: 12.5px; color: var(--text-dim); }
.status.error { color: var(--red); }
.status .dot { color: var(--green); }
.status-note { color: var(--amber); }
.range-label { font-size: 12.5px; color: var(--text-faint); margin-left: auto; }

/* ---------- Layout ---------- */
.dash { padding: 8px 28px 60px; display: flex; flex-direction: column; gap: 20px; max-width: 1440px; margin: 0 auto; }

.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-soft));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.card-head h2 { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.hint { font-size: 11.5px; color: var(--text-faint); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.kpi {
  background: linear-gradient(180deg, var(--surface), var(--bg-soft));
  border: 1px solid var(--border); border-radius: 14px; padding: 16px 16px 14px;
  position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: 0.7; }
.kpi-label { font-size: 11.5px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.kpi-delta { font-size: 12px; font-weight: 600; margin-top: 8px; display: inline-flex; align-items: center; gap: 3px; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.flat { color: var(--text-faint); }
.kpi-delta.inv-up { color: var(--red); }
.kpi-delta.inv-down { color: var(--green); }

/* ---------- Charts ---------- */
.chart-card .chart-wrap { height: 300px; position: relative; }
.legend { display: flex; gap: 16px; }
.lg { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ''; width: 10px; height: 10px; border-radius: 3px; }
.lg-spend::before { background: var(--accent); }
.lg-leads::before { background: var(--green); }

/* ---------- Tráfico (GA4) ---------- */
.ga-tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  background: rgba(245, 180, 84, 0.15); color: var(--amber);
  padding: 2px 7px; border-radius: 6px; vertical-align: middle;
}
.prop-switch { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 11px; border: 1px solid var(--border); }
.prop-switch button {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; font-family: inherit; white-space: nowrap;
}
.prop-switch button:hover { color: var(--text); }
.prop-switch button.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

.traffic-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.traffic-kpis .kpi { padding: 14px 15px 12px; }
.traffic-kpis .kpi-value { font-size: 22px; margin-top: 6px; }
.traffic-kpis .kpi::before { background: linear-gradient(90deg, #56c2e6, #2dd4a7); }

.traffic-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 22px; align-items: start; }
.traffic-chart-wrap .chart-wrap { height: 250px; position: relative; }
.legend.mini { justify-content: flex-end; margin-bottom: 8px; }
.lg-sessions::before { background: #56c2e6; }
.lg-conv::before { background: #2dd4a7; }
.side-title { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 12px; }
.split.side { grid-template-columns: 150px 1fr; gap: 14px; }
.traffic-sources { margin-top: 22px; border-top: 1px solid var(--border-soft); padding-top: 8px; }

/* Separador de zona — marca el cambio a otro tipo de datos */
.zone-divider { display: flex; align-items: center; gap: 16px; margin: 18px 2px 0; }
.zone-line { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--border), transparent); }
.zone-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #56c2e6; white-space: nowrap; }
.zone-label .ga-tag { margin-left: 2px; }

/* Zona de tráfico: tratamiento visual cian para diferenciarla de campañas */
.traffic-zone {
  position: relative; overflow: hidden;
  border-color: rgba(86, 194, 230, 0.30);
  background: linear-gradient(180deg, rgba(86, 194, 230, 0.06), var(--bg-soft));
}
.traffic-zone::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, #56c2e6, #2dd4a7); }
.zone-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; max-width: 560px; }
.traffic-zone.loading { opacity: 0.5; pointer-events: none; transition: opacity 0.2s; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.split { display: grid; grid-template-columns: 180px 1fr; gap: 18px; align-items: center; }
.donut-wrap { height: 180px; position: relative; }

.ranklist { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.ranklist li { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.ranklist .swatch { width: 10px; height: 10px; border-radius: 3px; }
.ranklist .lbl { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranklist .val { color: var(--text-dim); font-weight: 600; }
.ranklist .bar { grid-column: 2 / 4; height: 4px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: -4px; }
.ranklist .bar > span { display: block; height: 100%; border-radius: 3px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; color: var(--text-dim); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table.sortable th { cursor: pointer; user-select: none; }
.data-table.sortable th:hover { color: var(--text); }
.data-table th.r, .data-table td.r { text-align: right; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); color: var(--text); }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.data-table .campaign-name { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.data-table .strong { font-weight: 600; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.google { background: rgba(66, 133, 244, 0.15); color: #7eaaf7; }
.badge.meta { background: rgba(255, 90, 138, 0.15); color: #ff8fb0; }

.matrix th, .matrix td { text-align: right; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix td.heat { font-weight: 600; border-radius: 4px; }

/* ---------- Overlay ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 11, 15, 0.55); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(2px); }
.overlay.hidden { display: none; }
.spinner { width: 38px; height: 38px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { color: var(--text-faint); font-size: 13px; padding: 20px 12px; text-align: center; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
/* Header apilado cuando no entra en una línea */
@media (max-width: 1080px) {
  .topbar { flex-wrap: wrap; overflow-x: visible; }
  .controls { flex-wrap: wrap; }
}
@media (max-width: 680px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px; }
  .dash { padding: 8px 14px 50px; }
}
