/* ==========================================================================
   Constructor de Cursos IA — interfaz
   Modo claro por defecto; oscuro según el sistema o elegido por el usuario (data-theme).
   El color primario llega de .env (APP_PRIMARY_COLOR) como variables en el <head>:
   --primary, --primary-rgb, --primary-hover, --on-primary, --primary-ink-light/-dark.
   ========================================================================== */

:root {
    color-scheme: light;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --bg: #f7f6f2;
    --sidebar-bg: #f0eee8;
    --surface: #ffffff;
    --surface-2: #f5f4ef;
    --surface-3: #ebe9e2;
    --hover: rgba(20, 20, 19, .05);
    --active: rgba(20, 20, 19, .08);
    --border: #e4e1d8;
    --border-strong: #d3cfc4;
    --text: #1c1b18;
    --text-2: #4f4d47;
    --muted: #6d6b64;
    --faint: #9a978d;
    --input-bg: #ffffff;
    --shadow-sm: 0 1px 2px rgba(20, 20, 19, .06);
    --shadow: 0 8px 24px rgba(20, 20, 19, .08), 0 1px 2px rgba(20, 20, 19, .05);
    --shadow-lg: 0 24px 60px rgba(20, 20, 19, .18), 0 2px 6px rgba(20, 20, 19, .06);
    --overlay: rgba(20, 20, 19, .45);

    --link: var(--primary-ink-light);
    --primary-soft: rgba(var(--primary-rgb), .13);
    --primary-soft-2: rgba(var(--primary-rgb), .26);

    --success: #1d7040;
    --success-bg: #e2f2e7;
    --success-strong: #2f9e5a;
    --warn: #7f5300;
    --warn-bg: #fcefd3;
    --warn-strong: #d99a1c;
    --danger: #ad3027;
    --danger-bg: #fbe6e3;
    --danger-strong: #d8483d;

    --radius-sm: 7px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --sidebar-w: 268px;
    --rail-w: 66px;
    --ease: cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #121211;
        --sidebar-bg: #191918;
        --surface: #161615;
        --surface-2: #1e1e1c;
        --surface-3: #282826;
        --hover: rgba(255, 255, 255, .05);
        --active: rgba(255, 255, 255, .09);
        --border: #2a2a27;
        --border-strong: #3a3935;
        --text: #ecebe5;
        --text-2: #cac8c0;
        --muted: #a2a098;
        --faint: #76746d;
        --input-bg: #1a1a18;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow: 0 10px 30px rgba(0, 0, 0, .45);
        --shadow-lg: 0 24px 70px rgba(0, 0, 0, .6);
        --overlay: rgba(0, 0, 0, .6);
        --link: var(--primary-ink-dark);
        --primary-soft: rgba(var(--primary-rgb), .15);
        --primary-soft-2: rgba(var(--primary-rgb), .3);
        --success: #86d6a4;
        --success-bg: rgba(47, 158, 90, .16);
        --success-strong: #3fb56c;
        --warn: #f1c56e;
        --warn-bg: rgba(217, 154, 28, .15);
        --warn-strong: #e0a93a;
        --danger: #f3a097;
        --danger-bg: rgba(216, 72, 61, .17);
        --danger-strong: #e0574c;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121211;
    --sidebar-bg: #191918;
    --surface: #161615;
    --surface-2: #1e1e1c;
    --surface-3: #282826;
    --hover: rgba(255, 255, 255, .05);
    --active: rgba(255, 255, 255, .09);
    --border: #2a2a27;
    --border-strong: #3a3935;
    --text: #ecebe5;
    --text-2: #cac8c0;
    --muted: #a2a098;
    --faint: #76746d;
    --input-bg: #1a1a18;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, .6);
    --overlay: rgba(0, 0, 0, .6);
    --link: var(--primary-ink-dark);
    --primary-soft: rgba(var(--primary-rgb), .15);
    --primary-soft-2: rgba(var(--primary-rgb), .3);
    --success: #86d6a4;
    --success-bg: rgba(47, 158, 90, .16);
    --success-strong: #3fb56c;
    --warn: #f1c56e;
    --warn-bg: rgba(217, 154, 28, .15);
    --warn-strong: #e0a93a;
    --danger: #f3a097;
    --danger-bg: rgba(216, 72, 61, .17);
    --danger-strong: #e0574c;
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.55 var(--font-sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-family: var(--font-serif); font-weight: 500; font-size: 2rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; margin: 1.1rem 0 .5rem; }
h4 { font-size: .95rem; margin: 1rem 0 .4rem; }
p { margin: 0 0 .75rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.75rem 0; }
code, kbd, pre { font-family: var(--font-mono); }
::selection { background: var(--primary-soft-2); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); }
.help { color: var(--muted); font-size: .85rem; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; padding: .5rem .9rem; border-radius: var(--radius); background: var(--primary); color: var(--on-primary); }
.skip-link:focus { top: 12px; }
.empty-inline { color: var(--muted); font-style: italic; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.spacer { flex: 1; }

/* --- Estructura: barra lateral + contenido ------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app__main { min-width: 0; display: flex; flex-direction: column; }
.main { width: 100%; max-width: 1200px; margin: 0 auto; padding: 36px 40px 72px; flex: 1; }
.main:focus { outline: none; }
html[data-page="editor"] .main { max-width: 1680px; padding: 24px 28px 56px; }

.sidebar {
    position: sticky; top: 0; height: 100vh; z-index: 40;
    display: flex; flex-direction: column; gap: .35rem; padding: 14px 12px 10px;
    background: var(--sidebar-bg); border-right: 1px solid var(--border);
}
.sidebar__top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 4px 2px 8px 6px; }
.sidebar .sidebar__close { display: none; }
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__mark { width: 30px; height: 30px; flex: none; }
.brand__name { font-family: var(--font-serif); font-size: 1.06rem; font-weight: 500; line-height: 1.2; letter-spacing: -.005em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
img.brand__mark { object-fit: contain; }
/* Logo de Ajustes → Identidad: reemplaza al ícono (que vuelve en el menú contraído) y, si así se eligió, al nombre. */
.brand--logo .brand__mark { display: none; }
.brand__logo { display: flex; align-items: center; flex: 0 1 auto; min-width: 0; }
.brand__logo-img { height: 32px; width: auto; max-width: 100%; object-fit: contain; object-position: left center; }
/* Con logo para cada modo, se ve el del tema activo (el elegido por la persona o el del sistema). */
.logo--dark { display: none; }
:root[data-theme="dark"] .logo--light { display: none; }
:root[data-theme="dark"] .logo--dark { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .logo--light { display: none; }
    :root:not([data-theme="light"]) .logo--dark { display: block; }
}

.sidebar__search { position: relative; margin: 4px 2px 10px; }
.sidebar__search > .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
.sidebar__search input { height: 38px; padding: 0 56px 0 34px; border-color: var(--border); background: var(--input-bg); font-size: .92rem; }
.sidebar__search input::-webkit-search-cancel-button { display: none; }
.sidebar__search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
kbd { font-family: var(--font-sans); font-size: .72rem; line-height: 1.4; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 .35rem; white-space: nowrap; }

.sidebar__nav { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.nav-label { margin: 1.1rem .8rem .35rem; font-size: .72rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); }
.nav-link {
    position: relative; display: flex; align-items: center; gap: .8rem; min-height: 42px; padding: 0 .8rem;
    border-radius: var(--radius); color: var(--text-2); font-size: .96rem; white-space: nowrap;
}
.nav-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--active); color: var(--text); font-weight: 600; }
.nav-link > .icon { width: 20px; height: 20px; color: var(--muted); }
.nav-link[aria-current="page"] > .icon, .nav-link:hover > .icon { color: var(--text); }
.nav-link > span { overflow: hidden; text-overflow: ellipsis; }
.nav-link__meta { margin-left: auto; font-size: .82rem; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.nav-link--rail-only { display: none; }

.sidebar__bottom { display: flex; flex-direction: column; gap: 2px; margin: 0 -12px; padding: 8px 12px 0; border-top: 1px solid var(--border); }
.quota-mini { height: 4px; margin: -5px .8rem 6px 3.35rem; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.quota-mini span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.quota-mini--warn span { background: var(--warn-strong); }
.quota-mini--danger span { background: var(--danger-strong); }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: .7rem; padding: .55rem .55rem; margin: 2px 0 4px; border-radius: var(--radius); cursor: pointer; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: var(--hover); }
.user-menu > summary > .icon { color: var(--muted); width: 17px; height: 17px; }
.avatar { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--primary-soft); border: 1px solid var(--primary-soft-2); color: var(--link); font-weight: 600; font-size: .86rem; letter-spacing: .02em; }
.avatar--lg { width: 64px; height: 64px; border-radius: 16px; font-size: 1.35rem; }
.user-menu__who { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.user-menu__name { font-weight: 600; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu__meta { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu {
    position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 60;
    padding: 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.menu__who { display: flex; flex-direction: column; padding: .45rem .65rem .55rem; line-height: 1.35; }
.menu__who span { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.menu__item { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .65rem; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; font-size: .92rem; text-align: left; cursor: pointer; }
.menu__item:hover { background: var(--hover); text-decoration: none; }
.menu__item .icon { color: var(--muted); }
.menu__sep { height: 1px; margin: 6px -6px; background: var(--border); }
.menu__label { margin: 0; padding: .35rem .65rem .4rem; font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.menu form { margin: 0; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.menu .segmented { margin: 0 .25rem .3rem; }
.segmented button, .segmented a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: .45rem .35rem; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-size: .76rem; cursor: pointer; }
.segmented--row button, .segmented--row a { flex-direction: row; justify-content: center; gap: .45rem; font-size: .88rem; padding: .5rem .8rem; }
.segmented button:hover, .segmented a:hover { color: var(--text); text-decoration: none; }
.segmented [aria-pressed="true"], .segmented [aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented .icon { width: 17px; height: 17px; }

.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

/* Menú contraído a íconos (escritorio). */
@media (min-width: 881px) {
    html.nav-rail .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
    html.nav-rail .sidebar { padding: 14px 10px 10px; }
    html.nav-rail .sidebar__top { flex-direction: column; gap: 12px; padding: 4px 0 10px; }
    html.nav-rail .brand__name, html.nav-rail .nav-link > span, html.nav-rail .nav-label, html.nav-rail .sidebar__search,
    html.nav-rail .user-menu__who, html.nav-rail .user-menu > summary > .icon, html.nav-rail .quota-mini { display: none; }
    html.nav-rail .nav-link--rail-only { display: flex; }
    html.nav-rail .brand__logo { display: none; }
    html.nav-rail .brand--logo .brand__mark { display: block; }
    html.nav-rail .nav-link { justify-content: center; padding: 0; }
    html.nav-rail .nav-link:hover::after, html.nav-rail .nav-link:focus-visible::after {
        content: attr(data-label); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%); z-index: 70;
        padding: .3rem .6rem; border-radius: 6px; background: var(--text); color: var(--bg); font-size: .8rem; font-weight: 500; white-space: nowrap; pointer-events: none;
    }
    html.nav-rail .sidebar__nav { overflow: visible; }
    html.nav-rail .sidebar__bottom { margin: 0 -10px; padding: 8px 10px 0; }
    html.nav-rail .user-menu > summary { justify-content: center; padding: .45rem 0; }
    html.nav-rail .menu { right: auto; left: 0; width: 250px; }
}

/* Móvil: el menú es un panel que se abre desde la izquierda. */
@media (max-width: 880px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100%; transform: translateX(-104%); transition: transform .22s var(--ease); box-shadow: var(--shadow-lg); }
    html.nav-open .sidebar { transform: none; }
    html.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: var(--overlay); }
    .sidebar .sidebar__toggle { display: none; }
    .sidebar .sidebar__close { display: inline-grid; }
    .mobile-bar {
        display: flex; align-items: center; gap: .6rem; position: sticky; top: 0; z-index: 30; height: 58px; padding: 0 10px;
        background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
    }
    .mobile-bar .brand { flex: 1; }
    .mobile-bar .brand__mark { width: 28px; height: 28px; }
    .mobile-bar .brand__name { font-size: 1.02rem; }
    .mobile-bar .brand__logo-img { height: 28px; }
    .main, html[data-page="editor"] .main { padding: 22px 16px 56px; }
}

/* --- Encabezados de página ---------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem 1.5rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.page-head > div:first-child { min-width: 0; }
.page-head h1 { font-size: clamp(1.55rem, 2.3vw, 2.1rem); overflow-wrap: anywhere; }
.page-head .lead { margin: .45rem 0 0; color: var(--muted); max-width: 70ch; }
.eyebrow { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem; margin: 0 0 .55rem; font-size: .85rem; color: var(--muted); }
.eyebrow a { color: var(--muted); }
.eyebrow a:hover { color: var(--text); }
.eyebrow .icon { width: 14px; height: 14px; }
.head-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.head-actions form { margin: 0; }
/* Editor: un título largo se corta con «…» y deja las acciones a su derecha; solo si le quedarían menos de 14rem
   pasan las acciones abajo (en el móvil, el título usa hasta dos líneas). */
.page-head--fit > div:first-child { flex: 1 1 14rem; }
.page-head--fit h1 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; }
.greeting { font-size: clamp(1.7rem, 3vw, 2.25rem); }

.section { margin-top: 2.4rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-head h2 { font-size: 1.14rem; }
.section-head a { font-size: .93rem; text-decoration: underline; text-underline-offset: 3px; }

/* --- Botones -------------------------------------------------------------- */
.btn {
    --btn-h: 38px;
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem; height: var(--btn-h); padding: 0 .95rem;
    font: inherit; font-size: .93rem; font-weight: 500; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
    color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius);
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn .icon { width: 17px; height: 17px; }
.btn--primary { color: var(--on-primary); background: var(--primary); border-color: transparent; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--inverse { color: var(--bg); background: var(--text); border-color: transparent; }
.btn--inverse:hover { background: var(--text-2); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--hover); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); border-color: transparent; }
.btn--small { --btn-h: 31px; padding: 0 .7rem; gap: .4rem; font-size: .85rem; border-radius: var(--radius-sm); }
.btn--small .icon { width: 15px; height: 15px; }
.btn--block { width: 100%; }
.icon-btn {
    display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; flex: none;
    color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.icon-btn--danger:hover { background: var(--danger-bg); color: var(--danger); }
.link { font: inherit; padding: 0; color: var(--link); background: none; border: 0; cursor: pointer; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.link--danger { color: var(--danger); }
.link--muted { color: var(--muted); }

/* --- Avisos, etiquetas ----------------------------------------------------- */
.flashes { display: grid; gap: .6rem; margin-bottom: 1.4rem; }
.flash { display: flex; align-items: flex-start; gap: .65rem; margin-bottom: 1rem; padding: .8rem 1rem; border-radius: var(--radius); font-size: .93rem; line-height: 1.45; }
.flashes .flash { margin: 0; }
.flash > .icon { margin-top: 1px; }
.flash__text .icon { width: 15px; height: 15px; vertical-align: -2px; }
.flash__text { flex: 1; min-width: 0; }
.flash__close { width: 26px; height: 26px; margin: -3px -5px -3px 0; color: inherit; opacity: .7; }
.flash__close:hover { opacity: 1; background: transparent; color: inherit; }
.flash a { color: inherit; text-decoration: underline; }
.quota-banner { align-items: center; flex-wrap: wrap; }
.quota-banner .flash__text { min-width: min(100%, 260px); }
.quota-banner .btn { flex: none; color: var(--text); text-decoration: none; }
.flash--success { background: var(--success-bg); color: var(--success); }
.flash--error { background: var(--danger-bg); color: var(--danger); }
.flash--info { background: var(--primary-soft); color: var(--link); }
.flash--warn { background: var(--warn-bg); color: var(--warn); }
.flash--error-card { border-color: var(--danger-strong); }

.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .24rem .6rem; border-radius: 8px; background: var(--surface-3); color: var(--text-2); font-size: .8rem; font-weight: 500; line-height: 1.3; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill .icon { width: 14px; height: 14px; }
.pill--primary, .pill--new { background: var(--primary-soft); color: var(--link); }
.pill--success { background: var(--success-bg); color: var(--success); }
.pill--warn { background: var(--warn-bg); color: var(--warn); }
.pill--danger { background: var(--danger-bg); color: var(--danger); }

.badge { display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .62rem; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: .78rem; font-weight: 500; line-height: 1.4; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge--draft { color: var(--muted); }
.badge--ready { background: var(--success-bg); color: var(--success); }
.badge--error { background: var(--danger-bg); color: var(--danger); }
.badge--review, .badge--outline_review { background: var(--warn-bg); color: var(--warn); }
.badge--researching, .badge--outlining, .badge--generating { background: var(--primary-soft); color: var(--link); }
.badge--researching::before, .badge--outlining::before, .badge--generating::before { animation: pulse 1.6s ease-in-out infinite; }
.tag { display: inline-flex; align-items: center; padding: .05rem .5rem; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--muted); font-size: .74rem; line-height: 1.5; white-space: nowrap; }
.chip { display: inline-block; margin: .1rem; padding: .05rem .45rem; border-radius: 6px; background: var(--surface-3); font-size: .78rem; cursor: help; }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Tarjetas y estadísticas ---------------------------------------------- */
.card { margin-bottom: 1.25rem; padding: 1.3rem 1.45rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; margin-bottom: .9rem; }
.card.narrow { max-width: 440px; width: 100%; margin-inline: auto; }
.card--inner { margin: 0; background: var(--surface-2); }
.card--warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.card--danger { border-color: var(--danger-strong); }
.card.empty { text-align: center; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.card-head h2, .card-head h3 { margin: 0; font-size: 1.04rem; }
.card-head .help { margin-top: .2rem; }
.card-title { display: flex; align-items: center; gap: .6rem; }
.card-title .icon { color: var(--muted); }

.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 1150px) { .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) { .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid--2, .grid--3, .grid--4, .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

.stat-card { position: relative; display: flex; flex-direction: column; gap: .3rem; min-height: 176px; padding: 1.25rem 1.4rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.stat-card__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--text-2); font-size: .95rem; }
.stat-card__label { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.stat-card__label .icon { color: var(--muted); width: 16px; height: 16px; }
.stat-card__value { margin-top: auto; font-size: 2.15rem; font-weight: 600; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-card__value small { font-size: 1rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat-card__sub { color: var(--muted); font-size: .87rem; }
.stat-card__sub a { color: var(--success); text-decoration: underline; text-underline-offset: 3px; }
.stat-card__corner { position: absolute; right: 1.4rem; bottom: 1.35rem; }
.stat-card:has(.stat-card__corner) .stat-card__sub { padding-right: 76px; }
.stat-card--wide { min-height: 0; }
.stat-card--wide .stat-card__body { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.stat-card--wide .chart { width: min(460px, 100%); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stats > div { display: flex; flex-direction: column; }
.stats__value { font-size: 1.55rem; font-weight: 600; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.stats__label { color: var(--muted); font-size: .85rem; }

.kv { display: grid; grid-template-columns: minmax(130px, 200px) 1fr; gap: .55rem 1.25rem; margin: 0; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Anillo (porcentaje de cuota) */
.ring { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.4; }
.ring__track { stroke: var(--surface-3); }
.ring__value { stroke: var(--primary); stroke-linecap: round; transition: stroke-dasharray .6s var(--ease); }
.ring--warn .ring__value { stroke: var(--warn-strong); }
.ring--danger .ring__value { stroke: var(--danger-strong); }

/* Barra de progreso / medidor */
.meter { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; width: var(--value, 0%); min-width: 2px; border-radius: inherit; background: var(--primary); }
.meter--warn > span { background: var(--warn-strong); }
.meter--danger > span { background: var(--danger-strong); }
.meter--thin { height: 5px; }
progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 99px; background: var(--surface-3); overflow: hidden; color: var(--primary); }
progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; transition: width .4s var(--ease); }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }

/* Gráfico de barras (HTML/CSS: se adapta al tema y al ancho) */
.chart { position: relative; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 6px; }
.bars--sm { height: 64px; gap: 2px; }
.bars--xs { height: 46px; width: 150px; gap: 2px; }
.bars__bar { position: relative; flex: 1 1 0; min-width: 2px; height: var(--h, 0%); min-height: 2px; border-radius: 3px 3px 1px 1px; background: var(--primary); opacity: .85; transition: opacity .15s; }
.bars__bar--empty { background: var(--surface-3); opacity: 1; }
.bars__bar--current { opacity: 1; box-shadow: 0 0 0 1px var(--primary) inset; }
.bars__bar:hover { opacity: 1; }
.bars__bar[data-tip]:hover::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 5;
    padding: .35rem .55rem; border-radius: 7px; background: var(--text); color: var(--bg); font-size: .76rem; line-height: 1.35; white-space: pre; pointer-events: none;
}
.chart__axis { display: flex; justify-content: space-between; gap: .5rem; margin-top: .45rem; font-size: .75rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.chart__legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.delta { display: inline-flex; align-items: center; gap: .2rem; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .25rem .75rem; align-items: center; font-size: .9rem; }
.hbar + .hbar { margin-top: .75rem; }
.hbar__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar__value { color: var(--muted); font-variant-numeric: tabular-nums; }
.hbar .meter { grid-column: 1 / -1; height: 6px; }

/* --- Tablas -------------------------------------------------------------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); font-size: .92rem; }
.table th { padding: .7rem 1rem; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .8rem; font-weight: 500; text-align: left; white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; margin: 0; }
.table--compact th, .table--compact td { padding: .5rem .75rem; }
.table--plain { border: 0; border-radius: 0; background: transparent; }
.table--plain th:first-child, .table--plain td:first-child { padding-left: 0; }
.table--plain th:last-child, .table--plain td:last-child { padding-right: 0; }
.table--plain tbody tr:hover td { background: transparent; }
.table-wrap { overflow-x: auto; }
.table-wrap > .table { min-width: 560px; }
.cell-title { display: flex; flex-direction: column; min-width: 0; }
.cell-title strong { font-weight: 600; }
.cell-title span { color: var(--muted); font-size: .84rem; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .35rem 0; }

/* --- Formularios ---------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: 1.1rem; }
.form--grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-items: end; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .4rem; margin: 0; min-width: 0; }
.field > label, .form label:not(.choice) { display: flex; flex-direction: column; gap: .4rem; color: var(--text-2); font-size: .88rem; font-weight: 500; }
.field--error input, .field--error textarea, .field--error select { border-color: var(--danger-strong); }
input, select, textarea {
    width: 100%; padding: .55rem .75rem; font: inherit; font-size: .95rem; color: var(--text);
    background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft-2); }
input:disabled, select:disabled, textarea:disabled, input[readonly] { opacity: .65; }
textarea { resize: vertical; line-height: 1.5; }
::placeholder { color: var(--faint); opacity: 1; }
select {
    appearance: none; padding-right: 2.2rem; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a877e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .7rem center; background-size: 16px;
}
input[type="checkbox"], input[type="radio"] { width: 17px; height: 17px; margin: 0; padding: 0; flex: none; accent-color: var(--primary); box-shadow: none; }
input[type="color"] { width: 72px; height: 42px; padding: 4px; cursor: pointer; }
input[type="file"] { padding: .4rem; }
input[type="file"]::file-selector-button { margin-right: .75rem; padding: .4rem .8rem; font: inherit; font-size: .88rem; color: var(--text); background: var(--surface-3); border: 0; border-radius: var(--radius-sm); cursor: pointer; }
input[type="search"]::-webkit-search-decoration { appearance: none; }
fieldset { min-width: 0; }
fieldset.field { padding: .9rem 1rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
fieldset.field legend { padding: 0 .35rem; color: var(--text-2); font-size: .88rem; font-weight: 500; }
fieldset.plain { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; margin: 0; padding: 0; border: 0; }
fieldset.group { display: flex; flex-direction: column; gap: .95rem; min-width: 0; margin: 0; padding: 1rem 1.25rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius-lg); }
fieldset.group > legend { padding: 0 .45rem; font-weight: 600; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; }
/* Preferencia con explicación alineada al texto de la casilla (17 px + separación). */
.pref .help { margin: .2rem 0 0 calc(17px + .55rem); }
label.choice, .form label.choice { display: flex; flex-direction: row; align-items: center; gap: .55rem; color: var(--text); font-size: .93rem; font-weight: 400; cursor: pointer; }
.choices label.choice { padding: .5rem .8rem; background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius); transition: border-color .15s, background-color .15s; }
.choices label.choice:hover { border-color: var(--faint); }
.choices label.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choices label.choice:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--primary-soft-2); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .6rem; }
.form-actions form { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.inline-end { margin-top: -.25rem; text-align: right; }
.w-sm { max-width: 120px; }
.w-md { max-width: 200px; }
.w-color { max-width: 90px; }
.input-title { font-size: 1.05rem; font-weight: 600; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 2.8rem; }
.password-field .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
.input-icon > input { padding-left: 2.2rem; }

/* --- Inicio de sesión ----------------------------------------------------- */
.auth {
    min-height: 100vh; display: grid; place-items: center; padding: 40px 16px;
    background: radial-gradient(1100px 520px at 50% -10%, var(--primary-soft), transparent 70%), var(--bg);
}
.auth__inner { width: 100%; max-width: 420px; }
.auth__card { padding: 2rem 2rem 1.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
.auth__brand { display: flex; align-items: center; justify-content: center; gap: .7rem; margin-bottom: 1.6rem; font-family: var(--font-serif); font-size: 1.15rem; }
.auth__brand .brand__mark { width: 34px; height: 34px; }
.auth__brand .brand__name { font-size: inherit; }
.auth__brand .brand__logo-img { height: 44px; max-width: min(300px, 100%); object-position: center; }
.auth h1 { font-size: 1.75rem; margin-bottom: .35rem; text-align: center; }
.auth__lead { color: var(--muted); margin-bottom: 1.5rem; text-align: center; }
.auth__foot { margin: 1.25rem 0 0; text-align: center; color: var(--faint); font-size: .82rem; }
.auth .flash { margin-bottom: 1rem; }

/* --- Errores ------------------------------------------------------------- */
.error-page { max-width: 520px; margin: 8vh auto 0; text-align: center; }
.error-page__code { display: inline-grid; place-items: center; width: 64px; height: 64px; margin-bottom: 1.25rem; border-radius: 18px; background: var(--primary-soft); color: var(--link); }
.error-page__code .icon { width: 28px; height: 28px; }
.error-page h1 { margin-bottom: .6rem; }
.error-page p { color: var(--muted); }
.error-page .head-actions { justify-content: center; margin-top: 1.5rem; }

/* --- Tarjetas de curso --------------------------------------------------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 1rem; }
.course-card {
    position: relative; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    transition: border-color .15s, box-shadow .2s, transform .2s var(--ease);
}
.course-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.course-card:focus-within { border-color: var(--primary); }
.course-card__art { position: relative; height: 120px; display: grid; place-items: center; overflow: hidden; background: var(--art, var(--surface-3)); border-bottom: 1px solid var(--border); }
.course-card__art svg { width: 78px; height: 78px; }
.course-card__art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.course-card__body { flex: 1; display: flex; flex-direction: column; gap: .6rem; padding: .95rem 1.05rem 1rem; }
.course-card__title { margin: 0; font-size: 1.02rem; font-weight: 600; line-height: 1.3; }
.course-card__title a { color: var(--text); }
.course-card__title a:hover { text-decoration: none; }
.course-card__title a::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.course-card__tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.course-card__foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .82rem; color: var(--muted); }
.course-card__foot form { position: relative; z-index: 2; margin: 0; }
.course-card__actions { display: flex; align-items: center; gap: .1rem; margin-right: -.45rem; }
.course-card__actions:has(.btn) { gap: .35rem; margin-right: 0; }
/* Archivado: la portada se apaga para distinguirlo de un vistazo. */
.course-card--archived .course-card__art { filter: grayscale(.7); opacity: .75; }
/* Tarjeta para crear un curso: toda la tarjeta es el enlace al asistente. */
.course-card--new { align-items: center; justify-content: center; min-height: 250px; gap: .75rem; border-style: dashed; color: var(--muted); text-align: center; }
.course-card--new:hover { border-color: var(--primary); text-decoration: none; }
.course-card--new .empty__icon { margin: 0; transition: background-color .15s, color .15s; }
.course-card--new:hover .empty__icon { background: var(--primary); color: var(--on-primary); }
.course-card__new-title { color: var(--text); font-weight: 600; }

.resource-card { display: flex; flex-direction: column; gap: .45rem; padding: 1.1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); transition: border-color .15s, background-color .15s; }
.resource-card:hover { border-color: var(--border-strong); background: var(--surface-2); text-decoration: none; }
.resource-card__head { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.resource-card__head .icon { color: var(--muted); }
.resource-card p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }

.empty { padding: 3rem 1.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.empty h2 { color: var(--text); margin-bottom: .4rem; }
.empty p { max-width: 52ch; margin: 0 auto 1.1rem; }
.empty__icon { width: 46px; height: 46px; display: grid; place-items: center; margin: 0 auto .9rem; border-radius: 13px; background: var(--primary-soft); color: var(--link); }
.empty__icon .icon { width: 22px; height: 22px; }

.steps { counter-reset: step; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-top: 1.5rem; text-align: left; }
.steps li { list-style: none; padding: 1.1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--muted); font-size: .9rem; }
.steps strong { display: flex; align-items: center; gap: .55rem; margin-bottom: .35rem; color: var(--text); font-size: .98rem; }
.steps strong::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-size: .78rem; }
@media (max-width: 800px) { .steps { grid-template-columns: 1fr; } }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.toolbar .input-icon { width: min(320px, 100%); }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.tabs a { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border-radius: 7px; color: var(--muted); font-size: .88rem; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a .icon { width: 15px; height: 15px; }
.empty p .icon { width: 1.05em; height: 1.05em; vertical-align: -.15em; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm); }
.tabs .count { color: var(--faint); font-size: .8rem; font-variant-numeric: tabular-nums; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; align-items: flex-start; gap: .8rem; padding: .7rem 0; border-top: 1px solid var(--border); }
.activity li:first-child { border-top: 0; padding-top: 0; }
.activity__icon { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 9px; background: var(--surface-3); color: var(--muted); }
.activity__icon .icon { width: 16px; height: 16px; }
.activity__body { flex: 1; min-width: 0; font-size: .92rem; }
.activity__body a { color: var(--text); font-weight: 500; }
.activity__meta { color: var(--muted); font-size: .82rem; }

/* --- Cuenta y administración --------------------------------------------- */
.profile { display: flex; align-items: center; gap: 1.1rem; }
.profile h2 { font-size: 1.2rem; margin-bottom: .15rem; }
.profile p { margin: 0; color: var(--muted); }
.account-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
@media (max-width: 1080px) { .account-layout { grid-template-columns: minmax(0, 1fr); } }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.status-dot--ok { background: var(--success-strong); box-shadow: 0 0 0 3px var(--success-bg); }
.status-dot--warn { background: var(--warn-strong); box-shadow: 0 0 0 3px var(--warn-bg); }
.status-dot--bad { background: var(--danger-strong); box-shadow: 0 0 0 3px var(--danger-bg); }
.service { display: flex; align-items: flex-start; gap: .8rem; padding: .8rem 0; border-top: 1px solid var(--border); }
.service:first-of-type { border-top: 0; padding-top: .2rem; }
.service .status-dot { margin-top: .45rem; }
.service__name { font-weight: 600; font-size: .93rem; }
.service__detail { color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.log { margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: .8rem; }
.log li { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: .75rem; padding: .45rem 0; border-top: 1px solid var(--border); }
.log li:first-child { border-top: 0; }
.log time { color: var(--faint); }
.log span { overflow-wrap: anywhere; color: var(--text-2); }
@media (max-width: 700px) { .log li { grid-template-columns: 1fr; gap: .1rem; } }
.user-row { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.user-row .avatar { width: 32px; height: 32px; font-size: .78rem; border-radius: 9px; }
/* Nombre y correo editables en la tabla de usuarios: campos discretos que se guardan con el resto de la fila. */
.user-edit { display: grid; gap: .25rem; min-width: 220px; flex: 1; }
.user-edit__line { display: flex; align-items: center; gap: .4rem; }
.user-edit input { width: 100%; padding: .25rem .5rem; border-color: var(--border); background: transparent; }
.user-edit input:hover { border-color: var(--border-strong); }
.user-edit input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft-2); }
.user-edit__name { font-weight: 600; }
.user-edit__email { color: var(--muted); font-size: .84rem; }
details.disclosure > summary { cursor: pointer; color: var(--link); font-size: .9rem; list-style: none; display: inline-flex; align-items: center; gap: .35rem; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .icon { width: 16px; height: 16px; transition: transform .15s; }
details.disclosure[open] > summary .icon { transform: rotate(180deg); }

/* --- Asistente ------------------------------------------------------------ */
.wizard { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.stepper { position: sticky; top: 24px; }
.stepper__progress { margin: 0 .6rem 1rem; }
.stepper__progress p { display: flex; justify-content: space-between; margin: 0 0 .45rem; font-size: .82rem; color: var(--muted); }
.stepper ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.stepper__item a, .stepper__disabled { display: flex; align-items: center; gap: .7rem; padding: .5rem .6rem; border-radius: var(--radius); color: var(--text-2); font-size: .92rem; }
.stepper__item a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.stepper__disabled { color: var(--faint); }
.stepper__num { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--muted); font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper__num .icon { width: 14px; height: 14px; }
.stepper__item--done .stepper__num { background: var(--success-bg); color: var(--success); }
.stepper__item--current a { background: var(--active); color: var(--text); font-weight: 600; }
.stepper__item--current .stepper__num { background: var(--primary); color: var(--on-primary); }
.wizard__body { padding: 1.6rem 1.75rem; }
.wizard__body > h2 { font-family: var(--font-serif); font-weight: 500; font-size: 1.45rem; margin-bottom: .5rem; }
.wizard__body > h2 .step-no { color: var(--faint); margin-right: .35rem; }
.wizard__body .form-actions { margin-top: .5rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.source-forms { margin-top: 1.1rem; }
.source-forms h3 { margin-top: 0; }
.review-block { margin-bottom: .75rem; padding: .9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.review-block--problem { border-color: var(--danger-strong); }
.review-block__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.review-block h3 { margin: 0 0 .5rem; }
.review-block dl { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: .3rem 1rem; margin: 0; font-size: .92rem; }
.review-block dt { color: var(--muted); }
.review-block dd { margin: 0; }
.estimate { margin: 1.1rem 0; padding: 1rem 1.2rem; border-radius: var(--radius-lg); background: var(--primary-soft); color: var(--text); }
.estimate h3 { margin: 0 0 .5rem; display: flex; align-items: center; gap: .5rem; }
.estimate strong { color: var(--text); }
.estimate .help { color: var(--text-2); }

/* Nivel de razonamiento (revisión del asistente): tarjetas con descripción y consumo estimado */
.effort { margin: 1.1rem 0 .5rem; padding: 1rem 1.2rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); }
.effort > legend { display: flex; align-items: center; gap: .45rem; padding: 0 .45rem; font-weight: 600; }
.effort > legend .icon { width: 17px; height: 17px; color: var(--link); }
.effort__intro { margin: 0 0 .85rem; color: var(--text-2); font-size: .92rem; }
/* Columnas según el espacio del asistente (no del viewport): una, dos o tres tarjetas por fila. */
.effort__options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: .75rem; }
label.effort__option { display: flex; flex-direction: column; gap: .55rem; padding: .9rem 1rem 1rem; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); cursor: pointer; transition: border-color .15s, background-color .15s, box-shadow .15s; }
label.effort__option:hover { border-color: var(--faint); }
label.effort__option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
label.effort__option:has(input:focus-visible) { box-shadow: inset 0 0 0 1px var(--primary), 0 0 0 3px var(--primary-soft-2); }
.effort__head { display: flex; align-items: center; gap: .55rem; font-size: 1rem; font-weight: 600; }
.effort__head .pill { margin-left: auto; }
.effort__name { display: flex; flex-direction: column; line-height: 1.25; }
.effort__level { color: var(--faint); font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.effort__text { color: var(--text-2); font-size: .88rem; line-height: 1.5; }
.effort__figures { display: grid; gap: .3rem; margin-top: auto; padding-top: .65rem; border-top: 1px solid var(--border); color: var(--text-2); font-size: .84rem; font-variant-numeric: tabular-nums; }
.effort__figures > span { display: grid; grid-template-columns: 14px 1fr; align-items: start; gap: .45rem; }
.effort__figures .icon { width: 14px; height: 14px; margin-top: .15em; color: var(--faint); }
.effort__figures strong { color: var(--text); font-weight: 600; }
.effort__note { margin: .85rem 0 0; }
/* Tres opciones que se comparan entre sí (calidad de las animaciones): en tres columnas cuando el asistente tiene el
   ancho de una PC; si es más angosto, vuelven a acomodarse solas. */
.wizard__body { container-type: inline-size; }
@container (min-width: 520px) {
    .effort__options--three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
    .effort__options--three label.effort__option { padding: .8rem .85rem .9rem; }
    .effort__options--three .effort__head { font-size: .95rem; }
}

/* --- Progreso de la generación ------------------------------------------- */
.phases { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.25rem; padding: 0; list-style: none; }
.phases__item { display: flex; align-items: center; gap: .5rem; padding: .45rem .85rem .45rem .5rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .9rem; }
.phases__num { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); font-size: .75rem; font-weight: 600; }
.phases__item.is-done { color: var(--success); }
.phases__item.is-done .phases__num { background: var(--success-bg); }
.phases__item.is-current { color: var(--text); border-color: var(--primary); font-weight: 600; }
.phases__item.is-current .phases__num { background: var(--primary); color: var(--on-primary); }
.tasks { display: grid; gap: .35rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.task { display: flex; align-items: baseline; gap: .75rem; padding: .5rem .75rem; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .92rem; }
.task::before { content: "○"; color: var(--faint); width: 1rem; flex: none; text-align: center; }
.task--running::before { content: "◌"; color: var(--link); display: inline-block; animation: spin 1.2s linear infinite; }
.task--done::before { content: "✓"; color: var(--success); }
.task--failed::before { content: "✕"; color: var(--danger); }
.task__detail { color: var(--muted); font-size: .85rem; }
.task--failed .task__detail { color: var(--danger); }

/* --- Temario -------------------------------------------------------------- */
.module-card .objective-list { margin: .35rem 0 1rem; padding-left: 1.2rem; font-size: .92rem; }
.lesson-card { margin: .5rem 0; padding: .6rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.lesson-card summary { display: flex; justify-content: space-between; gap: 1rem; cursor: pointer; font-weight: 600; }
.lesson-card[open] { background: var(--surface); }
.lesson-card .field { margin-top: .7rem; }

/* --- Editor -------------------------------------------------------------- */
.editor { display: grid; grid-template-columns: 292px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.editor__nav { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; padding: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.editor__nav ol { list-style: none; margin: 0; padding: 0; }
.editor__nav a { display: flex; align-items: center; gap: .5rem; padding: .42rem .6rem; border-radius: var(--radius-sm); color: var(--text-2); font-size: .9rem; line-height: 1.35; }
.editor__nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.editor__nav a[aria-current="page"] { background: var(--primary-soft); color: var(--link); font-weight: 600; }
.editor__nav a > .icon { width: 16px; height: 16px; color: var(--faint); }
.editor__nav a[aria-current="page"] > .icon { color: currentColor; }
.editor__nav a > span { min-width: 0; }
.editor__nav .flag { margin-left: auto; display: inline-flex; color: var(--warn-strong); }
.editor__nav .flag .icon { width: 15px; height: 15px; }
.editor__module { margin: .9rem 0 .3rem; font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.editor__nav .editor__module a { padding: .3rem .6rem; font-size: inherit; color: inherit; line-height: 1.4; }
.editor__nav .editor__module a:hover { color: var(--text-2); }
.editor__nav .editor__module a[aria-current="page"] { color: var(--link); }
.editor__tools { display: grid; gap: 2px; margin-top: .75rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.editor__tools a { color: var(--muted); }
.editor__tools a .icon { width: 16px; height: 16px; }
.editor__main { min-width: 0; }
.ed-head { margin-bottom: 1rem; }
.ed-head h2 { margin: .15rem 0 .5rem; font-family: var(--font-serif); font-weight: 500; font-size: 1.6rem; }
.ed-details { margin: .45rem 0; }
.ed-details > summary { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; color: var(--link); font-size: .9rem; list-style: none; }
.ed-details > summary::-webkit-details-marker { display: none; }
.ed-details > summary .icon { width: 16px; height: 16px; }
.ed-details[open] > summary { margin-bottom: .75rem; }
details.card.ed-details > summary { display: flex; }
.lesson-view { padding: 1.5rem 2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); line-height: 1.7; font-size: 1rem; }
.lesson-view p, .lesson-view li { max-width: 78ch; }
.objectives { margin-bottom: 1.1rem; padding: .7rem 1rem; border-radius: var(--radius); background: var(--surface-2); }
/* Requisitos de módulos y lecciones (temario y editor) */
.requires-edit { display: flex; flex-direction: column; gap: .8rem; min-width: 0; margin: .3rem 0 1rem; padding: .85rem 1rem 1rem; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.requires-edit > legend { padding: 0 .35rem; color: var(--text-2); font-size: .88rem; font-weight: 600; }
.requires-edit__options { display: flex; flex-wrap: wrap; gap: .5rem; }
.requires-edit__options label.choice { padding: .45rem .75rem; background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: .9rem; }
.requires-edit__options label.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.requires-edit .field { margin: 0; }
.requires-view { display: flex; gap: .7rem; margin-bottom: 1.1rem; padding: .7rem 1rem; border-radius: var(--radius); background: var(--warn-bg); color: var(--text-2); font-size: .93rem; }
.requires-view > .icon { flex: none; width: 18px; height: 18px; margin-top: .3rem; color: var(--warn); }
.requires-view p { margin: 0; }
.unit-list { display: grid; gap: .5rem; margin: .6rem 0 0; padding-left: 1.3rem; }
.unit-list li { line-height: 1.5; }
.unit-list .pill { margin-left: .35rem; vertical-align: 1px; }
.lesson-card summary .badge .icon { width: 13px; height: 13px; margin-right: .2rem; vertical-align: -2px; }
.objectives ul { margin: .3rem 0; }
.ed-block { margin: .8rem -.9rem; padding: .6rem .9rem; border: 1px dashed transparent; border-radius: var(--radius); }
.ed-block:hover, .ed-block:focus-within { border-color: var(--border-strong); }
.ed-block h3 { margin-top: .2rem; }
.ed-block__bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.ed-block__actions { display: flex; gap: .3rem; opacity: .35; transition: opacity .15s; }
.ed-block:hover .ed-block__actions, .ed-block:focus-within .ed-block__actions { opacity: 1; }
.block--definition, .block--important, .block--example, .block--case, .block--activity, .block--reflection { border-left: 3px solid var(--primary); background: var(--surface-2); }
.block--important { border-left-color: var(--warn-strong); }
.block--summary, .block--terms { margin: 1rem 0; padding: .6rem 1.1rem; border-radius: var(--radius); background: var(--surface-2); }
.block--terms dt { margin-top: .5rem; font-weight: 600; }
.block--terms dd { margin: 0; }
a.cite { white-space: nowrap; text-decoration: none; border-bottom: 1px dotted currentColor; }
.references { margin-top: 1.5rem; border-top: 1px solid var(--border); font-size: .9rem; }
.refs { padding-left: 1.2rem; }
.refs li { margin: .35rem 0; overflow-wrap: anywhere; }
.refs li:target { background: var(--warn-bg); }
.glossary dt { margin-top: .6rem; font-weight: 600; }
.glossary dd { margin: 0; }
.review-panel { border-left: 3px solid var(--success-strong); }
.review-panel--grave { border-left-color: var(--danger-strong); }
.review-panel h3 { margin-top: 0; }
.finding { padding: .8rem 0; border-top: 1px solid var(--border); }
.finding__head { margin: 0 0 .45rem; font-size: .9rem; display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.finding__excerpt, .finding__suggestion, .evidence-quote { margin: .35rem 0; padding: .45rem .8rem; border-left: 3px solid var(--border-strong); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); font-size: .92rem; }
.finding__excerpt { border-left-color: var(--danger-strong); }
.finding__suggestion { border-left-color: var(--success-strong); }
.finding__explanation p { margin: .3rem 0; font-size: .92rem; }
.finding__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.ed-question { margin: .8rem 0; padding: .85rem 1.05rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.ed-question__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: 0 0 .35rem; }
.ed-question__stem { margin: .2rem 0 .45rem; }
.ed-options { margin: .3rem 0; padding-left: .5rem; list-style: none; }
.ed-options li { margin: .2rem 0; }
.ed-options li.is-correct { color: var(--success); font-weight: 600; }
.ed-question__explanation p { display: inline; }
.ed-option-table input { min-width: 140px; }
.ed-add { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.ed-add form { display: inline; margin: 0; }
.evidence-table td { vertical-align: top; }
.evidence-claim { margin: .2rem 0; }
.evidence-quote { font-style: italic; color: var(--muted); }
#evidence-filter { max-width: 320px; }

.figure { margin: .8rem 0; }
.figure img { display: block; max-width: 100%; height: auto; border-radius: var(--radius); background: var(--surface-2); }
.figure figcaption { display: flex; flex-direction: column; gap: .15rem; margin-top: .45rem; font-size: .88rem; }
.figure__caption { color: var(--text); }
.figure__credit { color: var(--muted); font-size: .8rem; }
.cover-card .figure img { width: 100%; max-height: 320px; object-fit: cover; }

/* Videos de YouTube, Vimeo o de un archivo: su enlace, solo en una línea del texto, se muestra como reproductor */
.video { max-width: 760px; margin: .9rem 0; }
.video__frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--radius); background: #0b0f19; }
.video__frame iframe, .video__frame video { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border: 0; }
.video--vertical .video__frame { width: min(100%, 300px); aspect-ratio: 9 / 16; }
.video__source { margin-top: .4rem; font-size: .85rem; }
.video__source a { display: inline-flex; align-items: center; gap: .35rem; color: var(--link); font-weight: 600; }
.video__source .icon { width: 15px; height: 15px; flex: none; }

.job-status { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin: .5rem 0; padding: .65rem .9rem; border-radius: var(--radius); background: var(--primary-soft); color: var(--link); font-size: .92rem; }
.job-status progress { flex: 0 0 140px; }
.job-status--failed { background: var(--danger-bg); color: var(--danger); }
.job-status__note { flex-basis: 100%; margin: -.35rem 0 0 calc(14px + .8rem); color: var(--text-2); font-size: .82rem; }
.job-status__note .btn { margin-left: .3rem; }
.form-actions > .job-status, .ed-add > .job-status { flex-basis: 100%; }
[data-job-error] { flex-basis: 100%; margin: .35rem 0 0; }
.anim-media { margin: -.3rem 0 .8rem; }
.ed-infographic img { width: auto; max-width: 100%; max-height: 72vh; margin: 0 auto; }
.ed-infographic a { display: block; text-align: center; }
.ed-infographic__check { margin: .2rem 0 .5rem; }
.ed-infographic__issues ul { margin: .4rem 0; padding-left: 1.1rem; }
.ed-infographic__issues li { margin: .25rem 0; }
.tag--level-2, .tag--level-3 { background: var(--primary-soft); color: var(--link); }
.anim-media__form { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.anim-media__form select { max-width: 320px; }
/* Rehacer una animación: versión nueva (elige el nivel) o corrección de la actual (conserva el nivel). */
.anim-redo label.choice { align-items: flex-start; line-height: 1.45; }
.anim-redo label.choice + label.choice { margin-top: .55rem; }
.anim-redo label.choice input { margin-top: .2rem; }
.anim-redo__adjust { display: none; }
.anim-redo:has(input[name="mode"][value="adjust"]:checked) :is(.anim-redo__level, .anim-redo__new) { display: none; }
.anim-redo:has(input[name="mode"][value="adjust"]:checked) .anim-redo__adjust { display: inline; }

/* Selector de imágenes del banco */
.picker { width: min(980px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.picker::backdrop { background: var(--overlay); }
.picker__form { display: flex; flex-direction: column; gap: .8rem; padding: 1.1rem 1.3rem 1.3rem; }
.picker__head { display: flex; justify-content: space-between; align-items: center; }
.picker__head h2 { margin: 0; font-size: 1.15rem; }
.picker__search { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; }
.picker__results { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; max-height: 50vh; overflow: auto; }
.picker__item { display: flex; flex-direction: column; gap: .3rem; padding: .35rem; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: .78rem; text-align: left; cursor: pointer; }
.picker__item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.picker__item[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
@media (max-width: 640px) { .picker__search { grid-template-columns: 1fr; } }

/* Diferencias entre versiones */
.diff { margin: .6rem 0; padding: .4rem .9rem; border-left: 3px solid var(--border-strong); }
.diff--added { border-left-color: var(--success-strong); }
.diff--removed { border-left-color: var(--danger-strong); }
.diff--changed { border-left-color: var(--primary); }
.diff__label { margin: 0 0 .25rem; font-size: .9rem; color: var(--muted); }
.diff__text { white-space: pre-wrap; line-height: 1.6; }
.diff--removed .diff__text { text-decoration: line-through; color: var(--muted); }
.diff ins { background: var(--success-bg); color: var(--success); text-decoration: none; border-radius: 3px; }
.diff del { background: var(--danger-bg); color: var(--danger); border-radius: 3px; }

/* Chat de edición (panel derecho) */
.chat { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(440px, 100vw); display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); }
body.has-chat .app__main { padding-right: min(440px, 100vw); }
@media (max-width: 1100px) { body.has-chat .app__main { padding-right: 0; } }
.chat__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.chat__head h2 { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: 1.02rem; }
.chat__head h2 .icon { color: var(--link); }
.chat__head-actions { display: flex; gap: .3rem; }
.chat__log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; padding: 1rem; }
.chat__intro { margin: 0; padding: .8rem .9rem; border-radius: var(--radius); background: var(--surface-2); color: var(--muted); font-size: .88rem; }
.chat__turn { display: flex; flex-direction: column; gap: .5rem; }
.chat__msg { padding: .65rem .85rem; border-radius: 12px; font-size: .92rem; line-height: 1.55; overflow-wrap: anywhere; }
.chat__msg--user { align-self: flex-end; max-width: 88%; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.chat__msg--assistant { align-self: flex-start; max-width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat__msg--assistant p { margin: .3rem 0; }
.chat__msg--working { display: flex; align-items: center; gap: .55rem; color: var(--muted); }
.chat__msg--error { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.chat__spinner { width: 14px; height: 14px; flex: none; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .9s linear infinite; }
.chat__actions { margin: .5rem 0 0; padding-left: 1.1rem; font-size: .86rem; }
.chat__tools { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .6rem; }
.chat__note { color: var(--muted); font-size: .82rem; }
.chat__form { display: flex; flex-direction: column; gap: .5rem; padding: .8rem 1rem 1rem; border-top: 1px solid var(--border); }
.chat__form textarea { min-height: 4.8rem; resize: vertical; }
.chat__form-actions { display: flex; justify-content: space-between; align-items: center; }
.chat__hint { color: var(--faint); font-size: .8rem; }

@media (max-width: 1100px) {
    .editor { grid-template-columns: minmax(0, 1fr); }
    .editor__nav { position: static; max-height: none; }
}
@media (max-width: 900px) {
    .wizard { grid-template-columns: minmax(0, 1fr); }
    .stepper { position: static; }
    .stepper ol { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (max-width: 700px) {
    .table:not(.table--plain) { display: block; overflow-x: auto; }
    .lesson-view { padding: 1rem 1.1rem; }
    .review-block dl, .kv { grid-template-columns: 1fr; }
    .wizard__body { padding: 1.2rem 1.1rem; }
    .card { padding: 1.1rem 1.1rem; }
    .page-head { align-items: flex-start; }
    .page-head--fit h1 { display: -webkit-box; white-space: normal; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* --- Tareas ------------------------------------------------------------------ */
.task-list { display: flex; flex-direction: column; }
.task-item { border-top: 1px solid var(--border); }
.task-item:first-child { border-top: 0; }
.task-item > summary { list-style: none; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 16px; align-items: center; gap: .35rem .9rem; padding: .8rem .25rem; cursor: pointer; border-radius: var(--radius); }
.task-item > summary::-webkit-details-marker { display: none; }
.task-item > summary:hover { background: var(--hover); }
.task-item__icon { display: grid; place-items: center; width: 32px; height: 32px; align-self: start; border-radius: 9px; background: var(--surface-3); color: var(--muted); }
.task-item__icon .icon { width: 16px; height: 16px; }
.task-item__main { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.task-item__title { font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.task-item__meta { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.task-item__progress { display: flex; align-items: center; gap: .65rem; margin-top: .35rem; font-size: .84rem; color: var(--text-2); }
.task-item__progress progress { width: 140px; flex: none; }
.task-item__side { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; text-align: right; }
.task-item__when { color: var(--muted); font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.task-item__chevron { width: 16px; height: 16px; color: var(--faint); transition: transform .15s; }
.task-item[open] .task-item__chevron { transform: rotate(180deg); }
.task-item__body { padding: .3rem .25rem 1.1rem calc(32px + 1.15rem); }
.task-item__body .kv { margin-bottom: .9rem; }
.task-item__phases { margin: 0; padding: 0; list-style: none; }
.task-list__note { margin-top: .6rem; }
.tasks-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; }
.tasks-filters select, .tasks-user select { width: auto; min-width: 200px; max-width: 100%; }
@media (max-width: 640px) {
    .task-item > summary { grid-template-columns: 32px minmax(0, 1fr) 16px; }
    .task-item__side { grid-column: 2; grid-row: 2; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: .35rem .6rem; text-align: left; }
    .task-item__chevron { grid-column: 3; grid-row: 1; }
    .task-item__body { padding-left: .25rem; }
    .task-item__progress progress { width: 90px; }
    .tasks-filters, .tasks-filters select, .tasks-user, .tasks-user select { width: 100%; }
}

/* --- Ajustes (administración) -------------------------------------------- */
.settings-brand { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .settings-brand { grid-template-columns: minmax(0, 1fr); } }
.color-field { display: flex; align-items: center; gap: .6rem; }
.color-field input[type="text"] { width: 9.5rem; font-family: var(--font-mono); text-transform: lowercase; }
/* Vista previa de la identidad: un mini panel con el color y el nombre elegidos (--pv y --pv-on los actualiza app.js). */
.brand-preview { margin: 0; display: grid; gap: .5rem; }
.brand-preview__mode { margin-top: .35rem; }
.brand-preview__app { display: grid; grid-template-columns: 46% 1fr; min-height: 128px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); font-size: .78rem; }
/* Cada vista previa lleva los colores de su modo, sea cual sea el tema de quien la mira (valores de :root). */
.brand-preview__app--light { color-scheme: light; --surface: #ffffff; --sidebar-bg: #f0eee8; --surface-3: #ebe9e2; --border: #e4e1d8; --text: #1c1b18; --muted: #6d6b64; --active: rgba(20, 20, 19, .08); }
.brand-preview__app--dark { color-scheme: dark; --surface: #161615; --sidebar-bg: #191918; --surface-3: #282826; --border: #2a2a27; --text: #ecebe5; --muted: #a2a098; --active: rgba(255, 255, 255, .09); }
.brand-preview__side { display: flex; flex-direction: column; gap: .3rem; padding: .7rem .55rem; background: var(--sidebar-bg); border-right: 1px solid var(--border); min-width: 0; }
.brand-preview__brand { display: flex; align-items: center; gap: .45rem; margin-bottom: .35rem; font-weight: 600; color: var(--text); min-width: 0; }
.brand-preview__brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-preview__mark { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--pv); color: var(--pv-on); }
.brand-preview__mark .icon { width: 14px; height: 14px; }
.brand-preview__mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-preview__mark.has-favicon { background: none; }
.brand-preview__mark.has-favicon .icon { display: none; }
.brand-preview__logo { flex: 0 1 auto; min-width: 0; height: 20px; width: auto; max-width: 100%; object-fit: contain; object-position: left center; }
.brand-preview__nav { display: flex; align-items: center; gap: .4rem; padding: .3rem .4rem; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.brand-preview__nav .icon { width: 13px; height: 13px; }
.brand-preview__nav.is-active { background: var(--active); color: var(--text); }
.brand-preview__main { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; padding: .8rem; min-width: 0; }
.brand-preview__title { font-weight: 600; color: var(--text); }
.brand-preview__button { display: inline-flex; align-items: center; gap: .3rem; padding: .35rem .6rem; border-radius: 7px; background: var(--pv); color: var(--pv-on); font-weight: 500; white-space: nowrap; }
.brand-preview__button .icon { width: 12px; height: 12px; }
.brand-preview__meter { width: 100%; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.brand-preview__meter span { display: block; width: 62%; height: 100%; background: var(--pv); }

/* Logos y favicon: miniatura sobre el fondo donde se usa cada imagen (colores fijos: no dependen del tema). */
.logo-fields { gap: 1.1rem; }
.logo-slot { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: .5rem 1rem; align-items: start; }
.logo-slot__thumb { display: grid; place-items: center; height: 4.5rem; padding: .6rem .7rem; border: 1px solid #e4e1d8; border-radius: var(--radius); overflow: hidden; }
.logo-slot__thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-slot__thumb--light { background: #ffffff; }
.logo-slot__thumb--dark { background: #191918; border-color: #2a2a27; }
.logo-slot__thumb--email { background: #191918; border-color: #2a2a27; } /* la cabecera de los correos (Email::HEADER) */
.logo-slot__thumb--email img { max-height: 44px; }
.logo-slot__thumb--checker { background: repeating-conic-gradient(#ebe9e2 0 25%, #ffffff 0 50%) 0 0 / 14px 14px; }
.logo-slot__thumb--checker img { width: 32px; height: 32px; }
.logo-slot__empty { font-size: .8rem; color: #8a877e; }
.logo-slot__thumb--dark .logo-slot__empty, .logo-slot__thumb--email .logo-slot__empty { color: #a2a098; }
.logo-slot.is-removed .logo-slot__thumb img { opacity: .2; }
.logo-slot__current { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem 1rem; }
.logo-slot__current .small { overflow-wrap: anywhere; }
.logo-slot__note { color: var(--warn); }
@media (max-width: 520px) { .logo-slot { grid-template-columns: minmax(0, 1fr); } }

/* Voces de narración */
.voices-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem 1rem; margin-bottom: .9rem; }
.voices-toolbar .input-icon { flex: 1 1 240px; max-width: 340px; }
.voices-toolbar__actions { display: flex; gap: .4rem; margin-left: auto; }
.voices-table > tbody > tr > td { padding-top: .55rem; padding-bottom: .55rem; }
.voices-table__order { white-space: nowrap; width: 1%; }
.voices-table__order .icon-btn { width: 30px; height: 30px; }
.voices-table__voice { width: 100%; min-width: 240px; }
.voices-table__voice > input { width: 100%; max-width: 460px; }
.voices-table__meta { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem .6rem; margin-top: .35rem; font-size: .82rem; }
.voices-table__meta .icon { width: 13px; height: 13px; vertical-align: -2px; }
.voices-table__play { width: 28px; height: 28px; margin-left: -.3rem; }
.voices-table__play .icon { width: 15px; height: 15px; }
.voices-table__play[aria-pressed="true"] { color: var(--primary); background: var(--primary-soft); }
.voices-table__name { font-weight: 500; color: var(--text); }
.voices-table__default { width: 1%; text-align: center; }
.voices-table tr.is-off .voices-table__meta, .voices-table tr.is-off .voices-table__voice > input { opacity: .55; }
.voices-table tr[hidden] { display: none; }
.voices-table tbody tr:first-child [data-move="up"], .voices-table tbody tr:last-child [data-move="down"] { visibility: hidden; }
/* En pantallas estrechas cada voz es una tarjeta: controles arriba, nombre y datos debajo. */
@media (max-width: 640px) {
    .table-wrap > .voices-table { min-width: 0; }
    .voices-table, .voices-table tbody { display: block; }
    .voices-table thead { display: none; }
    .voices-table > tbody > tr { display: grid; grid-template-columns: auto auto 1fr; grid-template-areas: "order enabled default" "voice voice voice"; align-items: center; gap: .35rem .75rem; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
    .voices-table > tbody > tr:last-child { border-bottom: 0; }
    .voices-table > tbody > tr > td { display: flex; align-items: center; gap: .4rem; padding: 0; border: 0; background: none; }
    .voices-table__order { grid-area: order; }
    .voices-table > tbody > tr > td:nth-child(2) { grid-area: enabled; }
    .voices-table > tbody > tr > td:nth-child(2)::after { content: "Activa"; font-size: .8rem; color: var(--muted); }
    .voices-table__voice { grid-area: voice; display: block !important; min-width: 0; width: auto; }
    .voices-table__default { grid-area: default; justify-self: end; width: auto; }
    .voices-table__default::before { content: "Predeterminada"; font-size: .8rem; color: var(--muted); }
}
/* Guardar siempre a mano aunque la lista sea larga. */
.voices-actions { position: sticky; bottom: 0; z-index: 3; display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; margin: 0 -1px -1px; padding: .9rem 0 .2rem; background: var(--surface); border-top: 1px solid var(--border); }

/* Ajustes · pronunciación de la narración */
.pron { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .pron { grid-template-columns: minmax(0, 1fr); } }
.pron__title { margin: 0 0 .6rem; font-size: .92rem; }
.pron__list { margin: 0 0 .8rem; padding-left: 1.1rem; display: grid; gap: .45rem; color: var(--text-2); font-size: .9rem; }
.pron__list li::marker { color: var(--faint); }
.pron textarea { font-family: var(--font-mono); font-size: .86rem; }
.pron__try { display: flex; gap: .5rem; }
.pron__try input { flex: 1; min-width: 0; }
.pron__result { display: block; padding: .7rem .85rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: .92rem; line-height: 1.5; overflow-wrap: anywhere; }
.pron code { white-space: nowrap; }

/* Diálogos de confirmación y aviso (reemplazan a confirm/alert del navegador) */
.modal { width: min(460px, calc(100vw - 32px)); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: var(--overlay); }
.modal[open] { animation: modal-in .16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@media (prefers-reduced-motion: reduce) { .modal[open] { animation: none; } }
.modal__box { display: grid; gap: .85rem; margin: 0; padding: 1.35rem 1.4rem 1.2rem; }
.modal__head { display: flex; align-items: center; gap: .8rem; }
.modal__icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 12px; background: var(--primary-soft); color: var(--link); }
.modal__icon .icon { width: 21px; height: 21px; }
.modal--danger .modal__icon { background: var(--danger-bg); color: var(--danger); }
.modal__title { margin: 0; font-size: 1.08rem; line-height: 1.35; }
.modal__message { margin: 0; color: var(--text-2); line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.modal__message:empty { display: none; }
.modal__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; margin-top: .35rem; }
.btn--danger-solid { color: #fff; background: var(--danger-strong); border-color: transparent; }
.btn--danger-solid:hover { background: var(--danger); }
@media (max-width: 480px) { .modal__actions .btn { flex: 1 1 auto; } }

/* Administración · todos los cursos */
.admin-courses__filters { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .9rem; }
.admin-courses__filters select { width: auto; min-width: 240px; max-width: 320px; }
.admin-courses__filters .input-icon { width: 280px; max-width: 100%; }
.admin-courses__owner { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin: 0 0 1rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.admin-courses__owner .btn { margin-left: auto; }
.admin-courses__count { margin: -.3rem 0 .8rem; }
.course-card__owner { position: relative; z-index: 2; display: inline-flex; align-items: center; gap: .45rem; width: fit-content; max-width: 100%; color: var(--muted); font-size: .84rem; }
.course-card__owner > span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.course-card__owner:hover { color: var(--link); text-decoration: none; }
/* Costo estimado (Todos los cursos): el total destacado y, debajo, generación y modificaciones alineadas a la derecha. */
.course-card__cost { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: .15rem .6rem; padding: .6rem .75rem .65rem;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-variant-numeric: tabular-nums; }
.course-card__cost-label { grid-column: 1 / -1; display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .7rem;
    font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.course-card__cost-label .icon { width: 14px; height: 14px; }
.course-card__cost-total { grid-column: 1 / -1; margin-bottom: .2rem; color: var(--text); font-size: 1.15rem; font-weight: 650; line-height: 1.2; white-space: nowrap; }
.course-card__cost-part { color: var(--muted); font-size: .78rem; line-height: 1.35; }
.course-card__cost-amount { text-align: right; white-space: nowrap; }
.course-card__cost-note { grid-column: 1 / -1; margin-top: .1rem; color: var(--faint); font-size: .76rem; line-height: 1.4; }
.avatar--xs { width: 22px; height: 22px; border-radius: 7px; font-size: .64rem; }
.pagination { display: flex; align-items: center; justify-content: center; gap: .8rem; margin-top: 1.4rem; }
.pagination__info { color: var(--muted); font-size: .88rem; }
@media (max-width: 640px) {
    .admin-courses__filters select, .admin-courses__filters .input-icon { width: 100%; max-width: none; }
}
