/*
 * Exámenes Spyder — estilo académico en negro y rojo.
 * El rojo de acento se cambia en --brand.
 */
:root {
  --brand: #ff1744;          /* rojo de acento */
  --brand-strong: #d50032;
  --brand-glow: rgba(255, 23, 68, .35);
  --bg: #000;
  --surface: #0f1417;        /* tarjetas */
  --surface-2: #161d21;      /* filas, hover */
  --input: #0a0e10;
  --border: #232d33;
  --fg: #cfd8dc;             /* texto */
  --heading: #fff;
  --muted: #8a9ba3;
  --ok: #00e676;
  --warn: #ff9100;
  --purple: #d500f9;
  --info: #4fc3f7;
  --radius: 6px;
  --font: "Inter", "Inter UI", -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font: 15px/1.6 var(--font); background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 32px 20px 48px; flex: 1; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--brand); color: #fff; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

h1, h2, h3 { color: var(--heading); line-height: 1.2; }
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 20px; }
h2 { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }
code { font-family: var(--mono); font-size: .88em; color: #fff; }

/* ---- Cabecera ---- */
.topbar {
  display: flex; align-items: center; gap: 28px; padding: 0 20px; height: 64px;
  background: #000; border-bottom: 1px solid var(--border);
  box-shadow: inset 0 -2px 0 var(--brand);
}
.brand { font-size: 1.35rem; font-weight: 900; color: var(--brand); letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-size: .62rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); margin-top: -2px; }
.topbar nav { display: flex; gap: 4px; flex: 1; height: 100%; }
.topbar nav a {
  display: flex; align-items: center; padding: 0 14px; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; border-bottom-color: var(--brand); }
.topbar .user { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.topbar .user a { color: var(--fg); }

/* ---- Pie ---- */
.site-footer { border-top: 1px solid var(--border); padding: 40px 20px 28px; background: #000; }
.site-footer .cols { max-width: 1240px; margin: 0 auto; display: grid; gap: 32px;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.site-footer h4 { margin: 0 0 14px; color: #fff; font-size: .82rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; }
.site-footer p { margin: 0; color: var(--muted); max-width: 520px; }
.site-footer p strong { color: var(--fg); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.site-footer li a { display: inline-flex; align-items: center; gap: 10px; color: #fff; }
.site-footer li svg { width: 16px; height: 16px; flex: none; fill: currentColor; color: var(--muted); }
.site-footer .legal { max-width: 1240px; margin: 32px auto 0; text-align: center; font-size: .82rem; color: var(--muted); }
@media (max-width: 720px) { .site-footer .cols { grid-template-columns: 1fr; } }

/* ---- Tarjetas y formularios ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 24px; }
.narrow { max-width: 460px; }
label { display: block; margin-bottom: 16px; font-weight: 600; color: var(--heading); font-size: .9rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; font-weight: 400;
  color: #fff; background: var(--input); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow); }
input[type=file] { padding: 8px; }
input[type=checkbox] { accent-color: var(--brand); }

button, a.button {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; font: inherit;
  font-size: .9rem; font-weight: 600;
  color: #fff; background: var(--brand); border: 1px solid var(--brand); border-radius: var(--radius);
  cursor: pointer; box-shadow: 0 6px 20px -6px var(--brand-glow); transition: background .15s, box-shadow .15s;
}
button:hover, a.button:hover { background: var(--brand-strong); text-decoration: none; }
button.secondary, a.button.secondary {
  background: transparent; color: var(--fg); border-color: var(--border); box-shadow: none;
}
button.secondary:hover, a.button.secondary:hover { border-color: var(--muted); color: #fff; background: var(--surface-2); }
button.danger { background: transparent; color: var(--brand); border-color: var(--brand); box-shadow: none; }
button.danger:hover { background: var(--brand); color: #fff; }
button.link { background: none; border: 0; box-shadow: none; color: var(--muted); padding: 0;
  text-transform: none; letter-spacing: 0; font-weight: 500; font-size: .9rem; }
button.link:hover { color: #fff; background: none; }
button.small, button.secondary.small { padding: 4px 10px; font-size: .8rem; }
button:disabled { opacity: .4; cursor: default; }
form.inline { display: inline; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.top-gap { margin-top: 16px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--fg); margin: 0 0 16px; }
label.check input { width: auto; margin: 0; }
.error { display: block; color: var(--brand); font-weight: 500; font-size: .85rem; margin-top: 4px; }
.muted { color: var(--muted); }

/* ---- Tablas ---- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; padding: 10px 12px; color: var(--muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td a { color: #fff; font-weight: 600; }
td.actions a { color: var(--brand); font-weight: 500; }
/* Enlaces de "volver" al principio de la página */
main > p:first-child > a, main > .flash + p > a { color: var(--muted); font-size: .9rem; }
main > p:first-child > a:hover, main > .flash + p > a:hover { color: #fff; }
td.actions form + form { margin-left: 6px; }
.row-warn { background: rgba(255, 23, 68, .06); }

/* ---- Mensajes, etiquetas, estados ---- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px;
  border: 1px solid var(--border); border-left: 3px solid var(--info); background: var(--surface); color: #fff; }
.flash-error { border-left-color: var(--brand); }
.flash-success { border-left-color: var(--ok); }
.badge { font-size: .72rem; font-weight: 700; color: var(--fg); background: var(--surface-2);
  border: 1px solid var(--border); padding: 1px 8px; border-radius: 999px; letter-spacing: 0; text-transform: none; }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--fg); border: 1px solid var(--border); white-space: nowrap; }
.tag-external_paste, .tag-warn, .tag-typing_burst { color: var(--brand); border-color: rgba(255, 23, 68, .45);
  background: rgba(255, 23, 68, .08); }
.tag-large_paste, .tag-backup { color: var(--warn); border-color: rgba(255, 145, 0, .4); background: rgba(255, 145, 0, .08); }
.tag-frequent_paste { color: var(--purple); border-color: rgba(213, 0, 249, .4); background: rgba(213, 0, 249, .08); }
.tag-session { color: var(--info); border-color: rgba(79, 195, 247, .4); background: rgba(79, 195, 247, .08); }
.status-open { color: var(--ok); border-color: rgba(0, 230, 118, .4); background: rgba(0, 230, 118, .08); }
.status-closed { color: var(--muted); }
.status-draft { color: var(--warn); border-color: rgba(255, 145, 0, .4); background: rgba(255, 145, 0, .08); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4a585f; margin-right: 6px; flex: none; }
.dot-on, .dot-online { background: var(--ok); box-shadow: 0 0 8px rgba(0, 230, 118, .6); }
.dot-finished { background: var(--muted); }
.dot-absent { background: transparent; border: 1px solid #4a585f; }

/* ---- Bloques varios ---- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }
.grid-2 .card { margin-bottom: 24px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: .9rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; color: #fff; }
pre.snippet { margin: 0; max-width: 440px; max-height: 6em; overflow: auto; font: .8rem/1.4 var(--mono);
  background: var(--input); border: 1px solid var(--border); padding: 6px 8px; border-radius: 4px;
  white-space: pre-wrap; word-break: break-all; color: #e6edf0; }
.link-box { max-width: none; font-size: .95rem; color: #fff; }
.ide-preview { width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--border); border-radius: var(--radius); background: #000; }
form.extra-time input { display: inline-block; width: 84px; margin: 0 6px 0 0; padding: 8px; }

/* Copias */
.grid-files { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 24px; }
@media (max-width: 760px) { .grid-files { grid-template-columns: 1fr; } }
.file-list { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.file-list li { padding: 6px 0; border-bottom: 1px solid var(--border); word-break: break-all; }
.file-list li span { display: block; font-size: .78rem; }
.file-list li.selected a { color: #fff; font-weight: 700; }
pre.code, pre.diff { background: var(--input); border: 1px solid var(--border); padding: 14px; border-radius: var(--radius);
  overflow: auto; font: .82rem/1.5 var(--mono); max-height: 70vh; color: #e6edf0; }
pre.diff span { display: block; min-height: 1.2em; }
pre.diff .add { background: rgba(0, 230, 118, .12); color: #b9f6ca; }
pre.diff .del { background: rgba(255, 23, 68, .14); color: #ffcdd2; }
pre.diff .hunk { color: var(--purple); }
details summary { cursor: pointer; color: var(--fg); margin-bottom: 8px; }

/* ---- Vista en directo ---- */
.live-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.live-clock { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff; }
.live-clock.low, .live-stats .low { color: var(--brand); }
.live-summary { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0 0 24px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.summary-item { color: var(--muted); font-size: .9rem; }
.summary-item strong { font-size: 1.6rem; font-weight: 800; color: #fff; margin-right: 6px; letter-spacing: -.02em; }
.summary-online.nonzero strong { color: var(--ok); }
.summary-alerts.nonzero strong { color: var(--brand); }
.live-layout { display: grid; grid-template-columns: 1fr minmax(280px, 340px); gap: 24px; align-items: start; }
@media (max-width: 960px) { .live-layout { grid-template-columns: 1fr; } }
.live-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.live-tools input[type=search] { width: auto; flex: 1; min-width: 180px; margin: 0; }
.live-tools label.check { margin: 0; }
.screens-tools select { display: inline-block; width: auto; margin: 0 0 0 8px; padding: 6px 8px; }
.segmented { display: inline-flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.segmented button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.live-card { display: block; background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid #4a585f; border-radius: var(--radius); padding: 12px 14px; color: var(--fg); }
.live-card:hover { border-color: var(--muted); text-decoration: none; }
.live-card.state-online { border-left-color: var(--ok); }
.live-card.state-finished { border-left-color: var(--muted); opacity: .7; }
.live-card.has-alerts { border-left-color: var(--brand); background: rgba(255, 23, 68, .05); }
.live-card-top { display: flex; align-items: center; gap: 6px; }
.live-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.live-meta { margin: 6px 0; font-size: .85rem; display: flex; gap: 6px; flex-wrap: wrap; }
.live-stats { font-size: .78rem; display: flex; gap: 12px; flex-wrap: wrap; }

.screen-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.screen-tile { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid #4a585f;
  border-radius: var(--radius); overflow: hidden; }
.screen-tile.state-online { border-top-color: var(--ok); }
.screen-tile.state-finished { border-top-color: var(--muted); }
.screen-tile.has-alerts { border-top-color: var(--brand); }
.screen-frame { aspect-ratio: 16 / 9; background: #000; position: relative; }
.screen-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.screen-off { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .9rem; }
.screen-info { padding: 10px 12px; }
.screen-info a { color: inherit; }
.screen-info a:hover { text-decoration: none; }
.screen-info .live-stats a { color: var(--brand); }

.live-feed { position: sticky; top: 16px; max-height: calc(100vh - 40px); overflow: auto; }
.live-feed ul { list-style: none; margin: 0; padding: 0; }
.feed-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.feed-item.fresh { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: rgba(255, 23, 68, .25); } to { background: transparent; } }
.feed-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.feed-head a { color: #fff; font-weight: 600; }
.feed-msg { font-size: .85rem; margin: 6px 0 8px; color: var(--fg); }

/* ---- Acceso (login) y páginas del alumno ---- */
.auth-page { display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 6vh; }
.auth-page h1 { font-size: 2.6rem; text-align: center; margin-bottom: 8px; }
.auth-page .lead { color: var(--muted); text-align: center; margin: 0 0 32px; max-width: 460px; }
.auth-page .card { width: 100%; max-width: 420px; }
.auth-page button { width: 100%; justify-content: center; margin-top: 8px; }
body.student .narrow-page { max-width: 560px; margin: 12vh auto; text-align: center; }
body.student .narrow-page .card { padding: 36px; }
body.student h1 { font-size: 2.1rem; }
body.student p { color: var(--fg); }
body.student button { margin-top: 8px; }
.spinner { width: 36px; height: 36px; margin: 0 auto 16px; border: 3px solid var(--border);
  border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 8px 16px; padding: 12px 16px 0; }
  .topbar .user { order: 2; margin-left: auto; }
  .topbar nav { order: 3; width: 100%; flex: none; height: 44px; overflow-x: auto; }
  .topbar nav a { padding: 0 10px; }
  main { padding: 24px 16px 40px; }
  h1 { font-size: 1.6rem; }
  /* Las tablas se desplazan dentro de su tarjeta, no la página */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .card { padding: 18px; }
}

/* Selector de idioma */
.lang-switch { display: inline-flex; gap: 6px; align-items: center; font-size: .8rem; font-weight: 700; letter-spacing: .06em; }
.lang-switch a { color: var(--muted); }
.lang-switch a:hover { color: #fff; text-decoration: none; }
.lang-switch strong { color: #fff; }
.lang-switch span { color: var(--border); }
.topbar .user form { display: inline-flex; align-items: center; gap: 14px; }
body.student .lang-switch { position: fixed; top: 16px; right: 20px; }
body.student .wide-page { max-width: 960px; margin: 8vh auto; padding: 0 20px; }
body.student .wide-page h1 { text-align: left; }
.code-file { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.code-file header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.code-file header strong { color: #fff; font-family: var(--mono); font-size: .9rem; }
.code-file pre.code { margin: 0; border: 0; border-radius: 0; max-height: none; }
