/* =========================================================
   CONTENT PAGES MOBILE OPTIMIZATIONS
   Mejoras para páginas de contenido (Topics, Memory Cards, etc.)
   ========================================================= */

/* === LAYOUT GENERAL DE PÁGINAS === */
@media (max-width: 1024px) {
  .topics-page,
  .memory-cards-page,
  .users-management,
  .access-tokens-page {
    padding: var(--mobile-padding);
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
  }

  /* Page Header */
  .bo-page-header,
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--mobile-padding);
    margin-bottom: var(--space-lg);
  }

  .bo-page-header-title,
  .page-header-title {
    width: 100%;
  }

  .bo-page-header-title h1,
  .page-header h1 {
    font-size: 1.5rem;
    word-break: break-word;
  }

  .bo-page-header-title .icon {
    font-size: 1.75rem;
  }

  .bo-page-header-actions,
  .page-header-actions {
    width: 100%;
    flex-direction: column;
    gap: var(--space-sm);
  }

  .bo-page-header-actions .btn,
  .page-header-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: var(--touch-target-min);
  }

  /* Ocultar textos en botones pequeños */
  .mobile-hide {
    display: none;
  }

  .mobile-only {
    display: inline;
  }
}

/* === TOPICS & MEMORY CARDS SECTIONS === */
@media (max-width: 1024px) {
  /* Parent Topic Section */
  .parent-topic-section,
  .topic-section {
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
  }

  .parent-topic-header,
  .topic-header {
    padding: var(--mobile-padding-sm);
    cursor: pointer;
    min-height: var(--touch-target-min);
  }

  .parent-topic-header:active,
  .topic-header:active {
    transform: scale(0.98);
  }

  .parent-topic-title,
  .topic-title {
    font-size: 1rem;
  }

  .parent-topic-icon,
  .topic-icon {
    font-size: 1.25rem;
    width: 36px;
    height: 36px;
  }

  .parent-topic-stats,
  .topic-stats {
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .stat-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  /* Collapse Toggle */
  .collapse-toggle {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 1rem;
  }

  /* Cards Grid */
  .cards-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-sm);
    padding: var(--mobile-padding-sm);
  }

  /* Memory Card */
  .memory-card {
    border-radius: var(--radius-md);
  }

  .memory-card-header {
    padding: var(--mobile-padding-sm);
  }

  .memory-card-body {
    padding: var(--mobile-padding-sm);
  }

  .memory-card-footer {
    padding: var(--mobile-padding-sm);
    flex-direction: column;
    gap: var(--space-sm);
  }

  .memory-card-actions {
    width: 100%;
    justify-content: space-between;
  }

  .memory-card-actions .btn {
    flex: 1;
    min-height: 36px;
  }

  /* Card Content */
  .card-question,
  .card-answer {
    font-size: 0.9375rem;
    line-height: 1.5;
  }

  .card-question {
    font-size: 1rem;
    font-weight: 600;
  }

  /* Card Metadata */
  .card-metadata {
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .card-metadata-item {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
}

/* === FILTERS & SEARCH === */
@media (max-width: 1024px) {
  .filters-section {
    padding: var(--mobile-padding-sm);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
  }

  .filters-row {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .filter-group {
    width: 100%;
  }

  .filter-label {
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
  }

  .filter-control {
    width: 100%;
    min-height: var(--touch-target-min);
    font-size: 1rem;
  }

  /* Search Bar */
  .search-bar {
    width: 100%;
    margin-bottom: var(--space-md);
  }

  .search-input {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--mobile-padding);
    font-size: 1rem;
    border-radius: var(--radius-md);
  }

  .search-icon {
    font-size: 1.125rem;
  }

  /* Filter Tags */
  .filter-tags {
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
  }

  .filter-tag {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-full);
  }

  .filter-tag-remove {
    margin-left: var(--space-xs);
    font-size: 0.875rem;
  }
}

/* === STATS & BADGES === */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
    min-height: 90px;
  }

  .stat-icon {
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  /* Badges */
  .badge,
  .bo-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.625rem;
  }

  .badge-icon {
    font-size: 0.875rem;
  }
}

/* === EMPTY STATES === */
@media (max-width: 1024px) {
  .empty-state {
    padding: var(--space-2xl) var(--mobile-padding);
    text-align: center;
  }

  .empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-lg);
  }

  .empty-state-title {
    font-size: 1.25rem;
    margin-bottom: var(--space-sm);
  }

  .empty-state-description {
    font-size: 0.9375rem;
    margin-bottom: var(--space-lg);
  }

  .empty-state-action {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
  }
}

/* === MODALS & DIALOGS === */
@media (max-width: 1024px) {
  .modal {
    padding: var(--mobile-padding-sm);
  }

  .modal-dialog {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-lg);
  }

  .modal-header {
    padding: var(--mobile-padding);
  }

  .modal-title {
    font-size: 1.125rem;
  }

  .modal-close {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .modal-body {
    padding: var(--mobile-padding);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
  }

  .modal-footer {
    padding: var(--mobile-padding);
    flex-direction: column-reverse;
    gap: var(--space-sm);
  }

  .modal-footer .btn {
    width: 100%;
  }
}

/* === MÓVIL PEQUEÑO === */
@media (max-width: 768px) {
  .topics-page,
  .memory-cards-page {
    padding: var(--mobile-padding-sm);
  }

  .bo-page-header,
  .page-header {
    padding: var(--mobile-padding-sm);
    margin-bottom: var(--space-md);
  }

  .bo-page-header-title h1,
  .page-header h1 {
    font-size: 1.25rem;
  }

  .bo-page-header-title .icon {
    font-size: 1.5rem;
  }

  /* Stats en columna única */
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .stat-card {
    padding: var(--space-sm) var(--mobile-padding-sm);
    min-height: 80px;
  }

  /* Cards más compactos */
  .memory-card-header,
  .memory-card-body,
  .memory-card-footer {
    padding: var(--mobile-padding-xs) var(--mobile-padding-sm);
  }

  .card-question {
    font-size: 0.9375rem;
  }

  .card-answer {
    font-size: 0.875rem;
  }

  /* Filters más compactos */
  .filters-section {
    padding: var(--mobile-padding-xs) var(--mobile-padding-sm);
  }

  .search-input {
    padding: var(--space-xs) var(--mobile-padding-sm);
  }
}

/* === MÓVIL MUY PEQUEÑO === */
@media (max-width: 480px) {
  .topics-page,
  .memory-cards-page {
    padding: var(--mobile-padding-xs);
  }

  .bo-page-header,
  .page-header {
    padding: var(--mobile-padding-xs) var(--mobile-padding-sm);
  }

  .bo-page-header-title h1,
  .page-header h1 {
    font-size: 1.125rem;
  }

  .parent-topic-header,
  .topic-header {
    padding: var(--mobile-padding-xs) var(--mobile-padding-sm);
  }

  .parent-topic-title,
  .topic-title {
    font-size: 0.9375rem;
  }

  .cards-grid {
    padding: var(--mobile-padding-xs);
  }

  .memory-card {
    border-radius: var(--radius-sm);
  }
}

/* === ANIMACIONES === */
@media (max-width: 1024px) {
  /* Animación de entrada para sections */
  @keyframes sectionFadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .parent-topic-section,
  .topic-section {
    animation: sectionFadeIn 0.3s ease;
    animation-fill-mode: backwards;
  }

  .parent-topic-section:nth-child(1),
  .topic-section:nth-child(1) {
    animation-delay: 0.05s;
  }

  .parent-topic-section:nth-child(2),
  .topic-section:nth-child(2) {
    animation-delay: 0.1s;
  }

  .parent-topic-section:nth-child(3),
  .topic-section:nth-child(3) {
    animation-delay: 0.15s;
  }

  /* Animación de entrada para cards */
  @keyframes cardFadeIn {
    from {
      opacity: 0;
      transform: scale(0.95);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  .memory-card {
    animation: cardFadeIn 0.3s ease;
    animation-fill-mode: backwards;
  }

  .memory-card:nth-child(1) {
    animation-delay: 0.05s;
  }

  .memory-card:nth-child(2) {
    animation-delay: 0.1s;
  }

  .memory-card:nth-child(3) {
    animation-delay: 0.15s;
  }

  /* Animación de colapso */
  @keyframes collapse {
    from {
      max-height: 2000px;
      opacity: 1;
    }
    to {
      max-height: 0;
      opacity: 0;
    }
  }

  @keyframes expand {
    from {
      max-height: 0;
      opacity: 0;
    }
    to {
      max-height: 2000px;
      opacity: 1;
    }
  }

  .cards-grid.collapsed {
    animation: collapse 0.3s ease;
    overflow: hidden;
  }

  .cards-grid.expanded {
    animation: expand 0.3s ease;
  }

  /* Animación de botón */
  .parent-topic-header:active,
  .topic-header:active,
  .memory-card:active {
    animation: buttonPress 0.2s ease;
  }
}

/* === MEJORAS DE INTERACCIÓN TÁCTIL === */
@media (max-width: 1024px) {
  /* Mejorar área de toque */
  .parent-topic-header,
  .topic-header,
  .memory-card,
  .filter-tag {
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .parent-topic-header:active,
  .topic-header:active {
    background: var(--bg-hover);
  }

  .memory-card:active {
    transform: scale(0.98);
  }

  .filter-tag:active {
    transform: scale(0.95);
  }

  /* Mejorar botones de acción */
  .memory-card-actions .btn:active {
    transform: scale(0.95);
  }

  /* Mejorar collapse toggle */
  .collapse-toggle:active {
    transform: scale(0.9) rotate(180deg);
  }
}

/* === SCROLL OPTIMIZATIONS === */
@media (max-width: 1024px) {
  /* Smooth scroll */
  .topics-container,
  .cards-grid,
  .modal-body {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  /* Ocultar scrollbar pero mantener funcionalidad */
  .topics-container::-webkit-scrollbar,
  .cards-grid::-webkit-scrollbar {
    width: 3px;
    height: 3px;
  }

  .topics-container::-webkit-scrollbar-track,
  .cards-grid::-webkit-scrollbar-track {
    background: transparent;
  }

  .topics-container::-webkit-scrollbar-thumb,
  .cards-grid::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 3px;
  }
}

/* === LANDSCAPE MODE === */
@media (max-width: 1024px) and (orientation: landscape) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .modal-body {
    max-height: calc(100vh - 150px);
  }
}

/* === DARK MODE OPTIMIZATIONS === */
@media (max-width: 1024px) {
  [data-theme="dark"] .parent-topic-section,
  [data-theme="dark"] .topic-section,
  [data-theme="dark"] .memory-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.8));
  }

  [data-theme="dark"] .parent-topic-header,
  [data-theme="dark"] .topic-header {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.6), rgba(30, 41, 59, 0.8));
  }

  [data-theme="light"] .parent-topic-section,
  [data-theme="light"] .topic-section,
  [data-theme="light"] .memory-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(248, 250, 252, 0.95));
  }

  [data-theme="light"] .parent-topic-header,
  [data-theme="light"] .topic-header {
    background: linear-gradient(135deg, rgba(241, 245, 249, 0.9), rgba(226, 232, 240, 0.95));
  }
}

/* === LOADING STATES === */
@media (max-width: 1024px) {
  @keyframes shimmer {
    0% {
      background-position: -200px 0;
    }
    100% {
      background-position: 200px 0;
    }
  }

  .loading-skeleton {
    background: linear-gradient(
      90deg,
      var(--bg-secondary) 0%,
      var(--bg-tertiary) 50%,
      var(--bg-secondary) 100%
    );
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
  }

  .memory-card.loading,
  .topic-section.loading {
    pointer-events: none;
  }

  .loading-text {
    height: 16px;
    margin-bottom: var(--space-xs);
  }

  .loading-title {
    height: 24px;
    width: 70%;
    margin-bottom: var(--space-sm);
  }
}

/* === MEJORAS DE ACCESIBILIDAD === */
@media (max-width: 1024px) {
  /* Focus visible */
  .parent-topic-header:focus-visible,
  .topic-header:focus-visible,
  .memory-card:focus-visible,
  .collapse-toggle:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  /* Mejorar contraste */
  .parent-topic-title,
  .topic-title,
  .card-question {
    color: var(--text-primary);
    font-weight: 600;
  }

  .card-answer,
  .card-metadata-item {
    color: var(--text-secondary);
  }

  /* Mejorar legibilidad */
  .card-question,
  .card-answer {
    line-height: 1.6;
  }
}

/* === REDUCIR MOVIMIENTO === */
@media (prefers-reduced-motion: reduce) {
  .parent-topic-section,
  .topic-section,
  .memory-card,
  .collapse-toggle {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .cards-grid.collapsed,
  .cards-grid.expanded {
    animation: none !important;
  }
}

/* === MEJORAS DE RENDIMIENTO === */
@media (max-width: 1024px) {
  /* Hardware acceleration */
  .parent-topic-section,
  .topic-section,
  .memory-card,
  .collapse-toggle {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  /* Optimizar rendering */
  .cards-grid {
    contain: layout style paint;
  }

  .memory-card {
    contain: layout style;
  }
}

/* === SWIPE GESTURES === */
@media (max-width: 1024px) {
  .memory-card {
    touch-action: pan-y;
  }

  .memory-card.swiping {
    transition: none;
  }

  .memory-card.swipe-left {
    transform: translateX(-100px);
    opacity: 0.5;
  }

  .memory-card.swipe-right {
    transform: translateX(100px);
    opacity: 0.5;
  }
}
