/**
 * Universal Media Widget Styles
 * Compatible with Luma and Hyvä themes
 */

/* Base widget wrapper */
.universal-media-widget {
    display: block;
    margin: 20px 0;
}

.universal-media-widget img,
.universal-media-widget video {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Figure wrapper (semantic HTML) */
.universal-media-widget.wrapper-figure {
    margin: 30px 0;
}

.universal-media-widget figcaption {
    margin-top: 10px;
    font-size: 14px;
    color: #666;
    font-style: italic;
    text-align: center;
}

/* Clickable caption for lightbox */
.universal-media-caption-link {
    /* Don't override color - inherit from figcaption */
    text-decoration: none !important;
    cursor: pointer !important;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    transition: all 0.3s ease;
}

.universal-media-caption-link:hover {
    opacity: 0.8;
}

.universal-media-caption-link:hover .caption-text {
    text-decoration: underline;
}

/* Thumbnail preview in caption */
.caption-thumbnail {
    display: inline-block;
    width: 40px;
    height: 40px;
    overflow: hidden;
    border-radius: 4px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    background: #ffffff; /* White background for transparent SVGs */
}

.caption-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Changed from cover to contain for SVGs */
    display: block;
}

/* Caption text */
.caption-text {
    flex: 1;
    text-align: center;
}

/* Zoom icon next to text */
.caption-icon {
    font-size: 18px;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.universal-media-caption-link:hover .caption-icon {
    opacity: 1;
    transform: scale(1.1);
}

/* Lightbox trigger - clickable image */
.universal-media-lightbox-trigger {
    cursor: zoom-in;
    display: inline-block;
    position: relative;
    transition: opacity 0.3s ease;
    text-decoration: none !important;
}

.universal-media-lightbox-trigger:hover {
    opacity: 0.9;
}

.universal-media-lightbox-trigger img {
    display: block;
}

/* Zoom icon overlay on image hover */
.universal-media-lightbox-trigger::after {
    content: '🔍';
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 18px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
}

.universal-media-lightbox-trigger:hover::after {
    opacity: 1;
}

/* Show zoom icon also when hovering over figure */
.universal-media-widget figure:hover .universal-media-lightbox-trigger::after {
    opacity: 1;
}

/* Lightbox modal */
.universal-media-lightbox {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.universal-media-lightbox img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    margin: auto;
    box-shadow: 0 0 50px rgba(255, 255, 255, 0.1);
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Lightbox close button */
.universal-media-lightbox button {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10000;
    transition: color 0.3s ease;
    padding: 0;
    line-height: 1;
    width: 45px;
    height: 45px;
}

.universal-media-lightbox button:hover,
.universal-media-lightbox button:focus {
    color: #bbb;
    outline: none;
}

/* PDF link styling */
.pdf-link-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #212529;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
}

a .pdf-link-text:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Amasty Jet Theme specific adjustments */
.amasty-technical-data {
    width: 100%;
    margin: 20px 0;
}

/* Ensure widget stays in gallery area on desktop */
@media (min-width: 769px) {
    .amtheme-product-wrap .amasty-technical-data {
        max-width: 100%;
        margin: 20px 0;
    }
}


/* Mobile - Combined responsive rules */
@media (max-width: 768px) {
    /* Amasty theme specific container */
    .amtheme-product-wrap {
        display: flex;
        flex-direction: column;
    }
    
    /* Gallery first */
    .product.info.media {
        display: flex;
        flex-direction: column;
        order: 1 !important;
    }
    
    /* Widget after gallery */
    .amasty-technical-data,
    .product-technical-data {
        order: 2 !important;
        width: 100% !important;
        margin: 20px 0 !important;
    }
    
    /* Product info after widget */
    .amtheme-product-info,
    .product-info-main {
        order: 3 !important;
    }
    
    /* Rest after */
    .amtheme-productinfo-wrap {
        order: 4 !important;
    }
    
    /* Widget adjustments */
    .universal-media-widget {
        margin: 15px 0;
    }
    
    .universal-media-widget figure {
        margin: 10px 0;
    }
    
    /* Lightbox adjustments */
    .universal-media-lightbox button {
        top: 10px;
        right: 10px;
        font-size: 30px;
        width: 35px;
        height: 35px;
    }
    
    .universal-media-lightbox img {
        max-width: 95%;
        max-height: 95%;
    }
    
    .universal-media-lightbox-trigger::after {
        font-size: 14px;
        padding: 3px 8px;
    }
    
    /* Caption adjustments for mobile - HORIZONTAL layout */
    .universal-media-caption-link {
        flex-direction: row; /* Keep horizontal */
        gap: 8px;
        padding: 10px 5px;
    }
    
    .caption-thumbnail {
        width: 50px;
        height: 50px;
    }
    
    .caption-text {
        font-size: 13px;
        text-align: left;
    }
    
    .caption-icon {
        font-size: 18px;
        margin-left: auto;
    }
}


/* Hyvä Theme specific adjustments */
body.hyva .universal-media-widget {
    /* Hyvä-specific styles if needed */
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .universal-media-widget figcaption {
        color: #aaa;
    }
    
    .pdf-link-text {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    a .pdf-link-text:hover {
        background: #1a202c;
        border-color: #2d3748;
    }
}

/* Loading state */
.universal-media-widget img[loading="lazy"] {
    background: #f0f0f0;
}

/* Print styles */
@media print {
    .universal-media-lightbox {
        display: none !important;
    }
    
    .universal-media-lightbox-trigger::after {
        display: none;
    }
}

/* SVG Style Isolation - Strong Reset */
.svg-isolated-wrapper {
    all: initial !important;
    display: inline-block !important;
    line-height: 0 !important;
    font-size: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
}

.svg-isolated-wrapper > div {
    all: unset !important;
    display: inline-block !important;
}

.svg-isolated-wrapper svg {
    display: block !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Prevent ANY external CSS from affecting SVG internals */
.svg-isolated-wrapper svg * {
    all: unset !important;
    box-sizing: content-box !important;
}

/* Legacy class support */
.svg-isolated {
    all: initial !important;
    display: inline-block !important;
}

.svg-isolated svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Reset common inherited styles for inline SVG */
.universal-media-widget svg {
    vertical-align: middle;
}

.universal-media-widget.svg-isolated svg * {
    /* Prevent theme styles from affecting SVG internals */
    box-sizing: content-box;
}