/* =====================================================================
   Encuestas de diagnostico PEI - IMLI 2026
   Hoja de estilos de los formularios publicos.
   La variable --color-encuesta la define cada index.php.
   ===================================================================== */

* { box-sizing: border-box; }

:root {
    --color-encuesta: #2563eb;
    --gris-fondo: #f1f5f9;
    --gris-borde: #dbe1e8;
    --gris-texto: #475569;
    --tinta: #16202e;
    --verde: #1e8e5a;
    --verde-claro: #5bb85b;
    --ambar: #f0ad4e;
    --rojo: #d9534f;
    --neutro: #9aa5b1;
    --radio: 10px;
}

html {
    /* Deja aire bajo la barra fija al saltar a una pregunta desde el celular. */
    scroll-padding-bottom: 100px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--gris-fondo);
    color: var(--tinta);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
}

.contenedor {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ------------------------------ Cabecera ---------------------------- */
.cabecera {
    background: var(--color-encuesta);
    color: #fff;
    padding: 26px 0 22px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}

.cabecera h1 {
    margin: 4px 0;
    font-size: 1.5rem;
    line-height: 1.3;
}

.cabecera-institucion {
    margin: 0;
    font-size: .8rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    opacity: .85;
}

.cabecera-publico {
    margin: 0;
    font-size: .95rem;
    opacity: .9;
}

/* ------------------------------ Tarjetas ---------------------------- */
main { padding: 24px 16px 60px; }

.tarjeta {
    background: #fff;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    padding: 22px 24px;
    margin-bottom: 22px;
}

.introduccion .referencia {
    margin: 0 0 12px;
    font-size: .75rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--gris-texto);
}

.introduccion h2 {
    font-size: 1rem;
    margin: 20px 0 6px;
    color: var(--color-encuesta);
}

.introduccion p { margin: 0 0 8px; color: var(--gris-texto); }

.leyenda {
    list-style: none;
    margin: 16px 0 0;
    padding: 14px;
    background: var(--gris-fondo);
    border-radius: var(--radio);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
}

.leyenda li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .9rem;
    color: var(--gris-texto);
}

.letra {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    font-size: .82rem;
    flex: none;
}

.letra-A { background: var(--verde); }
.letra-B { background: var(--verde-claro); }
.letra-C { background: var(--ambar); }
.letra-D { background: var(--rojo); }
.letra-E { background: var(--neutro); }

.aviso-anonimo {
    margin: 16px 0 0;
    padding: 12px 14px;
    border-left: 4px solid var(--color-encuesta);
    background: #f8fafc;
    font-size: .9rem;
    color: var(--gris-texto);
}

/* ------------------------------ Secciones --------------------------- */
.titulo-seccion {
    margin: 30px 0 12px;
    padding: 12px 18px;
    background: var(--color-encuesta);
    color: #fff;
    border-radius: var(--radio);
    font-size: 1rem;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.titulo-seccion small {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    opacity: .85;
}

/* ------------------------------ Preguntas --------------------------- */
.pregunta {
    background: #fff;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    padding: 16px 18px;
    margin-bottom: 12px;
    scroll-margin-top: 16px;
}

.pregunta-error {
    border-color: var(--rojo);
    background: #fef4f4;
}

.enunciado {
    margin: 0 0 12px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-weight: 500;
}

.numero {
    flex: none;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 8px;
    background: var(--gris-fondo);
    color: var(--gris-texto);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: 700;
}

.opciones {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.opcion {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 10px 6px;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    cursor: pointer;
    text-align: center;
    transition: background .12s, border-color .12s;
    user-select: none;
    /* Toque inmediato en el celular: sin espera de doble pulsación ni destello gris. */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.opcion:hover { background: var(--gris-fondo); }
.opcion:active { transform: scale(.97); }

.opcion input { position: absolute; opacity: 0; pointer-events: none; }

.opcion .marca {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid var(--gris-borde);
    color: var(--gris-texto);
    background: #fff;
    flex: none;
}

.opcion .texto { font-size: .74rem; color: var(--gris-texto); line-height: 1.25; }

.opcion-A input:checked ~ .marca { background: var(--verde);       border-color: var(--verde);       color: #fff; }
.opcion-B input:checked ~ .marca { background: var(--verde-claro); border-color: var(--verde-claro); color: #fff; }
.opcion-C input:checked ~ .marca { background: var(--ambar);       border-color: var(--ambar);       color: #fff; }
.opcion-D input:checked ~ .marca { background: var(--rojo);        border-color: var(--rojo);        color: #fff; }
.opcion-E input:checked ~ .marca { background: var(--neutro);      border-color: var(--neutro);      color: #fff; }

.opcion input:checked ~ .texto { color: var(--tinta); font-weight: 600; }
.opcion input:focus-visible ~ .marca { outline: 3px solid var(--color-encuesta); outline-offset: 2px; }

/* La tarjeta entera cambia al elegirla: en pantallas pequenas el circulo solo
   no se distingue bien de un vistazo. */
.opcion:focus-within { border-color: var(--color-encuesta); }
.opcion-A:has(input:checked) { border-color: var(--verde);       background: #eaf6f0; }
.opcion-B:has(input:checked) { border-color: var(--verde-claro); background: #eef8ee; }
.opcion-C:has(input:checked) { border-color: var(--ambar);       background: #fdf5e7; }
.opcion-D:has(input:checked) { border-color: var(--rojo);        background: #fdefee; }
.opcion-E:has(input:checked) { border-color: var(--neutro);      background: #f2f4f6; }

/* Respaldo para navegadores sin :has() (la clase la pone encuesta.js). */
.opcion.elegida-A { border-color: var(--verde);       background: #eaf6f0; }
.opcion.elegida-B { border-color: var(--verde-claro); background: #eef8ee; }
.opcion.elegida-C { border-color: var(--ambar);       background: #fdf5e7; }
.opcion.elegida-D { border-color: var(--rojo);        background: #fdefee; }
.opcion.elegida-E { border-color: var(--neutro);      background: #f2f4f6; }

/* --------------------------- Texto libre ---------------------------- */
.pregunta-abierta textarea {
    width: 100%;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    padding: 10px 12px;
    font: inherit;
    /* 16px exactos: por debajo de eso Safari en iPhone hace zoom al enfocar. */
    font-size: 16px;
    resize: vertical;
    color: var(--tinta);
}

.pregunta-abierta textarea:focus {
    outline: none;
    border-color: var(--color-encuesta);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

/* ------------------------------ Envio ------------------------------- */
.barra-envio {
    position: sticky;
    bottom: 0;
    margin-top: 24px;
    padding: 14px 18px;
    background: #fff;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    box-shadow: 0 -4px 18px rgba(15, 23, 42, .08);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    /* Separa el boton de la barra inferior del iPhone. */
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

.progreso { margin: 0; font-size: .9rem; color: var(--gris-texto); }

.progreso-pista {
    flex: 1 1 160px;
    height: 8px;
    background: var(--gris-fondo);
    border-radius: 99px;
    overflow: hidden;
}

.progreso-relleno {
    height: 100%;
    width: 0;
    background: var(--color-encuesta);
    transition: width .2s;
}

.boton-enviar {
    background: var(--color-encuesta);
    color: #fff;
    border: 0;
    border-radius: var(--radio);
    padding: 12px 26px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.boton-enviar:hover { filter: brightness(1.08); }
.boton-enviar:disabled { opacity: .55; cursor: not-allowed; }

.alerta-error {
    background: #fdecea;
    border: 1px solid #f5c2c0;
    color: #922b25;
    border-radius: var(--radio);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: .95rem;
}

/* Aviso de borrador recuperado (solo profesores y padres). */
.alerta-restaurada {
    background: #eef6ff;
    border: 1px solid #bcd9f5;
    color: #1c4c78;
    border-radius: var(--radio);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: .92rem;
}

.enlace-descartar {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: #1c4c78;
    text-decoration: underline;
    cursor: pointer;
    touch-action: manipulation;
}

/* -------------------------- Pantalla final -------------------------- */
.tarjeta-final { text-align: center; padding: 46px 24px; }
.tarjeta-final h2 { margin: 14px 0 8px; }
.tarjeta-final p { color: var(--gris-texto); margin: 4px 0; }
.tarjeta-final .nota { font-size: .88rem; margin-top: 14px; }

.icono-exito, .icono-info {
    width: 68px;
    height: 68px;
    margin: 0 auto;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #fff;
    font-weight: 700;
}

.icono-exito { background: var(--verde); }
.icono-info  { background: var(--color-encuesta); font-family: Georgia, serif; }

/* -------------------------------- Pie ------------------------------- */
.pie {
    padding: 18px 0 26px;
    text-align: center;
    font-size: .82rem;
    color: var(--gris-texto);
}

/* ----------------------------- Responsive --------------------------- */
@media (max-width: 640px) {
    .cabecera { padding: 18px 0 16px; }
    .cabecera h1 { font-size: 1.2rem; }
    main { padding: 16px 12px 40px; }
    .contenedor { padding: 0 12px; }
    .tarjeta { padding: 18px 16px; }
    .titulo-seccion { padding: 11px 14px; font-size: .92rem; }
    .pregunta { padding: 14px 12px; }
    .enunciado { gap: 8px; }
    .opciones { grid-template-columns: repeat(5, 1fr); gap: 5px; }
    /* 5 columnas siempre visibles; cada una supera los 44px de zona táctil. */
    .opcion { padding: 9px 2px; min-height: 74px; justify-content: center; }
    .opcion .marca { width: 30px; height: 30px; font-size: .85rem; }
    .opcion .texto { font-size: .64rem; hyphens: auto; }
    .barra-envio { gap: 10px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
    .boton-enviar { width: 100%; }
    .leyenda { gap: 6px 14px; padding: 12px; }
    .leyenda li { font-size: .84rem; }
}

/* Pantallas muy angostas (Android de 320px): se aprieta un poco mas. */
@media (max-width: 360px) {
    .opciones { gap: 4px; }
    .opcion { padding: 8px 1px; }
    .opcion .texto { font-size: .58rem; letter-spacing: -.2px; }
    .numero { min-width: 24px; height: 24px; font-size: .78rem; }
}
