/* 3d-viewer-styles.css */

/* Main Button on Product Page */
.view-3d-btn {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 16px 28px;
    background-color: #000;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-width: 0;
    width: auto;
    max-width: 100%;
    position: relative;
}

.view-3d-btn .view-3d-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-3d-btn .view-3d-img-icon {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    max-width: 20px !important;
    max-height: 20px !important;
    object-fit: contain;
    display: inline-block;
    vertical-align: middle;
    margin: 0;
    box-sizing: content-box;
}

.view-3d-btn .view-3d-text {
    opacity: 1;
    width: auto;
    margin-left: 0;
    overflow: visible;
    white-space: nowrap;
    transition: none;
    font-size: 14px;
    font-weight: 400;
}

.view-3d-btn:hover, .view-3d-btn:focus {
    background-color: #333;
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

/* Always expanded button style */
.view-3d-btn.always-expanded {
    min-width: auto;
    padding: 4px 12px;
    gap: 5px;
    width: auto;
    transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
    min-height: 35px;
    background-color: #e1e1e1;
}

.view-3d-btn.always-expanded .view-3d-text {
    opacity: 1;
    width: auto;
    margin-left: 0;
    overflow: visible;
    white-space: nowrap;
}

/*
 * Expand-on-hover effect for 3D/AR button (icon only by default, text on hover)
 */
.view-3d-btn.expand-on-hover {
    width: 64px;
    min-width: 64px;
    max-width: 100%;
    padding: 12px 12px;
    transition: width 0.8s, background 0.2s, box-shadow 0.2s, transform 0.2s;
    overflow: hidden;
    gap: 0;
}

.view-3d-btn.expand-on-hover .view-3d-text {
    opacity: 0;
    width: 0;
    margin-left: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.2s, width 0.8s, margin-left 0.2s;
}

.view-3d-btn.expand-on-hover:hover,
.view-3d-btn.expand-on-hover:focus {
    width: 100%;
    padding: 12px 24px;
    gap: 14px;
}

.view-3d-btn.expand-on-hover:hover .view-3d-text,
.view-3d-btn.expand-on-hover:focus .view-3d-text {
    opacity: 1;
    width: auto;
    margin-left: 10px;
}

/* Modal Styles - Only apply overflow hidden when modal is visible */
.modal {
    display: none;
    position: fixed;
    z-index: 999999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* QR Modal MUST appear above fullscreen - PERMANENT FIX */
[id*="qr-modal"].modal,
[id*="qr-modal"].modal-open,
div[id*="qr-modal"].modal,
.modal[id*="qr-modal"],
[id*="qr-modal"][style*="display: block"] {
    z-index: 99999999 !important;
    position: fixed !important;
    visibility: visible !important;
}

/* Force QR modal visibility in fullscreen modes - REMOVE STACKING CONTEXT */
body.wc-3d-fullscreen-mode [id*="qr-modal"].modal,
body:has(.wc-3d-native-fullscreen-active) [id*="qr-modal"].modal,
.wc-3d-fullscreen-active ~ [id*="qr-modal"].modal,
.wc-3d-native-fullscreen-active ~ [id*="qr-modal"].modal {
    z-index: 99999999 !important;
    position: fixed !important;
    display: block !important;
    visibility: visible !important;
    /* REMOVE backdrop-filter to prevent stacking context issues */
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    /* Use solid background instead */
    background-color: rgba(0, 0, 0, 0.9) !important;
}

/* Only when modal is shown */
body.modal-open {
    overflow: hidden;
}

.modal[style*="display: block"] {
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Modal content should be scrollable if needed */
.modal-content {
    position: relative;
    background-color: white;
    margin: 5vh auto;
    width: 550px;
    max-width: 550px;
    max-height: 90vh;
    border-radius: 8px;
    overflow: auto; /* Allow content scrolling if needed */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    align-self: center;
}

/* Modal Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.4em;
    font-weight: 600;
    color: #333;
}

#3d-viewer-modal .close {
    background: transparent !important;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #777;
    transition: color 0.2s ease;
}

.close:hover {
    color: #333;
    background-color: #242424;
}

/* AR Actions */
.ar-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px;
    background-color: transparent;
}

/* AR and Info Buttons */
.ar-button, #view-ar-button-ios {
    background-color: #007cba;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s ease;
    text-decoration: none;
}

.ar-button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ar-button-text {
    display: inline-block;
}

.ar-button:hover, #view-ar-button-ios:hover {
    background-color: #006ba1;
}

/* Info Button */
.info-button {
    background-color: transparent;
    border: 1px solid #ddd;
    color: #555;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.info-button:hover {
    background-color: #f0f0f0;
}

/* Viewer Container */
.viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
    overflow: hidden;
    background-color: #f1f1f1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

model-viewer {
    width: 100%;
    height: 100%;
    display: block;
    background-color: transparent;
    --poster-color: transparent;
    --progress-bar-color: #242424;
    --progress-bar-height: 5px;
}

.viewer-container, model-viewer {
    min-height: 400px;
    width: 100%;
}

/* Fix for iOS Safari display issues */
.ios model-viewer {
    opacity: 1 !important;
    z-index: 1;
}

/* Loading States */
.progress-bar {
    width: 100%;
    height: 5px;
    background: rgba(0, 0, 0, 0.1);
    position: absolute;
    bottom: 0;
    left: 0;
}

.update-bar {
    background: #007cba;
    width: 0%;
    height: 100%;
    transition: width 0.3s;
}

.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: #007cba;
    animation: spin 1s linear infinite;
    margin-top: 15px;
}

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

/* QR Code Container - Modal specific */
#3d-viewer-modal .qr-container {
    display: none;
    flex-direction: column;
    height: 400px;
    min-height: 400px;
    background-color: #f5f5f5;
    padding: 20px;
    text-align: center;
}

#3d-viewer-modal .qr-container[style*="display: flex"] {
    display: flex !important;
}

#3d-viewer-modal .viewer-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
}

#3d-viewer-modal .viewer-container[style*="display: none"] {
    display: none !important;
}

.back-button {
    align-self: flex-start;
    background-color: transparent !important;
    border: none;
    color: #007cba;
    cursor: pointer;
    padding: 5px 0;
    font-size: 16px;
    margin-bottom: 20px;
}

.back-button:hover {
    text-decoration: underline;
}

.qr-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.qr-header {
    margin-bottom: 20px;
    text-align: center;
}

.qr-header h4 {
    font-size: 1.2em;
    margin: 0 0 5px;
}

.qr-header p {
    margin: 0;
    color: #666;
}

.qr-code {
    margin: 20px 0;
}

.qr-code img {
    max-width: 200px;
    height: auto;
}

.copy-link-button {
    background-color: #242424 !important;
    color: white !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    margin-top: 15px !important;
}

.copy-link-button:hover {
    transform: scale(1.05);
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 12px 20px;
    border-radius: 4px;
    z-index: 1000000;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Compatibility Warning */
.compat-warning {
    display: block;
    font-size: 12px;
    color: #856404;
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    padding: 5px 10px;
    border-radius: 3px;
    margin-top: 5px;
    margin-bottom: 10px;
}

/* Fallback content */
.fallback {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #f5f5f5;
    padding: 20px;
    text-align: center;
    z-index: 5;
}

.fallback p {
    margin-bottom: 15px;
}

.fallback a {
    display: inline-block;
    background-color: #007cba;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    margin-top: 10px;
}

/* iOS specific styles */
.ios .viewer-container {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Add iOS class to body when detected */
body.ios model-viewer {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#view-ar-button{
    display: flex;
    background-color: transparent;
    color: #B76C3C;
    padding: 8px;
    border-radius: 0 !important;
    border: 1px solid #B76C3C;
}

#view-ar-button:hover{
    transform: scale(1.05);
}

#qr-code-container{
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

/* Responsive Design */
@media (min-width: 768px) {
    .modal-content {
        margin: 40px auto;
        max-width: 90%;
        max-height: calc(100vh - 80px);
        border-radius: 16px;
    }

    .viewer-container {
        height: 100%;
    }

    .ar-actions {
        top: 100px;
    }
}

@media (min-width: 1024px) {
    .modal-content {
        max-width: 80%;
    }

    .qr-content {
        padding: 48px;
        max-width: 360px;
    }
}

@media (max-width: 767px) {
    .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .ar-actions {
        top: 70px;
        padding: 8px;
    }

    .ar-button {
        padding: 8px 16px;
        font-size: 13px;
    }

    .info-button svg {
        width: 18px;
        height: 18px;
    }

    .viewer-container {
        height: calc(100vh - 130px);
    }

    .qr-container {
        height: calc(100vh - 130px);
    }

    .qr-content {
        padding: 24px;
    }

    .qr-header h4 {
        font-size: 18px;
    }

    .qr-code img {
        max-width: 180px;
    }

    .copy-link-button {
        padding: 10px 20px;
        font-size: 13px;
    }

    .back-button {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* Responsive adjustments for small screens */
@media (max-width: 480px) {
    .ar-actions {
        flex-direction: column;
        align-items: stretch;
    }

    #3d-viewer-modal {
        justify-content: center;
        align-items: center;
    }

    #3d-viewer-modal .modal-content {
        width: 96vw;
        max-width: 96vw;
        min-height: 70vh;
        max-height: 92vh;
        margin: 3vh auto;
    }
}

/* iOS Safari Fixes — scope to our modal only */
@supports (-webkit-touch-callout: none) {
    #3d-viewer-modal .modal-content {
        min-height: -webkit-fill-available;
        max-height: 100vh;
    }

    #3d-viewer-modal .viewer-container {
        min-height: 45vh;
    }

    #3d-viewer-modal model-viewer {
        min-height: 42vh;
    }
}

/* Fix for Safari on iOS (full-width section, etc.); modal overrides with mask none + !important below */
@media not all and (min-resolution:.001dpcm) { 
    @supports (-webkit-appearance:none) {
        model-viewer {
            -webkit-mask-image: -webkit-radial-gradient(white, black);
            mask-image: radial-gradient(white, black);
        }
    }
}

#3d-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 999999;
    display: none;
    overflow: hidden;
}

/*
 * Critical: percent heights on model-viewer collapse when the flex parent has no definite
 * block size — WebGL canvas can end up at 1×1 CSS pixels. Use flex + vh min-heights.
 */
#3d-viewer-modal .modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(550px, 96vw);
    max-width: min(550px, 96vw);
    max-height: 92vh;
    min-height: min(480px, 70vh);
    overflow: hidden;
    margin: 4vh auto;
    flex: 0 1 auto;
}

#3d-viewer-modal .modal-header {
    flex: 0 0 auto;
}

#3d-viewer-modal .viewer-container {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: min(360px, 50vh);
    height: min(58vh, 560px);
    max-height: 65vh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
}

#3d-viewer-modal model-viewer {
    display: block;
    width: 100% !important;
    flex: 1 1 auto;
    min-height: min(320px, 48vh);
    height: 100%;
    max-width: 100% !important;
    min-width: 0;
    background-color: transparent;
    /* none: browser must not steal drags for scroll/zoom — required for orbit on many phones */
    touch-action: none !important;
    -webkit-user-select: none;
    user-select: none;
    -webkit-mask-image: none !important;
    mask-image: none !important;
    --poster-color: transparent;
    --progress-bar-color: #4a90e2;
    --progress-bar-height: 2px;
    --progress-mask: none;
}

#3d-viewer-modal .ar-actions {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

#3d-viewer-modal .progress-bar {
    pointer-events: none;
}

/* iOS GPU compositing fix */
.ios #3d-viewer-modal model-viewer {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Prevent background scrolling when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}