/* Modal Styles - Matching MF Resume Design System */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(45, 27, 105, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: linear-gradient(135deg, var(--main-purple) 0%, var(--deep-purple) 100%);
    border-radius: 20px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 215, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    max-width: 90vw;
    max-height: 90vh;
    width: 600px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* Larger modal for preview view */
.modal-content:has(#templatePreviewView[style*="flex"]) {
    width: 800px;
    max-width: 95vw;
    height: 90vh;
    max-height: 90vh;
}

.modal-header {
    padding: 1rem 1.5rem 0.5rem 2rem;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    position: relative;
}

.modal-title {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 4vw, 1.75rem);
    font-weight: 700;
    color: var(--pure-white);
    margin: 0;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
    letter-spacing: -0.01em;
    line-height: 1;
}

.modal-close {
    background: none;
    border: none;
    color: var(--accent-gold);
    font-size: 1.8rem;
    font-weight: 400;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    line-height: 1;
    position: relative;
    flex-shrink: 0;
    font-family: Arial, sans-serif;
    transform: translateY(-1px);
}

.modal-close:hover {
    background: rgba(255, 215, 0, 0.1);
    transform: scale(1.1);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.modal-close:focus {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
}

.modal-body {
    padding: 1rem 2rem 2rem 2rem;
    color: var(--pure-white);
    font-family: var(--font-body);
    line-height: 1.6;
}

/* Custom Scrollbar Styling */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-orange) 100%);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #FFDD00 0%, #FF8C00 100%);
}

.modal-body p {
    margin: 0;
    opacity: 0.9;
    font-size: 1.1rem;
    text-align: center;
}

/* Template Grid Styles */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 0.5rem;
    padding: 0 0.5rem;
}

.template-item {
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.template-item:hover {
    transform: translateY(-8px);
}

.template-thumbnail {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 215, 0, 0.1);
    transition: all 0.3s ease;
}

.template-thumbnail:hover {
    box-shadow:
        0 16px 40px rgba(0, 0, 0, 0.4),
        0 0 0 2px rgba(255, 215, 0, 0.3),
        0 0 20px rgba(255, 215, 0, 0.2);
    transform: scale(1.02);
}

.template-thumbnail img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.template-thumbnail:hover img {
    transform: scale(1.05);
}

.template-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top,
            rgba(45, 27, 105, 0.95) 0%,
            rgba(45, 27, 105, 0.8) 70%,
            transparent 100%);
    padding: 1.5rem 1rem 1.25rem 1rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-thumbnail:hover .template-overlay {
    transform: translateY(0);
}

.template-name {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
    letter-spacing: 0.02em;
    text-align: center;
    line-height: 1.2;
    width: 100%;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .modal-content {
        width: 95vw;
        margin: 1rem;
    }

    .modal-header {
        padding: 1rem 1.5rem 0.5rem 1.5rem;
    }

    .modal-body {
        padding: 1rem 1.5rem 1.5rem 1.5rem;
    }

    .modal-title {
        font-size: 1.5rem;
    }

    .template-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 1rem;
    }

    .template-item:hover {
        transform: translateY(-4px);
    }

    .template-thumbnail:hover {
        transform: scale(1.01);
    }

    .template-name {
        font-size: 1rem;
    }
}

/* Animation for reduced motion */
@media (prefers-reduced-motion: reduce) {

    .modal,
    .modal-content,
    .modal-close {
        transition: none;
    }

    .modal-content {
        transform: none;
    }

    .modal.show .modal-content {
        transform: none;
    }
}

/* Focus trap styling */
.modal-content:focus {
    outline: none;
}

/* Modal Views */
.modal-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#templateSelectionView .modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    max-height: calc(90vh - 120px);
}

/* Back to Templates Button */
.back-to-templates {
    background: none;
    border: none;
    color: var(--pure-white);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem 0;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.back-to-templates:hover {
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

/* Preview view header with reduced padding */
#templatePreviewView .modal-header {
    padding: 0.5rem 1.5rem 0.5rem 2rem;
}

#templatePreviewView .modal-body {
    padding: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.preview-pages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0 1rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.preview-pages img {
    width: 100%;
    height: auto;
    display: block;
}

/* Custom Scrollbar for Preview Modal Body */
#templatePreviewView .modal-body::-webkit-scrollbar {
    width: 8px;
}

#templatePreviewView .modal-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#templatePreviewView .modal-body::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-orange) 100%);
    border-radius: 4px;
}

#templatePreviewView .modal-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #FFDD00 0%, #FF8C00 100%);
}

/* Custom Scrollbar for Preview Pages Container */
.preview-pages::-webkit-scrollbar {
    width: 8px;
}

.preview-pages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.preview-pages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-orange) 100%);
    border-radius: 4px;
}

.preview-pages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #FFDD00 0%, #FF8C00 100%);
}

/* Modal Footer */
.modal-footer {
    padding: 1rem 2rem;
    border-top: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    justify-content: center;
    background: linear-gradient(135deg, var(--main-purple) 0%, var(--deep-purple) 100%);
    flex-shrink: 0;
    min-height: 80px;
    align-items: center;
}

/* Get Template Button */
.get-template-btn {
    display: inline-block;
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-orange) 100%);
    color: var(--deep-purple) !important;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: none;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 18px rgba(255, 215, 0, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.get-template-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 32px rgba(255, 215, 0, 0.4);
    background: linear-gradient(135deg, #FFDD00 0%, #FF8C00 100%);
}

.get-template-btn:active {
    transform: translateY(-1px);
}

/* Mobile Responsive for Preview */
@media (max-width: 768px) {
    .modal-content:has(#templatePreviewView[style*="flex"]) {
        width: 95vw;
        height: 95vh;
        max-height: 95vh;
    }
    
    #templatePreviewView .modal-header {
        padding: 0.5rem 1rem 0.5rem 1.5rem;
    }
    
    #templatePreviewView .modal-body {
        padding: 0;
    }
    
    .preview-pages {
        padding: 0 0.5rem;
        gap: 0.5rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1.5rem;
        min-height: 70px;
        position: sticky;
        bottom: 0;
        z-index: 10;
    }
    
    .get-template-btn {
        font-size: 0.9rem;
        padding: 0.65rem 1.25rem;
    }
}

/* Ensure modal appears above everything */
.modal {
    z-index: 9999;
}