/* ==========================================================================
   VISTA MÓVIL TIPO APP - ENSAYA.CL
   Transformación completa para sentirse como app nativa
   ========================================================================== */

/* ==========================================================================
   VARIABLES MÓVIL
   ========================================================================== */
:root {
  --app-header-height: 60px;
  --app-bottom-nav-height: 75px;
  --sidebar-width: 280px;
  --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   HEADER MÓVIL ESTILO APP
   ========================================================================== */
@media (max-width: 991.98px) {

  /* Header principal móvil */
  .navbar {
    height: var(--app-header-height);
    padding: 0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    background: white !important;
  }

  .navbar .container {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 1rem;
  }

  /* Hamburger menu button */
  .mobile-menu-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
    position: relative;
  }

  .mobile-menu-btn:active {
    background: rgba(78, 115, 223, 0.1);
    transform: scale(0.95);
  }

  /* Icono hamburger animado */
  .hamburger-icon {
    width: 24px;
    height: 18px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .hamburger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: #4e73df;
    border-radius: 2px;
    transition: all 0.3s ease;
  }

  /* Estado activo del hamburger */
  .mobile-menu-btn.active .hamburger-icon span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
  }

  .mobile-menu-btn.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
  }

  .mobile-menu-btn.active .hamburger-icon span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
  }

  /* Logo centrado en móvil */
  .navbar-brand {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.25rem;
  }

  /* Acciones derecha (notificaciones, etc) */
  .mobile-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  /* ==========================================================================
     SIDEBAR/DRAWER
     ========================================================================== */

  /* Overlay oscuro */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all var(--sidebar-transition);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }

  .sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
  }

  /* Sidebar container */
  .mobile-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: white;
    transform: translateX(-100%);
    transition: transform var(--sidebar-transition);
    z-index: 1050;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

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

  /* Header del sidebar */
  .sidebar-header {
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, #4e73df 0%, #2e59d9 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 1rem;
  }

  .sidebar-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid white;
    object-fit: cover;
  }

  .sidebar-user-info h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
  }

  .sidebar-user-info p {
    margin: 0;
    font-size: 0.85rem;
    opacity: 0.9;
  }

  /* Items del sidebar */
  .sidebar-nav {
    padding: 1rem 0;
  }

  .sidebar-section {
    margin-bottom: 1.5rem;
  }

  .sidebar-section-title {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #9ca3af;
    letter-spacing: 0.5px;
  }

  .sidebar-item {
    display: flex;
    align-items: center;
    padding: 0.85rem 1rem;
    color: #374151;
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
    gap: 1rem;
  }

  .sidebar-item:hover {
    background: rgba(78, 115, 223, 0.05);
    color: #4e73df;
  }

  .sidebar-item.active {
    background: rgba(78, 115, 223, 0.1);
    color: #4e73df;
    font-weight: 600;
  }

  .sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #4e73df;
  }

  .sidebar-item i {
    font-size: 1.3rem;
    width: 24px;
    text-align: center;
  }

  .sidebar-item-badge {
    margin-left: auto;
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
  }

  /* Divider */
  .sidebar-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0.5rem 1rem;
  }

  /* Footer del sidebar */
  .sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    margin-top: auto;
  }

  .sidebar-footer-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    color: #6b7280;
    text-decoration: none;
    font-size: 0.9rem;
    gap: 0.75rem;
    border-radius: 8px;
    transition: all 0.15s ease;
  }

  .sidebar-footer-item:hover {
    background: #f3f4f6;
    color: #374151;
  }

  .sidebar-footer-item.logout {
    color: #ef4444;
  }

  .sidebar-footer-item.logout:hover {
    background: #fee2e2;
  }

  /* ==========================================================================
     CONTENIDO PRINCIPAL MÓVIL
     ========================================================================== */

  /* Ajustar para el header fijo */
  body {
    padding-top: var(--app-header-height);
  }

  main {
    padding-bottom: calc(var(--app-bottom-nav-height) + 1rem) !important;
    min-height: calc(100vh - var(--app-header-height) - var(--app-bottom-nav-height));
  }

  /* Page header estilo app */
  .page-header-mobile {
    background: white;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    position: sticky;
    top: var(--app-header-height);
    z-index: 10;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
  }

  .page-title-mobile {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 0.35rem 0;
  }

  .page-subtitle-mobile {
    font-size: 0.9rem;
    color: #6b7280;
    margin: 0;
  }

  .page-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #4e73df;
    color: white;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.75rem;
  }

  /* ==========================================================================
     BOTTOM NAVIGATION MEJORADO
     ========================================================================== */

  .bottom-nav-wrapper {
    background: white !important;
    border-top: 1px solid #e5e7eb !important;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08) !important;
    padding: 0.5rem 0 !important;
  }

  .nav-item-mobile {
    position: relative;
    padding: 0.35rem 0.25rem !important;
  }

  /* Indicador activo mejorado */
  .nav-item-mobile.active::before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 4px;
    background: #4e73df;
    border-radius: 0 0 999px 999px;
  }

  .nav-item-mobile.active {
    background: rgba(78, 115, 223, 0.05) !important;
    border-radius: 12px;
  }

  /* Animación al tocar */
  .nav-item-mobile:active {
    transform: scale(0.95);
  }

  /* ==========================================================================
     CARDS ESTILO APP
     ========================================================================== */

  .app-card {
    background: white;
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
    border: 1px solid #f3f4f6;
  }

  .app-card:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  }

  .app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
  }

  .app-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(78, 115, 223, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #4e73df;
  }

  .app-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
  }

  .app-card-meta {
    font-size: 0.85rem;
    color: #6b7280;
    margin: 0.25rem 0;
  }

  /* ==========================================================================
     TABS ESTILO APP
     ========================================================================== */

  .app-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem 1rem 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .app-tabs::-webkit-scrollbar {
    display: none;
  }

  .app-tab {
    flex-shrink: 0;
    padding: 0.6rem 1.25rem;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
  }

  .app-tab.active {
    background: #4e73df;
    color: white;
    box-shadow: 0 2px 8px rgba(78, 115, 223, 0.3);
  }

  .app-tab:active {
    transform: scale(0.95);
  }

  /* ==========================================================================
     PULL TO REFRESH INDICATOR
     ========================================================================== */

  .pull-to-refresh {
    position: fixed;
    top: var(--app-header-height);
    left: 50%;
    transform: translateX(-50%) translateY(-50px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    padding: 0.75rem 1.25rem;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
  }

  .pull-to-refresh.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(1rem);
  }

  .pull-to-refresh i {
    font-size: 1.2rem;
    color: #4e73df;
    animation: spin 1s linear infinite;
  }

  @keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

  /* ==========================================================================
     FLOATING ACTION BUTTON
     ========================================================================== */

  .fab {
    position: fixed;
    bottom: calc(var(--app-bottom-nav-height) + 1rem);
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e73df 0%, #2e59d9 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(78, 115, 223, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 100;
    transition: all 0.2s ease;
  }

  .fab:active {
    transform: scale(0.9);
  }

  .fab:hover {
    box-shadow: 0 6px 16px rgba(78, 115, 223, 0.5);
  }

  /* ==========================================================================
     SMOOTH ANIMATIONS
     ========================================================================== */

  /* Fade in animation */
  .fade-in {
    animation: fadeIn 0.3s ease;
  }

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

  /* Slide up animation */
  .slide-up {
    animation: slideUp 0.3s ease;
  }

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

  /* ==========================================================================
     TOASTS/SNACKBARS
     ========================================================================== */

  .toast-mobile {
    position: fixed;
    bottom: calc(var(--app-bottom-nav-height) + 1rem);
    left: 1rem;
    right: 1rem;
    background: #1f2937;
    color: white;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateY(200%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
  }

  .toast-mobile.show {
    transform: translateY(0);
  }

  .toast-mobile i {
    font-size: 1.3rem;
  }

  .toast-mobile.success {
    background: #10b981;
  }

  .toast-mobile.error {
    background: #ef4444;
  }

  .toast-mobile.warning {
    background: #f59e0b;
  }

}