*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #2563eb;
  --primary-dk: #1d4ed8;
  --primary-lt: #eff6ff;
  --success:    #16a34a;
  --danger:     #dc2626;
  --warning:    #d97706;
  --bg:         #f1f5f9;
  --card:       #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --text-soft:  #64748b;
  --radius:     10px;
  --topbar-h:   52px;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Utilidades ─────────────────────────────────────── */
.hidden { display: none !important; }

/* Vistas que ocupan 100vh con topbar fijo y body scrollable */
.view { height: 100vh; display: flex; flex-direction: column; }

/* Vistas centradas (login / registro) */
.center-view { align-items: center; justify-content: center; background: var(--bg); }

/* Vistas con topbar + cuerpo scrollable */
.paged-view {}
.page-body   { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; }

.container   { max-width: 960px; margin: 0 auto; }
.container-sm { max-width: 600px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.error-msg {
  background: #fef2f2; color: var(--danger);
  border: 1px solid #fecaca; border-radius: 6px;
  padding: .45rem .75rem; font-size: .85rem; margin-bottom: .75rem;
}
.ok-msg {
  background: #f0fdf4; color: var(--success);
  border: 1px solid #bbf7d0; border-radius: 6px;
  padding: .45rem .75rem; font-size: .85rem; margin-bottom: .75rem;
}
.hint { color: var(--text-soft); font-size: .78rem; display: block; margin-top: .2rem; }
.section-title { font-size: 1rem; font-weight: 600; color: var(--text-soft); margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Botones ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem 1rem; border: none; border-radius: 7px;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: background .12s, box-shadow .12s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dk); }
.btn-ghost    { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }
.btn-sm   { padding: .3rem .65rem; font-size: .8rem; }
.btn-full { width: 100%; }

/* ── Badges ─────────────────────────────────────────── */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 20px; font-size: .73rem; font-weight: 700; background: var(--primary); color: #fff; }
.badge-neutral { background: var(--bg); color: var(--text-soft); border: 1px solid var(--border); }

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  background: var(--card); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-title { font-weight: 600; font-size: .95rem; }
.topbar-user  { font-size: .82rem; color: var(--text-soft); }
.topbar-actions { display: flex; align-items: center; gap: .4rem; }

/* ── Auth ────────────────────────────────────────────── */
.auth-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2.25rem 2rem;
  width: 100%; max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
}
.auth-title { font-size: 1.65rem; font-weight: 800; text-align: center; margin-bottom: 1.5rem; color: var(--primary); letter-spacing: -.02em; }
.auth-link  { text-align: center; font-size: .85rem; color: var(--text-soft); margin-top: 1rem; }
.auth-link a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ── Campos ──────────────────────────────────────────── */
.field { margin-bottom: .9rem; }
.field > label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; color: var(--text); }
.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=number],
.field input[type=file],
.field textarea,
.field select {
  width: 100%; padding: .5rem .7rem;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: .875rem; background: var(--card); color: var(--text);
  transition: border-color .12s;
}
.field input:focus,.field textarea:focus,.field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.field textarea { resize: vertical; }

/* ── Temas grid ──────────────────────────────────────── */
.temas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: .85rem; }
.tema-card {
  background: var(--card); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.tema-card:hover { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,.08); }
.tema-card h3 { font-size: .95rem; margin-bottom: .3rem; }
.tema-card p  { font-size: .82rem; color: var(--text-soft); margin-bottom: .6rem; line-height: 1.45; }
.tema-card .tema-meta { font-size: .78rem; color: var(--text-soft); }

/* ── Config test ─────────────────────────────────────── */
.num-control { display: flex; align-items: center; gap: .5rem; }
.num-control input { width: 70px; text-align: center; }
.modo-selector { display: flex; gap: .75rem; margin-top: .3rem; }
.modo-opcion { flex: 1; cursor: pointer; }
.modo-opcion input { display: none; }
.modo-card {
  border: 2px solid var(--border); border-radius: 8px;
  padding: .8rem; text-align: center; transition: border-color .12s, background .12s;
}
.modo-card strong { display: block; font-size: .9rem; margin-bottom: .2rem; }
.modo-card span   { font-size: .75rem; color: var(--text-soft); }
.modo-opcion input:checked + .modo-card { border-color: var(--primary); background: var(--primary-lt); }

/* ── Test ────────────────────────────────────────────── */
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 1.1rem; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width .3s; }

.test-card { display: flex; flex-direction: column; }
.enunciado { font-size: 1rem; line-height: 1.65; margin-bottom: 1.1rem; font-weight: 500; }

.opciones { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .85rem; }
.opcion-btn {
  display: flex; align-items: flex-start; gap: .65rem;
  width: 100%; text-align: left; padding: .65rem .85rem;
  background: var(--bg); border: 2px solid var(--border); border-radius: 8px;
  font-size: .875rem; cursor: pointer; transition: border-color .12s, background .12s;
}
.opcion-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-lt); }
.opcion-btn .letra { font-weight: 700; min-width: 1.1rem; color: var(--text-soft); flex-shrink: 0; }
.opcion-btn.seleccionada { border-color: var(--primary); background: var(--primary-lt); }
.opcion-btn.correcta     { border-color: var(--success); background: rgba(22,163,74,.07); }
.opcion-btn.incorrecta   { border-color: var(--danger);  background: rgba(220,38,38,.06); }
.opcion-btn:disabled { cursor: default; }

.feedback { padding: .75rem .9rem; border-radius: 8px; font-size: .85rem; line-height: 1.5; margin-bottom: .6rem; }
.feedback.correcto   { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.feedback.incorrecto { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

.test-nav { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .35rem; }

/* ── Resultados ──────────────────────────────────────── */
.resultado-header { text-align: center; padding: 1.75rem; }
.score { font-size: 3.25rem; font-weight: 900; line-height: 1; letter-spacing: -.03em; }
.score.bueno  { color: var(--success); }
.score.regular{ color: var(--warning); }
.score.malo   { color: var(--danger); }
.score-texto  { font-size: 1rem; color: var(--text-soft); margin-top: .4rem; }

.detalle-lista { display: flex; flex-direction: column; gap: .5rem; }
.detalle-item { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: .9rem 1rem; border-left: 4px solid var(--border); }
.detalle-item.ok { border-left-color: var(--success); }
.detalle-item.ko { border-left-color: var(--danger); }
.detalle-item .di-enunciado { font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
.detalle-item .di-respuestas { font-size: .8rem; color: var(--text-soft); }
.detalle-item .di-respuestas span { font-weight: 600; }
.detalle-item .di-justificacion { font-size: .78rem; color: var(--text-soft); margin-top: .3rem; font-style: italic; }

/* ── Admin layout (topbar fijo + sidebar + main scrollables) ── */
.admin-body {
  display: flex; flex: 1; overflow: hidden; gap: 0; padding: 0;
}
.admin-sidebar {
  width: 300px; min-width: 260px; max-width: 320px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 1rem;
  display: flex; flex-direction: column; gap: .75rem;
}
.admin-main {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
}

.sidebar-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
}
.sidebar-title { font-size: .85rem; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .85rem; }

/* Lista con scroll propio */
.scroll-list { display: flex; flex-direction: column; gap: .5rem; }

/* Tabs admin */
.admin-tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
.admin-tab { background: none; border: none; padding: .4rem .9rem; border-radius: 6px; font-size: .875rem; font-weight: 500; color: var(--text-soft); cursor: pointer; }
.admin-tab.active { background: var(--primary); color: #fff; }

/* Buscador usuarios */
.admin-usuarios-header { display: flex; align-items: center; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.input-search { flex: 1; min-width: 160px; padding: .45rem .75rem; border: 1px solid var(--border); border-radius: 8px; font-size: .875rem; background: var(--card); color: var(--text); }

/* Usuario item (admin) */
.admin-user-item { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem; display: flex; align-items: center; gap: .5rem; }
.admin-user-item .aui-info { flex: 1; min-width: 0; }
.admin-user-item .aui-nombre { font-weight: 500; font-size: .875rem; }
.admin-user-item .aui-email { font-size: .78rem; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-admin { background: var(--primary); color: #fff; font-size: .7rem; padding: .15rem .45rem; border-radius: 4px; font-weight: 600; }

/* Tema item (admin) */
.admin-tema-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: .8rem 1rem; display: flex; align-items: center; gap: .5rem;
}
.admin-tema-item .atm-titulo { flex: 1; font-weight: 500; font-size: .875rem; }
.admin-tema-item .atm-count  { font-size: .78rem; color: var(--text-soft); }

/* Pregunta item (admin) */
.admin-preg-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: .8rem 1rem;
}
.admin-preg-item .api-enunciado { font-size: .85rem; font-weight: 500; margin-bottom: .3rem; line-height: 1.45; }
.admin-preg-item .api-meta { font-size: .76rem; color: var(--text-soft); display: flex; gap: .75rem; flex-wrap: wrap; }
.admin-preg-item .api-actions { display: flex; gap: .35rem; margin-top: .5rem; }

/* Opciones dinámicas en formulario */
.opcion-row { display: flex; align-items: center; gap: .4rem; margin-bottom: .4rem; }
.opcion-row .letra-lbl { font-size: .8rem; font-weight: 700; color: var(--text-soft); min-width: 1.4rem; }
.opcion-row input { flex: 1; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 6px; font-size: .85rem; }
.opcion-row input:focus { outline: none; border-color: var(--primary); }

/* ── Historial ───────────────────────────────────────── */
.historial-tabla { width: 100%; border-collapse: collapse; font-size: .875rem; }
.historial-tabla th { text-align: left; padding: .55rem .75rem; border-bottom: 2px solid var(--border); color: var(--text-soft); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.historial-tabla td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); }
.historial-tabla tr:last-child td { border-bottom: none; }

/* ── Modal ───────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 1.65rem; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
.modal-box h3 { margin-bottom: 1.1rem; font-size: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 640px) {
  .admin-body { flex-direction: column; overflow-y: auto; }
  .admin-sidebar { width: 100%; max-width: 100%; border-right: none; border-bottom: 1px solid var(--border); overflow-y: visible; }
  .admin-main { overflow-y: visible; }
  .modo-selector { flex-direction: column; }
}
