:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;
  --text-mute: #94a3b8;
  --blue: #2563eb;
  --blue-2: #1d4ed8;
  --blue-soft: #eff6ff;
  --pos: #16a34a;
  --neg: #dc2626;
  --neu: #6b7280;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

/* ── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
}
.brand-mark {
  width: 28px; height: 28px;
  background: var(--blue);
  color: white;
  border-radius: 6px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  letter-spacing: -0.02em;
}
.brand-mark.large { width: 48px; height: 48px; font-size: 18px; border-radius: 10px; }
.brand-text { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-text em { font-style: normal; color: var(--text-3); font-weight: 500; }

.topnav { display: flex; align-items: center; gap: 20px; }
.topnav a {
  color: var(--text-2); text-decoration: none; font-size: 13.5px; font-weight: 500;
  padding: 6px 4px; border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--blue); }
.linkbtn {
  background: transparent; border: 0; padding: 4px 8px;
  color: var(--text-3); font-size: 13.5px; cursor: pointer; font-family: inherit;
}
.linkbtn:hover { color: var(--neg); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--surface-3);
  border-radius: 999px;
}
.user-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--blue); color: white;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.user-name { font-size: 13px; color: var(--text-2); }

.main { padding: 32px 0 64px; }
.login-main { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, #f8fafc 0%, #eff6ff 100%); }
.container { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login-shell { width: 100%; max-width: 420px; padding: 24px; }
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand .brand-mark.large { margin: 0 auto; }
.login-brand h1 { font-size: 22px; margin: 16px 0 4px; letter-spacing: -0.02em; }
.login-brand h1 em { font-style: normal; color: var(--text-3); font-weight: 500; }
.login-tag { color: var(--text-3); font-size: 13px; margin: 0; }
.login-form { display: grid; gap: 14px; }
.login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  font-family: var(--font);
}
.login-form input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.login-foot { text-align: center; font-size: 12px; color: var(--text-mute); margin: 20px 0 0; }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 4px; }
.alert-error { background: #fef2f2; color: var(--neg); border: 1px solid #fecaca; }

.btn-primary {
  background: var(--blue);
  color: white;
  border: 0;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--blue-2); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Radios grid ───────────────────────────────────────────────────── */
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
.page-sub { color: var(--text-3); font-size: 14px; margin: 0; }

.radio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.radio-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.radio-card:hover { border-color: var(--blue); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.radio-card--inactiva { cursor: not-allowed; opacity: 0.7; }
.radio-card--inactiva:hover { transform: none; border-color: var(--border); box-shadow: none; }
.radio-card__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.radio-card__dial { font-size: 12px; color: var(--text-3); font-weight: 600; letter-spacing: 0.03em; }
.radio-card__body h2 { font-size: 18px; margin: 0 0 4px; letter-spacing: -0.01em; }
.radio-card__ciudad { color: var(--text-3); font-size: 13px; margin: 0 0 16px; }
.radio-card__stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.radio-card__stats > div { display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.stat-lbl { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.03em; }
.radio-card__nota { margin: 12px 0 0; font-size: 12px; color: var(--text-mute); font-style: italic; }

/* ── Pills ─────────────────────────────────────────────────────────── */
.pill {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.4;
}
.pill-on { background: #dcfce7; color: #166534; }
.pill-off { background: #fef3c7; color: #92400e; }
.pill-neutral { background: var(--surface-3); color: var(--text-2); }

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--text-2); letter-spacing: -0.005em; }
.card-lead { color: var(--text-3); font-size: 13px; margin: 0 0 16px; }
.cards-grid { display: grid; gap: 16px; margin-bottom: 16px; }
.cards-2 { grid-template-columns: repeat(2, 1fr); }
.cards-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) {
  .cards-2 { grid-template-columns: 1fr; }
  .cards-4 { grid-template-columns: repeat(2, 1fr); }
}

.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-lbl { font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.kpi-val { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ── Dashboard head ────────────────────────────────────────────────── */
.dash { max-width: 1400px; margin: 0 auto; padding: 24px; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 24px; flex-wrap: wrap; }
.dash-title h1 { font-size: 22px; margin: 4px 0 4px; letter-spacing: -0.02em; }
.dash-sub { color: var(--text-3); font-size: 13px; margin: 0; display: flex; gap: 10px; align-items: center; }
.back-link { color: var(--text-3); font-size: 12px; text-decoration: none; }
.back-link:hover { color: var(--blue); }

.dash-filtros { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.dash-filtros label { display: grid; gap: 4px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.dash-filtros input, .dash-filtros select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font-family: var(--font);
  font-size: 13px;
}
.quickrange { display: flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.quickrange button {
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--border);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--font);
  font-weight: 500;
}
.quickrange button:last-child { border-right: 0; }
.quickrange button:hover { background: var(--surface-3); color: var(--text); }
.quickrange button.active { background: var(--blue); color: white; }

/* ── Tabs ──────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs button {
  background: transparent; border: 0;
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-body { display: block; }

/* ── Tables ────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-3);
  color: var(--text-2);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-strong);
}
.tbl tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl-scroll { display: block; max-height: 480px; overflow-y: auto; }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
.neu { color: var(--neu); }
.cell-wide { max-width: 440px; }

/* ── Hallazgos ─────────────────────────────────────────────────────── */
.hallazgos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.hall-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.hall-time { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.hall-item ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-2); }
.hall-item li { margin: 4px 0; }
.hall-detail p { margin: 6px 0; font-size: 13.5px; color: var(--text-2); }
.hall-resumen { font-size: 13px; color: var(--text-3); margin-top: 8px !important; line-height: 1.6; }
.mini-dist { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.mini-dist-item { font-size: 11px; color: var(--text-3); }
.mini-dist-item em { color: var(--text-mute); font-style: normal; }
.mini-dist-item strong { color: var(--text-2); }

.empty { color: var(--text-mute); font-size: 13px; font-style: italic; padding: 20px 0; text-align: center; }

/* ── Heatmap ───────────────────────────────────────────────────────── */
.heatmap {
  display: grid;
  gap: 2px;
  overflow-x: auto;
  padding: 4px 0;
}
.heatmap-row { display: grid; grid-template-columns: 100px repeat(24, minmax(24px, 1fr)); gap: 2px; align-items: center; }
.heatmap-row.head { font-size: 10px; color: var(--text-mute); font-weight: 600; }
.heatmap-cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--surface-3); position: relative; }
.heatmap-cell.h0 { background: #f1f5f9; }
.heatmap-cell.h1 { background: #dbeafe; }
.heatmap-cell.h2 { background: #93c5fd; }
.heatmap-cell.h3 { background: #3b82f6; }
.heatmap-cell.h4 { background: #1d4ed8; }
.heatmap-row .lbl { font-size: 12px; color: var(--text-2); text-align: right; padding-right: 8px; }

/* ── Comparador ────────────────────────────────────────────────────── */
.cmp-controls { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.cmp-controls label { display: grid; gap: 4px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.cmp-controls select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font-family: var(--font);
  font-size: 13px;
  min-width: 200px;
}
.cmp-totales { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
.cmp-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; display: grid; gap: 4px; }
.cmp-name { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.cmp-num { font-size: 18px; font-weight: 700; color: var(--text); }
.cmp-sent { font-size: 12px; color: var(--text-3); }
.cmp-sent b { color: var(--text-2); }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-inline label { display: grid; gap: 4px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.form-inline input, .form-inline select {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font-family: var(--font);
  font-size: 13.5px;
}
.hint { color: var(--text-mute); font-size: 12px; margin: 12px 0 0; }

/* ── Chart wrappers (fix loop de estiramiento) ─────────────────── */
.chart-wrap { position: relative; width: 100%; height: 260px; overflow: hidden; }
.chart-wrap.short { height: 200px; }
.chart-wrap.tall { height: 380px; }
.chart-wrap canvas { display: block; }
