:root {
  --bg: #050914;
  --bg2: #070f1f;
  --card: #0f172a;
  --card2: #131c33;
  --text: #e6edf7;
  --muted: #9fb0cf;
  --accent: #25D366;
  --accent2: #128C7E;
  --line: rgba(255, 255, 255, .08);
  --good: #25D366;
  --bad: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, var(--bg), var(--bg2));
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.muted { color: var(--muted); }
.center { text-align: center; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, .6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.brand h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: -.2px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  flex-shrink: 0;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user {
  background: rgba(37, 211, 102, .12);
  color: var(--accent);
  border: 1px solid rgba(37, 211, 102, .25);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.btn-ghost:hover {
  background: var(--card2);
  color: var(--text);
  border-color: rgba(255, 255, 255, .15);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  opacity: .4;
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 500;
}
.kpi-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
  margin-top: 2px;
}
.kpi-delta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

.span-full { grid-column: 1 / -1; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.chart-tall { min-height: 320px; }
.chart-md { min-height: 280px; }

.table-wrap {
  overflow-x: auto;
  margin: 0 -8px;
}
.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.recent-table th,
.recent-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.recent-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: rgba(255, 255, 255, .02);
}
.recent-table tbody tr:hover {
  background: rgba(255, 255, 255, .02);
}
.recent-table .ts {
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.recent-table .lead-name {
  font-weight: 500;
}
.tag {
  display: inline-block;
  background: rgba(159, 176, 207, .1);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}

.foot {
  text-align: center;
  padding: 16px;
  font-size: 12px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablet — 1100px */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet pequeña / phablet — 860px */
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .container { padding: 18px; gap: 16px; }
}

/* Móvil — 720px */
@media (max-width: 720px) {
  body { font-size: 13px; }

  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 12px;
  }
  .topbar .brand { flex: 1 1 auto; order: 1; }
  .topbar .brand h1 { font-size: 14px; }
  .topbar-controls { order: 2; }
  .topbar-meta {
    flex: 1 1 100%;
    order: 3;
    justify-content: flex-end;
    font-size: 11px;
    gap: 8px;
    color: var(--muted);
  }
  #lastUpdated { font-size: 11px; }
  #userBadge { font-size: 11px; padding: 2px 8px; }
  .btn-ghost { padding: 8px 10px; font-size: 12px; min-height: 36px; }

  .container { padding: 14px; gap: 14px; }

  .kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 24px; }
  .kpi-label { font-size: 10px; }
  .kpi-delta { font-size: 11px; }

  .card { padding: 14px; border-radius: 12px; }
  .card-head h2 { font-size: 12px; }

  .chart-tall { min-height: 240px; }
  .chart-md { min-height: 220px; }

  /* Tabla móvil: ocultar columnas y mantener formato tabla */
  .recent-table th:nth-child(1),
  .recent-table td:nth-child(1),
  .recent-table th:nth-child(4),
  .recent-table td:nth-child(4),
  .recent-table th:nth-child(5),
  .recent-table td:nth-child(5),
  .recent-table th:nth-child(7),
  .recent-table td:nth-child(7),
  .recent-table th:nth-child(8),
  .recent-table td:nth-child(8) { display: none; }

  .recent-table th,
  .recent-table td { padding: 8px 8px; font-size: 12px; }
  .recent-table .ts { font-size: 11px; }
  .recent-table .lead-name { font-weight: 500; }

  /* Heatmap puede necesitar scroll horizontal en pantallas chicas */
  #chartHeatmap { overflow-x: auto; }
}

/* Móvil chico — 420px */
@media (max-width: 420px) {
  .topbar { padding: 9px 12px; column-gap: 8px; }
  .topbar .brand h1 { font-size: 13px; }
  .topbar-meta { font-size: 10px; gap: 6px; }
  #lastUpdated { font-size: 10px; }
  #userBadge { font-size: 10px; padding: 2px 7px; }
  .container { padding: 12px; }
  .kpis { gap: 8px; }
  .kpi-value { font-size: 22px; }
  .recent-table td::before { min-width: 72px; }
}
