.temario-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem 3rem;
}

.temario-sidebar {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  align-self: start;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  max-height: calc(100vh - var(--header-h) - 2rem);
  overflow-y: auto;
}

.temario-sidebar::-webkit-scrollbar {
  width: 4px;
}

.temario-sidebar::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 4px;
}

.temario-tema {
  margin-bottom: 0.5rem;
}

.temario-tema-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg2);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.temario-tema-header:hover {
  background: var(--accent-light);
}

.temario-tema-header .arrow {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.2s;
  color: var(--text3);
}

.temario-tema-header.open .arrow {
  transform: rotate(90deg);
}

.temario-capitulos {
  list-style: none;
  padding: 0.25rem 0 0.25rem 0.75rem;
  display: none;
}

.temario-tema-header.open + .temario-capitulos {
  display: block;
}

.temario-capitulo {
  padding: 0.45rem 0.75rem;
  margin: 2px 0;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.temario-capitulo::before {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
}

.temario-capitulo:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.temario-capitulo.active {
  background: var(--accent);
  color: #fff;
}

.temario-capitulo.active::before {
  background: #fff;
}

.temario-capitulo .badge {
  margin-left: auto;
  font-size: 0.65rem;
  background: var(--border);
  color: var(--text3);
  padding: 1px 6px;
  border-radius: 4px;
}

.temario-capitulo.active .badge {
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
}

.temario-content {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 2rem;
  min-height: 400px;
}

.temario-content h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.temario-content .chapter-subtitle {
  color: var(--text3);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.temario-content .chapter-body {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
  /* Red de seguridad: si algo (una tabla, una imagen sin max-width) sigue
     siendo mas ancho que la tarjeta, que haga scroll solo el, no la pagina. */
  overflow-x: auto;
}

/* Los graficos de JSXGraph llevan width/height fijos en px en el propio
   contenido de cada capitulo (p.ej. 480x320). max-width los deja encoger
   en movil sin pelearse con el "width" inline: son propiedades distintas,
   no hace falta !important. La relacion de aspecto puede variar un poco
   en pantallas muy estrechas, pero el grafico no se corta ni desborda. */
.temario-content .chapter-body img,
.temario-content .chapter-body .jxgbox {
  max-width: 100%;
  height: auto;
}

.temario-content .chapter-body p:not(:last-child) {
  margin-bottom: 1rem;
}

.temario-content .chapter-body ul,
.temario-content .chapter-body ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}

.temario-content .chapter-body li {
  margin-bottom: 0.3rem;
}

.temario-content .chapter-body em {
  color: var(--text3);
}

.temario-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text3);
}

.temario-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.temario-empty h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--text2);
}

@media (max-width: 768px) {
  .temario-layout {
    /* minmax(0, 1fr) y no 1fr a secas: por defecto un item de grid no se
       encoge por debajo del ancho de su contenido (min-width:auto). Un
       jxgbox de 480px fijo dentro del capitulo bastaba para forzar TODA
       la columna (sidebar incluido) a ese ancho en un movil de 375px. */
    grid-template-columns: minmax(0, 1fr);
    padding: 0 1rem 2rem;
    gap: 1.25rem;
  }

  .temario-sidebar {
    position: static;
    max-height: none;
    padding: 1rem;
  }

  .temario-content {
    padding: 1.25rem;
  }
}
