@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

/* ---------- Tokens ---------- */
:root {
  --ink: #1E3A52;
  --ink-soft: #2c4f6c;
  --paper: #F5F6F4;
  --paper-2: #ffffff;
  --chalk-green: #3F6659;
  --pencil-red: #C1443A;
  --mustard: #E4A73B;
  --graphite: #3A3A38;
  --graphite-soft: #6b6b67;
  --border: rgba(58, 58, 56, 0.13);
  --border-strong: rgba(58, 58, 56, 0.22);
  --shadow-card: 0 1px 2px rgba(30, 58, 82, .05), 0 6px 20px rgba(30, 58, 82, .07);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --sidebar-w: 288px;
  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--graphite);
  background: var(--paper);
  line-height: 1.55;
}

h1, h2, h3 { font-family: var(--font-head); font-weight: 700; color: var(--ink); margin: 0; }

a { color: inherit; }

button { font-family: inherit; }

.oculto { display: none !important; }

/* ---------- Focus visibility ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 2.5px solid var(--mustard);
  outline-offset: 2px;
  border-radius: 4px;
}
.sidebar :focus-visible { outline-color: var(--mustard); outline-offset: 1px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(245, 246, 244, 0.12);
}
.brand-mark {
  font-size: 1.4rem;
  transform: rotate(-8deg);
  display: inline-block;
}
.brand-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: .2px;
}

.nav-primary { padding: 14px 12px 4px; }

.nav-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: rgba(245, 246, 244, 0.82);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.nav-link:hover { background: rgba(245, 246, 244, 0.09); color: var(--paper); }
.nav-link.is-active { background: rgba(245, 246, 244, 0.14); color: var(--paper); font-weight: 600; }
.nav-link svg { flex-shrink: 0; opacity: .85; }

.nav-clases {
  padding: 10px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.nav-clases-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 6px;
}
.nav-clases-head h2 {
  font-family: var(--font-body);
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: rgba(245, 246, 244, 0.55);
}
.btn-icon {
  background: rgba(245, 246, 244, 0.1);
  border: none;
  color: var(--paper);
  width: 24px; height: 24px;
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.btn-icon:hover { background: rgba(245, 246, 244, 0.22); }

/* Tree */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree-empty {
  color: rgba(245, 246, 244, 0.5);
  font-size: .85rem;
  padding: 10px 8px;
  font-style: italic;
}
.tree-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .89rem;
  color: rgba(245, 246, 244, 0.88);
  user-select: none;
}
.tree-row:hover { background: rgba(245, 246, 244, 0.09); }
.tree-row.is-current { background: rgba(228, 167, 59, 0.22); color: var(--paper); }
.tree-row-clase { font-weight: 600; }
.chev {
  flex-shrink: 0;
  transition: transform .18s ease;
  opacity: .7;
}
.tree-row[aria-expanded="true"] .chev { transform: rotate(90deg); }
.tree-count {
  margin-left: auto;
  font-size: .72rem;
  color: rgba(245, 246, 244, 0.45);
  font-family: var(--font-mono);
}
.tree-alumnos, .tree-examenes { padding-left: 18px; overflow: hidden; }
.tree-alumnos.oculto, .tree-examenes.oculto { display: none; }
.tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row-alumno .tree-label { flex: 1; }
.chev-mini {
  flex-shrink: 0;
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
  opacity: .75;
}
.chev-mini:hover { background: rgba(245, 246, 244, 0.14); }
.chev-mini svg { transition: transform .16s ease; }
.chev-mini[aria-expanded="true"] svg { transform: rotate(90deg); }
.tree-examen {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 6px 20px;
  font-size: .82rem;
  color: rgba(245, 246, 244, 0.72);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.tree-examen:hover { background: rgba(245, 246, 244, 0.09); }
.tree-examen-titulo { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-examen-nota { font-family: var(--font-mono); font-size: .78rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-alta { background: #6fbfa6; }
.dot-media { background: var(--mustard); }
.dot-baja { background: #e08278; }
.tree-add {
  color: rgba(245, 246, 244, 0.6);
  font-size: .82rem;
  font-style: normal;
}
.tree-add:hover { color: var(--paper); }

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid rgba(245, 246, 244, 0.12);
}

/* ---------- Mobile menu button / backdrop ---------- */
.btn-menu {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 60;
  background: var(--ink);
  color: var(--paper);
  border: none;
  width: 42px; height: 42px;
  border-radius: 10px;
  align-items: center; justify-content: center;
  box-shadow: var(--shadow-card);
  cursor: pointer;
}
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(30, 58, 82, 0.45);
  z-index: 45;
}

/* ---------- Main / views ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 40px 44px 80px;
}
.view-root { max-width: 900px; margin: 0 auto; }
.view { animation: aparecer .25s ease both; }
@keyframes aparecer { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Pantalla de autenticación ---------- */
#auth-root {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
#auth-root .view-auth { width: 100%; max-width: 380px; }
#auth-root .view-header { text-align: center; }
.auth-switch { text-align: center; font-size: .9rem; color: var(--graphite-soft); }

.view-header { margin-bottom: 28px; }
.breadcrumb {
  font-size: .82rem;
  color: var(--graphite-soft);
  margin: 0 0 4px;
  font-weight: 500;
}
.view-header h1 { font-size: 1.9rem; }
.view-sub { color: var(--graphite-soft); margin: 8px 0 0; font-size: .98rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 26px 28px;
}
.card + .card { margin-top: 22px; }
.card h2 { font-size: 1.15rem; margin-bottom: 4px; }

/* ---------- Stat grid (dashboard) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat-card {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  box-shadow: var(--shadow-card);
}
.stat-card .stat-value {
  display: block;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 2.1rem;
  color: var(--ink);
  line-height: 1;
}
.stat-card .stat-label {
  display: block;
  margin-top: 8px;
  font-size: .84rem;
  color: var(--graphite-soft);
  font-weight: 500;
}
.stat-card.accent-green .stat-value { color: var(--chalk-green); }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card-action {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-card);
  transition: border-color .15s ease, transform .15s ease;
}
.card-action:hover { border-color: var(--ink); transform: translateY(-1px); }
.card-action .card-action-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-action strong { display: block; font-size: 1rem; color: var(--ink); }
.card-action span.desc { font-size: .84rem; color: var(--graphite-soft); }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 46px 20px;
  color: var(--graphite-soft);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 10px; display: block; opacity: .8; }
.empty-state p { margin: 0 0 16px; font-size: .95rem; }
.empty-state.small { padding: 18px 10px; font-size: .88rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--ink-soft); }
.btn-primary:disabled { background: #9caebb; cursor: wait; }
.btn-outline { background: transparent; color: var(--ink); border: 1.4px solid var(--border-strong); }
.btn-outline:hover { border-color: var(--ink); }
.btn-sm { padding: 7px 13px; font-size: .84rem; }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(245, 246, 244, .55);
  border-top-color: var(--paper);
  border-radius: 50%;
  animation: girar .7s linear infinite;
  flex-shrink: 0;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-card { display: flex; flex-direction: column; gap: 4px; }
.field-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 4px; }
.field { flex: 1; min-width: 180px; margin-bottom: 16px; }
.field label, label.field-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
input[type=text], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.4px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-family: inherit;
  background: var(--paper-2);
  color: var(--graphite);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 70px; }
textarea.textarea-json {
  font-family: var(--font-mono);
  font-size: .85rem;
  min-height: 220px;
  line-height: 1.6;
}

.field-hint {
  margin: 8px 0 0;
  font-size: .82rem;
  color: var(--mustard);
  background: #fbf1e0;
  border: 1px solid #f0dcae;
  border-radius: var(--radius-sm);
  padding: 8px 11px;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
}

.form-msg { margin-top: 14px; font-size: .9rem; }
.msg { padding: 11px 14px; border-radius: var(--radius-sm); font-size: .89rem; border: 1px solid transparent; }
.msg-ok { background: #eaf3ef; color: var(--chalk-green); border-color: #cfe6db; }
.msg-error { background: #fbeae8; color: var(--pencil-red); border-color: #f2cdc8; }
.msg-info { background: #eaf0f4; color: var(--ink); border-color: #d3e0e8; }

/* Dropzone */
.dropzone {
  position: relative;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--paper);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--ink); background: #eef1ee; }
.dropzone svg { color: var(--ink); opacity: .55; }
.dropzone-content p { margin: 10px 0 0; font-size: .92rem; }
.dropzone-hint { color: var(--graphite-soft); font-size: .8rem !important; margin-top: 4px !important; }
.dropzone-preview { display: flex; align-items: center; gap: 14px; justify-content: center; }
.dropzone-preview img {
  max-height: 120px; max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.dropzone.oculto .dropzone-content { display: none; }

details.ejemplo-details {
  margin: 6px 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
details.ejemplo-details summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: .86rem;
  font-weight: 600;
  color: var(--ink);
}
details.ejemplo-details pre.ejemplo-json {
  margin: 0;
  padding: 14px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: .78rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--graphite);
}

/* ---------- Alumno view ---------- */
.alumno-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.alumno-actions .alumno-meta { color: var(--graphite-soft); font-size: .88rem; }

.examen-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 14px;
  overflow: hidden;
}
.examen-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  background: var(--paper);
}
.examen-card-head:hover { background: #eef1ee; }
.examen-card-titulo { flex: 1; font-weight: 600; color: var(--ink); }
.examen-card-nota { font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem; }
.examen-card-nota.tier-alta { color: var(--chalk-green); }
.examen-card-nota.tier-media { color: var(--mustard); }
.examen-card-nota.tier-baja { color: var(--pencil-red); }
.examen-card-fecha { font-size: .78rem; color: var(--graphite-soft); }
.examen-card-body { padding: 18px 20px 22px; border-top: 1px solid var(--border); }
.examen-card-body.oculto { display: none; }
.examen-card-estado {
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: capitalize;
}
.examen-card-estado.estado-corregido { background: #eaf3ef; color: var(--chalk-green); }
.examen-card-estado.estado-pendiente { background: #fbf1e0; color: #9c7318; }
.examen-card-estado.estado-error { background: #fbeae8; color: var(--pencil-red); }

/* ---------- Correction reveal: the signature mark animation ---------- */
.preguntas-marcadas { display: flex; flex-direction: column; gap: 4px; }
.pregunta-marca {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  opacity: 0;
  transform: translateX(-10px);
}
.pregunta-marca:last-child { border-bottom: none; }
.pregunta-marca.show {
  opacity: 1;
  transform: none;
  transition: opacity .32s ease, transform .32s ease;
}

.marca-svg { flex-shrink: 0; margin-top: 1px; }
.marca-trazo {
  fill: none;
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-dashoffset .55s cubic-bezier(.4,.1,.2,1);
}
.marca-check { stroke: var(--chalk-green); }
.marca-partial { stroke: var(--mustard); }
.marca-cross { stroke: var(--pencil-red); }

.pregunta-info { flex: 1; min-width: 0; }
.pregunta-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 3px; flex-wrap: wrap; }
.pregunta-num { font-weight: 700; color: var(--ink); font-size: .9rem; }
.pregunta-tipo {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--graphite-soft);
  background: var(--paper);
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.pregunta-puntos { font-family: var(--font-mono); font-size: .84rem; font-weight: 600; color: var(--graphite); margin-left: auto; }
.pregunta-feedback { margin: 2px 0 0; font-size: .89rem; color: var(--graphite-soft); }

.nota-final {
  margin-top: 22px;
  padding: 22px;
  border-radius: var(--radius-md);
  text-align: center;
  background: var(--paper);
  border: 1.5px dashed var(--border-strong);
  opacity: 0;
  transform: scale(1.9) rotate(-9deg);
}
.nota-final.show {
  opacity: 1;
  transform: scale(1) rotate(-2.5deg);
  transition: opacity .3s ease, transform .45s cubic-bezier(.34, 1.56, .64, 1);
}
.nota-final-label {
  display: block;
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--graphite-soft);
  margin-bottom: 6px;
}
.nota-final-valor {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 3rem;
  line-height: 1;
  color: var(--ink);
}
.nota-final-valor small { font-size: 1.3rem; font-weight: 500; color: var(--graphite-soft); }
.nota-final.tier-alta .nota-final-valor { color: var(--chalk-green); }
.nota-final.tier-media .nota-final-valor { color: var(--mustard); }
.nota-final.tier-baja .nota-final-valor { color: var(--pencil-red); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 58, 82, 0.42);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 80;
  animation: fundir .15s ease;
}
@keyframes fundir { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--paper-2);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(30, 58, 82, .28);
}
.modal-box h2 { font-size: 1.15rem; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 90;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 320px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  box-shadow: var(--shadow-card);
  animation: entrar-toast .2s ease;
}
@keyframes entrar-toast { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast-ok { background: var(--chalk-green); color: var(--paper); }
.toast-error { background: var(--pencil-red); color: var(--paper); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .btn-menu { display: flex; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 55;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open { display: block; }
  .main { padding: 76px 18px 60px; }
  .field-row { flex-direction: column; gap: 0; }
}

@media (max-width: 480px) {
  .nota-final-valor { font-size: 2.3rem; }
  .card { padding: 20px 18px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .pregunta-marca, .nota-final { opacity: 1; transform: none; }
}
