/* ==========================================================================
   LAYOUT CSS: Menú Lateral Fijo, Drawer Deslizable y Barra de Progreso
   Generador de Cuadernillos Educativos (P02)
   ========================================================================== */

.app-wrapper {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-app);
}

/* ==========================================================================
   BARRA LATERAL FIJA (SIDEBAR)
   ========================================================================== */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1),
              transform var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  position: relative;
  box-shadow: 2px 0 8px rgba(15, 23, 42, 0.03);
}

/* Estado contraído en pantalla de escritorio */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Encabezado del menú lateral */
.sidebar-header {
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  height: var(--topbar-height);
  flex-shrink: 0;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
  user-select: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  transition: opacity var(--transition-speed), width var(--transition-speed);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.7rem;
  color: var(--secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar.collapsed .brand-text {
  opacity: 0;
  pointer-events: none;
  width: 0;
}

.btn-sidebar-toggle {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: background var(--transition-speed), color var(--transition-speed), border-color var(--transition-speed);
}

.btn-sidebar-toggle:hover {
  background: var(--bg-muted);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-mobile-close {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

/* ==========================================================================
   NAVEGACIÓN INTERNA Y ELEMENTOS
   ========================================================================== */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94A3B8;
  padding: 14px 14px 6px;
  white-space: nowrap;
  transition: opacity var(--transition-speed);
}

.sidebar.collapsed .nav-section-title {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s ease-in-out;
  position: relative;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--text-main);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
}

.nav-item .nav-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Estado activo resaltado */
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 15%;
  bottom: 15%;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
}

.nav-label {
  flex: 1;
  font-size: 0.92rem;
  transition: opacity var(--transition-speed);
}

.nav-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-muted);
}

.nav-item.active .nav-badge {
  background: var(--primary-surface);
  color: var(--primary);
}

/* Comportamiento cuando el sidebar está contraído */
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge {
  display: none;
}

/* Tooltip flotante en estado contraído */
.sidebar.collapsed .nav-item[data-tooltip] {
  position: relative;
}

.sidebar.collapsed .nav-item[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #1E293B;
  color: #FFFFFF;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  animation: tooltipFade 0.15s ease-out;
}

@keyframes tooltipFade {
  from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* ==========================================================================
   PIE DE LA BARRA LATERAL: BLOQUE DE PROMPTS Y PROGRESO
   ========================================================================== */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.progress-card {
  background: linear-gradient(135deg, #F8FAFC 0%, #EEF2FF 100%);
  border: 1px solid var(--primary-surface);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
}

.progress-title {
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.progress-title svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.progress-count {
  color: var(--text-main);
  font-weight: 800;
  background: #FFFFFF;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  border: 1px solid #C7D2FE;
  font-size: 0.74rem;
}

.progress-bar-bg {
  width: 100%;
  height: 7px;
  background: #E2E8F0;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4F46E5 0%, #10B981 100%);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.progress-phase-label {
  font-size: 0.7rem;
  color: #64748B;
  display: flex;
  justify-content: space-between;
  font-weight: 500;
}

.sidebar.collapsed .sidebar-footer {
  padding: 12px 6px;
  display: flex;
  justify-content: center;
}

.sidebar.collapsed .progress-card {
  padding: 8px 4px;
  align-items: center;
}

.sidebar.collapsed .progress-title,
.sidebar.collapsed .progress-phase-label,
.sidebar.collapsed .progress-bar-bg {
  display: none;
}

.sidebar.collapsed .progress-count {
  font-size: 0.7rem;
  padding: 3px 5px;
}

/* ==========================================================================
   ÁREA PRINCIPAL Y TOPBAR
   ========================================================================== */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-mobile-menu {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  align-items: center;
  justify-content: center;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
}

.page-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.breadcrumb-root {
  color: var(--text-muted);
  font-weight: 500;
}

.breadcrumb-separator {
  color: #CBD5E1;
}

.breadcrumb-current {
  font-weight: 700;
  color: var(--text-main);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.views-container {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding: 24px;
}

.view-panel {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.view-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Overlay para móvil y tablet */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 90;
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   RESPONSIVE: Tablet & Mobile (<= 992px)
   ========================================================================== */
@media (max-width: 992px) {
  .btn-mobile-menu {
    display: flex;
  }
  
  .btn-mobile-close {
    display: flex;
  }

  .btn-sidebar-toggle {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px !important;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar.collapsed {
    width: 280px;
  }

  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .nav-badge,
  .sidebar.collapsed .nav-section-title,
  .sidebar.collapsed .progress-title,
  .sidebar.collapsed .progress-phase-label,
  .sidebar.collapsed .progress-bar-bg {
    display: flex !important;
    opacity: 1 !important;
    width: auto !important;
    height: auto !important;
  }

  .sidebar.collapsed .nav-item {
    justify-content: flex-start !important;
    padding: 10px 14px !important;
  }

  .views-container {
    padding: 16px;
  }

  .topbar {
    padding: 0 16px;
  }
}

/* ==========================================================================
   MODO ESTUDIANTE & MODO AUTENTICACIÓN (PANTALLA COMPLETA)
   Oculta sidebar y topbar administrativa para niños o formulario de login
   ========================================================================== */
body.is-student-portal .sidebar,
body.is-student-portal .topbar,
body.is-student-portal .sidebar-overlay,
body.is-auth-view .sidebar,
body.is-auth-view .topbar,
body.is-auth-view .sidebar-overlay {
  display: none !important;
}

body.is-student-portal .main-wrapper,
body.is-auth-view .main-wrapper {
  margin-left: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
}

body.is-student-portal .views-container,
body.is-auth-view .views-container {
  padding: 0 !important;
  height: 100vh !important;
  max-height: 100vh !important;
  overflow-y: auto !important;
}

body.is-student-portal {
  background: #F0FDF4; /* Fondo fresco y alegre para niños */
}

body.is-auth-view {
  background: #F8FAFC;
}
