@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;800&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --bg:             #0F172A;
  --surface:        #1E293B;
  --border:         #334155;
  --accent:         #38BDF8;
  --accent-confirm: #4ADE80;
  --text:           #F1F5F9;
  --text-muted:     #94A3B8;
  --radius:         12px;
}

body {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

main {
  max-width: 680px;
  margin: 48px auto;
  padding: 0 24px;
}

h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: none;
  color: var(--text);
  margin: 0 0 4px 0;
  padding: 0;
  border: none;
  line-height: 1;
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

section p,
section > label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

select {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

select:focus {
  border-color: var(--accent);
  outline: none;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

fieldset legend {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.campo-grupo {
  margin-bottom: 12px;
}

.campo-grupo label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}

.campo-grupo input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 0;
}

.campo-grupo input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}

ul#criterios-lista {
  list-style: none;
  padding: 0;
  margin: 0;
}

ul#criterios-lista li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

ul#criterios-lista li:last-child {
  border-bottom: none;
}

ul#criterios-lista input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 3px;
}

ul#criterios-lista label {
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.5;
}

#aviso-sugerencia {
  font-size: 13px;
  color: var(--accent);
  min-height: 20px;
  margin-top: 8px;
}

button {
  display: inline-block;
  padding: 11px 24px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
}

#btn-sugerir {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
  margin-right: 12px;
}

#btn-sugerir:hover {
  background: var(--accent);
  color: var(--bg);
}

#btn-copiar {
  background: var(--accent);
  color: var(--bg);
}

#btn-copiar:hover {
  opacity: 0.85;
}

.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.3), transparent);
  animation: shimmer 0.8s ease forwards;
}

@keyframes shimmer {
  from { transform: translateX(0); }
  to   { transform: translateX(200%); }
}

h1 .word-docen { color: #F1F5F9; }
h1 .word-ce    { color: #38BDF8; }

#seccion-progreso {
  padding: 14px 24px;
}

#progreso-porcentaje {
  color: var(--accent);
  font-weight: 700;
}

#progreso-conteo {
  color: var(--text-muted);
}

/* ===================================================
   POPUP DE AYUDA
   Estructura: fondo + contenedor fijo (flex column)
   con zona de scroll interna + pie fijo
   =================================================== */

.popup-fondo {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.85);
  z-index: 9998;
}

/* Estado inicial: oculto. JS lo abre con display:flex */
.popup-ayuda {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 520px;
  width: 90%;
  max-height: 80vh;
  max-height: 80dvh;
  overflow: hidden;
  z-index: 9999;
}

/* Zona scrollable: todo el contenido menos el botón de cierre */
.popup-ayuda-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 32px 32px 16px 32px;
}

/* Pie fijo: siempre visible independientemente del scroll */
.popup-pie {
  flex: 0 0 auto;
  padding: 0 32px 28px 32px;
}

.popup-titulo {
  color: var(--accent);
  margin: 0 0 4px 0;
  font-size: 18px;
}

.popup-subtitulo {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 16px 0;
}

.popup-separador {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.popup-paso {
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.popup-lista {
  list-style: none;
  padding: 0;
  margin: 0 0 6px 0;
}

.popup-lista li {
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  padding: 3px 0 3px 16px;
  position: relative;
}

.popup-lista li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

.popup-ejemplo {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Courier New', monospace;
  margin: 8px 0 4px 0;
}

.popup-aviso {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.popup-btn-cerrar {
  background: var(--accent);
  color: var(--bg);
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.popup-btn-cerrar:hover {
  opacity: 0.85;
}

/* ===================================================
   RESPONSIVE — MOBILE FIRST
   Breakpoints:
     ≤ 480px   → móvil pequeño (iPhone SE, Galaxy A series)
     481–768px → móvil grande / tablet portrait (iPhone Pro Max, iPad mini)
   El CSS base ya está optimizado para ≥ 769px.
   =================================================== */

/* --- Tablet portrait y móvil grande (≤ 768px) --- */
@media (max-width: 768px) {

  main {
    margin: 24px auto;
    padding: 0 16px;
  }

  h1 {
    font-size: 26px;
    margin-bottom: 16px;
  }

  section {
    padding: 16px 18px;
    margin-bottom: 12px;
  }

  /* Botones en columna — en línea se salen en pantallas de 390px */
  #btn-sugerir,
  #btn-copiar {
    display: block;
    width: 100%;
    margin-right: 0;
    margin-bottom: 10px;
    padding: 14px;
    font-size: 14px;
  }

  /* 16px mínimo para evitar zoom automático de Safari iOS al hacer foco */
  select,
  .campo-grupo input[type="text"] {
    font-size: 16px;
    padding: 12px 14px;
  }

  ul#criterios-lista input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 1px;
  }

  ul#criterios-lista li {
    padding: 12px 0;
    gap: 12px;
  }

  ul#criterios-lista label {
    font-size: 13px;
  }

  .popup-ayuda {
    width: 95%;
    max-height: 85vh;
    max-height: 85dvh;
  }

  .popup-ayuda-scroll {
    padding: 24px 20px 12px 20px;
  }

  .popup-pie {
    padding: 0 20px 20px 20px;
  }

  .popup-titulo {
    font-size: 16px;
  }

  .popup-paso,
  .popup-lista li {
    font-size: 13px;
  }

  .popup-ejemplo {
    font-size: 11px;
    padding: 10px 12px;
  }
}

/* --- Móvil pequeño (≤ 480px) --- */
@media (max-width: 480px) {

  main {
    margin: 16px auto;
    padding: 0 12px;
  }

  h1 {
    font-size: 22px;
  }

  section {
    padding: 14px 14px;
    border-radius: 10px;
  }

  fieldset legend,
  section p,
  section > label,
  .campo-grupo label {
    font-size: 10px;
  }

  /* Área táctil mínima Apple HIG / Material Design: 44–48px */
  #btn-sugerir,
  #btn-copiar {
    padding: 16px;
    font-size: 15px;
  }

  /* Popup a pantalla completa en móvil pequeño */
  .popup-ayuda {
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 0;
  }

  .popup-ayuda-scroll {
    padding: 20px 16px 10px 16px;
  }

  .popup-pie {
    padding: 0 16px 16px 16px;
  }

  #seccion-progreso {
    padding: 12px 14px;
    font-size: 13px;
  }
}