/*
 * Estilos de la plataforma. Contrastes AA como mínimo, foco siempre visible,
 * diseño adaptable y respeto a las preferencias de movimiento reducido.
 */

:root {
    --color-bg: #f6f6f4;
    --color-surface: #ffffff;
    --color-text: #1f2328;
    --color-muted: #50575f;
    --color-border: #8a939c;
    --color-border-light: #d0d5da;
    --color-primary: #0b57d0;
    --color-primary-hover: #0842a0;
    --color-header: #1f2a44;
    --color-focus: #ffd84d;
    --color-focus-ring: #1a1a1a;
    --color-success: #1b6b30;
    --color-success-bg: #e6f4ea;
    --color-error: #b3261e;
    --color-error-bg: #fdecea;
    --color-warning: #7a4100;
    --color-warning-bg: #fff4e0;
    --color-info: #0b3d91;
    --color-info-bg: #e8f0fe;
    --radius: 6px;
    --max-width: 72rem;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

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

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

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font);
    font-size: 1.0625rem;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--color-primary);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
}

a:hover {
    color: var(--color-primary-hover);
    text-decoration-thickness: 3px;
}

/* Foco visible y de alto contraste en cualquier fondo */
:focus-visible {
    outline: 3px solid var(--color-focus-ring);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px var(--color-focus);
}

[tabindex="-1"]:focus {
    outline: none;
    box-shadow: none;
}

.error-summary:focus,
.error-summary:focus-visible {
    outline: 3px solid var(--color-focus-ring);
    box-shadow: 0 0 0 6px var(--color-focus);
}

h1, h2, h3, h4 {
    line-height: 1.25;
    margin: 1.5em 0 0.5em;
}

h1 {
    font-size: 2rem;
    margin-top: 0.5em;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

code, pre, .code {
    font-family: var(--font-mono);
    font-size: 0.95em;
}

pre {
    background: #f0f1f3;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

.narrow {
    max-width: 34rem;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -10rem;
    z-index: 100;
    background: var(--color-focus);
    color: var(--color-text);
    padding: 0.75rem 1rem;
    font-weight: bold;
}

.skip-link:focus {
    top: 1rem;
}

/* Cabecera y navegación */
.site-header {
    background: var(--color-header);
    color: #fff;
}

.header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

.brand {
    color: #fff;
    font-weight: bold;
    font-size: 1.2rem;
    text-decoration: none;
}

.brand:hover {
    color: #fff;
    text-decoration: underline;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    align-items: center;
}

.nav-list a,
.nav-list .link-button {
    color: #fff;
    padding: 0.25rem 0;
}

.nav-list a[aria-current="page"] {
    font-weight: bold;
    text-decoration-thickness: 3px;
}

.link-button {
    background: none;
    border: 0;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.inline-form {
    display: inline;
    margin: 0;
}

.main-content {
    flex: 1;
    padding-top: 1rem;
    padding-bottom: 3rem;
}

.site-footer {
    background: #e9eaec;
    border-top: 1px solid var(--color-border-light);
    padding: 1rem 0;
    font-size: 0.95rem;
}

.subnav ul,
.breadcrumbs ol,
.button-row,
.actions,
.pager ul,
.pagination ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.subnav {
    border-bottom: 1px solid var(--color-border-light);
    padding: 0.5rem 0;
    margin-bottom: 1rem;
}

.subnav a[aria-current="page"] {
    font-weight: bold;
}

.breadcrumbs {
    font-size: 0.95rem;
    margin: 0.5rem 0;
}

.breadcrumbs li:not(:last-child)::after {
    content: "›";
    margin-left: 1rem;
    color: var(--color-muted);
}

/* Textos auxiliares */
.lead {
    font-size: 1.15rem;
}

.muted,
.meta {
    color: var(--color-muted);
}

.small {
    font-size: 0.9rem;
}

.eyebrow {
    color: var(--color-muted);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.85rem;
    margin: 0;
}

.section-label {
    font-size: 1.1rem;
    color: var(--color-muted);
}

/* Tarjetas y paneles */
.card-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
}

.card,
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.panel {
    margin: 1.5rem 0;
}

.card-title {
    margin-top: 0;
    font-size: 1.3rem;
}

.card-summary > :last-child {
    margin-bottom: 0;
}

.danger-zone {
    border-color: var(--color-error);
}

details > summary {
    cursor: pointer;
    font-weight: bold;
}

/* Contenido Markdown */
.prose {
    max-width: 48rem;
}

.prose table {
    border-collapse: collapse;
    margin: 1rem 0;
}

.prose th,
.prose td {
    border: 1px solid var(--color-border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}

.prose blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 4px solid var(--color-border);
    background: #f0f1f3;
}

.content-page {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.5rem;
    margin: 1rem 0;
}

.content-page h1 {
    margin-top: 0.25em;
}

.answer-text,
.feedback {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #f0f1f3;
    border-left: 4px solid var(--color-border);
    padding: 0.75rem 1rem;
    margin: 0.5rem 0 1rem;
    max-width: 48rem;
}

.feedback {
    border-left-color: var(--color-primary);
    background: var(--color-info-bg);
}

.history li {
    margin-bottom: 1rem;
}

/* Listas del temario */
.module {
    margin-bottom: 1.5rem;
}

.item-list {
    padding-left: 1.5rem;
}

.item-list li {
    margin: 0.4rem 0;
}

.item-type {
    color: var(--color-muted);
}

.admin-item-list {
    padding-left: 1.5rem;
}

.admin-item-list > li {
    border-top: 1px solid var(--color-border-light);
    padding: 0.5rem 0;
}

.admin-item-title {
    margin: 0 0 0.4rem;
    font-weight: bold;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

/* Etiquetas de estado: siempre con texto, el color es un refuerzo */
.badge {
    display: inline-block;
    border: 1px solid currentColor;
    border-radius: 999px;
    padding: 0 0.6rem;
    font-size: 0.85rem;
    font-weight: bold;
    white-space: nowrap;
}

.badge-success { color: var(--color-success); background: var(--color-success-bg); }
.badge-error { color: var(--color-error); background: var(--color-error-bg); }
.badge-warning { color: var(--color-warning); background: var(--color-warning-bg); }
.badge-neutral { color: var(--color-muted); background: #eef0f2; }

/* Avisos */
.alert {
    border-left: 6px solid;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
}

.alert > p {
    margin: 0;
}

.alert > p + p {
    margin-top: 0.5rem;
}

.alert-success { border-color: var(--color-success); background: var(--color-success-bg); }
.alert-error { border-color: var(--color-error); background: var(--color-error-bg); }
.alert-warning { border-color: var(--color-warning); background: var(--color-warning-bg); }
.alert-info { border-color: var(--color-info); background: var(--color-info-bg); }

.error-summary {
    border: 4px solid var(--color-error);
    background: var(--color-surface);
    padding: 1rem 1.25rem;
    margin: 1rem 0 1.5rem;
    max-width: 48rem;
}

.error-summary h2 {
    margin-top: 0;
    font-size: 1.25rem;
}

.error-summary ul {
    margin: 0;
    padding-left: 1.25rem;
}

.error-summary a {
    color: var(--color-error);
    font-weight: bold;
}

/* Formularios */
.form {
    max-width: 48rem;
    margin: 1rem 0;
}

.field {
    margin: 0 0 1.25rem;
}

fieldset.field {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

legend {
    font-weight: bold;
    padding: 0 0.25rem;
}

label {
    display: block;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.hint {
    color: var(--color-muted);
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
}

.field-error {
    color: var(--color-error);
    font-weight: bold;
    margin: 0 0 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="file"],
select,
textarea {
    display: block;
    width: 100%;
    max-width: 100%;
    font: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.5rem;
}

input[type="file"] {
    padding: 0.4rem;
}

textarea {
    min-height: 8rem;
    resize: vertical;
}

textarea.code {
    font-family: var(--font-mono);
    font-size: 0.95rem;
}

[aria-invalid="true"] {
    border-color: var(--color-error);
    border-width: 3px;
}

.checkbox,
.radio {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 0.6rem;
    align-items: start;
    margin: 0 0 1rem;
}

.checkbox input,
.radio input {
    width: 1.35rem;
    height: 1.35rem;
    margin: 0.15rem 0 0;
    accent-color: var(--color-primary);
}

.checkbox label,
.radio label {
    font-weight: normal;
    margin: 0;
}

.checkbox .hint,
.checkbox .field-error {
    grid-column: 2;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: flex-end;
    margin: 1rem 0;
}

.filter-form .field {
    margin: 0;
    min-width: 12rem;
}

.filter-form input,
.filter-form select {
    margin: 0;
}

.recaptcha-status:empty {
    display: none;
}

/* Botones */
.button {
    display: inline-block;
    font: inherit;
    font-weight: bold;
    line-height: 1.3;
    text-align: center;
    text-decoration: none;
    color: #fff;
    background: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius);
    padding: 0.6rem 1.1rem;
    min-height: 44px;
    cursor: pointer;
}

.button:hover {
    color: #fff;
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    text-decoration: none;
}

.button[disabled] {
    opacity: 0.65;
    cursor: progress;
}

.button-secondary {
    color: var(--color-primary);
    background: var(--color-surface);
}

.button-secondary:hover {
    color: #fff;
}

.button-danger {
    background: var(--color-error);
    border-color: var(--color-error);
}

.button-danger:hover {
    background: #8c1d17;
    border-color: #8c1d17;
}

.button-small {
    font-size: 0.9rem;
    padding: 0.3rem 0.7rem;
    min-height: 36px;
}

.button-row {
    margin: 1rem 0;
}

.link-list {
    padding-left: 1.25rem;
}

/* Tablas */
.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
}

table {
    border-collapse: collapse;
    width: 100%;
    background: var(--color-surface);
}

caption {
    text-align: left;
    font-weight: bold;
    padding: 0.5rem 0;
}

th,
td {
    text-align: left;
    vertical-align: top;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
}

thead th {
    border-bottom: 2px solid var(--color-border);
    background: #eef0f2;
}

tbody th {
    font-weight: normal;
}

/* Progreso */
.progress-label {
    margin: 0 0 0.25rem;
    font-weight: bold;
}

progress {
    width: 100%;
    max-width: 30rem;
    height: 1.25rem;
    accent-color: var(--color-success);
}

/* Resumen en lista de definiciones */
.summary-list {
    margin: 1rem 0;
    max-width: 48rem;
}

.summary-list > div {
    display: grid;
    grid-template-columns: 10rem 1fr;
    gap: 1rem;
    border-bottom: 1px solid var(--color-border-light);
    padding: 0.4rem 0;
}

.summary-list dt {
    font-weight: bold;
}

.summary-list dd {
    margin: 0;
}

/* Estadísticas */
.stats {
    list-style: none;
    padding: 0;
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
}

.stats li {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 1rem;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: bold;
}

/* Navegación entre contenidos */
.pager {
    margin: 2rem 0;
    border-top: 1px solid var(--color-border-light);
    padding-top: 1rem;
}

.pager ul {
    justify-content: space-between;
}

.pager li {
    flex: 1 1 12rem;
}

.pager li:nth-child(2) {
    text-align: center;
}

.pager li:last-child {
    text-align: right;
}

.pager-title {
    display: block;
    font-weight: bold;
}

.pagination a {
    display: inline-block;
    min-width: 2.5rem;
    padding: 0.35rem 0.6rem;
    text-align: center;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.pagination a[aria-current="page"] {
    background: var(--color-primary);
    color: #fff;
    font-weight: bold;
}

.debug pre {
    white-space: pre-wrap;
}

@media (max-width: 40rem) {
    h1 {
        font-size: 1.6rem;
    }

    .summary-list > div {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .pager li,
    .pager li:nth-child(2),
    .pager li:last-child {
        text-align: left;
    }
}

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

@media (forced-colors: active) {
    .badge,
    .button {
        border: 1px solid ButtonText;
    }
}

@media print {
    .site-header,
    .site-footer,
    .pager,
    .subnav,
    form {
        display: none;
    }
}
