:root {
  --bg: #f4f6fa;
  --bg-2: #eceff5;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --panel-3: #eef2f8;
  --line: #e2e7ef;
  --line-soft: #edf1f6;
  --text: #16202e;
  --muted: #5b6b80;
  --muted-2: #8592a4;
  --accent: #f4611f;
  --accent-2: #d9600f;
  --pos: #1f9d6b;
  --neg: #d94b4b;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 16px 40px rgba(23, 40, 70, 0.10);
  --shadow-sm: 0 4px 14px rgba(23, 40, 70, 0.07);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 520px at 88% -14%, rgba(244, 97, 31, 0.09) 0%, transparent 55%),
    radial-gradient(900px 500px at 3% -8%, rgba(244, 97, 31, 0.04) 0%, transparent 52%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.1px;
}

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 30px 22px 70px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.muted { color: var(--muted); }

/* ============ Header ============ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 26px;
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; flex-direction: column; line-height: 1; }
.brand-mark { font-size: 25px; font-weight: 900; letter-spacing: -0.8px; }
.brand-accent { color: var(--accent); }
.brand-tld { color: var(--muted); font-weight: 700; }
.brand-sub { font-size: 10.5px; color: var(--muted-2); margin-top: 5px; letter-spacing: 2.5px; text-transform: uppercase; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 18px; }
.day-badge {
  display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1;
  padding-right: 18px; border-right: 1px solid var(--line);
}
.day-badge-num { font-size: 15px; font-weight: 700; }
.day-badge-num strong { color: var(--accent-2); }
.day-badge-lbl { font-size: 10px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 1.5px; margin-top: 2px; }
.header-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.header-meta strong { color: var(--text); font-weight: 600; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pos); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: pulse 1.9s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.5); }
  70% { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* ============ Study head ============ */
.study-head { margin-top: 6px; }
.eyebrow {
  color: var(--accent-2); font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  font-size: 11.5px; margin: 0 0 10px; display: inline-flex; align-items: center; gap: 7px;
}
.pin { font-size: 9px; }
.study-head h1 { margin: 0 0 12px; font-size: 33px; line-height: 1.1; letter-spacing: -1px; font-weight: 800; }
.question { margin: 0; color: var(--muted); font-style: italic; max-width: 620px; font-size: 15px; }

/* ============ Panels ============ */
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 140%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.panel-head h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; }
.panel-head p { margin: 0; font-size: 13px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 13px; border-radius: 7px; cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--panel-3); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============ KPIs ============ */
.kpis {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 16px;
}
.kpi-skeleton { color: var(--muted); padding: 20px; }
.kpi {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 130%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  min-height: 118px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.kpi-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted-2); font-weight: 600; }
.kpi-main { display: flex; align-items: center; gap: 14px; }
.kpi-photo { width: 52px; height: 52px; border-radius: 14px; object-fit: cover; border: 2px solid var(--c, var(--line)); flex-shrink: 0; }
.kpi-value { font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.kpi-value small { font-size: 16px; font-weight: 700; color: var(--muted); }
.kpi-name { font-size: 15px; font-weight: 700; line-height: 1.15; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi-foot { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi.kpi-lead { background: linear-gradient(135deg, rgba(244, 97, 31, 0.10) 0%, var(--panel) 62%); border-color: rgba(244, 97, 31, 0.30); }
.kpi-chip {
  align-self: flex-start; font-size: 10.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; color: #fff;
}

/* Delta pills */
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12.5px; padding: 2px 8px; border-radius: 999px; }
.delta.up { color: var(--pos); background: rgba(52, 211, 153, 0.12); }
.delta.down { color: var(--neg); background: rgba(248, 113, 113, 0.12); }
.delta.flat { color: var(--muted); background: rgba(138, 151, 171, 0.12); }

/* ============ Grid 2 ============ */
.grid-2 { display: grid; grid-template-columns: 1.7fr 1fr; gap: 20px; }
.chart-holder { position: relative; height: 320px; }
.chart-holder.tall { height: 380px; }

/* Donut */
.donut-wrap { display: flex; flex-direction: column; gap: 18px; }
.donut-holder { position: relative; height: 230px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.donut-center-num { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.donut-center-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted-2); font-weight: 600; margin-top: 2px; }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.donut-legend li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.dl-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.dl-name { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-val { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============ Ranking table ============ */
.rank-table { display: flex; flex-direction: column; }
.rank-row {
  display: grid;
  grid-template-columns: 34px 46px 1fr 116px 92px 76px;
  align-items: center;
  gap: 14px;
  padding: 13px 8px;
  border-top: 1px solid var(--line-soft);
  transition: background 0.15s ease;
}
.rank-row:hover { background: rgba(23, 40, 70, 0.025); }
.rank-row.is-leader { background: linear-gradient(90deg, rgba(244, 97, 31, 0.07), transparent 42%); }
.rank-pos { font-size: 15px; font-weight: 800; color: var(--muted-2); text-align: center; }
.rank-row.is-leader .rank-pos { color: var(--accent-2); }
.rank-photo { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; border: 2px solid var(--c); }
.rank-id .rank-name { font-weight: 700; font-size: 14.5px; line-height: 1.15; }
.rank-party { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: #fff; padding: 2px 8px; border-radius: 999px; margin-top: 5px; }
.rank-barwrap { display: flex; flex-direction: column; gap: 5px; }
.rank-barrow { display: flex; align-items: center; gap: 9px; }
.rank-track { flex: 1; height: 9px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 6px; transition: width 0.7s cubic-bezier(.22,1,.36,1); }
.rank-pct { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 58px; text-align: right; }
.spark { display: block; }
.rank-mom { text-align: right; }
.rank-head {
  display: grid;
  grid-template-columns: 34px 46px 1fr 116px 92px 76px;
  gap: 14px; padding: 0 8px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted-2); font-weight: 600;
}
.rank-head .th-r { text-align: right; }
.rank-head .th-c { text-align: center; }
.rank-note { font-size: 12px; margin: 14px 0 0; }

/* ============ Methodology ============ */
.methodology h3 { margin: 0 0 16px; font-size: 17px; }
.method-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.method-item {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 16px; text-align: center;
}
.method-num { display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.method-lbl { display: block; font-size: 10.5px; color: var(--muted-2); margin-top: 4px; text-transform: uppercase; letter-spacing: 1px; }
.method-desc { line-height: 1.65; margin: 0 0 12px; font-size: 13.5px; }
.method-desc strong { color: var(--text); }
.disclaimer {
  background: #fff6ec;
  border: 1px solid #ffd9b8;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: #9a4b12;
  font-size: 12.5px;
}
.disclaimer strong { color: #7a3a0c; }

/* ============ Footer ============ */
.site-footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  max-width: 1240px; margin: 0 auto; padding: 26px 22px 44px;
  color: var(--muted-2); font-size: 12.5px;
  border-top: 1px solid var(--line);
}

/* ============ Responsive ============ */
@media (max-width: 940px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi.kpi-lead { grid-column: 1 / -1; }
}

/* ============ Login (auth) ============ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 30px 26px;
}
.auth-brand { display: flex; flex-direction: column; line-height: 1; margin-bottom: 22px; }
.auth-title { font-size: 21px; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.4px; }
.auth-lead { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
.auth-error {
  background: #fdecec;
  border: 1px solid #f4c3c3;
  color: #b23b3b;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.2px; }
.auth-field input {
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(244, 97, 31, 0.14);
  background: #fff;
}
.auth-btn {
  margin-top: 6px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.auth-btn:hover { filter: brightness(1.05); }
.auth-btn:active { transform: translateY(1px); }
.auth-foot { text-align: center; color: var(--muted-2); font-size: 11.5px; margin: 20px 0 0; }

/* ============ Header: usuario / logout ============ */
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px;
}
.user-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); }
.logout-link {
  font-size: 13px; font-weight: 600; color: var(--accent-2);
  text-decoration: none; padding: 7px 12px; border-radius: 999px;
  border: 1px solid transparent; transition: background 0.15s, border-color 0.15s;
}
.logout-link:hover { background: #fff2ea; border-color: #f6d3bf; }

/* ============ Portal de encuestas ============ */
.survey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}
.survey-card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 22px 20px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.survey-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: #f6c9b3;
}
.survey-card-top { display: flex; align-items: center; justify-content: space-between; }
.survey-tag {
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--accent-2); background: #fff2ea; border: 1px solid #f8d6c3;
  padding: 4px 10px; border-radius: 999px;
}
.survey-day { font-size: 12px; font-weight: 600; color: var(--muted); }
.survey-title { font-size: 17px; font-weight: 800; margin: 0; letter-spacing: -0.3px; line-height: 1.25; }
.survey-q { font-size: 13px; color: var(--muted); margin: 0; font-style: italic; }
.survey-leader {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.survey-leader-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.survey-leader-txt { font-size: 13px; color: var(--text); }
.survey-leader-pct { font-weight: 800; margin-left: 4px; color: var(--accent-2); }
.survey-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted-2); }
.survey-cta { margin-top: 2px; font-size: 13.5px; font-weight: 700; color: var(--accent-2); }

/* Tarjeta de captacion (encuesta binaria si/no) */
.survey-card--static { cursor: default; }
.survey-card--static:hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--line); }
.survey-state { font-size: 11.5px; font-weight: 700; letter-spacing: 0.2px; }
.survey-state--open { color: var(--pos); }
.survey-state--closed { color: var(--muted-2); }
.binary-bar {
  display: flex; height: 12px; border-radius: 999px; overflow: hidden;
  background: var(--panel-3); border: 1px solid var(--line-soft);
}
.binary-si { background: var(--pos); }
.binary-no { background: var(--neg); }
.binary-legend { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text); }
.binary-legend em { color: var(--muted-2); font-style: normal; }
.binary-legend b { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot-si { background: var(--pos); }
.dot-no { background: var(--neg); }
.binary-empty {
  font-size: 12.5px; color: var(--muted); background: var(--panel-2);
  border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px;
}

/* Pagina de tracking de conocimiento */
.grid-1 { display: grid; grid-template-columns: 1fr; gap: 20px; }
.survey-state--wait { color: var(--accent-2); }
.binary-legend--head { gap: 16px; }
.binary-legend--head span { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; }
.table-wrap { overflow-x: auto; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.hist-table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted-2); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.hist-table th.num, .hist-table td.num { text-align: right; }
.hist-table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); color: var(--text); }
.hist-table tbody tr:last-child td { border-bottom: none; }
.hist-table tbody tr:hover td { background: rgba(23, 40, 70, 0.025); }
.hist-table tbody tr.row-live td { background: #fff6ec; }
.hist-table tbody tr.row-live td:first-child { color: var(--accent-2); font-weight: 700; }

@media (max-width: 680px) {
  .survey-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  /* Historial: tabla -> tarjetas apiladas para no desbordar en celular */
  .table-wrap { overflow-x: visible; }
  .hist-table { border-collapse: separate; border-spacing: 0; }
  .hist-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .hist-table tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel);
    padding: 6px 12px;
  }
  .hist-table tbody tr.row-live { background: #fff6ec; border-color: #f6d3bf; }
  .hist-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 7px 0 !important;
    border-bottom: 1px solid var(--line-soft) !important;
    text-align: right;
  }
  .hist-table tbody tr td:last-child { border-bottom: none !important; }
  .hist-table tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: var(--muted-2);
    text-align: left;
  }
  .hist-table tbody tr.hist-empty td { display: block; text-align: center; }
  .hist-table tbody tr.hist-empty td::before { content: none; }
}
@media (max-width: 680px) {
  .study-head h1 { font-size: 25px; }
  .kpis { grid-template-columns: 1fr; }
  .method-grid { grid-template-columns: 1fr 1fr; }
  .rank-head { display: none; }
  .rank-row {
    grid-template-columns: 30px 42px 1fr 70px;
    grid-template-areas: "pos photo id pct";
    row-gap: 8px;
  }
  .rank-pos { grid-area: pos; }
  .rank-photo { grid-area: photo; }
  .rank-id { grid-area: id; }
  .rank-pct { grid-area: pct; }
  .rank-barwrap, .rank-mom { display: none; }
}
