/**
 * RESPONSIVE STYLES - Daniel Magzul Website
 * Estilos adaptables para móviles, tablets y desktop
 * Mobile First Approach
 */

/* ============================================
   MOBILE FIRST BASE STYLES
   ============================================ */

/* Asegurar que las imágenes sean responsive por defecto */
img {
    max-width: 100%;
    height: auto;
}

/* Prevenir overflow horizontal */
body {
    overflow-x: hidden;
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* ============================================
   MOBILE STYLES (320px - 640px)
   ============================================ */
@media screen and (max-width: 640px) {
    /* Navbar Mobile */
    #navbar .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    #navbar a[data-page] {
        font-size: 1rem;
    }
    
    /* Logo más pequeño en mobile */
    #navbar a.font-bold {
        font-size: 1.5rem !important;
    }
    
    /* Hero Section Mobile */
    section.relative.h-screen {
        height: 100vh;
        min-height: 600px;
    }
    
    section.relative.h-screen h1 {
        font-size: 2rem !important;
        line-height: 1.2;
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    section.relative.h-screen p.text-xl {
        font-size: 1rem !important;
        padding: 0 1rem;
        margin-bottom: 1.5rem;
    }
    
    /* Botones apilados verticalmente */
    section.relative.h-screen .space-x-4 {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0 2rem;
        margin-left: 0 !important;
    }
    
    section.relative.h-screen .space-x-4 > * {
        margin-left: 0 !important;
    }
    
    section.relative.h-screen .space-x-4 a,
    section.relative.h-screen .space-x-4 button {
        width: 100%;
        text-align: center;
        padding: 0.875rem 1.5rem;
        font-size: 0.95rem;
    }
    
    /* Grid de productos - 1 columna */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3,
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
        padding: 0 1rem;
    }
    
    /* Cards de productos con padding */
    .bg-white.shadow-md.rounded-lg,
    .bg-white.shadow-lg.rounded-lg {
        margin: 0;
    }
    
    /* Títulos más pequeños */
    h1 {
        font-size: 2rem !important;
    }
    
    h2.text-4xl, 
    h2.text-5xl {
        font-size: 1.875rem !important;
        line-height: 1.2;
    }
    
    h3.text-2xl, 
    h3.text-3xl {
        font-size: 1.5rem !important;
    }
    
    /* Textos */
    p.text-lg, 
    p.text-xl {
        font-size: 1rem !important;
        line-height: 1.6;
    }
    
    /* Container con padding adecuado */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Secciones con menos padding */
    section.py-16, 
    section.py-20,
    section.py-24 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }
    
    /* Carrito de compras - ancho completo en mobile */
    #cart-drawer {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    #cart-drawer .p-4 {
        padding: 1rem;
    }
    
    #cart-items {
        font-size: 0.875rem;
    }
    
    /* Items del carrito en mobile */
    #cart-items > div {
        margin-bottom: 1rem;
        padding: 0.75rem;
    }
    
    #cart-items img {
        max-width: 60px;
        height: auto;
    }
    
    /* Botones del carrito optimizados para touch */
    #checkout-button,
    #close-cart-button {
        font-size: 1rem;
        padding: 0.875rem 1rem;
        min-height: 48px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    #checkout-button {
        width: 100%;
        font-weight: 600;
    }
    
    /* Subtotal más visible */
    #cart-subtotal {
        font-size: 1.25rem;
    }
    
    /* Página de Playbacks - Checkout */
    .md\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* Formulario de pago en mobile */
    #payment-form {
        padding: 1rem;
    }
    
    #payment-form input,
    #payment-form select {
        width: 100%;
        padding: 0.875rem;
        font-size: 16px !important;
        border-radius: 0.5rem;
        border: 1px solid #d1d5db;
        touch-action: manipulation;
    }
    
    #payment-form input:focus,
    #payment-form select:focus {
        outline: 2px solid #000;
        outline-offset: 2px;
    }
    
    #payment-form button[type="submit"] {
        width: 100%;
        padding: 1rem;
        font-size: 1.125rem;
        font-weight: 600;
        min-height: 52px;
        border-radius: 0.5rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Métodos de pago aceptados */
    .flex.flex-wrap.gap-2 img {
        width: auto;
        height: 28px;
    }
    
    /* Mensaje de seguridad */
    .bg-green-50 {
        padding: 0.75rem;
        margin: 1rem 0;
        border-radius: 0.5rem;
    }
    
    /* Clases virtuales - Formulario de reserva */
    #class-booking-form input,
    #class-booking-form select,
    #class-booking-form textarea {
        width: 100%;
        padding: 0.875rem;
        font-size: 16px !important;
        border-radius: 0.5rem;
        touch-action: manipulation;
    }
    
    #class-booking-form button {
        width: 100%;
        padding: 1rem;
        font-size: 1.125rem;
        min-height: 52px;
        border-radius: 0.5rem;
        touch-action: manipulation;
    }
    
    /* Información de la clase en mobile */
    .bg-green-50.border-l-4 {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    /* Botones de agregar al carrito */
    button.bg-black,
    button.bg-gray-800 {
        min-height: 48px;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Notificaciones en mobile */
    #notification {
        position: fixed;
        top: 80px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 2rem);
        max-width: 400px;
        padding: 1rem;
        font-size: 0.95rem;
        z-index: 9999;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Estados de mensajes en mobile */
    #payment-status,
    .payment-status,
    .error-message,
    .success-message {
        margin: 1rem 0;
        padding: 1rem;
        border-radius: 0.5rem;
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    #payment-status .font-bold {
        font-size: 1rem;
        margin-bottom: 0.25rem;
    }
    
    /* Loading spinner visible */
    .animate-spin {
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
    
    /* Botones en estado loading */
    button[disabled] {
        opacity: 0.7;
        cursor: wait;
    }
    
    button svg.animate-spin {
        display: inline-block;
        margin-right: 0.5rem;
    }
    
    /* Checkout total destacado */
    #checkout-total {
        font-size: 1.25rem;
        padding: 1rem;
        background: #f9fafb;
        border-radius: 0.5rem;
        margin: 1rem 0;
    }
    
    /* Lista de items en checkout */
    #checkout-items-list {
        max-height: 300px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.5rem;
    }
    
    #checkout-items-list > div {
        padding: 0.75rem 0;
    }
    
    /* Métodos de pago en mobile */
    .flex-wrap.gap-2 {
        justify-content: center;
        gap: 0.75rem;
    }
    
    /* Iconos de pago más grandes en mobile */
    img[alt*="visa"],
    img[alt*="mastercard"],
    img[alt*="amex"] {
        height: 32px;
        width: auto;
    }
    
    /* Campos requeridos más visibles */
    input:required,
    select:required {
        border-left: 3px solid #000;
    }
    
    input:invalid,
    select:invalid {
        border-color: #ef4444;
    }
    
    input:valid,
    select:valid {
        border-color: #10b981;
    }
    
    /* Labels más legibles */
    label {
        font-size: 0.95rem;
        font-weight: 500;
        margin-bottom: 0.5rem;
        display: block;
    }
    
    /* Scroll to top en páginas largas */
    html {
        scroll-padding-top: 80px;
    }
    
    /* Prevenir zoom en inputs (importante para iOS) */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Footer - Stack vertical */
    footer .grid {
        grid-template-columns: 1fr !important;
        text-align: center;
        gap: 2rem;
    }
    
    footer .flex.justify-center {
        flex-wrap: wrap;
    }
    
    /* Formularios - Optimización para móviles */
    form {
        padding: 0 1rem;
    }
    
    form input,
    form textarea,
    form select {
        font-size: 16px !important; /* Previene zoom automático en iOS */
        padding: 0.75rem;
        width: 100%;
    }
    
    form button[type="submit"] {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
    
    /* Biografía - Stack vertical */
    .md\:flex.items-center {
        flex-direction: column !important;
        text-align: center;
    }
    
    .md\:flex.items-center img {
        width: 100% !important;
        max-width: 280px;
        margin: 0 auto 2rem;
        height: auto;
    }
    
    .md\:w-1\/3,
    .md\:w-2\/3 {
        width: 100% !important;
    }
    
    /* Audio players responsive */
    audio {
        width: 100%;
        max-width: 100%;
        height: 40px;
    }
    
    /* Video embeds responsive */
    iframe {
        width: 100%;
        height: auto;
        aspect-ratio: 16/9;
    }
    
    /* Eventos timeline */
    .space-y-8 > div,
    .space-y-6 > div {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Tablas responsive */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Menú móvil mejorado */
    #mobile-menu {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    #mobile-menu a {
        font-size: 1.125rem;
        padding: 1rem;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    /* Espaciado entre secciones */
    section + section {
        margin-top: 2rem;
    }
    
    /* Padding top para evitar navbar */
    main > div > section:first-child {
        padding-top: 4rem;
    }
}

/* ============================================
   OPTIMIZACIONES ADICIONALES MOBILE
   ============================================ */
@media screen and (max-width: 640px) {
    /* Evitar doble tap en iOS */
    button,
    a {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Modal/Drawer optimizado */
    [class*="drawer"],
    [class*="modal"] {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Sticky footer en carrito */
    #cart-drawer .border-t {
        position: sticky;
        bottom: 0;
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Loading states en botones */
    button:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }
    
    button:active:not(:disabled) {
        transform: scale(0.98);
    }
    
    /* Scroll suave en carrito */
    #cart-items {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 1rem;
    }
    
    /* Items del carrito más legibles */
    #cart-items .flex {
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }
    
    /* Precio destacado */
    #cart-items .font-bold {
        font-size: 1.125rem;
        color: #000;
    }
    
    /* Cantidades en carrito */
    #cart-items input[type="number"] {
        width: 60px;
        text-align: center;
        font-size: 16px !important;
        padding: 0.5rem;
        border: 1px solid #d1d5db;
        border-radius: 0.375rem;
    }
    
    /* Botones de cantidad */
    #cart-items button {
        min-height: 36px;
        min-width: 36px;
        padding: 0.5rem;
        border-radius: 0.375rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Botón eliminar item */
    #cart-items button svg {
        width: 20px;
        height: 20px;
    }
    
    /* Separador entre items */
    #cart-items > div {
        border-bottom: 1px solid #e5e7eb;
        padding-bottom: 1rem;
        margin-bottom: 1rem;
    }
    
    #cart-items > div:last-child {
        border-bottom: none;
    }
    
    /* Imagen de producto en carrito */
    #cart-items img {
        border-radius: 0.375rem;
        object-fit: cover;
    }
    
    /* Nombre de producto truncado */
    #cart-items .text-sm {
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 1.4;
    }
    
    /* Header del carrito sticky */
    #cart-drawer .border-b {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    /* Overlay oscuro cuando el carrito está abierto */
    #cart-drawer:not(.translate-x-full)::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
    
    /* Animación suave del carrito */
    #cart-drawer {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* ============================================
   TABLET PORTRAIT (641px - 768px)
   ============================================ */
@media screen and (min-width: 641px) and (max-width: 768px) {
    /* Navbar con espaciado ajustado */
    #navbar a[data-page] {
        font-size: 0.95rem;
    }
    
    #navbar .space-x-8 {
        gap: 1rem;
    }
    
    /* Carrito con ancho intermedio */
    #cart-drawer {
        max-width: 450px !important;
    }
    
    /* Formulario de pago en 1 columna */
    #payment-form .md\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* Grid de 2 columnas */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3,
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem;
    }
    
    /* Hero con tamaños intermedios */
    section.relative.h-screen h1 {
        font-size: 3rem !important;
    }
    
    section.relative.h-screen p.text-xl {
        font-size: 1.25rem !important;
    }
    
    /* Títulos */
    h2.text-4xl, 
    h2.text-5xl {
        font-size: 2.5rem !important;
    }
    
    h3.text-2xl, 
    h3.text-3xl {
        font-size: 1.75rem !important;
    }
    
    /* Carrito con ancho intermedio */
    #cart-drawer {
        max-width: 400px !important;
    }
    
    /* Botones con ancho automático */
    section.relative.h-screen .space-x-4 {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    section.relative.h-screen .space-x-4 a {
        width: auto;
        min-width: 160px;
    }
}

/* ============================================
   TABLET LANDSCAPE (769px - 1024px)
   ============================================ */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    /* Navbar optimizado */
    #navbar a[data-page] {
        font-size: 1rem;
    }
    
    #navbar .space-x-8 {
        gap: 1.5rem;
    }
    
    /* Grid optimizado para tablets */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    
    /* Hero */
    section.relative.h-screen h1 {
        font-size: 3.5rem !important;
    }
    
    section.relative.h-screen p.text-xl {
        font-size: 1.375rem !important;
    }
    
    /* Container con ancho máximo */
    .container {
        max-width: 960px;
    }
}

/* ============================================
   DESKTOP (1025px - 1280px)
   ============================================ */
@media screen and (min-width: 1025px) and (max-width: 1280px) {
    .container {
        max-width: 1024px;
    }
    
    /* 3 columnas para grids de 4 */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ============================================
   LARGE DESKTOP (1281px+)
   ============================================ */
@media screen and (min-width: 1281px) {
    .container {
        max-width: 1280px;
        margin: 0 auto;
    }
    
    /* Asegurar que los grids de 4 columnas funcionen */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE OPTIMIZATION
   ============================================ */
@media screen and (max-height: 500px) and (orientation: landscape) {
    /* Hero section ajustado para landscape */
    section.relative.h-screen {
        height: auto !important;
        min-height: 100vh;
        padding: 5rem 0 2rem;
    }
    
    section.relative.h-screen h1 {
        font-size: 2rem !important;
        margin-bottom: 0.5rem;
    }
    
    section.relative.h-screen p {
        font-size: 0.875rem !important;
        margin-bottom: 1rem;
    }
    
    section.relative.h-screen .space-x-4 {
        gap: 0.5rem;
    }
    
    section.relative.h-screen .space-x-4 a {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Navbar más compacto */
    #navbar {
        padding: 0.5rem 0;
    }
    
    /* Secciones más compactas */
    section.py-16,
    section.py-20 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Aumentar área de toque para mejor UX */
    button, 
    a.nav-link,
    .cursor-pointer,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.75rem 1rem;
    }
    
    /* Feedback visual en touch */
    button:active,
    a:active,
    .cursor-pointer:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
    
    /* Deshabilitar hover en touch */
    a:hover,
    button:hover {
        transform: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    /* Ocultar elementos no necesarios para imprimir */
    header, 
    footer,
    #cart-drawer,
    #mobile-menu,
    button,
    .no-print {
        display: none !important;
    }
    
    /* Optimizar para impresión */
    main {
        margin: 0;
        padding: 0;
    }
    
    body {
        background: white;
        color: black;
    }
    
    /* Evitar saltos de página */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    img {
        page-break-inside: avoid;
    }
    
    /* Mostrar URLs de enlaces */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }
}

/* ============================================
   HIGH RESOLUTION DISPLAYS (RETINA)
   ============================================ */
@media (-webkit-min-device-pixel-ratio: 2), 
       (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   EXTRA SMALL DEVICES (max-width: 360px)
   ============================================ */
@media screen and (max-width: 360px) {
    #navbar a.font-bold {
        font-size: 1.25rem !important;
    }
    
    section.relative.h-screen h1 {
        font-size: 1.75rem !important;
    }
    
    section.relative.h-screen p.text-xl {
        font-size: 0.875rem !important;
    }
    
    h2.text-4xl, 
    h2.text-5xl {
        font-size: 1.5rem !important;
    }
    
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* ============================================
   ULTRA WIDE SCREENS (1920px+)
   ============================================ */
@media screen and (min-width: 1920px) {
    .container {
        max-width: 1536px;
    }
    
    /* Mantener diseño equilibrado en pantallas grandes */
    section.relative.h-screen h1 {
        font-size: 5rem !important;
    }
    
    section.relative.h-screen p.text-xl {
        font-size: 1.5rem !important;
    }
}
