/* 
PRODUCT MODAL CSS - MOBILE FIRST DESIGN
Responsive modal system optimized for mobile users (80% of traffic)
*/

/* MODAL OVERLAY */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
    /* Ensure modal works on all mobile browsers */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

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

/* MODAL CONTAINER */
.modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--white);
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 1001;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
    
    /* Enhanced scrollbar visibility */
    scrollbar-width: thick;
    scrollbar-color: #007bff #f1f1f1;
}

/* Webkit scrollbar styling for better visibility */
.modal::-webkit-scrollbar {
    width: 12px;
}

.modal::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 6px;
}

.modal::-webkit-scrollbar-thumb {
    background: #007bff;
    border-radius: 6px;
    border: 2px solid #f1f1f1;
}

.modal::-webkit-scrollbar-thumb:hover {
    background: #0056b3;
}

.modal.active {
    transform: translateY(0);
}

/* MODAL HEADER */
.modal-header {
    position: sticky;
    top: 0;
    background-color: var(--white);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.modal-drag-handle {
    width: 40px;
    height: 4px;
    background-color: #ddd;
    border-radius: 2px;
    margin: 0 auto 1rem;
    cursor: grab;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background-color: var(--light-bg);
}

/* MODAL CONTENT */
.modal-content {
    padding: 0 1rem 1rem;
}

.modal-product-image {
    width: 100%;
    max-width: 250px;
    height: auto;
    max-height: 180px;
    object-fit: contain;
    border-radius: 8px;
    margin: 0 auto 1rem;
    display: block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background-color: var(--white);
}

.modal-product-title {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.8rem;
    text-align: center;
}

.modal-product-specs {
    background-color: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 2px solid #e9ecef;
}

.modal-specs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: start;
}

.modal-spec-item {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.125rem 0;
    font-size: 0.85rem;
}

.modal-spec-label {
    font-weight: bold;
    color: var(--text-color);
    white-space: nowrap;
}

.modal-spec-value {
    color: var(--secondary-color);
    font-weight: 600;
    white-space: nowrap;
}

.modal-product-price {
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--accent-color);
    text-align: center;
    margin-bottom: 0.8rem;
    padding: 0.8rem;
    background-color: var(--light-bg);
    border-radius: 8px;
}

.modal-price-old {
    font-size: 1rem !important;
    color: #999 !important;
    text-decoration: line-through !important;
    font-weight: normal !important;
    margin-right: 0.5rem;
}

.modal-price-current {
    font-size: 1.2rem !important;
    font-weight: bold !important;
    color: var(--accent-color) !important;
}

.modal-product-colors {
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
}

.modal-colors-label {
    font-weight: bold;
    margin-bottom: 0.5rem;
    display: block;
    color: var(--text-color);
}

.modal-product-description {
    line-height: 1.5;
    color: var(--text-color);
    margin-bottom: 1rem;
    background-color: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--secondary-color);
}

.modal-product-description h4 {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0 0 0.8rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-product-description p {
    margin-bottom: 0.8rem;
}

/* MODAL ACTIONS */
.modal-actions {
    position: sticky;
    bottom: 0;
    background-color: var(--white);
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
}

.modal-btn {
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-btn-primary {
    background-color: var(--secondary-color);
    color: var(--white);
}

.modal-btn-primary:hover {
    background-color: var(--primary-color);
    transform: translateY(-1px);
}

.modal-btn-secondary {
    background-color: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
}

.modal-btn-secondary:hover {
    background-color: var(--secondary-color);
    color: var(--white);
}

/* NAVIGATION ARROWS */
.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(255, 255, 255, 0.9);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--primary-color);
    transition: all 0.2s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.modal-nav:hover {
    background-color: var(--white);
    transform: translateY(-50%) scale(1.1);
}

.modal-nav-prev {
    left: 1rem;
}

.modal-nav-next {
    right: 1rem;
}

/* MOBILE-SPECIFIC IMPROVEMENTS */
@media (max-width: 767px) {
    .modal-overlay {
        /* Ensure full coverage on mobile */
        position: fixed;
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height for better mobile support */
    }
    
    .modal {
        /* Ensure modal is properly positioned on mobile */
        width: 100%;
        max-height: 90vh;
        max-height: 90dvh; /* Use dynamic viewport height */
        /* Ensure modal appears above everything else */
        z-index: 1001;
        /* Force hardware acceleration for smoother animations */
        will-change: transform;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .modal-product-image {
        max-height: 150px; /* Even smaller on mobile for more text visibility */
        max-width: 200px;
    }
    
    .modal-content {
        padding: 0 3rem 0.8rem; /* Extra side padding to avoid arrows */
    }
    
    .modal-product-description {
        /* Make description more prominent on mobile */
        border-left-width: 6px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    /* Enhanced scrollbar for mobile */
    .modal::-webkit-scrollbar {
        width: 8px;
    }
    
    .modal::-webkit-scrollbar-thumb {
        background: #007bff;
        border-radius: 4px;
    }
    
    /* Fix navigation arrows positioning on mobile */
    .modal-nav {
        top: 20%; /* Move arrows higher to avoid statistics */
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .modal-nav-prev {
        left: 0.5rem;
    }
    
    .modal-nav-next {
        right: 0.5rem;
    }
}

/* TABLET PORTRAIT STYLES (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    .modal {
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translate(-50%, -50%) scale(0.9);
        border-radius: 12px;
        max-width: 600px;
        max-height: 80vh;
        width: 90%;
    }
    
    .modal.active {
        transform: translate(-50%, -50%) scale(1);
    }
    
    .modal-drag-handle {
        display: none;
    }
    
    .modal-product-image {
        max-width: 300px;
        max-height: 250px;
    }
    
    .modal-specs-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .modal-actions {
        position: static;
        margin-top: 1rem;
    }
    
    .modal-content {
        padding: 0 4rem 1rem; /* Extra side padding to avoid arrows */
    }
    
    /* Fix navigation arrows positioning on tablet portrait */
    .modal-nav {
        top: 25%; /* Move arrows higher to avoid statistics */
    }
}

/* TABLET LANDSCAPE AND DESKTOP STYLES (768px and up, landscape or desktop) */
@media (min-width: 768px) and ((orientation: landscape) or (min-width: 1024px)) {
    .modal {
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translate(-50%, -50%) scale(0.9);
        border-radius: 12px;
        max-width: 600px;
        max-height: 80vh;
        width: 90%;
    }
    
    .modal.active {
        transform: translate(-50%, -50%) scale(1);
    }
    
    .modal-drag-handle {
        display: none;
    }
    
    .modal-product-image {
        max-width: 400px;
        max-height: 300px;
    }
    
    .modal-specs-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .modal-actions {
        position: static;
        margin-top: 1rem;
    }
}

/* DESKTOP STYLES (1024px and up) */
@media (min-width: 1024px) {
    .modal {
        max-width: 700px;
        max-height: 85vh;
    }
    
    .modal-content {
        padding: 0 2rem 2rem;
    }
    
    .modal-product-image {
        max-width: 200px;
        max-height: 180px;
    }
    
    .modal-specs-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.75rem;
    }
    
    /* Fix navigation arrows positioning on desktop to avoid covering statistics */
    .modal-nav {
        top: 15%; /* Move arrows to top 15% of modal for better spacing */
        transform: translateY(0); /* Remove center transform */
    }
    
    .modal-nav:hover {
        transform: scale(1.1); /* Remove translateY from hover */
    }
}


/* TOUCH GESTURES AND ANIMATIONS */
.modal-swipe-indicator {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background-color: rgba(0, 0, 0, 0.1);
    color: var(--text-color);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* LOADING STATE */
.modal-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
}

.modal-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--light-bg);
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ACCESSIBILITY */
.modal-overlay:focus-within .modal {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* DARK MODE SUPPORT (if needed later) */
@media (prefers-color-scheme: dark) {
    .modal {
        background-color: #2d3748;
        color: #e2e8f0;
    }
    
    .modal-header {
        background-color: #2d3748;
        border-bottom-color: #4a5568;
    }
    
    .modal-actions {
        background-color: #2d3748;
        border-top-color: #4a5568;
    }
}
