@import "tailwindcss";

/* ── Tokens ── */
:root {
  /* ── Marca RE ── */
  --color-re-teal:           #43BBC8;
  --color-re-dark:           #494F4F;
  --color-re-orange:         #F8AD13;
  --color-re-orange-intense: #EE761A;
  --color-re-light:          #E7E6E5;
  --color-re-white:          #FFFFFF;

  /* ── Sistema (primario = teal RE) ── */
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-primary: #43BBC8;
  --color-primary-hover: #3DAAB6;
  --color-primary-light: #e8f8fa;
  --color-accent: #43BBC8;
  --color-error: #b91c1c;
  --color-error-bg: #fef2f2;
  --color-border: #d1d5db;
  --color-border-focus: #43BBC8;
  --color-sensitive: #fef3c7;
  --color-sensitive-border: #f59e0b;
  --radius: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* El contenido entre header y footer crece para empujar el footer al fondo */
.layout-content { flex: 1; }

/* ── Skip link ── */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 4px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { left: 4px; }

/* ── Screen reader only ── */
/* El legend/label de los widgets dentro del wizard se oculta visualmente —
   el enunciado ya se muestra una sola vez en .wizard-prompt-block. Se deja
   el texto accesible (nombre del fieldset/label) en vez de quitarlo. */
.sr-only,
.wizard-answer-area .question-legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Survey wrapper ── */
.survey-wrapper {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ── Survey header ── */
.survey-header {
  padding: 32px 0 16px;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 16px;
}
.survey-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--color-text);
}
.survey-anon-note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* ── Progress bar ── */
.survey-progress-sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 8px 0;
}
.progress-bar-container {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 8px;
  position: relative;
}
.progress-bar-fill {
  height: 8px;
  background: var(--color-primary);
  border-radius: 4px;
  transition: width 0.3s ease;
  flex-shrink: 0;
}
.progress-bar-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  position: absolute;
  right: 0;
  top: -18px;
}

/* ── Sections ── */
.survey-section {
  margin-top: 32px;
}
.section-header { margin-bottom: 16px; }
.section-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 6px;
  padding: 10px 14px;
  background: var(--color-primary-light);
  border-left: 4px solid var(--color-primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--color-primary-hover);
}
/* ── Question wrapper ── */
.question-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}

/* ── Fieldset (radio/checkbox/rating) ── */
.question-fieldset {
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}
.question-legend {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
  line-height: 1.4;
}
.required-mark { color: var(--color-error); }
.q-code {
  font-size: 0.78em;
  font-weight: 700;
  color: #7A8FA0;
  letter-spacing: 0.02em;
}

/* ── Options list ── */
.options-list { display: flex; flex-direction: column; gap: 8px; }
.option-item {}
.option-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.4;
}
.option-label:hover { border-color: var(--color-accent); background: var(--color-primary-light); }
.option-label:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  font-weight: 500;
}
.option-disabled { opacity: 0.45; cursor: not-allowed; }
.option-disabled:hover { border-color: var(--color-border); background: transparent; }
.option-input {
  margin-top: 2px;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.option-input:disabled { cursor: not-allowed; }
.option-text { flex: 1; }

/* ── Max select hint ── */
.max-select-hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin: 0 0 10px;
}

/* ── Rating ── */
.rating-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.rating-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.rating-steps {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.rating-step { display: flex; }
.rating-input { /* hidden via sr-only */ }
.rating-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  color: var(--color-text);
}
.rating-step:has(input:checked) .rating-dot {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.rating-step:has(input:focus-visible) .rating-dot {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}
.rating-step:hover .rating-dot { border-color: var(--color-accent); background: var(--color-primary-light); }
.rating-step:has(input:checked):hover .rating-dot { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: #fff; }

/* ── Text short (single-line input) ── */
.text-short-input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.15s;
  color: var(--color-text);
  background: var(--color-surface);
}
.text-short-input:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* ── Barrio autocomplete ── */
.barrio-autocomplete-wrapper { position: relative; }
.barrio-autocomplete-list {
  /* position: fixed + top/left/width set by JS via getBoundingClientRect()
     so the list escapes any overflow:auto ancestor (wizard-answer-area) */
  position: fixed;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-focus);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
}
.barrio-autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--color-text);
  transition: background 0.1s;
}
.barrio-autocomplete-item:hover,
.barrio-autocomplete-item--active {
  background: var(--color-primary-light);
  color: #494F4F;
}

/* ── Textarea ── */
.text-area {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.15s;
  color: var(--color-text);
  background: var(--color-surface);
}
.text-area:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* ── Field error ── */
.field-error {
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-error::before { content: '⚠'; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
  text-decoration: none;
}
.btn:focus-visible {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary {
  background: transparent;
  color: #494F4F;
  border-color: var(--color-primary);
}
.btn-secondary:hover { background: var(--color-primary-light); }

/* ── Form footer ── */
.form-footer {
  padding: 24px 0 16px;
  display: flex;
  justify-content: flex-end;
}

/* ── Summary ── */
.summary-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 80px;
}
.summary-header { margin-bottom: 28px; }
.summary-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 8px; }
.summary-subtitle { color: var(--color-text-muted); margin: 0 0 12px; }
.summary-note {
  font-size: 0.875rem;
  background: var(--color-sensitive);
  border: 1px solid var(--color-sensitive-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0;
}
.summary-section-heading {
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 12px;
  background: var(--color-primary-light);
  border-left: 4px solid var(--color-primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 24px 0 8px;
  color: var(--color-primary-hover);
}
.summary-list { margin: 0; padding: 0; }
.summary-item {
  border-bottom: 1px solid var(--color-border);
  padding: 12px 0;
}
.summary-question {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.summary-code {
  font-weight: 700;
  color: #494F4F;
  margin-right: 4px;
}
.summary-answer {
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text);
  margin: 0;
}
.summary-actions {
  padding-top: 28px;
  display: flex;
  justify-content: flex-start;
}

/* ── Geo select widget ── */
.geo-select-wrapper { display: flex; flex-direction: column; gap: 16px; }
.geo-select-group { display: flex; flex-direction: column; gap: 8px; }
.geo-select {
  display: block; width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border); border-radius: var(--radius);
  font-size: 1rem; font-family: inherit; background: var(--color-surface);
  color: var(--color-text); cursor: pointer; appearance: auto;
  transition: border-color 0.15s;
}
.geo-select:focus { outline: none; border-color: var(--color-border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.geo-select-disabled { opacity: 0.5; cursor: not-allowed; background: #f3f4f6; }
.geo-label-disabled { color: var(--color-text-muted); }
.geo-disabled-hint { font-size: 0.8125rem; font-weight: 400; color: var(--color-text-muted); }

/* ── Brand header ── */
.brand-header {
  background: var(--color-primary-light); border-left: 4px solid var(--color-primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 14px; margin: 16px 0 0;
}
.brand-text { margin: 0; font-size: 0.875rem; color: var(--color-primary-hover); line-height: 1.5; }

/* ── Consent screen ── */
.consent-container { max-width: 720px; margin: 0 auto; padding: 32px 16px 80px; }
.consent-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 24px; }
.consent-section { margin-bottom: 24px; }
.consent-section-title { font-size: 1.0625rem; font-weight: 700; margin: 0 0 10px; }
.consent-list { margin: 8px 0 0; padding-left: 20px; line-height: 1.7; display: flex; flex-direction: column; gap: 8px; }
.consent-anon-box {
  background: var(--color-sensitive); border: 1px solid var(--color-sensitive-border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 24px;
  font-size: 0.9375rem; line-height: 1.6;
}
.consent-checkboxes { margin-bottom: 28px; display: flex; flex-direction: column; gap: 14px; }
.consent-checkbox-label {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border: 1.5px solid var(--color-border); border-radius: var(--radius);
  cursor: pointer; transition: border-color 0.15s, background 0.15s; line-height: 1.5;
}
.consent-checkbox-label:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-light); }
.consent-checkbox-input { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; accent-color: var(--color-primary); cursor: pointer; }
.consent-checkbox-text { flex: 1; }
.consent-required-badge { display: inline-block; font-size: 0.75rem; font-weight: 600; color: #494F4F; background: var(--color-primary-light); padding: 1px 6px; border-radius: 4px; }
.consent-optional-badge { display: inline-block; font-size: 0.75rem; font-weight: 600; color: var(--color-text-muted); background: #f3f4f6; padding: 1px 6px; border-radius: 4px; }
.consent-footer { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.consent-required-hint { margin: 0; font-size: 0.875rem; color: var(--color-text-muted); }
.btn-disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Thank you / error screens ── */
.thank-you-container, .error-container { max-width: 560px; margin: 80px auto; padding: 0 16px; }
.thank-you-title, .error-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 16px; }
.thank-you-body { color: var(--color-text-muted); line-height: 1.7; margin: 0 0 12px; }

/* ── No survey state ── */
.no-survey {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
  padding: 0 16px;
}
.no-survey-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 12px; }
.no-survey-hint {
  font-size: 0.875rem;
  background: #f3f4f6;
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: left;
  font-family: 'Courier New', monospace;
  margin-top: 16px;
}

/* ══════════════════════════════════════════════════════════════
   WIZARD (4D) — layout de altura estable (UX 1+2+3)
   1) viewport estable: enunciado anclado en el tercio superior, no centrado
   2) header (progreso) y footer (Anterior/Siguiente) fijos, fuera del área
      que cambia de tamaño — nunca "saltan" entre pantallas
   3) área de respuesta con altura máxima + scroll interno + fade inferior
   ══════════════════════════════════════════════════════════════ */
.wizard-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 160px); /* deja lugar al header/footer de marca (layout.tsx) */
}

.wizard-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 0;
}
.wizard-topbar-brand {
  margin: 0 0 8px;
  padding: 0;
  background: transparent;
  border-left: none;
}

/* Stage: altura fija, no auto-crece con el contenido de la pregunta actual. */
.wizard-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 48px; /* ancla el enunciado en el tercio superior, no centrado vertical */
}

.wizard-section-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  text-align: left;
}
.wizard-section-number {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #494F4F;
  margin: 0 0 8px;
}
.wizard-section-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--color-text);
}
.wizard-section-desc {
  font-size: 1.0625rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: 480px;
  margin: 0;
}

/* Enunciado: bloque con altura reservada constante, mismo lugar pantalla tras pantalla. */
.wizard-prompt-block {
  min-height: 116px;
  flex-shrink: 0;
  margin-bottom: 20px;
}
.wizard-instance-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary-hover);
  background: var(--color-primary-light);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.wizard-prompt-code {
  display: block;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #7A8FA0;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}
.wizard-prompt-text {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.35;
  margin: 0 0 8px;
}
.wizard-prompt-hint {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* Área de respuesta: altura máxima + scroll interno + fade inferior cuando hay más abajo.
   flex: 0 1 auto (NO flex:1) — mide según su contenido, nunca se estira a llenar el alto
   disponible. Si creciera con flex:1, una pregunta corta (3 opciones) dejaría la caja con
   espacio vacío abajo y el fade ::after (sticky bottom:0) quedaría flotando justo después
   del contenido real, lejos del borde inferior visual de la caja — en vez de pegado a él. */
.wizard-answer-area {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 480px;
  overflow-y: auto;
  padding-bottom: 8px;
}
.wizard-answer-area.has-overflow { padding-bottom: 44px; }
/* El fade SOLO se pinta cuando .wizard-answer-area mide overflow real
   (clase has-overflow agregada por JS — ver wizard-form.tsx). CSS no tiene
   forma de detectar scrollHeight > clientHeight por sí solo: un ::after
   incondicional (o un mask-image fijo) se pinta igual sobre el final de la
   caja aunque el contenido entre completo, mostrando una franja/degradado
   fantasma en preguntas cortas. */
.wizard-answer-area.has-overflow::after {
  content: '';
  position: sticky;
  bottom: 0;
  display: block;
  height: 28px;
  margin-top: -28px;
  background: linear-gradient(to bottom, transparent, var(--color-surface) 75%);
  pointer-events: none;
}

.wizard-bottombar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 16px 0;
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.wizard-bottombar-hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .wizard-prompt-text { font-size: 1.1875rem; }
  .wizard-section-title { font-size: 1.5rem; }
  .wizard-answer-area { max-height: 400px; }
  /* column-reverse: el botón primario (Siguiente/Enviar) queda arriba —
     el pulgar llega más fácil al centro de la pantalla que a la base. */
  .wizard-bottombar { flex-direction: column-reverse; }
  .wizard-bottombar .btn { width: 100%; }
  .wizard-bottombar-hint { order: 3; }
}

/* ── Loading skeleton ── */
.loading-wrapper {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px;
}
.skeleton { background: #e5e7eb; border-radius: var(--radius); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Focus visible (global override) ── */
:focus-visible {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}

/* ── Mobile-first responsive ── */
@media (max-width: 480px) {
  .survey-title { font-size: 1.25rem; }
  .rating-wrapper { flex-direction: column; align-items: flex-start; }
  .form-footer { justify-content: stretch; }
  .btn { width: 100%; }
}

/* ── Survey header (marca RE) ── */
.survey-header-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.survey-header-logo { display: block; height: 48px; width: auto; flex-shrink: 0; }
.survey-header-title {
  color: var(--color-re-white);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}

/* ── Survey footer ── */
.survey-footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  margin-top: 40px;
}
.survey-footer-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.survey-footer-label {
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
  white-space: nowrap;
}
.survey-footer-logo { height: 32px; width: auto; display: block; }

/* ══════════════════════════════════════════════════════════════
   DASHBOARD — tema claro (marca Re)
   Fondo: #E7E6E5 · Widgets: #FFFFFF · Teal: #43BBC8
   ══════════════════════════════════════════════════════════════ */
.db-page {
  display: flex; min-height: 100vh;
  background: #E7E6E5; color: #494F4F;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.db-main { flex: 1; padding: 24px; overflow-x: hidden; }
.db-page-header { margin-bottom: 20px; }
.db-page-title { font-size: 1.375rem; font-weight: 700; color: #494F4F; margin: 0 0 4px; }
.db-page-subtitle { font-size: 0.8125rem; color: #6B7878; margin: 0; }
.db-active-filter { color: var(--color-re-teal); font-weight: 600; }
.db-survey-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.db-survey-link {
  font-size: 0.75rem; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  border: 1px solid rgba(67,187,200,0.3); color: #6B7878; text-decoration: none;
  transition: all 0.2s ease;
}
.db-survey-link:hover { color: #494F4F; border-color: var(--color-re-teal); }
.db-survey-link-active { background: var(--color-re-teal); color: #FFFFFF; border-color: var(--color-re-teal); }
.db-section { margin-bottom: 16px; }
.db-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}

/* ── Widget shell ── */
.db-widget {
  background: #FFFFFF;
  border: 1px solid rgba(67,187,200,0.2);
  border-radius: 10px;
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}
.db-widget:hover { box-shadow: 0 0 20px rgba(67,187,200,0.18); }
.db-widget-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px 8px;
}
.db-widget-title { font-size: 0.875rem; font-weight: 600; color: #494F4F; margin: 0; }
.db-widget-n { font-size: 0.75rem; color: #6B7878; }
.db-widget-body { padding: 0 16px 16px; }

/* ── Suppressed / loading states ── */
.db-suppressed {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100px; text-align: center; color: #6B7878; gap: 6px;
}
.db-suppressed-icon { font-size: 1.5rem; }
.db-suppressed-hint { font-size: 0.75rem; color: #9CA8A8; }
.db-suppressed-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: #9CA8A8;
}
.db-skeleton-block { background: rgba(73,79,79,0.08); border-radius: 6px; animation: pulse 1.4s ease-in-out infinite; }
.db-error { color: #ef4444; font-size: 0.875rem; padding: 12px; }
.db-loading-page { padding: 24px; background: #E7E6E5; min-height: 100vh; }

/* ── KPI row ── */
.db-kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  padding: 0;
}
.db-kpi-card {
  background: #FFFFFF; border: 1px solid rgba(67,187,200,0.2);
  border-radius: 10px; padding: 16px; text-align: center;
  display: flex; flex-direction: column; gap: 4px;
  transition: box-shadow 0.3s;
}
.db-kpi-card:hover { box-shadow: 0 0 20px rgba(67,187,200,0.18); }
/* Título de KPI: mayúsculas, bold, siempre visible */
.db-kpi-title { font-size: 0.8125rem; font-weight: 700; color: #494F4F; text-transform: uppercase; letter-spacing: 0.04em; }
/* Subtítulo de KPI: código de pregunta + descripción */
.db-kpi-subtitle { font-size: 0.6875rem; color: #8A9A9A; font-weight: 400; line-height: 1.4; margin-bottom: 4px; }
.db-kpi-value {
  font-size: 2rem; font-weight: 700; color: var(--color-re-teal);
  font-variant-numeric: tabular-nums; margin-top: 4px;
}
.db-kpi-value-suppressed { font-size: 1.25rem; color: #9CA8A8; }
.db-kpi-note { font-size: 0.75rem; color: #6B7878; }
.db-kpi-suppressed-block { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 8px; }
/* Compat — se puede quitar si ya no se usa */
.db-kpi-label { font-size: 0.8125rem; color: #494F4F; }
.db-kpi-sub { font-size: 0.75rem; color: #6B7878; }

/* Subtítulo de widget-shell */
.db-widget-title-group { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.db-widget-subtitle { font-size: 0.75rem; color: #8A9A9A; font-weight: 400; margin: 0; line-height: 1.4; }

/* ── Mapa tile ── */
.db-map-wrapper { position: relative; }
.db-map-tooltip {
  position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
  background: #E7E6E5; color: #494F4F; font-size: 0.75rem;
  padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(67,187,200,0.3);
  white-space: nowrap; z-index: 10; pointer-events: none;
}
.db-tile-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  grid-template-rows: repeat(6, 1fr); min-height: 220px;
}
.db-tile {
  border: none; border-radius: 4px; cursor: pointer; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: filter 0.15s, outline 0.15s;
  min-height: 36px;
}
.db-tile:hover { filter: brightness(1.2); }
.db-tile:focus-visible { outline: 2px solid var(--color-re-teal); outline-offset: 1px; }
.db-tile-selected { outline: 2px solid #fff; }
.db-tile-suppressed { background-image: repeating-linear-gradient(
  45deg, transparent, transparent 4px, rgba(255,255,255,0.06) 4px, rgba(255,255,255,0.06) 8px
) !important; }
.db-tile-name { font-size: 0.5rem; color: #fff; text-align: center; line-height: 1.2; font-weight: 600; }
.db-tile-pct { font-size: 0.6rem; color: rgba(255,255,255,0.85); font-weight: 700; }

/* ── Donut ── */
.db-donut-wrapper { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.db-donut-svg { width: 130px; height: 130px; flex-shrink: 0; }
.db-donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.db-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; }
.db-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.db-legend-val { margin-left: auto; font-weight: 600; color: var(--color-re-teal); }

/* ── Gauge ── */
.db-gauge-wrapper { text-align: center; }
.db-gauge-svg { width: 100%; max-width: 160px; }
.db-gauge-zona { font-size: 0.9rem; font-weight: 700; margin: 4px 0 2px; }
.db-gauge-hint { font-size: 0.7rem; color: #9CA8A8; margin: 0; }

/* ── Bar chart ── */
.db-bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.db-bar-item { display: flex; align-items: center; gap: 8px; }
.db-bar-label { font-size: 0.75rem; color: #494F4F; width: 180px; flex-shrink: 0; line-height: 1.3; }
.db-bar-track { flex: 1; background: rgba(73,79,79,0.10); border-radius: 4px; height: 14px; overflow: hidden; }
.db-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.db-bar-pct { font-size: 0.75rem; color: var(--color-re-teal); width: 40px; text-align: right; font-weight: 600; }

/* ── Heatmap / hexbin shared ── */
.db-heatmap-scroll { overflow-x: auto; }
.db-heatmap-grid { display: grid; gap: 2px; }
.db-heatmap-header {
  font-size: 0.625rem; color: #6B7878; text-align: center; padding: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.db-heatmap-rowlabel { font-size: 0.625rem; color: #6B7878; padding: 2px 4px; line-height: 1.2; }
.db-heatmap-cell {
  border-radius: 3px; min-height: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: rgba(255,255,255,0.8); transition: filter 0.15s;
}
.db-heatmap-cell:hover { filter: brightness(1.2); }
.db-hexbin-note { font-size: 0.75rem; color: #6B7878; margin-bottom: 8px; }

/* ── Pirámide ── */
.db-piramide { display: flex; flex-direction: column; gap: 6px; }
.db-piramide-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.db-piramide-row { display: flex; align-items: center; gap: 6px; }
.db-piramide-label { font-size: 0.7rem; color: #6B7878; width: 90px; flex-shrink: 0; text-align: right; }
.db-piramide-bars { flex: 1; display: flex; gap: 2px; }
.db-piramide-bar-wrap { display: flex; flex-direction: column; }
.db-piramide-bar { height: 20px; border-radius: 3px; min-width: 4px; transition: width 0.4s; }
.db-piramide-n { font-size: 0.7rem; color: #6B7878; width: 24px; text-align: right; }

/* ── Tabla riesgo ── */
.db-table-wrapper { overflow-x: auto; }
.db-table-note { font-size: 0.75rem; color: #6B7878; margin-bottom: 10px; }
.db-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.db-table th { color: #6B7878; font-weight: 600; text-align: left; padding: 8px 12px; border-bottom: 1px solid #2a3547; }
.db-table td { padding: 10px 12px; border-bottom: 1px solid #1e2d42; color: #494F4F; }
.db-table tr:last-child td { border-bottom: none; }
.db-risk-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 700; color: #fff; }

/* ── Sidebar ── */
.db-sidebar {
  width: 220px; flex-shrink: 0; background: #F0EFEE;
  border-right: 1px solid rgba(67,187,200,0.15);
  padding: 12px; transition: width 0.3s ease;
  display: flex; flex-direction: column; gap: 8px;
}
.db-sidebar-collapsed { width: 52px; }
.db-sidebar-toggle {
  background: none; border: 1px solid rgba(67,187,200,0.3);
  color: var(--color-re-teal); border-radius: 6px; padding: 6px;
  cursor: pointer; font-size: 0.75rem; white-space: nowrap;
}
.db-sidebar-content { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.db-filter-group { display: flex; flex-direction: column; gap: 4px; }
.db-filter-label { font-size: 0.75rem; font-weight: 600; color: #6B7878; text-transform: uppercase; letter-spacing: 0.05em; }
.db-filter-select {
  background: #FFFFFF; border: 1px solid #2a3547; color: #494F4F;
  border-radius: 6px; padding: 6px 8px; font-size: 0.8125rem; width: 100%;
}
.db-filter-check { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: #494F4F; cursor: pointer; }
.db-filter-check input { accent-color: var(--color-re-teal); width: 14px; height: 14px; }
.db-filter-reset {
  background: rgba(67,187,200,0.1); border: 1px solid rgba(67,187,200,0.3);
  color: var(--color-re-teal); border-radius: 6px; padding: 8px;
  cursor: pointer; font-size: 0.8125rem; font-weight: 600;
  transition: background 0.15s;
}
.db-filter-reset:hover { background: rgba(67,187,200,0.2); }

/* ── Tres miradas: tabs ── */
.db-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid rgba(67,187,200,0.15); }
.db-tab {
  padding: 10px 18px; font-size: 0.8125rem; font-weight: 600; color: #6B7878;
  cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
}
.db-tab:hover { color: #494F4F; }
.db-tab-active { color: var(--color-re-teal); border-bottom-color: var(--color-re-teal); }
.db-tab-lens { font-size: 0.6875rem; color: #5e6f8c; font-weight: 400; }

/* ── Tres miradas: intro de cada lente ── */
.db-lens-intro {
  background: #F0EFEE; border-left: 3px solid var(--color-re-teal);
  border-radius: 0 8px 8px 0; padding: 10px 14px; margin-bottom: 16px;
  font-size: 0.8125rem; color: #494F4F; line-height: 1.5;
}

/* ── Card destacada (estrella) ── */
.db-widget-star {
  border-color: var(--color-re-teal);
}
.db-widget-star .db-widget-title { color: #494F4F; }

/* ── Big stat (KPI de una sola cifra, dentro de WidgetShell) ── */
.db-big-stat { font-size: 2.375rem; font-weight: 700; color: var(--color-re-teal); line-height: 1; }
.db-big-stat-warn { color: #f0b429; }
.db-big-stat-danger { color: #f06b6b; }
.db-big-stat-sub { font-size: 0.75rem; color: #8A9A9A; margin-top: 6px; line-height: 1.4; }

/* ── Punto ciego: contraste de dos barras ── */
.db-gap-viz { display: flex; align-items: flex-end; gap: 24px; justify-content: center; padding: 8px 0 4px; }
.db-gap-col { text-align: center; }
.db-gap-bar { width: 56px; border-radius: 6px 6px 0 0; margin: 0 auto; transition: height 0.4s; }
.db-gap-val { font-size: 0.8125rem; font-weight: 700; margin-bottom: 4px; }
.db-gap-lab { font-size: 0.6875rem; color: #8A9A9A; margin-top: 6px; }
.db-gap-brecha { text-align: center; font-size: 0.75rem; color: #9A7200; margin-top: 10px; }

/* ── Placeholder (Mirada País / Humana, "próximamente") ── */
.db-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 220px; text-align: center; color: #8A9A9A;
  background: #F0EFEE; border: 1px dashed rgba(67,187,200,0.25); border-radius: 12px;
  padding: 32px 24px;
}
.db-placeholder-icon { font-size: 1.75rem; }
.db-placeholder-title { font-size: 1rem; font-weight: 600; color: #494F4F; }
.db-placeholder-hint { font-size: 0.8125rem; max-width: 420px; line-height: 1.5; }

/* ── Admin: control de respuestas (Etapa 3V) ── */
.admin-page { max-width: 1100px; margin: 0 auto; padding: 24px; }
.admin-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}
.admin-title { font-size: 1.375rem; font-weight: 700; color: var(--color-text); margin: 0 0 4px; }
.admin-subtitle { font-size: 0.8125rem; color: var(--color-text-muted); margin: 0; }
.admin-survey-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.admin-refresh {
  display: inline-block; padding: 8px 16px; border-radius: var(--radius);
  background: var(--color-primary); color: #fff; font-size: 0.8125rem;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.admin-refresh:hover { background: var(--color-primary-hover); }
.admin-survey-select {
  font-size: 0.8125rem; padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid var(--color-border); color: var(--color-text);
  background: var(--color-surface);
}
.admin-action-link {
  font-size: 0.75rem; font-weight: 600; color: var(--color-primary);
  text-decoration: none;
}
.admin-action-link:hover { text-decoration: underline; }
.admin-pagination {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-top: 16px; font-size: 0.8125rem;
}
.admin-pagination-link { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.admin-pagination-link:hover { text-decoration: underline; }
.admin-pagination-disabled { color: var(--color-text-muted); cursor: default; }
.admin-pagination-current { color: var(--color-text-muted); }
.admin-back-link {
  display: inline-block; margin-bottom: 12px; font-size: 0.8125rem;
  font-weight: 600; color: var(--color-primary); text-decoration: none;
}
.admin-back-link:hover { text-decoration: underline; }
.admin-detail-section { margin-bottom: 24px; }
.admin-detail-section-title {
  font-size: 1.0625rem; font-weight: 700; color: var(--color-text);
  margin: 0 0 10px;
}
.admin-detail-instance { margin-bottom: 14px; }
.admin-instance-badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600;
  color: var(--color-primary-hover); background: var(--color-primary-light);
  padding: 3px 10px; border-radius: 999px; margin-bottom: 6px;
}
.admin-table-wrapper {
  overflow-x: auto; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.admin-table th {
  position: sticky; top: 0; background: var(--color-re-dark); color: #fff;
  font-weight: 600; text-align: left; padding: 10px 12px; white-space: nowrap;
}
.admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--color-border); color: var(--color-text); vertical-align: top; }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr.admin-group-even { background: var(--color-bg); }
.admin-table tbody tr.admin-group-start td { border-top: 2px solid var(--color-re-dark); }
.admin-table tbody tr:hover { background: var(--color-primary-light); }
.admin-prompt { color: var(--color-text); }
.admin-row-toggle { cursor: pointer; }
.admin-toggle-icon {
  display: inline-block; width: 14px; margin-right: 4px;
  color: var(--color-text-muted); font-size: 0.7rem;
}
.admin-row-toggle-btn {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
}
.admin-nodata {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  background: var(--color-re-light); color: var(--color-re-dark);
  opacity: 0.6; font-size: 0.7rem; font-style: italic;
}
.admin-empty { padding: 24px; text-align: center; color: var(--color-text-muted); }
.admin-error { color: var(--color-error); font-weight: 600; }
.admin-error-detail {
  background: var(--color-error-bg); border-radius: var(--radius);
  padding: 12px; font-family: 'Courier New', monospace; font-size: 0.75rem;
  overflow-x: auto;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .db-kpi-row { grid-template-columns: repeat(2,1fr); }
  .db-sidebar { width: 100%; border-right: none; border-bottom: 1px solid rgba(67,187,200,0.15); }
  .db-page { flex-direction: column; }
  .admin-col-optional { display: none; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 24px;
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 28px;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}
.login-error { margin: 0; }
.login-password-wrapper { position: relative; }
.login-password-wrapper .text-short-input { padding-right: 40px; }
.login-password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  cursor: pointer;
}
.login-password-toggle:hover { color: var(--color-text); }
.login-submit {
  margin-top: 8px;
  padding: 10px 20px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.login-submit:hover:not(:disabled) { background: var(--color-primary-hover); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Admin sign-out ── */
.admin-header-actions { display: flex; align-items: center; gap: 12px; }
.admin-signout {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.admin-signout:hover { color: var(--color-error); border-color: var(--color-error); }
