/* CSS Variables */
:root {
    --status-bar-height: env(safe-area-inset-top, 60px);
}

/* Modal Components */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    max-width: 90vw;
    max-height: 95vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    background: var(--color-surface-elevated);
    border: 2px solid var(--color-border);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    color: var(--color-text);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--color-primary);
    color: white;
    transform: scale(1.1);
}

.engraving-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8);
    padding: var(--space-8);
    padding-top: calc(var(--space-8) + 80px); /* Increased padding to avoid close button */
    max-width: 1200px;
    margin: 0 auto;
}

/* Joy-Driven Typography Hierarchy */
.engraving-info h2 {
    font-family: var(--font-family-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: var(--space-4);
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: -0.5px;
}

.engraving-info h3 {
    font-family: var(--font-family-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-3);
    line-height: 1.3;
    position: relative;
}

.engraving-info h3::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 40px;
    height: 2px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: 2px;
}

.engraving-info p {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
}

.engraving-info .description {
    font-size: 1.1rem;
    color: var(--color-text);
    font-weight: 400;
    margin-bottom: var(--space-6);
}

/* Metadata with Visual Interest */
.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    padding: var(--space-4);
    background: linear-gradient(135deg, var(--color-surface-elevated), var(--color-surface-variant));
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
}

.metadata-item {
    padding: var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    transition: all var(--duration-fast) var(--ease-out);
    border: 1px solid transparent;
}

.metadata-item:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metadata-item strong {
    display: block;
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-2);
}

.metadata-item span {
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 500;
}

.engraving-image-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.engraving-image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

.image-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    z-index: 5;
    transition: opacity 0.3s ease;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-3);
}

.loading-text {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    opacity: 0.9;
}

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

/* Progressive Image Loading Styles */
.progressive-image {
    transition: opacity 0.5s ease-in-out;
}

.image-quality-indicator {
    position: absolute;
    top: var(--space-3);
    left: var(--space-3);
    z-index: 6;
}

.quality-badge {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.quality-badge.preview {
    background: rgba(255, 193, 7, 0.9);
    color: #000;
}

.quality-badge.full {
    background: rgba(76, 175, 80, 0.9);
    color: white;
}

.quality-badge.error {
    background: rgba(244, 67, 54, 0.9);
    color: white;
}

.engraving-img {
    max-width: 100%;
    max-height: 70vh; /* Much larger on desktop - up to 70% of viewport height */
    object-fit: contain;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

/* Large desktop screens - maximize image size */
@media (min-width: 1200px) {
    .engraving-img {
        max-height: 75vh; /* Even larger on very large screens */
    }
    
    .modal-content {
        max-width: 95vw; /* Use more screen width */
    }
    
    .engraving-details {
        max-width: 1400px; /* Increase max container width */
    }
}

/* Desktop screens */
@media (min-width: 769px) and (max-width: 1199px) {
    .engraving-img {
        max-height: 65vh; /* Large but not overwhelming */
    }
}

.engraving-img:hover {
    transform: scale(1.02);
    border-color: var(--color-primary);
    box-shadow: 0 8px 32px rgba(76, 175, 80, 0.3);
}

/* Full-screen image modal */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000; /* Increased z-index to be above landmarks */
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.image-modal.visible {
    opacity: 1;
}

.image-modal-content {
    width: 100vw;
    height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding-top: calc(var(--status-bar-height) + 16px);
    padding-bottom: 16px;
}

.image-modal img {
    max-width: calc(100vw - 40px); /* Add some padding */
    max-height: calc(100vh - 40px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 0;
    box-shadow: none;
    display: block; /* Ensure proper centering */
    margin: auto;
    z-index: 3001; /* Above modal background */
    transform-origin: center center;
}

.image-modal-close {
    position: fixed;
    top: calc(var(--status-bar-height) + 16px);
    right: max(env(safe-area-inset-right, 24px), var(--space-6));
    background: rgba(30, 30, 30, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
    z-index: 3002; /* Above the image */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.image-modal-close:hover {
    background: rgba(var(--color-primary-rgb, 59, 130, 246), 0.8);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.image-modal-back {
    display: none; /* Hide back button on mobile */
}

.image-modal-title {
    display: none; /* Hide title overlay in full-screen view */
}

/* Zoomable image container */
.image-zoom-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

.image-zoom-container:active {
    cursor: grabbing;
}

.image-zoom-container img {
    transition: transform 0.2s ease;
    transform-origin: center center;
}

.zoom-controls {
    position: absolute;
    bottom: 80px;
    right: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 10;
}

.zoom-btn {
    background: var(--color-surface-elevated);
    border: 2px solid var(--color-border);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--color-text);
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: var(--color-primary);
    color: white;
    transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .engraving-details {
        display: flex !important;
        flex-direction: column !important;
        gap: var(--space-4);
        padding: var(--space-4);
        padding-top: calc(var(--space-4) + 60px);
        grid-template-columns: none !important;
    }
    
    .engraving-image-container {
        order: 1 !important;
        width: 100% !important;
        margin-bottom: var(--space-4);
        flex-shrink: 0;
    }
    
    .engraving-info {
        order: 2 !important;
        width: 100% !important;
        flex: 1;
    }
    
    .engraving-img {
        max-height: 300px;
        width: 100%;
        object-fit: contain;
    }
    
    .modal-content {
        max-width: 95vw;
        max-height: 90vh;
    }
    
    .zoom-controls {
        bottom: 60px;
        right: var(--space-2);
    }
    
    .zoom-btn {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .engraving-details {
        display: flex !important;
        flex-direction: column !important;
        padding: var(--space-3);
        padding-top: calc(var(--space-3) + 50px);
        gap: var(--space-3);
        grid-template-columns: none !important;
    }
    
    .engraving-image-container {
        order: 1 !important;
        width: 100% !important;
        margin-bottom: var(--space-3);
        flex-shrink: 0;
    }
    
    .engraving-info {
        order: 2 !important;
        width: 100% !important;
        flex: 1;
    }
    
    .engraving-img {
        max-height: 250px;
        width: 100%;
        object-fit: contain;
    }
    
    .modal-close {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }
    
    .image-modal-close {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
    }
}
