:root {
    --fondo: #f4f6f8;
    --tarjeta: #ffffff;
    --texto: #1c2530;
    --suave: #5d6b7a;
    --borde: #dde3ea;
    --primario: #0b6bcb;
    --primario-oscuro: #08529c;
    --ok: #1a8a4a;
    --ok-fondo: #e6f5ec;
    --mal: #c0392b;
    --mal-fondo: #fdecea;
    --medio: #b7791f;
    --doble: #6b46c1;
    --radio: 12px;
    --sombra: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--fondo);
    color: var(--texto);
    line-height: 1.45;
}

a { color: var(--primario); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: 1.05rem; margin: .4rem 0 .6rem; }
h1:focus { outline: none; }

/* ---------- estructura ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .7rem 1rem; background: var(--tarjeta); border-bottom: 1px solid var(--borde);
}
.marca { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--texto); }
.menu { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; font-size: .95rem; }
.menu a { text-decoration: none; color: var(--suave); }
.menu a.active { color: var(--primario); font-weight: 600; }
.btn-link { background: none; border: 0; color: var(--suave); cursor: pointer; font: inherit; padding: 0; }

.contenido { max-width: 820px; margin: 0 auto; padding: 1rem; min-height: calc(100vh - 140px); }
.pie { text-align: center; font-size: .8rem; color: var(--suave); padding: 1.5rem 1rem; }

.card {
    background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
    box-shadow: var(--sombra); padding: 1.1rem; margin-bottom: 1rem;
}
.centro { text-align: center; }
.sub { color: var(--suave); font-size: .92rem; }
.cargando { color: var(--suave); padding: 2rem 0; text-align: center; }
.titulo-fila { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }

/* ---------- formularios ---------- */
label { display: block; margin-bottom: .8rem; font-size: .92rem; font-weight: 600; }
label small { font-weight: 400; color: var(--suave); }
input, select, textarea {
    display: block; width: 100%; margin-top: .3rem; padding: .65rem .75rem;
    border: 1px solid var(--borde); border-radius: 8px; font: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primario); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 .4rem 0 0; }
label.check { display: flex; align-items: center; font-weight: 500; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
fieldset { border: 1px solid var(--borde); border-radius: 8px; margin: 0 0 1rem; padding: .8rem; }
legend { font-weight: 600; font-size: .92rem; padding: 0 .3rem; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; align-items: end; }
.alt-edit { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.alt-edit input:not([type=radio]) { margin: 0; }
.filtros { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: .6rem; }
.filtros > * { margin: 0; }

.auth { max-width: 420px; margin: 2rem auto; }
.pie-form { text-align: center; font-size: .92rem; margin: 1rem 0 0; }

/* ---------- botones ---------- */
.btn {
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
    padding: .65rem 1.1rem; border-radius: 8px; border: 1px solid var(--borde);
    background: #fff; color: var(--texto); font: inherit; font-weight: 600; cursor: pointer;
    text-decoration: none; text-align: center;
}
.btn:hover:not(:disabled) { border-color: var(--primario); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn.primario:hover:not(:disabled) { background: var(--primario-oscuro); }
.btn.peligro { color: var(--mal); }
.btn.chico { padding: .35rem .7rem; font-size: .85rem; }
.btn.ancho { width: 100%; }
.btn.grande { padding: 1rem; font-size: 1.05rem; width: 100%; }
.btn small { font-weight: 400; font-size: .8rem; opacity: .85; margin-top: .2rem; }

.acciones { display: grid; gap: .7rem; margin-top: .5rem; }
.acciones.fila { display: flex; flex-wrap: wrap; align-items: center; }

/* ---------- alertas y etiquetas ---------- */
.alerta { padding: .7rem .9rem; border-radius: 8px; margin: .6rem 0; font-size: .92rem; }
.alerta.error { background: var(--mal-fondo); color: var(--mal); }
.alerta.ok { background: var(--ok-fondo); color: var(--ok); }
.alerta.info { background: #e8f1fb; color: var(--primario-oscuro); }

.etiquetas { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag { font-size: .75rem; padding: .15rem .55rem; border-radius: 99px; background: #eef2f6; color: var(--suave); font-weight: 600; }
.tag.doble { background: #efe9fb; color: var(--doble); }
.tag.ok { background: var(--ok-fondo); color: var(--ok); }
.tag.mal { background: var(--mal-fondo); color: var(--mal); }
.ok { color: var(--ok); } .medio { color: var(--medio); } .mal { color: var(--mal); }

/* ---------- inicio ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: .8rem; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--suave); font-size: .82rem; }
.lista-temas { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.tema {
    width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: .15rem;
    padding: .75rem .9rem; border: 1px solid var(--borde); border-radius: 8px; background: #fff;
    font: inherit; text-align: left; cursor: pointer;
}
.tema:hover:not(:disabled) { border-color: var(--primario); }
.tema span:first-child { font-weight: 600; }
.tema small { color: var(--suave); }

/* ---------- examen ---------- */
.examen-barra { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; color: var(--suave); margin-bottom: .4rem; flex-wrap: wrap; }
.reloj { font-weight: 700; color: var(--texto); font-variant-numeric: tabular-nums; }
.reloj.alerta-tiempo { color: var(--mal); }
.progreso { height: 6px; background: var(--borde); border-radius: 99px; overflow: hidden; margin-bottom: 1rem; }
.progreso div { height: 100%; background: var(--primario); transition: width .2s; }
.pregunta h2 { font-size: 1.15rem; margin-top: .7rem; }
.imagen-pregunta { max-width: 220px; max-height: 220px; display: block; margin: .5rem auto 1rem; }
.alternativas { display: grid; gap: .55rem; }
.alternativa {
    display: flex; gap: .7rem; align-items: flex-start; text-align: left;
    padding: .8rem .9rem; border: 2px solid var(--borde); border-radius: 10px; background: #fff;
    font: inherit; cursor: pointer;
}
.alternativa:hover { border-color: #9cc3ea; }
.alternativa.elegida { border-color: var(--primario); background: #eaf3fc; }
.letra {
    flex: 0 0 1.7rem; height: 1.7rem; border-radius: 50%; background: #eef2f6;
    display: inline-flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase;
}
.alternativa.elegida .letra { background: var(--primario); color: #fff; }
.nav-preguntas { display: flex; justify-content: space-between; align-items: center; gap: .7rem; margin: 1rem 0; }
.mapa summary { cursor: pointer; color: var(--suave); font-size: .9rem; }
.grilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); gap: .4rem; margin-top: .7rem; }
.celda { padding: .45rem 0; border: 1px solid var(--borde); border-radius: 6px; background: #fff; cursor: pointer; font: inherit; }
.celda.resp { background: #eaf3fc; border-color: #9cc3ea; }
.celda.actual { outline: 2px solid var(--primario); }

.modal-fondo { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal { max-width: 420px; width: 100%; margin: 0; }

/* ---------- resultado ---------- */
.resultado { text-align: center; }
.resultado.aprobado { border-top: 5px solid var(--ok); }
.resultado.reprobado { border-top: 5px solid var(--mal); }
.veredicto { font-size: 1.6rem; font-weight: 800; }
.puntaje { font-size: 1.2rem; margin: .3rem 0; }
.puntaje b { font-size: 2.2rem; }
.resultado .acciones.fila { justify-content: center; }
.filtro { margin: 0 0 .8rem; }
.filtro label { font-weight: 500; display: flex; align-items: center; }
.revision.bien { border-left: 4px solid var(--ok); }
.revision.mal { border-left: 4px solid var(--mal); }
.alternativas-revision { padding-left: 1.1rem; margin: .4rem 0; }
.alternativas-revision li { margin: .25rem 0; padding: .2rem .4rem; border-radius: 6px; }
.alternativas-revision li.correcta { background: var(--ok-fondo); color: var(--ok); font-weight: 600; }
.alternativas-revision li.elegida-mal { background: var(--mal-fondo); color: var(--mal); text-decoration: line-through; }
.explicacion { background: #f6f8fb; border-radius: 8px; padding: .7rem .8rem; font-size: .92rem; margin-top: .5rem; }
.explicacion small { color: var(--suave); }

/* ---------- tablas / admin ---------- */
.tabla-scroll { overflow-x: auto; padding: 0; }
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th, .tabla td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla th { color: var(--suave); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
.admin-item.inactiva { opacity: .6; }
.mini-alts { margin: .3rem 0 .6rem; padding-left: 1.3rem; font-size: .9rem; }
.mini-alts li.correcta { color: var(--ok); font-weight: 600; }
code { background: #eef2f6; padding: .05rem .3rem; border-radius: 4px; }

/* ---------- arranque y error ---------- */
.arranque { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; color: var(--suave); }
.arranque-logo { font-size: 3rem; animation: latido 1.2s infinite; }
@keyframes latido { 50% { transform: scale(1.12); } }

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: #fff4d6; padding: .7rem 1rem; box-shadow: 0 -1px 3px rgba(0,0,0,.15);
}
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

@media (max-width: 560px) {
    .fila-2, .filtros { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; gap: .4rem; }
    .contenido { padding: .8rem; }
}
