/* ---- Tipografía (alojada en el propio sitio, sin terceros) ---- */
@font-face {
    font-family: "Figtree";
    src: url("assets/fonts/figtree-latin.woff2") format("woff2");
    font-weight: 300 900;
    font-style: normal;
    font-display: swap;
}

/* ---- Tokens ---- */
/* El azul y el magenta salen del logo de Maristas; el cian, del de IP. */
:root {
    color-scheme: light dark;
    --bg: #f2f3fa;
    --card: #ffffff;
    --field: #fafaff;
    --ink: #161a3a;
    --muted: #575c78;
    --accent: #1a2992;
    --accent-hover: #141f73;
    --accent-ink: #ffffff;
    --accent-weak: #e6e8f8;
    --brand-1: #bb4293;
    --brand-2: #1a2992;
    --brand-ip: #1ab8dc;
    --error: #b3261e;
    --error-ink: #ffffff;
    --border: #dadeee;
    --border-strong: #b4b9d6;
    --radius: 20px;
    --radius-inner: 12px;
    --shadow: 0 1px 2px rgba(22, 26, 58, .05), 0 24px 48px -24px rgba(26, 41, 146, .3);
    --ease: cubic-bezier(.2, .7, .2, 1);
    /* Los logos están dibujados para fondo claro: en modo oscuro llevan placa. */
    --logo-plate: transparent;
    --logo-pad: 0px;
    --logo-shift: -3px;
}

:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0c0f22;
        --card: #151934;
        --field: #10142b;
        --ink: #eceefb;
        --muted: #a1a7c8;
        --accent: #aab2ff;
        --accent-hover: #c3c8ff;
        --accent-ink: #0c0f22;
        --accent-weak: #262c57;
        --brand-1: #e07fbd;
        --brand-2: #8f98ff;
        --error: #ff9d96;
        --error-ink: #2a0b09;
        --border: #2a2f58;
        --border-strong: #454c82;
        --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 24px 48px -24px rgba(0, 0, 0, .7);
        --logo-plate: #f4f5fb;
        --logo-pad: 8px 12px;
        --logo-shift: 0px;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    display: grid;
    /* minmax(0, …): la columna nunca crece más que la pantalla, aunque el
       contenido (p. ej. la tabla de respuestas) sea más ancho. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    justify-items: center;
    padding: clamp(20px, 5vh, 56px) 16px 20px;
    background: var(--bg);
    color: var(--ink);
    font-family: "Figtree", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* Fondo: un velo magenta arriba (Maristas) y otro cian abajo (IP). */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(60rem 32rem at 10% -10%, color-mix(in srgb, var(--brand-1) 11%, transparent), transparent 70%),
        radial-gradient(52rem 30rem at 100% 110%, color-mix(in srgb, var(--brand-ip) 10%, transparent), transparent 70%);
}

/* ---- Tarjeta ---- */
.tarjeta {
    position: relative;
    align-self: center;
    width: 100%;
    max-width: 460px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    --pad-x: 28px;
    --pad-b: 34px;
    padding: 32px var(--pad-x) var(--pad-b);
    overflow: hidden;
    animation: entrar .5s var(--ease) both;
}

/* Franja de marca en el borde superior. */
.tarjeta::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 4px;
    background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
}

.tarjeta--centrada { text-align: center; }

/* ---- Logos ---- */
.logo-colegio,
.credito img {
    display: block;
    box-sizing: content-box;
    width: auto;
    padding: var(--logo-pad);
    background: var(--logo-plate);
    border-radius: 10px;
}

.logo-colegio {
    height: 72px;
    margin: 0 0 20px var(--logo-shift);
}

.tarjeta--centrada .logo-colegio { margin-inline: auto; }

.encabezado { margin-bottom: 26px; }

h1 {
    margin: 0 0 8px;
    font-size: clamp(1.6rem, 1.35rem + 1.2vw, 1.9rem);
    font-weight: 700;
    line-height: 1.12;
    letter-spacing: -.022em;
    text-wrap: balance;
}

.subtitulo {
    margin: 0;
    color: var(--muted);
    text-wrap: balance;
}

/* ---- Campos ---- */
.campo { margin-bottom: 20px; display: flex; flex-direction: column; min-width: 0; }

/* El curso lleva más texto ("1º de primaria") que la sección ("A"). */
.fila { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; }

label {
    margin-bottom: 7px;
    font-size: .9rem;
    font-weight: 600;
}

input, select {
    width: 100%;
    font: inherit;
    font-size: 16px; /* evita el zoom automático en iOS */
    color: var(--ink);
    background-color: var(--field);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-inner);
    padding: 12px 14px;
    min-height: 50px;
    /* Transparente: solo se ve en modo de alto contraste, donde no hay sombras. */
    outline: 2px solid transparent;
    outline-offset: 2px;
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23575c78' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 38px;
    cursor: pointer;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a7c8' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    }
}

input:focus, select:focus {
    border-color: var(--accent);
    background-color: var(--card);
    box-shadow: 0 0 0 4px var(--accent-weak);
}

input[aria-invalid="true"], select[aria-invalid="true"] {
    border-color: var(--error);
}

input[aria-invalid="true"]:focus, select[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--error) 18%, transparent);
}

.ayuda { margin-top: 7px; font-size: .84rem; color: var(--muted); }

.error { margin-top: 7px; font-size: .86rem; color: var(--error); font-weight: 500; }

/* ---- Avisos ---- */
.aviso {
    margin: 0 0 22px;
    padding: 12px 14px;
    border-radius: var(--radius-inner);
    font-size: .92rem;
    text-wrap: pretty;
}
.aviso--error {
    background: color-mix(in srgb, var(--error) 10%, transparent);
    color: var(--error);
    border: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
}
.aviso--info {
    background: var(--accent-weak);
    color: var(--ink);
    border: 1px solid color-mix(in srgb, var(--accent) 16%, transparent);
}

/* ---- Botón ---- */
.boton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-top: 8px;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-ink);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-inner);
    padding: 14px 18px;
    min-height: 54px;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 10px 20px -12px color-mix(in srgb, var(--accent) 85%, transparent);
    transition: background-color .2s ease, box-shadow .2s ease, opacity .2s ease, transform .2s var(--ease);
    touch-action: manipulation;
}
.boton:active { transform: scale(.985); transition-duration: .06s; }
.boton:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
    outline-offset: 3px;
}

.boton--secundario {
    width: auto;
    margin-top: 24px;
    padding: 12px 22px;
    min-height: 48px;
    color: var(--accent);
    background: var(--accent-weak);
    box-shadow: none;
}

/* El hover solo donde hay puntero: en pantallas táctiles se queda "pegado". */
@media (hover: hover) {
    input:hover:not(:focus), select:hover:not(:focus) { border-color: var(--border-strong); }
    input[aria-invalid="true"]:hover:not(:focus), select[aria-invalid="true"]:hover:not(:focus) { border-color: var(--error); }

    .boton:hover {
        background: var(--accent-hover);
        box-shadow: 0 14px 24px -12px color-mix(in srgb, var(--accent) 90%, transparent);
        transform: translateY(-1px);
    }
    .boton:active { transform: scale(.985); }
    .boton--secundario:hover {
        background: color-mix(in srgb, var(--accent) 16%, var(--card));
        box-shadow: none;
    }
}

/* ---- Términos y condiciones (final del formulario) ---- */
.condiciones {
    margin: 4px 0 18px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-inner);
    background: var(--field);
}

.condiciones summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    min-height: 50px;
    border-radius: inherit;
    font-size: .94rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    list-style: none;
    transition: background-color .18s ease;
}
.condiciones summary::-webkit-details-marker { display: none; }
/* Flecha: una máscara, para que tome el color del texto en claro y en oscuro. */
.condiciones summary::after {
    content: "";
    flex: none;
    width: 16px;
    height: 16px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
    transition: transform .2s var(--ease);
}
.condiciones[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.condiciones[open] summary::after { transform: rotate(180deg); }
.condiciones summary:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
    outline-offset: 2px;
}

.condiciones__texto {
    padding: 2px 14px 8px;
    border-top: 1px solid var(--border);
    font-size: .9rem;
    line-height: 1.55;
}
.condiciones__texto h2 { margin: 14px 0 0; font-size: 1rem; line-height: 1.3; text-wrap: balance; }
.condiciones__texto h3 { margin: 18px 0 6px; font-size: .9rem; }
.condiciones__texto p { margin: 0 0 10px; text-wrap: pretty; }

.casilla {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0;
    font-size: .95rem;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
}
.casilla input {
    flex: none;
    width: 24px;
    height: 24px;
    min-height: 0;
    margin: -1px 0 0;
    padding: 0;
    border-radius: 7px;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
}
.casilla input:checked {
    border-color: var(--accent);
    background-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .casilla input:checked {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230c0f22' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
    }
}

/* Hasta que se marca la casilla, el botón de enviar queda atenuado y sale una
   línea que lo explica. Es solo una ayuda visual (evita un envío fallido, que
   obligaría a reescribir las contraseñas): quien manda es el servidor. */
.ayuda--envio { display: none; margin-bottom: 0; text-align: center; }
form:has(#acepta:not(:checked)) .ayuda--envio { display: block; }
form:has(#acepta:not(:checked)) button[type="submit"] {
    opacity: .45;
    box-shadow: none;
    pointer-events: none;
}

@media (hover: hover) {
    .condiciones summary:hover { background: var(--accent-weak); }
}

/* ---- Página de gracias ---- */
.tilde {
    width: 68px;
    height: 68px;
    margin: 6px auto 22px;
    display: grid;
    place-items: center;
    color: var(--accent);
    background: var(--accent-weak);
    border-radius: 50%;
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent-weak) 45%, transparent);
}

/* ---- Login ---- */
.tarjeta--angosta { max-width: 400px; }

.pie {
    margin: 18px 0 0;
    text-align: center;
    font-size: .88rem;
}
.pie a, .enlace {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    transition: color .18s ease;
}
.pie a:hover, .enlace:hover { color: var(--accent); text-decoration: underline; }
.pie a:focus-visible, .enlace:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
    outline-offset: 1px;
}

/* ---- Administración: listado de respuestas ---- */
.tarjeta--ancha {
    max-width: 1120px;
    align-self: start;
    /* Recorta igual que hidden, pero deja fijo el encabezado de la tabla al bajar. */
    overflow: clip;
}

.cabecera-admin {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.cabecera-admin .enlace { margin: -6px -10px 0 0; font-size: .88rem; white-space: nowrap; }

.barra {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px 24px;
    margin-bottom: 24px;
}
.barra .encabezado { margin-bottom: 0; }
.barra__acciones { display: flex; flex-wrap: wrap; gap: 10px; }

.boton--compacto {
    width: auto;
    margin-top: 0;
    gap: 8px;
    padding: 10px 16px;
    min-height: 44px;
    font-size: .94rem;
}

.boton--peligro {
    color: var(--error-ink);
    background: var(--error);
    box-shadow: none;
}

.oculto {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* La tabla llega hasta los bordes de la tarjeta. */
.tabla {
    width: calc(100% + 2 * var(--pad-x));
    margin: 0 calc(-1 * var(--pad-x)) calc(-1 * var(--pad-b));
    border-collapse: collapse;
    font-size: .94rem;
    text-align: left;
}

.tabla th {
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}
.tabla th[aria-sort] { color: var(--accent); }
.tabla th a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: -5px -8px;
    padding: 5px 8px;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    transition: color .18s ease, background-color .18s ease;
}
.tabla th a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
    outline-offset: 1px;
}

.flecha { flex: none; transition: transform .2s var(--ease); }
.flecha--desc { transform: rotate(180deg); }

.c-nombre { font-weight: 600; }
.c-curso, .c-seccion { white-space: nowrap; }
.c-correo, .c-clave { overflow-wrap: anywhere; }
.c-fecha { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Monoespaciada: distingue l/I/1 y O/0 cuando hay que copiar la contraseña. */
.clave { font-family: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace; font-size: .9rem; }
.clave--oculta { color: var(--muted); letter-spacing: .1em; }

.accion {
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    color: var(--error);
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 7px 10px;
    cursor: pointer;
    transition: background-color .18s ease;
}
.accion:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--error) 45%, transparent);
    outline-offset: 1px;
}

@media (hover: hover) {
    .tabla tbody tr { transition: background-color .15s ease; }
    .tabla tbody tr:hover { background: color-mix(in srgb, var(--accent-weak) 55%, transparent); }
    .tabla th a:hover { color: var(--ink); background: var(--accent-weak); }
    .tabla th[aria-sort] a:hover { color: var(--accent); }
    .accion:hover { background: color-mix(in srgb, var(--error) 12%, transparent); }
    .boton--peligro:hover {
        background: color-mix(in srgb, var(--error) 86%, var(--ink));
        box-shadow: none;
    }
}

/* Escritorio: tabla clásica con el encabezado fijo al bajar. */
@media (min-width: 761px) {
    .tabla th {
        position: sticky;
        top: 0;
        z-index: 1;
        padding: 11px 12px;
        background: var(--field);
        box-shadow: inset 0 1px 0 var(--border), inset 0 -1px 0 var(--border);
    }
    .tabla td {
        padding: 12px;
        border-bottom: 1px solid var(--border);
        vertical-align: middle;
    }
    .tabla tbody tr:last-child td { border-bottom: 0; }
    .tabla th:first-child, .tabla td:first-child { padding-left: var(--pad-x); }
    .tabla th:last-child, .tabla td:last-child { padding-right: calc(var(--pad-x) - 10px); }
    .c-accion { width: 1%; text-align: right; white-space: nowrap; }
}

/* Móvil: cada respuesta es una ficha y el encabezado pasa a ser la barra de orden. */
@media (max-width: 760px) {
    .tabla, .tabla thead, .tabla tbody { display: block; }

    .tabla thead tr {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 10px var(--pad-x);
        overflow-x: auto;
        scrollbar-width: none;
        background: var(--field);
        box-shadow: inset 0 1px 0 var(--border), inset 0 -1px 0 var(--border);
    }
    .tabla thead tr::before { content: "Ordenar por"; flex: none; margin-right: 4px; font-size: .8rem; color: var(--muted); }
    .tabla th { flex: none; }
    .tabla th.sin-orden { display: none; }
    .tabla th a { margin: 0; padding: 6px 10px; border: 1px solid var(--border); background: var(--card); }
    .tabla th[aria-sort] a { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

    .tabla tbody tr {
        display: grid;
        grid-template-columns: 1fr auto auto;
        /* Fecha y "Eliminar" comparten la última franja (una a cada lado), así
           el botón no ensancha las columnas de curso y sección. */
        grid-template-areas:
            "nombre curso  seccion"
            "correo correo correo"
            "clave  clave  clave"
            "final  final  final";
        align-items: baseline;
        gap: 3px 5px;
        padding: 14px var(--pad-x);
        border-bottom: 1px solid var(--border);
    }
    .tabla tbody tr:last-child { border-bottom: 0; }
    .tabla td { display: block; min-width: 0; }
    .c-nombre  { grid-area: nombre; }
    .c-curso   { grid-area: curso; }
    .c-seccion { grid-area: seccion; }
    .c-correo  { grid-area: correo; color: var(--muted); }
    .c-clave   { grid-area: clave; }
    .c-clave::before { content: "Contraseña: "; font-size: .84rem; color: var(--muted); }
    .c-fecha   { grid-area: final; font-size: .86rem; }
    .c-accion  { grid-area: final; justify-self: end; margin-right: -10px; }
}

/* Confirmación de borrado: un popover nativo, sin JavaScript. Oculto por
   defecto para que un navegador antiguo no lo muestre suelto en la fila. */
.confirmar {
    display: none;
    width: min(400px, calc(100vw - 32px));
    margin: auto;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--ink);
    box-shadow: var(--shadow);
    font-size: 1rem;
    font-weight: 400;
    text-align: left;
    white-space: normal;
}
.confirmar:popover-open { display: block; }
.confirmar::backdrop { background: rgba(12, 15, 34, .5); }
.confirmar h2 { margin: 0 0 8px; font-size: 1.2rem; line-height: 1.2; letter-spacing: -.012em; }
.confirmar p { margin: 0 0 22px; color: var(--muted); text-wrap: pretty; }
.confirmar strong { color: var(--ink); }
.confirmar form { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

@media (prefers-reduced-motion: no-preference) {
    .confirmar:popover-open { animation: entrar .22s var(--ease) both; }
}

/* ---- Lista vacía ---- */
.vacio {
    padding: 36px 20px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-inner);
    text-align: center;
    color: var(--muted);
}
.vacio p { margin: 0 auto; max-width: 44ch; text-wrap: balance; }
.vacio .vacio__titulo { margin-bottom: 6px; font-size: 1.05rem; font-weight: 600; color: var(--ink); }

/* ---- Crédito de IP Informática (pie de página) ---- */
.credito {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 28px;
    font-size: .8rem;
    color: var(--muted);
    animation: entrar .5s .15s var(--ease) both;
}
.credito img { height: 38px; }

/* ---- Movimiento ---- */
@keyframes entrar {
    from { opacity: 0; transform: translateY(14px); }
}

@keyframes trazar {
    to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: no-preference) {
    .tilde path {
        stroke-dasharray: 20;
        stroke-dashoffset: 20;
        animation: trazar .45s .35s cubic-bezier(.6, 0, .2, 1) forwards;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}

@media (max-width: 420px) {
    .tarjeta { --pad-x: 20px; --pad-b: 28px; padding-top: 28px; }
    .logo-colegio { height: 64px; }
}
