:root {
  /* Paleta segura para daltonismo: eje azul <-> ámbar/oro + neutros.
     Los estados NO dependen de rojo/verde: se refuerzan con icono + texto. */
  --bg: #0f1720;
  --panel: #17212b;
  --panel-2: #1e2a37;
  --line: #2c3a49;
  --text: #e8eef4;
  --muted: #9fb0c0;
  --blue: #3b82f6;
  --blue-strong: #2563eb;
  --gold: #e0a92e;
  --gold-strong: #c8891a;
  --ok: #4ea3ff;      /* azul: correcto/hecho */
  --warn: #e0a92e;    /* ámbar: atención/pendiente */
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--gold); font-weight: 600; }

/* ---- Botones ---- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: filter .15s, background .15s, border-color .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue-strong); border-color: var(--blue-strong); color: #fff; }
.btn-ghost { background: transparent; }
.btn-gold { background: var(--gold-strong); border-color: var(--gold-strong); color: #1a1205; }
.btn-danger { background: transparent; border-color: var(--gold-strong); color: var(--gold); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

/* ---- Login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-card { width: 340px; max-width: 100%; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.login-card .btn { margin-top: 6px; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 6px; margin-left: 8px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 15px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--blue-strong); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ---- Vistas ---- */
main { padding: 22px; max-width: 1100px; margin: 0 auto; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.view-head h2 { margin: 0 0 4px; font-size: 20px; }
.inline { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.num { width: 130px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 8px 10px; border-radius: 8px; }
.sel { min-width: 240px; max-width: 380px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.sel:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

/* ---- Formulario de alta de cron ---- */
.cron-form { padding: 16px; margin-top: 16px; }
.cron-form .inline { align-items: flex-end; gap: 12px; }
.cron-form .sel { min-width: 180px; }
#cronBox { margin-top: 18px; }
tr.row-pausada td { opacity: .55; }
tr.row-pausada td .badge { opacity: 1; }   /* el badge de estado se ve nítido */

/* ---- Formulario de usuario (modal) ---- */
.userform { display: flex; flex-direction: column; gap: 14px; }
.userform .form-row { display: flex; flex-direction: column; gap: 5px; }
.txt { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 9px 11px; border-radius: 8px; font-size: 14px; width: 100%; }
.txt:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.userform .sel { max-width: 100%; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

/* ---- Toolbar de tabla (filtro + paginación) ---- */
.tabletools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.tabletools .left, .tabletools .right { display: flex; align-items: center; gap: 10px; }
.filtro { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 9px; min-width: 240px; font-size: 14px; }
.filtro:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.pagesize { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 6px 8px; border-radius: 8px; }
.pageinfo { min-width: 46px; text-align: center; }

/* ---- Cabeceras ordenables ---- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th .arrow { color: var(--muted); font-size: 12px; }

/* ---- Tabla de informes (vista unificada): compacta y con nombre amplio ---- */
#alumnosBox table { min-width: 0; width: 100%; }
#alumnosBox th { white-space: nowrap; }                                 /* títulos en una sola línea */
#alumnosBox td:first-child, #alumnosBox th:first-child { width: 26%; min-width: 190px; }
#alumnosBox td:first-child strong { white-space: normal; overflow-wrap: anywhere; }
#alumnosBox .acciones, #alumnosBox .infocell { flex-wrap: wrap; }        /* botones fluyen a 2 líneas si hace falta */
#alumnosBox .infocell input.num { width: 84px; }
#alumnosBox .infocell input.notacampo { width: 54px; text-align: center; }  /* dígito.dígito */
/* Nota Moodle: campo de solo texto (sin flechas de incremento/decremento) */
.notacampo::-webkit-outer-spin-button, .notacampo::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.notacampo { -moz-appearance: textfield; appearance: textfield; }
#alumnosBox td, #alumnosBox th { padding: 10px 10px; }

/* ---- Tablas ---- */
.tablewrap { margin-top: 12px; overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---- Badges (con icono + texto, no solo color) ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); }
.badge.ok   { color: var(--ok);   border-color: color-mix(in oklab, var(--ok) 45%, var(--line)); }
.badge.warn { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 45%, var(--line)); }
.badge.type { color: var(--text); background: var(--panel-2); }
.nota { font-weight: 700; }

/* ---- Jobs ---- */
.jobs { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.job-head { display: flex; align-items: center; gap: 10px; }
.job pre { margin: 8px 0 0; background: #0b1219; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 220px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: 820px; max-width: 100%; max-height: 90dvh; display: flex; flex-direction: column; }
.modal-card.wide { width: 1100px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow: auto; }
/* Estilo del informe (HTML de Moodle) dentro del modal */
.modal-body h2 { margin-top: 0; }
.modal-body ul { padding-left: 20px; }
.modal-body em { color: var(--muted); }

.acciones { display: flex; gap: 8px; justify-content: flex-end; white-space: nowrap; }
.infocell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.nota.small { font-size: 13px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 14px; cursor: pointer; }
.inline .check { margin-top: 0; margin-bottom: 2px; }   /* alineado con los selectores/botón */
.check input { width: 16px; height: 16px; accent-color: var(--blue); }
.infocell input.num { width: 92px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Editor de informe ---- */
.editor-wrap { display: flex; flex-direction: column; gap: 12px; }
.editor-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; position: sticky; top: 0; background: var(--panel); padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.editor-tools .sep { flex: 1; }
.editor-tools input.num { width: 100px; }
.report-editor { min-height: 45vh; max-height: 62vh; overflow: auto; background: #0b1219; border: 1px solid var(--line); border-radius: 8px; padding: 16px; line-height: 1.6; }
.report-editor:focus { outline: 2px solid var(--blue); }
.report-editor h2 { margin-top: 0; }
.report-editor ul { padding-left: 20px; }

/* ---- Visor de recursos ---- */
.pdfframe { width: 100%; height: 78dvh; border: 0; border-radius: 8px; background: #fff; }
.md { line-height: 1.6; }
.md h1, .md h2, .md h3 { margin: .6em 0 .3em; }
.md ul { padding-left: 22px; }
.md code { background: #0b1219; border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; font-size: 90%; }
.md pre.code { background: #0b1219; border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; }
.md a { color: var(--blue); }
.plain { white-space: pre-wrap; background: #0b1219; border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 30; }
.toast.warn { border-color: var(--gold-strong); }

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; width: 100%; }
  main { padding: 16px; }
}
