/* ============================================
   UX Improvements - Global Styles
   Mejoras de experiencia de usuario para
   dispositivos móviles y desktop
   ============================================ */

/* ============================================
   1. Smooth Scrolling & Base
   ============================================ */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* ============================================
   2. Focus States - Accesibilidad
   ============================================ */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 2px;
}

/* ============================================
   3. Loading States
   ============================================ */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

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

/* ============================================
   4. Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: calc(100% - 40px);
}

.toast {
    padding: 14px 20px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideInRight 0.3s ease, fadeOut 0.3s ease 4.7s forwards;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}

.toast-success { background: #10b981; }
.toast-error { background: #ef4444; }
.toast-warning { background: #f59e0b; }
.toast-info { background: #3b82f6; }

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ============================================
   5. Bottom Navigation (Mobile)
   ============================================ */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid rgba(0,0,0,0.1);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    color: #64748b;
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s;
    border-radius: 8px;
    min-width: 64px;
}

.bottom-nav-item:active {
    background: rgba(0,0,0,0.05);
}

.bottom-nav-item.active {
    color: var(--primary-color, #2563eb);
}

.bottom-nav-icon {
    font-size: 22px;
    line-height: 1;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: block;
    }
    
    /* Ajustar footer para no chocar con bottom nav */
    .footer {
        padding-bottom: 80px !important;
    }
}

/* ============================================
   6. Pull to Refresh (Visual feedback)
   ============================================ */
.pull-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.2s;
    z-index: 9999;
}

.pull-indicator.active {
    top: 20px;
}

/* ============================================
   7. Better Form Inputs
   ============================================ */
input, select, textarea {
    font-size: 16px; /* Previene zoom en iOS */
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea,
select {
    appearance: none;
    -webkit-appearance: none;
    border-radius: 10px;
    padding: 14px 16px;
    border: 2px solid #e2e8f0;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    background: white;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Placeholder styling */
::placeholder {
    color: #94a3b8;
    opacity: 1;
}

/* ============================================
   8. Improved Buttons
   ============================================ */
button, .btn {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Ripple effect */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, rgba(255,255,255,0.3) 10%, transparent 10%);
    background-repeat: no-repeat;
    background-position: 50%;
    transform: scale(10, 10);
    opacity: 0;
    transition: transform 0.5s, opacity 1s;
}

.btn-ripple:active::after {
    transform: scale(0, 0);
    opacity: 0.3;
    transition: 0s;
}

/* ============================================
   9. Image Lazy Loading Placeholder
   ============================================ */
img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

img[loading="lazy"].loaded {
    animation: none;
    background: none;
}

/* ============================================
   10. Smooth Page Transitions
   ============================================ */
.page-enter {
    opacity: 0;
    transform: translateY(10px);
}

.page-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s, transform 0.3s;
}

/* ============================================
   11. Floating Action Button
   ============================================ */
.fab {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color, #2563eb);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 999;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

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

@media (max-width: 768px) {
    .fab {
        bottom: 100px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}

/* ============================================
   12. Scroll Progress Indicator
   ============================================ */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color, #2563eb), var(--secondary-color, #8b5cf6));
    z-index: 10001;
    transition: width 0.1s;
}

/* ============================================
   13. Better Modals
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

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

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #e2e8f0;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

@media (max-width: 768px) {
    .modal-content {
        max-height: 85vh;
        margin: auto 0 0 0;
        border-radius: 16px 16px 0 0;
        max-width: 100%;
    }
    
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
}

/* ============================================
   13b. Image Lightbox
   ============================================ */
.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.image-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(8px);
}

.lightbox-container {
    position: relative;
    z-index: 1;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.image-lightbox.active .lightbox-container {
    transform: scale(1);
}

.lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: lightboxFadeIn 0.3s ease;
}

@keyframes lightboxFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.lightbox-title {
    margin-top: 1.5rem;
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    text-align: center;
    padding: 0 2rem;
    max-width: 800px;
}

.lightbox-close {
    position: absolute;
    top: -50px;
    right: 0;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 32px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    z-index: 2;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.lightbox-close:active {
    transform: scale(0.95);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 32px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    z-index: 2;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.lightbox-prev {
    left: -70px;
}

.lightbox-next {
    right: -70px;
}

@media (max-width: 768px) {
    .lightbox-container {
        width: 100%;
        max-height: 100vh;
        padding: 0;
    }
    
    .lightbox-image {
        max-height: 75vh;
        max-width: 100%;
        width: auto;
        height: auto;
        border-radius: 0;
    }
    
    .lightbox-close {
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
        font-size: 28px;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(10px);
        -webkit-tap-highlight-color: transparent;
    }
    
    .lightbox-close:active {
        background: rgba(0, 0, 0, 0.9);
        transform: scale(0.9);
    }
    
    .lightbox-nav {
        width: 44px;
        height: 44px;
        font-size: 24px;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(10px);
        -webkit-tap-highlight-color: transparent;
    }
    
    .lightbox-nav:active {
        background: rgba(0, 0, 0, 0.9);
        transform: translateY(-50%) scale(0.9);
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
    
    .lightbox-title {
        font-size: 0.95rem;
        padding: 0 1rem;
        margin-top: 1rem;
        line-height: 1.4;
    }
    
    .lightbox-content {
        padding: 0;
    }
    
    /* Better touch targets for gallery - allow normal scroll */
    .gallery-item {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: auto;
        cursor: pointer;
    }
    
    /* Prevent issues with lightbox image */
    .lightbox-image {
        touch-action: none;
    }
}

/* ============================================
   14. Swipe Gestures Visual Feedback
   ============================================ */
.swipeable {
    touch-action: pan-y;
    user-select: none;
}

.swipe-hint {
    position: relative;
    overflow: hidden;
}

.swipe-hint::after {
    content: '← Desliza →';
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #94a3b8;
    opacity: 0;
    animation: fadeInOut 3s ease-in-out;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
}

/* ============================================
   15. Improved Scrollbars (Desktop)
   ============================================ */
@media (min-width: 769px) {
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    
    ::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }
}

/* ============================================
   16. Selection Color
   ============================================ */
::selection {
    background: var(--primary-color, #2563eb);
    color: white;
}

::-moz-selection {
    background: var(--primary-color, #2563eb);
    color: white;
}

/* ============================================
   17. Print Styles
   ============================================ */
@media print {
    .navbar,
    .bottom-nav,
    .fab,
    .scroll-progress,
    .toast-container {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
    }
    
    .section {
        page-break-inside: avoid;
    }
}
