/* Cursos EM TRAI — design system
   Tipografía: Instrument Serif (títulos) + DM Sans (interfaz/cuerpo)
   Paleta: papel cálido + tinta navy + acento azul EM TRAI + verde aprobado + rojo ladrillo (error)
*/

:root {
  --paper: #f6f4ee;
  --surface: #ffffff;
  --ink: #1b2430;
  --ink-soft: #5b6472;
  --line: #e3ded1;
  --line-soft: #ece8dd;
  --brand: #0a6cd4;
  --brand-ink: #05407e;
  --brand-tint: #e8f1fc;
  --ok: #2d8a4e;
  --ok-tint: #e7f5ec;
  --err: #b3402e;
  --err-tint: #fbebe7;
  --amber: #b8863b;
  --amber-tint: #fbf1e0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(27, 36, 48, 0.04), 0 8px 24px rgba(27, 36, 48, 0.05);
  --shadow-card-hover: 0 4px 10px rgba(27, 36, 48, 0.06), 0 16px 36px rgba(27, 36, 48, 0.09);
  --focus-ring: 0 0 0 3px rgba(10, 108, 212, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14181f;
    --surface: #1b212b;
    --ink: #ecebe6;
    --ink-soft: #a2a9b4;
    --line: #2b323d;
    --line-soft: #232a34;
    --brand: #4c9bef;
    --brand-ink: #bfe0ff;
    --brand-tint: #17293e;
    --ok: #5cbb82;
    --ok-tint: #16281d;
    --err: #e2695a;
    --err-tint: #331e1c;
    --amber: #d9ac67;
    --amber-tint: #322717;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-card-hover: 0 4px 10px rgba(0, 0, 0, 0.25), 0 16px 36px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  line-height: 1.5;
}

@media (prefers-reduced-motion: no-preference) {
  a, button, input, .course, .option { transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease, filter .15s ease; }
}

h1, h2, h3 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
h1 { font-size: clamp(1.9rem, 3.2vw, 2.6rem); }
h2 { font-size: clamp(1.3rem, 2vw, 1.6rem); }
h3 { font-size: 1.05rem; font-family: "DM Sans", sans-serif; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; margin-top: 28px; }

a { color: var(--brand); }
a:hover { color: var(--brand-ink); }
a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 2px; }

/* ---------- layout ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.25rem;
  color: var(--ink);
  white-space: nowrap;
}
.brand-sep { color: var(--brand); }

.userbox {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .92rem;
  color: var(--ink-soft);
}
.userbox a { color: var(--ink-soft); text-decoration: none; }
.userbox a:hover { color: var(--brand); }
.userbox-name { color: var(--ink); font-weight: 500; }

.container { max-width: 760px; margin: 0 auto; padding: 40px 24px 80px; }
.container-wide { max-width: 920px; }

.page-head { margin-bottom: 28px; }
.eyebrow {
  margin: 0 0 4px;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--brand);
}
.sub { color: var(--ink-soft); margin: 4px 0 0; max-width: 60ch; }

.back {
  display: inline-block;
  margin-bottom: 20px;
  font-size: .92rem;
  text-decoration: none;
  color: var(--ink-soft);
}
.back:hover { color: var(--brand); }

/* ---------- cards & grid ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.course {
  text-decoration: none;
  color: inherit;
  display: block;
}
.course:hover, .course:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--brand);
}
.course:focus-visible { outline: none; }
.course h2 { font-size: 1.3rem; }
.course-desc { color: var(--ink-soft); font-size: .92rem; margin: 0 0 16px; }

.course-progress { display: flex; flex-direction: column; gap: 8px; }
.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}
.course-progress:has(.badge.done) .bar span { background: var(--ok); }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--brand-tint);
  color: var(--brand-ink);
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.done { background: var(--ok-tint); color: var(--ok); }
.badge.muted { background: var(--line-soft); color: var(--ink-soft); }
.badge.pending { background: var(--amber-tint); color: var(--amber); margin-left: 6px; }
.badge.role-admin { background: var(--brand-tint); color: var(--brand-ink); }
.badge.role-student { background: var(--line-soft); color: var(--ink-soft); }

/* ---------- forms ---------- */

.auth { max-width: 420px; margin: 40px auto 0; text-align: left; }

form { display: flex; flex-direction: column; }
label { display: block; margin-bottom: 16px; font-size: .88rem; font-weight: 500; color: var(--ink-soft); }

input, select, button {
  font: inherit;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  margin-top: 6px;
}
input::placeholder { color: #9aa2ad; }
input:hover, select:hover { border-color: #c7c1b0; }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.hint { font-size: .8rem; color: var(--ink-soft); margin: -8px 0 16px; }

button {
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  width: auto;
  align-self: flex-start;
  padding: 11px 22px;
  position: relative;
}
button:hover { background: var(--brand-ink); }
button:active { transform: translateY(1px); }
button:disabled { cursor: default; opacity: .8; }
button.is-loading { color: transparent; }
button.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.row { flex-direction: row; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.row .field { flex: 1 1 180px; margin-bottom: 0; }
.row button { margin-top: 6px; }

.form-msg { min-height: 1.2em; margin: 12px 0 0; font-size: .9rem; }
.form-msg.ok { color: var(--ok); }
.form-msg.error { color: var(--err); }

/* ---------- banners / states ---------- */

.banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  margin: 0 0 18px;
}
.banner.error, p.error { background: var(--err-tint); color: var(--err); }
.banner.ok { background: var(--ok-tint); color: var(--ok); }
.error { color: var(--err); }
.loading, .empty { color: var(--ink-soft); }
.empty { padding: 24px 0; text-align: center; }
.result.ok { color: var(--ok); font-weight: 600; }
.result.fail { color: var(--err); font-weight: 600; }
.result { margin-top: 14px; }

/* ---------- curso / módulos (visor por etapas: un módulo a la vez) ---------- */

.module {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
  position: relative;
}

.stepper-progress { display: flex; align-items: center; gap: 12px; margin: 0 0 24px; }
.stepper-progress .bar { flex: 1; }
.stepper-progress .badge { flex: none; }

.module-actions { margin-top: 24px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.module-actions .back { margin: 0; }

.module-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.module-num {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--brand);
  color: var(--brand-ink);
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.module-head h2 { margin: 0; }

.content { line-height: 1.7; color: var(--ink); }
.content :is(h2, h3) { font-family: "Instrument Serif", Georgia, serif; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink); }
.content ul { padding-left: 1.3em; }
.content strong { color: var(--brand-ink); }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 14px 0;
}
legend {
  font-weight: 600;
  padding: 0 6px;
  font-size: .95rem;
}

.options { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: 0;
  font-weight: 400;
  font-size: .95rem;
  color: var(--ink);
}
.option:hover { border-color: var(--brand); background: var(--brand-tint); }
.option input { width: auto; margin: 0; accent-color: var(--brand); }
.option:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.option:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }

form.quiz > button { margin-top: 10px; }

/* ---------- tablas (admin) ---------- */

.count { font-size: .95rem; font-weight: 400; color: var(--ink-soft); margin-left: 6px; }
.btn-link {
  float: right;
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--brand);
  color: var(--brand-ink);
  padding: 5px 12px;
  border-radius: 999px;
}
.btn-link:hover { background: var(--brand-tint); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); font-size: .88rem; white-space: nowrap; }
th { color: var(--ink-soft); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--brand-tint); }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .container { padding: 24px 16px 60px; }
  .card, .module { padding: 18px; }
  .row { flex-direction: column; align-items: stretch; }
  .row .field { flex: none; }
  .row button { width: 100%; align-self: stretch; }
  th, td { font-size: .82rem; padding: 8px; }
  .btn-link { float: none; display: inline-block; margin-top: 8px; }
  .userbox { font-size: .82rem; gap: 10px; }
}

/* Botón "Abrir Tutor EM TRAI" en la barra superior */
.topbar .tutor-link {
  text-decoration: none;
  background: #0A7ED4;
  color: #fff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  margin: 0 auto 0 16px;
}
.topbar .tutor-link:hover { filter: brightness(1.06); }
@media (max-width: 560px) { .topbar .tutor-link { font-size: .8rem; padding: 6px 10px; } }
