/* ============================================
   ESTILOS CONTENIDOS - DISEÑO PROFESIONAL
   Dropdowns interactivos para materias
   Mobile-First Responsive Design
   ============================================ */

:root {
  --bg-body: #F1F5F9;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F8FAFC;
  --text-main: #1E293B;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --border-card: #E2E8F0;
  --border-card-hover: #CBD5E1;
  --section-title-color: #0E4B77;
  --input-bg: #FFFFFF;
  --input-text: #1E293B;
  --input-border: #E2E8F0;
  --modal-bg: #FFFFFF;
  --link-color: #0E4B77;
  --shadow-main: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --bg-body: #0B1120 !important;
  --bg-card: #1E293B !important;
  --bg-card-hover: #2A384F !important;
  --text-main: #F8FAFC !important;
  --text-secondary: #CBD5E1 !important;
  --text-muted: #94A3B8 !important;
  --border-card: #334155 !important;
  --border-card-hover: #475569 !important;
  --section-title-color: #38BDF8 !important;
  --input-bg: #1E293B !important;
  --input-text: #F8FAFC !important;
  --input-border: #334155 !important;
  --modal-bg: #1E293B !important;
  --link-color: #38BDF8 !important;
  --shadow-main: 0 4px 6px -1px rgba(0, 0, 0, 0.4) !important;
}

/* ============================================
   FILTRO EN TIEMPO REAL POR ASIGNATURA
   ============================================ */

.materia-filter-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto var(--space-5, 1.25rem) auto;
  box-sizing: border-box;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.materia-filter-icon,
.search-icon {
  position: absolute;
  left: var(--space-4, 1.25rem);
  font-size: 1.1rem;
  color: var(--text-muted, #94A3B8);
  pointer-events: none;
  z-index: 2;
  transition: color 0.3s ease;
}

#search-input,
#filtro-materia,
.materia-filter-input {
  width: 100%;
  padding: var(--space-4, 1rem) 7.5rem var(--space-4, 1rem) calc(var(--space-4, 1rem) + 2rem);
  border: 2px solid var(--input-border, #E2E8F0);
  border-radius: var(--radius-xl, 1rem);
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--input-bg, #FFFFFF);
  color: var(--input-text, #1E293B);
  outline: none;
  box-shadow: var(--shadow-main, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
  box-sizing: border-box;
}

#search-input::placeholder,
#filtro-materia::placeholder,
.materia-filter-input::placeholder {
  color: var(--text-muted, #94A3B8);
  font-weight: 400;
}

#search-input:hover,
#filtro-materia:hover,
.materia-filter-input:hover {
  border-color: var(--border-card-hover, #CBD5E1);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
}

#search-input:focus,
#filtro-materia:focus,
.materia-filter-input:focus {
  border-color: var(--accent-sky, #0EA5E9);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15), var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
}

.search-input-wrapper:focus-within .search-icon,
.materia-filter-wrapper:focus-within .materia-filter-icon {
  color: var(--accent-sky, #0EA5E9);
}

.filter-badge-container {
  position: absolute;
  right: var(--space-3, 0.75rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  z-index: 3;
}

.filter-counter-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-sky, #0EA5E9);
  background: rgba(14, 165, 233, 0.12);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  white-space: nowrap;
}

.filter-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted, #94A3B8);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, transform 0.2s ease;
}

.filter-clear-btn:hover {
  color: #EF4444;
  transform: scale(1.15);
}

/* ============================================
   GRID DE CATEGORÍAS (DROPDOWNS)
   ============================================ */

.category-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4, 1rem);
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: var(--space-2, 0.5rem) 0;
}

/* ============================================
   DROPDOWN CONTAINER
   ============================================ */

.dropdown {
  width: 100%;
  position: relative;
}

.dropdown details {
  width: 100%;
  border-radius: var(--radius-xl, 1rem);
  overflow: hidden;
  box-shadow: var(--shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
  transition: box-shadow 0.3s ease;
}

.dropdown details[open] {
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
}

/* ============================================
   DROPDOWN SUMMARY (BOTÓN PRINCIPAL)
   ============================================ */

.dropdown-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-5, 1.25rem) var(--space-5, 1.25rem);
  background: var(--bg-card, #FFFFFF);
  color: var(--section-title-color, #0E4B77);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  border: 2px solid var(--border-card, #E2E8F0);
  border-radius: var(--radius-xl, 1rem);
  cursor: pointer;
  list-style: none;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Indicador superior animado */
.dropdown-summary::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--section-title-color, #0E4B77);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

/* Icono de flecha animado */
.dropdown-summary::after {
  content: '›';
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--text-muted, #94A3B8);
  transform: rotate(0deg);
  transition: transform 0.3s ease, color 0.3s ease;
  margin-left: var(--space-2, 0.5rem);
  flex-shrink: 0;
}

/* Estados hover y active */
.dropdown-summary:hover,
.dropdown-summary:focus-visible {
  border-color: var(--section-title-color, #0E4B77);
  background: var(--bg-card-hover, #F8FAFC);
  color: var(--section-title-color, #0E4B77);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
}

.dropdown-summary:hover::before,
.dropdown-summary:focus-visible::before {
  transform: scaleX(1);
}

.dropdown-summary:hover::after,
.dropdown-summary:focus-visible::after {
  color: var(--section-title-color, #0E4B77);
}

/* Estado abierto */
.dropdown details[open] .dropdown-summary {
  border-color: var(--section-title-color, #0E4B77);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
  box-shadow: none;
  transform: translateY(0);
}

.dropdown details[open] .dropdown-summary::before {
  transform: scaleX(1);
}

.dropdown details[open] .dropdown-summary::after {
  transform: rotate(90deg);
  color: var(--section-title-color, #0E4B77);
}

/* Variante gris */
.dropdown-summary.gris {
  color: var(--text-secondary, #64748B);
  border-color: var(--border-card, #E2E8F0);
  background: var(--bg-card, #F8FAFC);
}

.dropdown-summary.gris::before {
  background: var(--accent-sky, #0EA5E9);
}

.dropdown-summary.gris:hover,
.dropdown-summary.gris:focus-visible {
  border-color: var(--accent-sky, #0EA5E9);
  color: var(--section-title-color, #334155);
  background: var(--bg-card-hover, #FFFFFF);
}

.dropdown details[open] .dropdown-summary.gris {
  border-color: var(--accent-sky, #0EA5E9);
}

/* ============================================
   DROPDOWN CONTENT (CONTENIDO DESPLEGABLE)
   ============================================ */

.dropdown-content {
  background: var(--bg-card, #FFFFFF);
  border: 2px solid var(--section-title-color, #0E4B77);
  border-top: none;
  border-bottom-left-radius: var(--radius-xl, 1rem);
  border-bottom-right-radius: var(--radius-xl, 1rem);
  overflow: hidden;
  animation: slideDown 0.3s ease-out;
  transform-origin: top;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dropdown-summary.gris + .dropdown-content {
  border-color: var(--accent-sky, #0EA5E9);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: scaleY(0.8);
  }
  to {
    opacity: 1;
    transform: scaleY(1);
  }
}

/* ============================================
   LISTA DE DOCUMENTOS
   ============================================ */

.dropdown-list {
  list-style: none;
  padding: var(--space-2, 0.5rem);
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1, 0.25rem);
}

.dropdown-list li {
  width: 100%;
}

.dropdown-list a {
  display: flex;
  align-items: center;
  gap: var(--space-3, 0.75rem);
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  color: var(--text-secondary, #334155);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-md, 0.5rem);
  transition: all 0.2s ease;
  position: relative;
  line-height: 1.4;
  word-break: break-word;
}

/* Icono de documento antes del enlace */
.dropdown-list a::before {
  content: '📄';
  font-size: 1.1rem;
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.dropdown-list a:hover,
.dropdown-list a:focus-visible {
  background: var(--bg-card-hover, #F1F5F9);
  color: var(--link-color, #0E4B77);
  padding-left: var(--space-5, 1.25rem);
}

.dropdown-list a:hover::before,
.dropdown-list a:focus-visible::before {
  opacity: 1;
}

/* Indicador de enlace externo */
.dropdown-list a[target="_blank"]::after {
  content: '↗';
  font-size: 0.8rem;
  color: var(--text-muted, #94A3B8);
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.dropdown-list a[target="_blank"]:hover::after,
.dropdown-list a[target="_blank"]:focus-visible::after {
  opacity: 1;
}

/* ============================================
   SKELETON LOADING PLACEHOLDERS
   ============================================ */
.skeleton-item {
  list-style: none;
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  width: 100%;
}

.skeleton-bar {
  height: 1.25rem;
  border-radius: var(--radius-md, 0.5rem);
  background: linear-gradient(
    90deg,
    rgba(226, 232, 240, 0.5) 25%,
    rgba(203, 213, 225, 0.85) 50%,
    rgba(226, 232, 240, 0.5) 75%
  );
  background-size: 200% 100%;
  animation: skeletonPulse 1.4s ease-in-out infinite;
  display: block;
}

[data-theme="dark"] .skeleton-bar {
  background: linear-gradient(
    90deg,
    rgba(51, 65, 85, 0.4) 25%,
    rgba(71, 85, 105, 0.7) 50%,
    rgba(51, 65, 85, 0.4) 75%
  );
  background-size: 200% 100%;
}

.skeleton-bar.short {
  width: 50%;
}

.skeleton-bar.medium {
  width: 72%;
}

.skeleton-bar.long {
  width: 88%;
}

@keyframes skeletonPulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}


/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet (640px+) */
@media (min-width: 640px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-5, 1.25rem);
    max-width: 900px;
  }
  
  .dropdown-summary {
    font-size: 1.05rem;
    padding: var(--space-5, 1.25rem) var(--space-6, 1.5rem);
  }
  
  .dropdown-summary::after {
    font-size: 1.75rem;
  }
  
  .dropdown-list a {
    font-size: 0.95rem;
    padding: var(--space-4, 1rem);
  }
}

/* Tablet grande / Desktop pequeño (768px+) */
@media (min-width: 768px) {
  .category-grid {
    gap: var(--space-6, 1.5rem);
  }
  
  .dropdown-summary {
    font-size: 1.1rem;
    min-height: 100px;
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: var(--space-2, 0.5rem);
  }
  
  .dropdown-summary::after {
    margin-left: 0;
    margin-top: var(--space-1, 0.25rem);
  }
  
  .dropdown-list a {
    font-size: 1rem;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .category-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6, 1.5rem);
    max-width: 1200px;
  }
  
  .dropdown-summary {
    font-size: 1.125rem;
    padding: var(--space-6, 1.5rem);
    min-height: 120px;
  }
  
/*

  .dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    margin-top: -2px;
    box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.1));
  }
 */
  
  /* Ajuste para dropdowns en grid de 4 columnas */
  .dropdown:nth-child(4n) .dropdown-content {
    right: 0;
    left: auto;
  }
}

/* Pantallas muy grandes (1280px+) */
@media (min-width: 1280px) {
  .category-grid {
    gap: var(--space-8, 2rem);
  }
  
  .dropdown-summary {
    min-height: 130px;
    font-size: 1.2rem;
  }
}

/* ============================================
   ORIENTACIÓN LANDSCAPE EN MÓVILES
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) and (max-width: 767px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3, 0.75rem);
  }
  
  .dropdown-summary {
    padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
    font-size: 0.9rem;
    min-height: auto;
  }
  
  .dropdown-content {
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* ============================================
   ACCESIBILIDAD Y OPTIMIZACIONES
   ============================================ */

/* Ocultar marker nativo en Safari */
.dropdown-summary::-webkit-details-marker {
  display: none;
}

/* Focus visible para teclado */
.dropdown-summary:focus-visible {
  outline: 3px solid var(--accent-blue, #3B82F6);
  outline-offset: 2px;
}

.dropdown-list a:focus-visible {
  outline: 2px solid var(--accent-blue, #3B82F6);
  outline-offset: -2px;
}

/* Touch optimizations */
@media (hover: none) {
  .dropdown-summary:hover {
    transform: none;
    box-shadow: var(--shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
  }
  
  .dropdown-summary:active {
    transform: scale(0.98);
    background: var(--gray-50, #F8FAFC);
    transition: transform 0.1s ease;
  }
  
  .dropdown-list a:hover {
    padding-left: var(--space-4, 1rem);
  }
}

/* Reducir motion */
@media (prefers-reduced-motion: reduce) {
  .dropdown-summary,
  .dropdown-summary::before,
  .dropdown-summary::after,
  .dropdown-content,
  .dropdown-list a {
    transition: none;
  }
  
  .dropdown-content {
    animation: none;
  }
}

/* Móviles muy pequeños */
@media (max-width: 359px) {
  .dropdown-summary {
    font-size: 0.9rem;
    padding: var(--space-4, 1rem);
  }
  
  .dropdown-list a {
    font-size: 0.85rem;
    padding: var(--space-3, 0.75rem);
  }
  
  .dropdown-list a::before {
    font-size: 1rem;
  }
}

/* ============================================
   ANIMACIONES DE ENTRADA
   ============================================ */

.dropdown {
  animation: fadeInUp 0.5s ease-out backwards;
}

.dropdown:nth-child(1) { animation-delay: 0.05s; }
.dropdown:nth-child(2) { animation-delay: 0.1s; }
.dropdown:nth-child(3) { animation-delay: 0.15s; }
.dropdown:nth-child(4) { animation-delay: 0.2s; }

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

/* ============================================
   ESTADOS ESPECIALES
   ============================================ */

/* Dropdown vacío o sin contenido */
.dropdown-list:empty::before {
  content: 'No hay documentos disponibles';
  display: block;
  padding: var(--space-4, 1rem);
  color: var(--gray-400, #94A3B8);
  font-style: italic;
  text-align: center;
  font-size: 0.9rem;
}

/* Scrollbar personalizado para contenido largo */
.dropdown-content {
  scrollbar-width: thin;
  scrollbar-color: var(--gray-300, #CBD5E1) transparent;
}

.dropdown-content::-webkit-scrollbar {
  width: 6px;
}

.dropdown-content::-webkit-scrollbar-track {
  background: transparent;
}

.dropdown-content::-webkit-scrollbar-thumb {
  background-color: var(--gray-300, #CBD5E1);
  border-radius: 3px;
}

/* ============================================
   SECCIÓN DE CÓDIGO (ESTILO GITHUB DARK)
   Actualización: Barra Negra 100% y Cuadro 80%
   ============================================ */

.code-section {
  width: 100%;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc; /* Fondo ligero para resaltar el cuadro oscuro */
}

.code-dropdown {
  width: 100%;
}

/* Barra que ocupa el 100% en NEGRO */
.code-summary {
  display: flex;
  flex-wrap: wrap; 
  gap: 10px; 
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 10%;
  background: #121212;
  color: #ffffff;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  transition: all 0.3s ease;
  border-bottom: 1px solid #333;
}

.code-summary:hover {
  background: #000000;
  color: #3b82f6; /* Cambio a azul brillante al pasar el mouse */
}

/* Quitar flecha nativa de HTML */
.code-summary::-webkit-details-marker {
  display: none;
}

.code-badge {
  background: #333;
  color: #94a3b8;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: 'Consolas', monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* El cuadro de código al 80% centrado */
.code-window {
  width: 80%;
  max-width: 1100px;
  margin: 3rem auto; /* Separación superior e inferior */
  background: #1e1e1e; /* Fondo estilo VS Code */
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  border: 1px solid #333;
  animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Cabecera del cuadro (botones tipo Mac) */
.code-header {
  display: flex;
  justify-content: flex-start; /* Alinea los puntos y el nombre a la izquierda */
  align-items: center;
  position: relative; /* Necesario para posicionar el botón */
}

.code-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.red { background: #ff5f56; }
.yellow { background: #ffbd2e; }
.green { background: #27c93f; }

.file-name {
  color: #858585;
  font-size: 0.85rem;
  font-family: 'Segoe UI', sans-serif;
  margin-left: 15px;
}

/* Formato del texto de código */
.code-window pre {
  margin: 0;
  padding: 25px;
  overflow-x: auto; /* Scroll si el código es muy ancho */
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.code-window code {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  color: #dcdcaa; /* Color hueso/amarillo suave */
  line-height: 1.6;
  font-size: 0.95rem;
  display: block; /* Para que el padding del pre funcione bien */
}

.copy-btn {
  margin-left: auto; /* Empuja el botón a la derecha */
  background: #444;
  color: #efefef;
  border: none;
  padding: 4px 12px;
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.copy-btn:hover {
  background: #555;
  color: #3b82f6;
}

.copy-btn.copied {
  background: #27c93f; /* Verde cuando se copia */
  color: #fff;
}

/* Quitar subrayado a los números de la barra negra */
.code-summary a {
  text-decoration: none;
}

/* Opcional: Que cambien de color al pasar el mouse para que se note que son links */
.code-summary a:hover .code-badge {
  background: #3b82f6;
  color: white;
}

.code-footer {
  display: flex;
  justify-content: flex-end; /* Lo alinea a la derecha */
  padding: 10px;
  background-color: #1e1e1e; /* Color similar al fondo del código */
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.back-to-top {
  text-decoration: none;
  color: #888;
  font-size: 0.8rem;
  font-weight: bold;
  transition: color 0.2s;
}

.back-to-top:hover {
  color: #3b82f6; /* Azul para resaltar */
}

/* Ajuste específico para móviles */
@media (max-width: 768px) {
  .code-summary {
    /* En móviles centramos para que se vea mejor al romperse la línea */
    justify-content: center; 
    padding: 1rem 5%;
    font-size: 0.85rem;
    gap: 8px; /* Un poco menos de espacio en móviles */
  }

  /* Opcional: Para que el título ocupe toda la línea y los botones queden debajo */
  .code-summary > span:first-child {
    width: 100%;
    text-align: center;
    margin-bottom: 5px;
  }
}

/* Animación de apertura */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}