:root {
  --ink: #241a2b;
  --ink-soft: #6b6173;
  --plum: #5b3a73;
  --plum-strong: #442a57;
  --plum-wash: #ece4f2;
  --bg: #efecf3;
  --surface: #ffffff;
  --surface-sunk: #f7f5fa;
  --line: #dcd5e3;
  --rojo: #c2412f;
  --ambar: #c98a0b;
  --azul: #2c6db0;
  --verde: #2a8560;
  --danger-wash: #fbe9e6;
  --focus: #8a5cb0;
  --radius-panel: 14px;
  --radius-control: 8px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ede7f2; --ink-soft: #a99fb2; --plum: #b597c9; --plum-strong: #d2bde0;
    --plum-wash: #2f2439; --bg: #17121b; --surface: #211a27; --surface-sunk: #1b151f;
    --line: #3a3042; --rojo: #e2705f; --ambar: #e3b04a; --azul: #6aa3dd; --verde: #5bbf93;
    --danger-wash: #3a2120; --focus: #c9a9e0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #ede7f2; --ink-soft: #a99fb2; --plum: #b597c9; --plum-strong: #d2bde0;
  --plum-wash: #2f2439; --bg: #17121b; --surface: #211a27; --surface-sunk: #1b151f;
  --line: #3a3042; --rojo: #e2705f; --ambar: #e3b04a; --azul: #6aa3dd; --verde: #5bbf93;
  --danger-wash: #3a2120; --focus: #c9a9e0; color-scheme: dark;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Schibsted Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: .86rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Controles */
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label.field > span.hint { font-weight: 400; color: var(--ink-soft); font-size: .84rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: inherit;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 9px 11px;
  width: 100%;
  transition: border-color .15s, background .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--plum); background: var(--surface); outline: none; box-shadow: 0 0 0 3px var(--plum-wash); }
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--plum); padding: 0; }

.btn {
  font: inherit; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 999px;
  padding: 9px 18px; cursor: pointer;
  background: var(--plum-wash); color: var(--plum-strong);
  transition: transform .12s var(--ease), background .15s, opacity .15s;
}
.btn:hover { background: color-mix(in srgb, var(--plum-wash) 70%, var(--plum) 30%); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--plum); color: #fff; }
.btn.primary:hover { background: var(--plum-strong); }
:root[data-theme="dark"] .btn.primary { color: #1b1320; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #1b1320; } }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-sunk); }
.btn.danger { background: var(--danger-wash); color: var(--rojo); }
.btn.small { padding: 6px 12px; font-size: .86rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* Semáforo: el motivo de la marca */
.lights { display: inline-flex; gap: 5px; }
.lights i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.lights i:nth-child(1) { background: var(--rojo); }
.lights i:nth-child(2) { background: var(--ambar); }
.lights i:nth-child(3) { background: var(--azul); }
.lights i:nth-child(4) { background: var(--verde); }

/* Login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 36px 32px 30px;
  display: grid; gap: 22px;
  animation: rise .6s var(--ease) both;
}
.login-title { display: grid; gap: 10px; }
.login-title h1 { font-size: 2.2rem; }
.login-error { background: var(--danger-wash); color: var(--rojo); border-radius: var(--radius-control); padding: 10px 12px; font-size: .9rem; }

/* Estructura */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; position: relative; }
.tab {
  font: inherit; font-weight: 600; background: none; border: 0; cursor: pointer;
  color: var(--ink-soft); padding: 8px 14px; border-radius: 999px;
  transition: color .15s, background .2s;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--plum-strong); background: var(--plum-wash); }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .9rem; }
main { max-width: 1320px; margin: 0 auto; padding: 26px 28px 80px; }
.view { animation: fade .35s var(--ease) both; }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-panel); padding: 24px;
}

/* Pasos del seguimiento (secuencia real, por eso numerados) */
.steps { display: flex; gap: 0; margin-bottom: 22px; counter-reset: step; }
.step {
  flex: 1; display: flex; align-items: center; gap: 10px;
  font: inherit; text-align: left; background: none; border: 0; padding: 0 12px 12px 0;
  color: var(--ink-soft); cursor: pointer; position: relative;
  border-bottom: 2px solid var(--line);
  transition: color .2s;
}
.step::after {
  content: ""; position: absolute; left: 0; bottom: -2px; height: 2px; width: 0;
  background: var(--plum); transition: width .5s var(--ease);
}
.step.done::after, .step.current::after { width: 100%; }
.step:disabled { cursor: default; }
.step b {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: .85rem; flex: none;
  transition: background .2s, color .2s;
}
.step.current { color: var(--ink); font-weight: 700; }
.step.current b { background: var(--plum); border-color: var(--plum); color: #fff; }
.step.done { color: var(--plum-strong); }

.dropzone {
  display: grid; place-items: center; gap: 8px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius-panel);
  padding: 40px 20px; cursor: pointer; background: var(--surface-sunk);
  transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.dropzone.over { border-color: var(--plum); background: var(--plum-wash); transform: scale(1.01); }
.dropzone.disabled { cursor: not-allowed; opacity: .55; }
.dropzone strong { font-size: 1.05rem; }
.summary-line { display: flex; gap: 22px; flex-wrap: wrap; }
.summary-line div { display: grid; }
.summary-line strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.warning { background: color-mix(in srgb, var(--ambar) 16%, var(--surface)); border-left: 3px solid var(--ambar); padding: 10px 14px; border-radius: 6px; font-size: .9rem; }

/* Mesa de trabajo: alumnos + editor */
.workbench {
  display: grid; grid-template-columns: minmax(300px, 400px) 1fr;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-panel); overflow: hidden; min-height: 620px;
}
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line); grid-column: 1 / -1;
}
.toolbar select { width: auto; }
.toolbar .spacer { flex: 1; }
.roster { border-right: 1px solid var(--line); overflow-y: auto; max-height: 72vh; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 10px 18px; font-size: .8rem; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; }

.student {
  --tone: var(--line);
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  padding: 13px 16px 13px 22px; cursor: pointer; border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.student::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  background: var(--tone); transition: width .25s var(--ease);
}
.student:hover { background: var(--surface-sunk); }
.student[aria-selected="true"] { background: var(--plum-wash); }
.student[aria-selected="true"]::before { width: 9px; }
.student.excluded { opacity: .5; }
.student.tone-rojo { --tone: var(--rojo); }
.student.tone-amarillo { --tone: var(--ambar); }
.student.tone-azul { --tone: var(--azul); }
.student.tone-verde { --tone: var(--verde); }
.student .name { font-weight: 650; }
.student .meta { font-size: .82rem; color: var(--ink-soft); grid-column: 1; }
.student .include { grid-row: 1 / span 3; grid-column: 2; align-self: center; }
.track { display: flex; gap: 3px; grid-column: 1; margin-top: 4px; }
.track i { flex: 1; max-width: 26px; height: 6px; border-radius: 3px; background: var(--line); }
.track i.on { background: var(--tone); }
.badge {
  display: inline-block; font-size: .76rem; font-weight: 650; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-sunk); color: var(--ink-soft); border: 1px solid var(--line);
}
.badge.draft { background: var(--plum-wash); color: var(--plum-strong); border-color: transparent; }
.badge.sent { background: color-mix(in srgb, var(--verde) 16%, var(--surface)); color: var(--verde); border-color: transparent; }
.student.just-sent::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--verde) 25%, transparent), transparent);
  animation: sweep .9s var(--ease) both;
}

.editor { padding: 22px 26px; display: grid; gap: 16px; align-content: start; }
.editor textarea { min-height: 340px; }
.editor-head { display: flex; justify-content: space-between; gap: 16px; align-items: start; flex-wrap: wrap; }
.status-pill { display: inline-flex; gap: 8px; align-items: center; font-size: .86rem; color: var(--ink-soft); }
.status-pill i { width: 10px; height: 10px; border-radius: 50%; background: var(--tone, var(--line)); }
.empty { display: grid; place-items: center; text-align: center; gap: 10px; padding: 60px 20px; color: var(--ink-soft); }

/* Progreso de trabajos */
.jobbar {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  width: min(640px, calc(100% - 32px)); z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; display: grid; gap: 10px;
  box-shadow: 0 18px 50px -20px rgba(36, 26, 43, .45);
  animation: rise .4s var(--ease) both;
}
.meter { height: 8px; border-radius: 4px; background: var(--surface-sunk); overflow: hidden; }
.meter span {
  display: block; height: 100%; border-radius: 4px; background: var(--plum);
  transition: width .6s var(--ease);
  background-image: linear-gradient(90deg, transparent 0, rgba(255,255,255,.35) 50%, transparent 100%);
  background-size: 200% 100%; animation: shimmer 1.6s linear infinite;
}
.meter.finished span { animation: none; background-image: none; }
.log {
  font-size: .82rem; line-height: 1.45; max-height: 150px; overflow-y: auto;
  background: var(--surface-sunk); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap;
}
.log .err { color: var(--rojo); }

/* Ventanas y avisos */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(23, 18, 27, .45);
  display: grid; place-items: center; padding: 16px; animation: fade .2s both;
}
.dialog {
  width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px; padding: 26px; display: grid; gap: 16px;
  animation: pop .3s var(--ease) both;
}
.dialog.wide { width: min(860px, 100%); }
.dialog dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.dialog dt { color: var(--ink-soft); }
.dialog dd { margin: 0; font-weight: 600; }
.quote { background: var(--surface-sunk); border-radius: 8px; padding: 10px 12px; font-size: .9rem; white-space: pre-wrap; }
pre.code { background: var(--surface-sunk); border-radius: 8px; padding: 12px; font-size: .8rem; overflow: auto; max-height: 55vh; margin: 0; }

.toasts { position: fixed; top: 74px; right: 20px; z-index: 60; display: grid; gap: 10px; width: min(380px, calc(100% - 32px)); }
.toast {
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: .9rem;
  animation: slide-in .35s var(--ease) both;
}
.toast.error { background: var(--rojo); color: #fff; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.list th { font-size: .84rem; color: var(--ink-soft); font-weight: 600; }

.settings { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); align-items: start; }
.settings .wide { grid-column: 1 / -1; }
.choice { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--plum); background: var(--plum-wash); }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

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

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .user { margin-left: 0; width: 100%; justify-content: space-between; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 18px 16px 120px; }
  .workbench { grid-template-columns: 1fr; }
  .roster { border-right: 0; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .editor { padding: 18px 16px; }
  .steps .step span { display: none; }
  .settings { grid-template-columns: 1fr; }
  .panel { padding: 18px 16px; }
  .login-panel { padding: 28px 20px 24px; }
}
