/**
 * style.css v4.1 - UX Móvil y Optimizaciones de Rendimiento
 * Laboratorio de Simulaciones de Academia Tarvos
 *
 * ESTRUCTURA:
 * 1. Variables CSS (Dark Mode)
 * 2. Reset y Estilos Globales
 * 3. Layout Principal
 * 4. Cabecera y Título
 * 5. Tarjetas de Aplicación (Cards)
 * 6. Barra Lateral de Filtros (Sidebar) - **CON LÓGICA MÓVIL**
 * 7. Contenido Principal y Controles - **CON BOTÓN DE FILTROS MÓVIL**
 * 8. Footer
 * 9. Animaciones y Utilidades
 * 10. Diseño Responsivo (Media Queries)
 */

/* ================================================================== */
/* 1. Variables CSS (Dark Mode)                                       */
/* ================================================================== */
:root {
  --color-primary: #22d3ee;       
  --color-primary-hover: #67e8f9; 
  --color-bg-main: #0f172a;       
  --color-bg-content: #1e293b;   
  --color-border: #334155;       
  --color-text-title: #f1f5f9;    
  --color-text-body: #cbd5e1;     
  --color-text-muted: #94a3b8;    
  --color-focus-ring: #67e8f9;   
  --color-image-placeholder: #334155; 
  --font-family-main: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --border-radius: 12px; 
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================================================== */
/* 2. Reset y Estilos Globales                                        */
/* ================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family-main);
  background-color: var(--color-bg-main);
  color: var(--color-text-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.sidebar-open {
    overflow: hidden; /* Evita el scroll del fondo cuando el menú está abierto */
}

h1, h2, h3, h4, h5, h6 {
  color: var(--color-text-title);
  font-weight: 600;
  line-height: 1.3;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}
a:hover {
  color: var(--color-primary-hover);
}

:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 3px;
  border-radius: var(--border-radius);
}
.toggle-btn:focus-visible, #mobile-filter-btn:focus-visible, #close-sidebar-btn:focus-visible {
    border-radius: 4px;
}

::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--color-bg-main);
}
::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 10px;
  border: 2px solid var(--color-bg-main);
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}

/* ================================================================== */
/* 3. Layout Principal                                                */
/* ================================================================== */
.lab-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 3rem;
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  padding: 3rem 2rem;
  flex-grow: 1;
}

/* ================================================================== */
/* 4. Cabecera y Título                                               */
/* ================================================================== */
.lab-header {
    text-align: center;
    padding: 4rem 2rem 2rem;
}
.lab-header__title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-text-title);
    margin-bottom: 0.5rem;
}
.lab-header__subtitle {
    font-size: 1.125rem;
    color: var(--color-text-muted);
    max-width: 60ch;
    margin: 0 auto;
}

/* ================================================================== */
/* 5. Tarjetas de Aplicación (Cards)                                  */
/* ================================================================== */
.apps-container.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
}

.app-card {
  background-color: var(--color-bg-content);
  border-radius: var(--border-radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: var(--transition-smooth);
  box-shadow: var(--shadow-md);
}
.app-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary);
}

.card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.card-figure {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: var(--color-image-placeholder);
}
.card-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease, opacity 0.5s ease;
  opacity: 0;
}
.card-figure img:not([loading="lazy"]), .card-figure img[loading="lazy"][src] {
    opacity: 1;
}
.app-card:hover .card-figure img {
  transform: scale(1.05);
}

.card-body {
  padding: 1.5rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}
.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--color-text-title);
}
.card-description {
  font-size: 0.95rem;
  color: var(--color-text-body);
  flex-grow: 1;
}

/* ================================================================== */
/* 6. Barra Lateral de Filtros (Sidebar)                              */
/* ================================================================== */
.lab-sidebar {
    position: sticky;
    top: 2rem;
    align-self: start;
    height: calc(100vh - 4rem);
    overflow-y: auto;
}

#close-sidebar-btn {
    display: none; /* Oculto por defecto */
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.5rem;
}
#close-sidebar-btn:hover {
    color: var(--color-text-title);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}
.sidebar-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-title);
}

.filter-group {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}
.filter-group:not(:last-child) {
  border-bottom: 1px solid var(--color-border);
}

.filter-group-title .toggle-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0;
  cursor: pointer;
  color: var(--color-text-title);
}

.toggle-btn .toggle-icon {
  color: var(--color-text-muted);
  transition: transform 0.3s ease;
}
.toggle-btn[aria-expanded="true"] .toggle-icon {
  transform: rotate(45deg);
  color: var(--color-primary);
}

/* --- ACORDEÓN PERFORMANTE --- */
.filter-group-content {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease-in-out;
}
.filter-group-content.expanded {
  grid-template-rows: 1fr;
}
.filter-group-content ul {
  overflow: hidden;
  list-style: none;
  padding-top: 0.75rem;
}

.filter-group-content label {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.25rem;
  cursor: pointer;
  font-size: 1rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}
.filter-group-content label:hover {
    background-color: rgba(255,255,255,0.05);
}

.filter-checkbox {
  appearance: none;
  width: 1.35em;
  height: 1.35em;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  margin-right: 0.75em;
  flex-shrink: 0;
  transition: var(--transition-smooth);
  background-color: transparent;
  cursor: pointer;
  position: relative;
}
.filter-checkbox:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}
.filter-checkbox:checked::before {
    content: '✔';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-bg-content);
    font-size: 0.9em;
    font-weight: bold;
}
.filter-checkbox:hover {
  border-color: var(--color-primary);
}

/* ================================================================== */
/* 7. Contenido Principal y Controles                                 */
/* ================================================================== */
.main-content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

#mobile-filter-btn {
    display: none; /* Oculto en desktop */
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-body);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    display: none;
    align-items: center;
    gap: 0.5rem;
}

.results-count {
  font-size: 1.1rem;
  color: var(--color-text-muted);
}
.results-count strong {
  font-weight: 700;
  color: var(--color-text-title);
}

.view-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sort-by select {
  padding: 0.6rem 2.5rem 0.6rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background-color: var(--color-bg-content);
  color: var(--color-text-body);
  font-size: 0.95rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25em;
  transition: border-color 0.2s;
}
.sort-by select:hover {
    border-color: var(--color-text-muted);
}

.view-btn {
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-muted);
  padding: 0.5rem;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: var(--transition-smooth);
}
.view-btn:hover {
  color: var(--color-primary);
  background-color: var(--color-bg-content);
}
.view-btn.active {
  color: var(--color-primary);
  background-color: var(--color-bg-content);
  border-color: var(--color-border);
}

/* ================================================================== */
/* 8. Footer                                                          */
/* ================================================================== */
.site-footer {
  margin-top: auto; 
  padding: 3rem 2rem;
  background-color: var(--color-bg-content);
  border-top: 1px solid var(--color-border);
  text-align: center;
  color: var(--color-text-muted);
}

/* ... (resto del footer sin cambios) ... */

/* ================================================================== */
/* 9. Animaciones y Utilidades                                        */
/* ================================================================== */
.app-card.hidden {
  display: none;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ================================================================== */
/* 10. Diseño Responsivo (Media Queries)                              */
/* ================================================================== */
@media (max-width: 1024px) {
  .lab-layout {
    grid-template-columns: 1fr;
    padding: 2rem 1.5rem;
    gap: 2.5rem;
  }

  /* --- LÓGICA SIDEBAR MÓVIL --- */
  .lab-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    background-color: var(--color-bg-content);
    padding: 2rem;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .lab-sidebar {
    transform: translateX(0);
  }
  body.sidebar-open::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  #close-sidebar-btn {
      display: block;
  }

  #mobile-filter-btn {
      display: inline-flex;
  }

  .main-content-header {
      justify-content: space-between;
  }
  .results-count {
      display: none; /* Opcional: ocultar contador en la barra principal en móvil */
  }
}

@media (max-width: 768px) {
  .lab-layout {
      padding: 1.5rem 1rem;
  }
  .main-content-header {
    flex-direction: row; /* Mantener en fila */
    align-items: center;
    gap: 1rem;
  }
  .apps-container.view-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
}

@media (max-width: 480px) {
  body {
      font-size: 0.95rem;
  }
  .lab-layout {
      padding: 1rem;
  }
  .apps-container.view-grid {
    grid-template-columns: 1fr;
  }
  .view-controls {
      display: none; /* Ocultar controles de vista en pantallas muy pequeñas */
  }
}