:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --ink: #1c2536;
    --muted: #64708a;
    --line: #e4e8f2;
    --brand: #2f5bea;
    --brand-dark: #1e40c4;
    --ok: #1a9d5a;
    --ok-bg: #e7f7ee;
    --fail: #d64545;
    --fail-bg: #fdecec;
    --warn: #b8860b;
    --warn-bg: #fff8e6;
    --shadow: 0 2px 14px rgba(26, 40, 80, .07);
    --radius: 12px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }

/* Topbar */
.topbar { height: 58px; background: var(--surface); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; padding: 0 20px; gap: 16px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand a { display: flex; align-items: center; gap: 8px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), #7aa0ff);
    color: #fff; display: grid; place-items: center; font-weight: 800; }
.test-name { font-weight: 600; color: var(--muted); }
.student-chip { background: var(--bg); padding: 6px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.timer { background: #eaf0ff; color: var(--brand-dark); padding: 6px 12px; border-radius: 20px; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.low { background: #fff3e0; color: #b8860b; animation: pulse 1s infinite; }
.timer.expired { background: var(--fail-bg); color: var(--fail); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* Modal (pantalla final) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,30,55,.5); display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: 0 16px 56px rgba(0,0,0,.3); }
.modal.final { width: min(420px, 94vw); padding: 34px 30px; text-align: center; }
.final-badge { font-size: 56px; line-height: 1; }
.modal.final h2 { margin: 12px 0 8px; font-size: 24px; }
.modal.final p { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0 0 22px; }
.modal.final .btn { min-width: 140px; }

/* Home */
.home-main { max-width: 980px; margin: 0 auto; padding: 40px 20px; }
.hero h1 { font-size: 34px; margin: 0 0 8px; }
.hero p { color: var(--muted); font-size: 17px; max-width: 640px; }
.start-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 24px; margin: 28px 0; display: grid; gap: 14px; max-width: 460px; }
.start-card h2 { margin: 0 0 4px; font-size: 20px; }
.start-card label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.start-card input, .start-card select { padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; font-family: inherit; }
.tests-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 10px; }
.test-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.test-card h3 { margin: 8px 0 6px; }
.test-card p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); background: #eaf0ff; padding: 3px 9px; border-radius: 20px; }
.count { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Buttons */
.btn { font: inherit; font-weight: 600; border: none; border-radius: 9px; padding: 11px 18px; cursor: pointer; transition: background .15s, opacity .15s; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: #eaf0ff; color: var(--brand-dark); }
.btn-secondary:hover:not(:disabled) { background: #dbe6ff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
/* Solo las acciones destructivas se ponen rojas al pasar el mouse. */
#resetBtn:hover:not(:disabled), .btn-del-test:hover:not(:disabled) { color: var(--fail); border-color: #f0c9c9; }

/* Player layout */
.player-grid { display: grid; grid-template-columns: 1fr 400px; height: calc(100vh - 58px); }
.instructions, .workspace { overflow-y: auto; }

/* Instructions column */
.instructions { padding: 30px 34px; }
.ins-head { margin-bottom: 22px; }
.ins-head h1 { margin: 0 0 6px; font-size: 27px; }
.ins-desc { color: var(--muted); font-size: 15px; margin: 0 0 12px; }
.file-line { background: var(--bg); display: inline-block; padding: 8px 14px; border-radius: 9px; font-size: 14px; margin: 0; }

.ex-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.ex-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.ex-card.done { border-color: #bfe6cf; }
.ex-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ex-num { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.ex-card.done .ex-num { background: var(--ok); }
.ex-title { font-weight: 700; font-size: 16px; flex: 1; }
.ex-instructions { font-size: 14.5px; line-height: 1.6; color: #33405c; }
.chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.fail { background: var(--fail-bg); color: var(--fail); }
.chip.pend { background: var(--bg); color: var(--muted); }

/* Workspace */
.workspace { padding: 30px 22px; background: linear-gradient(180deg, #fbfcff, var(--bg)); border-left: 1px solid var(--line); }
.ws-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.progress-ring { text-align: center; font-size: 22px; font-weight: 800; color: var(--brand); background: #eaf0ff; border-radius: 10px; padding: 14px; margin-bottom: 18px; }
.progress-ring.complete { background: var(--ok-bg); color: var(--ok); }

.ws-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; }
.ws-steps > li { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; }
.step-n { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.step-main { display: grid; gap: 8px; }
.step-main .btn { width: 100%; }
.step-txt { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.ws-reset { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); text-align: center; }
.ws-reset .btn { width: 100%; }

/* Result */
.result-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-top: 18px; }
.result-head { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 10px; margin-bottom: 14px; }
.result-head.ok { background: var(--ok-bg); }
.result-head.partial { background: var(--warn-bg); }
.result-head.fail { background: var(--fail-bg); }
.badge-big { min-width: 44px; height: 44px; padding: 0 8px; border-radius: 12px; display: grid; place-items: center; font-size: 17px; font-weight: 800; color: #fff; flex: none; }
.result-head.ok .badge-big { background: var(--ok); }
.result-head.partial .badge-big { background: var(--warn); }
.result-head.fail .badge-big { background: var(--fail); }

.result-exercises { display: grid; gap: 12px; }
.res-ex { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.res-ex.ok { border-color: #bfe6cf; }
.res-ex-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 14px; background: var(--bg); }
.res-ex.ok .res-ex-head { background: var(--ok-bg); }
.res-ex.fail .res-ex-head { background: var(--fail-bg); }
.res-ex-head strong { flex: 1; }
.res-ex-icon { font-weight: 800; }
.res-ex.ok .res-ex-icon { color: var(--ok); }
.res-ex.fail .res-ex-icon { color: var(--fail); }
.res-ex-score { font-weight: 700; color: var(--muted); font-size: 13px; }
.crit-list { list-style: none; margin: 0; padding: 8px 12px; display: grid; gap: 6px; }
.crit { display: flex; gap: 9px; font-size: 13px; }
.crit > span:first-child { font-weight: 800; flex: none; }
.crit.ok > span:first-child { color: var(--ok); }
.crit.fail > span:first-child { color: var(--fail); }
.crit span:last-child { display: grid; gap: 1px; }
.crit em { color: var(--muted); font-style: normal; font-size: 12px; }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
    padding: 12px 20px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 50; max-width: 92vw; }
.toast-success { background: var(--ok); }
.toast-error { background: var(--fail); }

/* Panel del docente */
.panel-tag { font-size: 12px; font-weight: 700; color: var(--brand); background: #eaf0ff; padding: 3px 9px; border-radius: 20px; margin-left: 8px; }
.teacher-login { max-width: 420px; margin: 60px auto; padding: 0 20px; }
.login-hint { font-size: 12px; color: var(--muted); margin: 0; }
.login-hint code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.teacher-dash { max-width: 1100px; margin: 0 auto; padding: 26px 20px; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.dash-head h1 { margin: 0; font-size: 24px; }
.test-select { font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.test-select select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.dash-summary { display: flex; gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; display: grid; text-align: center; box-shadow: var(--shadow); }
.stat-n { font-size: 24px; font-weight: 800; color: var(--brand); }
.stat span:last-child { font-size: 12px; color: var(--muted); }

.dash-table { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tr { display: grid; grid-template-columns: 1.4fr 0.8fr repeat(6, 42px) 0.7fr 1.3fr 0.7fr; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.tr.th { background: var(--bg); font-weight: 700; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tr.done { background: #fbfffc; }
.td-ex { text-align: center; }
.td-att, .td-last { color: var(--muted); font-size: 12.5px; }
.dot { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-weight: 800; font-size: 12px; }
.dot.ok { background: var(--ok-bg); color: var(--ok); }
.dot.fail { background: var(--fail-bg); color: var(--fail); }
.dot.pend { background: var(--bg); color: #b9c0d0; }
.prog-chip { font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--bg); color: var(--muted); font-size: 12.5px; }
.prog-chip.ok { background: var(--ok-bg); color: var(--ok); }
.link-btn { border: none; background: none; color: var(--brand); font: inherit; font-size: 13px; cursor: pointer; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.tr-detail { padding: 14px 18px; background: var(--bg); border-bottom: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.detail-grid h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.flags { background: var(--warn-bg); color: var(--warn); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; }
.sig-list { display: grid; gap: 4px; }
.sig { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.sub-list { display: grid; gap: 6px; }
.sub-link { font-size: 13px; color: var(--brand); background: var(--surface); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; }
.sub-link em { color: var(--muted); font-style: normal; font-size: 11.5px; }
.empty { color: var(--muted); font-size: 13px; }

/* Tabs de Navegación del Docente */
.nav-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); background: var(--surface); padding: 0 20px; }
.nav-tab { padding: 12px 18px; font-size: 14px; font-weight: 700; color: var(--muted); border: none; background: transparent; cursor: pointer; border-bottom: 3px solid transparent; transition: all .15s; }
.nav-tab:hover { color: var(--ink); }
.nav-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Gestión de Pruebas */
.tests-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.tests-head h1 { margin: 0 0 4px; font-size: 24px; }
.tests-head p { margin: 0; color: var(--muted); font-size: 14px; }
.tests-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.test-manage-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: space-between; gap: 14px; }
.test-manage-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.test-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.test-badge.app { background: #eaf0ff; color: var(--brand); }
.test-badge.time { background: #fff8e6; color: var(--warn); }
.test-manage-card h3 { margin: 6px 0 4px; font-size: 18px; }
.test-manage-card p { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.test-manage-file { font-size: 12.5px; color: var(--muted); background: var(--bg); padding: 6px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; }
.test-manage-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--line); }

/* Editor de Pruebas y Ejercicios */
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.editor-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin-bottom: 20px; }
.editor-card h2 { margin: 0 0 16px; font-size: 18px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-group { display: grid; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 13px; font-weight: 700; color: var(--ink); }
.form-group input, .form-group select, .form-group textarea { font: inherit; font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(47,91,234,.12); }
.file-dropzone { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; background: var(--bg); cursor: pointer; transition: all .15s; margin-top: 6px; }
.file-dropzone:hover { border-color: var(--brand); background: #f0f4ff; }
.current-file-badge { font-size: 12.5px; color: var(--ok); background: var(--ok-bg); padding: 4px 10px; border-radius: 6px; display: inline-block; margin-top: 6px; font-weight: 600; }

.ex-edit-list { display: grid; gap: 18px; margin-top: 14px; }
.ex-edit-card { background: #fbfcff; border: 1px solid var(--line); border-radius: 10px; padding: 18px; position: relative; }
.ex-edit-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.ex-badge { background: var(--brand); color: #fff; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 800; }
.criteria-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-top: 12px; }
.criteria-box h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.criteria-cols, .criterion-row { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr 1.5fr 36px; gap: 8px; align-items: center; }
.criteria-cols { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.criterion-row { margin-bottom: 8px; padding: 4px; border-radius: 8px; }
.criterion-row select, .criterion-row input { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.criterion-row input:disabled { background: var(--bg); }
.criterion-row.has-warning { background: var(--warn-bg); outline: 1px solid #f3e2b3; }
.ck-warning { grid-column: 1 / -1; font-size: 12px; color: var(--warn); padding: 0 4px 2px; }
.ck-warning.ck-info { color: var(--muted); }
.ex-warnings { background: var(--warn-bg); border: 1px solid #f3e2b3; color: #7a5a00; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.55; margin-bottom: 12px; display: grid; gap: 4px; }

/* Generación con IA */
.ai-card { border-color: #c9d6ff; background: linear-gradient(180deg, #f7f9ff, var(--surface)); }
.ai-card h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ai-status { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.ai-status.ok { background: var(--ok-bg); color: var(--ok); }
.ai-status.off { background: var(--bg); color: var(--muted); }
.ai-help { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin: 0 0 14px; }
.ai-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ai-spacer { flex: 1; }
.ai-result { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: var(--ok-bg); color: #155c38; font-size: 13.5px; line-height: 1.6; display: grid; gap: 4px; }
.ai-result.busy { background: #eaf0ff; color: var(--brand-dark); }
.ai-result.error { background: var(--fail-bg); color: #8a2525; border: 1px solid #f0c9c9; }
.ai-detail { font-size: 12px; color: #6b3a3a; font-family: ui-monospace, Menlo, monospace; word-break: break-word; margin-top: 4px; }
.ai-box-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ai-box-actions .btn { padding: 7px 12px; font-size: 13px; }
.ai-unsupported { margin-top: 6px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.ai-unsupported ul { margin: 6px 0 0; padding-left: 18px; }
.ai-modal { width: min(760px, 96vw); max-height: 92vh; display: flex; flex-direction: column; }
.ai-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.ai-modal-head h2 { margin: 0; font-size: 18px; }
.ai-modal-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 16px; }
.ai-modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.ai-reason { background: var(--warn-bg); color: #7a5a00; border: 1px solid #f3e2b3; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.ai-step { display: grid; gap: 8px; }
.ai-step-head { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.ai-step-head .btn { margin-left: auto; padding: 7px 14px; font-size: 13px; }
.ai-step textarea { width: 100%; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.ai-step textarea[readonly] { background: var(--bg); }

/* Configuración de IA */
.ai-settings { max-width: 680px; }
.field-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.field-hint a { color: var(--brand); text-decoration: underline; }
.inline-field { display: flex; gap: 8px; }
.inline-field input { flex: 1; min-width: 0; }
.ai-advanced { margin: 4px 0 14px; }
.ai-advanced summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 12px; }
.ai-test-result { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; line-height: 1.5; word-break: break-word; }
.ai-test-result.ok { background: var(--ok-bg); color: #155c38; }
.ai-test-result.fail { background: var(--fail-bg); color: #8a2525; }
.btn-icon { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 14px; }
.btn-icon:hover { color: var(--fail); border-color: #f0c9c9; background: var(--fail-bg); }
.editor-actions { display: flex; gap: 12px; justify-content: flex-end; padding: 20px 0; }

@media (max-width: 760px) {
    .tr { grid-template-columns: 1.4fr 0.8fr 0.7fr 0.6fr; }
    .td-ex { display: none; }
    .detail-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .criterion-row { grid-template-columns: 1fr; }
    .criteria-cols { display: none; }
    .ai-spacer { display: none; }
}

/* Responsive */
@media (max-width: 900px) {
    .player-grid { grid-template-columns: 1fr; height: auto; }
    .workspace { border-left: none; border-top: 1px solid var(--line); }
}
