/* ==========================================================================
   Forprocer LMS - Portal del Alumno
   Indice del curso con sidebar de progreso, modulos accordion y lecciones
   con estados. Diseno glassmorphism usando tokens del sistema de diseno.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Layout principal: Sidebar de progreso + contenido de modulos
   -------------------------------------------------------------------------- */
.portal-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--space-6);
  align-items: start;
  min-height: calc(100vh - var(--navbar-height) - var(--space-12));
}

.portal-layout__sidebar {
  position: sticky;
  top: calc(var(--navbar-height) + var(--space-6));
}

/* --------------------------------------------------------------------------
   Sidebar de progreso (fija a la izquierda con glassmorphism)
   -------------------------------------------------------------------------- */
.portal-sidebar {
  background: var(--glass-bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border-strong);
  border-radius: var(--glass-radius);
  box-shadow: var(--glass-shadow);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
}

/* --------------------------------------------------------------------------
   Circulo de progreso SVG
   -------------------------------------------------------------------------- */
.portal-sidebar__progress-circle {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.portal-sidebar__progress-circle svg {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

/* Pista del circulo (fondo gris) */
.portal-sidebar__progress-circle .progress-track {
  fill: none;
  stroke: var(--color-gray-200);
  stroke-width: 8;
}

/* Relleno del circulo (color primario, animado) */
.portal-sidebar__progress-circle .progress-fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292;
  transition: stroke-dashoffset 1s ease;
}

/* Texto central del circulo (porcentaje + etiqueta) */
.portal-sidebar__progress-circle .progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.portal-sidebar__progress-circle .progress-text__value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-gray-900);
  line-height: 1;
}

.portal-sidebar__progress-circle .progress-text__label {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  margin-top: var(--space-1);
}

/* --------------------------------------------------------------------------
   Estadisticas de la sidebar (lecciones, horas, etc.)
   -------------------------------------------------------------------------- */
.portal-sidebar__stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.portal-sidebar__stat {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--color-gray-100);
  transition: background-color var(--transition-fast);
}

.portal-sidebar__stat:hover {
  background: rgba(255, 255, 255, 0.8);
}

/* Icono de cada estadistica */
.portal-sidebar__stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary-100);
  color: var(--color-primary);
  flex-shrink: 0;
}

.portal-sidebar__stat-icon svg {
  width: 18px;
  height: 18px;
}

/* Informacion textual de la estadistica */
.portal-sidebar__stat-info {
  flex: 1;
  min-width: 0;
}

.portal-sidebar__stat-label {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  display: block;
  line-height: var(--leading-tight);
}

.portal-sidebar__stat-value {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-gray-900);
  display: block;
  line-height: var(--leading-tight);
}

/* Indicadores de cumplimiento: check verde o cruz roja */
.portal-sidebar__check {
  color: var(--color-success);
}

.portal-sidebar__cross {
  color: var(--color-error);
}

/* --- Tutor en sidebar --- */
.portal-sidebar-tutor {
  margin-top: var(--space-4);
  padding: var(--space-4);
}

.portal-sidebar-tutor__titulo {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--space-3);
}

.portal-sidebar-tutor__info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.portal-sidebar-tutor__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(52, 144, 132, 0.1);
  color: var(--color-primary);
  flex-shrink: 0;
}

.portal-sidebar-tutor__avatar svg {
  width: 20px;
  height: 20px;
}

.portal-sidebar-tutor__nombre {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-gray-800);
}

/* --- Foros en sidebar --- */
.portal-sidebar-foros {
  margin-top: var(--space-4);
  padding: var(--space-4);
}

.portal-sidebar-foros__titulo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-gray-900);
  margin: 0 0 var(--space-3);
}

.portal-sidebar-foros__titulo svg {
  width: 18px;
  height: 18px;
  color: var(--color-primary);
}

.portal-sidebar-foros__lista {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.portal-sidebar-foros__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-gray-700);
  font-size: var(--text-sm);
  transition: background 0.12s ease, color 0.12s ease;
}

.portal-sidebar-foros__item:hover {
  background: var(--color-gray-100);
  color: var(--color-primary);
  text-decoration: none;
}

.portal-sidebar-foros__nombre {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-sidebar-foros__count {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-gray-400);
  background: var(--color-gray-100);
  padding: 1px 8px;
  border-radius: var(--radius-full);
}

/* Caja de financiadores (separada del sidebar de progreso) */
.portal-financiadores {
  margin-top: var(--space-4);
  padding: var(--space-5);
  text-align: center;
}

.portal-financiadores__label {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  margin-bottom: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--font-medium);
}

.portal-financiadores__grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--space-4);
}

.portal-financiadores__img {
  max-height: 52px;
  max-width: 140px;
  object-fit: contain;
}

/* --------------------------------------------------------------------------
   Tarjeta de bienvenida (cerrable por el alumno)
   -------------------------------------------------------------------------- */
.portal-bienvenida {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary-light) 100%);
  border-radius: var(--glass-radius);
  padding: var(--space-6);
  color: var(--color-white);
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-6);
  animation: portalFadeIn 0.4s ease forwards;
}

/* Decoracion circular de fondo */
.portal-bienvenida::after {
  content: '';
  position: absolute;
  top: -30%;
  right: -5%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.portal-bienvenida__content {
  position: relative;
  z-index: 1;
  padding-right: var(--space-8);
}

.portal-bienvenida__title {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-white);
  margin-bottom: var(--space-2);
}

.portal-bienvenida__text {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
  line-height: var(--leading-relaxed);
}

/* Boton de cerrar bienvenida */
.portal-bienvenida__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  z-index: 2;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.portal-bienvenida__close:hover {
  color: var(--color-white);
  background: rgba(255, 255, 255, 0.15);
}

.portal-bienvenida__close svg {
  width: 18px;
  height: 18px;
}

/* Animacion de cierre (dismiss) */
.portal-bienvenida.is-dismissing {
  animation: portalFadeOut 0.3s ease forwards;
}

@keyframes portalFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes portalFadeOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* --------------------------------------------------------------------------
   Contenedor de modulos
   -------------------------------------------------------------------------- */
.portal-modulos {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* --------------------------------------------------------------------------
   Modulo accordion (glassmorphism card)
   -------------------------------------------------------------------------- */
.portal-modulo {
  background: var(--glass-bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border-strong);
  border-radius: var(--glass-radius);
  box-shadow: var(--glass-shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition-base);
}

.portal-modulo:hover {
  box-shadow: var(--glass-shadow);
}

/* Header del modulo (clickeable para expandir/colapsar) */
.portal-modulo__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.portal-modulo__header:hover {
  background: rgba(var(--color-primary-rgb), 0.03);
}

/* Icono chevron que rota al expandir */
.portal-modulo__chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--color-gray-400);
  transition: transform var(--transition-base), color var(--transition-fast);
}

.portal-modulo__chevron svg {
  width: 20px;
  height: 20px;
}

.portal-modulo.is-expanded .portal-modulo__chevron {
  transform: rotate(90deg);
  color: var(--color-primary);
}

/* Numero del modulo (badge circular) */
.portal-modulo__number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary-100);
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  flex-shrink: 0;
}

/* Informacion del modulo (nombre + meta) */
.portal-modulo__info {
  flex: 1;
  min-width: 0;
}

.portal-modulo__nombre {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-gray-900);
  margin: 0;
  line-height: var(--leading-tight);
}

.portal-modulo__meta {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Separador circular entre datos meta */
.portal-modulo__meta-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-gray-300);
}

/* Badge de progreso del modulo (ej: "3/5") */
.portal-modulo__progress-badge {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  background: var(--color-primary-100);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  flex-shrink: 0;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Lista de lecciones (collapsible con animacion)
   -------------------------------------------------------------------------- */
.portal-modulo__lecciones {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
}

.portal-modulo.is-expanded .portal-modulo__lecciones {
  max-height: 2000px;
  transition: max-height 0.6s ease;
}

.portal-modulo__lecciones-inner {
  padding: 0 var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-gray-100);
}

/* --------------------------------------------------------------------------
   Leccion individual dentro de un modulo
   -------------------------------------------------------------------------- */
.portal-leccion {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-top: var(--space-1);
  border-radius: var(--radius-lg);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: inherit;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
  cursor: pointer;
}

.portal-leccion:hover {
  background: var(--color-gray-50);
  text-decoration: none;
  transform: translateX(2px);
}

.portal-leccion:first-child {
  margin-top: var(--space-3);
}

/* --- Estado: Completada --- */
.portal-leccion--completada {
  border-left-color: var(--color-success);
}

.portal-leccion--completada:hover {
  background: var(--color-success-light);
}

.portal-leccion--completada .portal-leccion__icon {
  color: var(--color-success);
  background: var(--color-success-light);
}

.portal-leccion--completada .portal-leccion__nombre {
  color: var(--color-gray-600);
}

.portal-leccion--completada .portal-leccion__badge {
  color: var(--color-success);
}

/* --- Estado: En progreso --- */
.portal-leccion--en-progreso {
  border-left-color: var(--color-primary);
}

.portal-leccion--en-progreso:hover {
  background: rgba(var(--color-primary-rgb), 0.05);
}

.portal-leccion--en-progreso .portal-leccion__icon {
  color: var(--color-primary);
  background: var(--color-primary-100);
}

/* --- Estado: Bloqueada --- */
.portal-leccion--bloqueada {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.portal-leccion--bloqueada .portal-leccion__icon {
  color: var(--color-gray-400);
  background: var(--color-gray-100);
}

/* --- Estado: Pendiente de apertura (fecha futura) --- */
.portal-leccion--pendiente-apertura {
  opacity: 0.6;
  pointer-events: auto;
  cursor: pointer;
}

.portal-leccion--pendiente-apertura .portal-leccion__icon {
  color: var(--color-warning, #f0ad4e);
  background: rgba(240, 173, 78, 0.1);
}

.portal-leccion__fecha-apertura {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-warning, #f0ad4e);
  margin-top: 2px;
}

/* --- Módulo cerrado --- */
.portal-modulo--cerrado {
  opacity: 0.6;
}

.portal-modulo--cerrado .portal-modulo__number {
  color: var(--color-warning, #f0ad4e);
  background: rgba(240, 173, 78, 0.1);
}

.portal-modulo__apertura-info {
  color: var(--color-warning, #f0ad4e);
  font-size: var(--text-xs);
  margin-left: var(--space-1);
}

/* --------------------------------------------------------------------------
   Icono de estado de la leccion
   -------------------------------------------------------------------------- */
.portal-leccion__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-gray-100);
  color: var(--color-gray-500);
  flex-shrink: 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.portal-leccion__icon svg {
  width: 20px;
  height: 20px;
}

/* --------------------------------------------------------------------------
   Informacion de la leccion (nombre + meta + mini progreso)
   -------------------------------------------------------------------------- */
.portal-leccion__info {
  flex: 1;
  min-width: 0;
}

.portal-leccion__nombre {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-gray-800);
  line-height: var(--leading-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-leccion__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-gray-400);
  margin-top: 2px;
}

.portal-leccion__meta-tipo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.portal-leccion__meta-tipo svg {
  width: 12px;
  height: 12px;
}

.portal-leccion__meta-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-gray-300);
}

/* Mini barra de progreso dentro de la leccion */
.portal-leccion__progress {
  width: 100%;
  height: 3px;
  background: var(--color-gray-200);
  border-radius: 2px;
  margin-top: var(--space-1);
  overflow: hidden;
}

.portal-leccion__progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Badge de duracion o check a la derecha */
.portal-leccion__badge {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--color-gray-400);
  flex-shrink: 0;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Responsive: Tablet (<= 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .portal-layout {
    grid-template-columns: 240px 1fr;
    gap: var(--space-4);
  }

  .portal-sidebar {
    padding: var(--space-4);
  }

  .portal-sidebar__progress-circle {
    width: 100px;
    height: 100px;
  }

  .portal-sidebar__progress-circle svg {
    width: 100px;
    height: 100px;
  }

  .portal-sidebar__progress-circle .progress-text__value {
    font-size: var(--text-xl);
  }
}

/* --------------------------------------------------------------------------
   Responsive: Movil (<= 768px) - Sidebar se convierte en barra compacta
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .portal-layout {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .portal-layout__sidebar {
    position: relative;
    top: 0;
  }

  /* Sidebar se transforma en barra horizontal compacta */
  .portal-sidebar {
    flex-direction: row;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    border-radius: var(--glass-radius-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Circulo de progreso mas pequeno en movil */
  .portal-sidebar__progress-circle {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
  }

  .portal-sidebar__progress-circle svg {
    width: 64px;
    height: 64px;
  }

  .portal-sidebar__progress-circle .progress-track,
  .portal-sidebar__progress-circle .progress-fill {
    stroke-width: 6;
  }

  /* Recalcular dasharray para radio menor: 2 * PI * (32 - 3) = ~182.21 */
  .portal-sidebar__progress-circle .progress-fill {
    stroke-dasharray: 182.212;
    stroke-dashoffset: 182.212;
  }

  .portal-sidebar__progress-circle .progress-text__value {
    font-size: var(--text-sm);
  }

  .portal-sidebar__progress-circle .progress-text__label {
    display: none;
  }

  /* Stats se muestran en fila horizontal */
  .portal-sidebar__stats {
    flex-direction: row;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
  }

  .portal-sidebar__stat {
    flex: 1;
    min-width: 100px;
    padding: var(--space-2);
    flex-direction: column;
    text-align: center;
    gap: var(--space-1);
  }

  .portal-sidebar__stat-icon {
    width: 28px;
    height: 28px;
  }

  .portal-sidebar__stat-icon svg {
    width: 14px;
    height: 14px;
  }

  /* Modulos a ancho completo con padding reducido */
  .portal-modulo__header {
    padding: var(--space-3) var(--space-4);
  }

  .portal-modulo__lecciones-inner {
    padding: 0 var(--space-3) var(--space-3);
  }

  .portal-leccion {
    padding: var(--space-3) var(--space-2);
  }

  /* Bienvenida compacta */
  .portal-bienvenida {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
  }

  .portal-bienvenida__title {
    font-size: var(--text-lg);
  }

  .portal-bienvenida__text {
    font-size: var(--text-xs);
  }
}

/* --------------------------------------------------------------------------
   Responsive: Movil pequeno (<= 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .portal-sidebar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .portal-sidebar__stats {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .portal-sidebar__stat {
    min-width: 80px;
  }

  .portal-modulo__number {
    width: 28px;
    height: 28px;
    font-size: var(--text-xs);
  }

  .portal-modulo__nombre {
    font-size: var(--text-xs);
  }

  .portal-leccion__icon {
    width: 28px;
    height: 28px;
  }

  .portal-leccion__icon svg {
    width: 16px;
    height: 16px;
  }
}

/* --- Desglose de nota ponderada --- */
.nota-desglose {
  padding: var(--space-2) var(--space-3);
  background: var(--color-gray-50);
  border-radius: var(--radius-md);
  margin-top: var(--space-1);
}

.nota-desglose__item {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  padding: 2px 0;
}
