/**
 * Uncode Theme Lightbox Customization
 * Matches the custom lightbox styling from MemberPress plugin
 * Specifically styles the Uncode theme's lightgallery to have:
 * - Actions in top right, vertically stacked
 * - Tooltips on buttons
 * - Counter in top left
 * - Consistent styling with plugin lightbox
 *
 * IMPORTANT: Uses very high specificity to override both Uncode and plugin defaults
 */

/* Force immediate positioning to prevent flicker */
body .lg-outer .lg-content,
body .lg-content {
    top: 68px !important; /* Adjust for fixed header height */
    transition: none !important; /* Disable transition to prevent flicker */
}

/* Ensure smooth repositioning if needed */
body .lg-outer.lg-animate-slide .lg-content {
    transition: transform 0.3s ease !important; /* Only animate transform, not top */
}

body .lg-outer .lg-dropdown {
    right: 55px;
}

/* =========================================
   Toolbar - Position and Layout
   ========================================= */
body .lg-outer .lg-toolbar,
body #lg-outer-1 .lg-toolbar,
body .lg-container .lg-outer .lg-toolbar {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    left: auto !important;
    bottom: auto !important;

    display: flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    justify-content: flex-start !important;
    gap: 8px !important;

    height: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;

    background: transparent !important;
    border: none !important;
    overflow: visible !important;
    transform: none !important;

    z-index: 99999 !important;
}

/* =========================================
   Toolbar Buttons - Complete Reset & Styling
   ========================================= */
body .lg-toolbar .lg-icon,
body .lg-toolbar .lg-toolbar-icon,
body .lg-toolbar button.lg-icon,
body .lg-toolbar a.lg-toolbar-icon,
body #lg-toolbar-1 .lg-icon,
body #lg-toolbar-1 .lg-toolbar-icon {
    /* Reset positioning */
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;

    /* Flex layout for icon + label */
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;

    /* Size */
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    max-width: 48px !important;
    max-height: 48px !important;

    /* Spacing */
    margin: 0 !important;
    padding: 0 !important;
    padding-bottom: 0 !important;

    /* Background & Border */
    background: rgba(255, 255, 255, 0.95) !important;
    background-color: rgba(255, 255, 255, 0.95) !important;
    border: none !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;

    /* Text/Icon Color */
    color: #333 !important;
    fill: #333 !important;

    /* States */
    opacity: 1 !important;
    cursor: pointer !important;

    /* Transitions */
    transition: all 0.2s ease !important;

    /* Font */
    font-size: 24px !important;
    line-height: 1 !important;
    text-align: center !important;
}

/* Hover state */
body .lg-toolbar .lg-icon:hover,
body .lg-toolbar .lg-toolbar-icon:hover,
body .lg-toolbar button.lg-icon:hover,
body .lg-toolbar a.lg-toolbar-icon:hover {
    background: #fff !important;
    background-color: #fff !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
    opacity: 1 !important;
}

/* Icon/SVG styling inside buttons */
body .lg-toolbar .lg-icon svg,
body .lg-toolbar .lg-toolbar-icon svg,
body .lg-toolbar .lg-icon:before,
body .lg-toolbar .lg-toolbar-icon:after {
    width: 22px !important;
    height: 22px !important;
    margin: 0 !important;
    margin-bottom: 0 !important;
    color: #333 !important;
    fill: #333 !important;
    stroke: #333 !important;
}

/* Override icon font colors */
body .lg-toolbar .lg-icon:after,
body .lg-toolbar .lg-icon:before {
    color: #333 !important;
}

/* =========================================
   Button Labels (text below icons)
   ========================================= */
body .lg-toolbar .button-label,
body .lg-toolbar .lg-icon .button-label,
body .lg-toolbar .lg-toolbar-icon .button-label {
    position: static !important;
    display: none !important; /* Hide by default, will be handled by tooltips */

    margin: 0 !important;
    margin-top: 4px !important;
    padding: 0 !important;

    color: #333 !important;
    font-size: 10px !important;
    font-weight: 500 !important;
    letter-spacing: 0.3px !important;
    white-space: nowrap !important;
    text-align: center !important;
    text-transform: capitalize !important;

    opacity: 1 !important;
    transform: none !important;

    line-height: 1.2 !important;
}

/* =========================================
   Tooltips
   ========================================= */
body .lg-toolbar .tooltip {
    position: relative !important;
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* Hide empty tooltip wrappers (those without button children) */
body .lg-toolbar .tooltip:not(:has(.lg-icon)):not(:has(.lg-toolbar-icon)) {
    display: none !important;
}

body .lg-toolbar .tooltip .tooltiptext {
    position: absolute !important;
    right: calc(100% + 10px) !important;
    top: 50% !important;
    left: auto !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    z-index: 999999 !important;

    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;

    transition: opacity 0.3s ease, visibility 0.3s ease !important;

    background: #333 !important;
    background-color: #333 !important;
    color: #fff !important;

    padding: 6px 12px !important;
    margin: 0 !important;

    border-radius: 4px !important;
    border: none !important;

    white-space: nowrap !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    line-height: 1.4 !important;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

/* Tooltip arrow */
body .lg-toolbar .tooltip .tooltiptext::after {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    left: 100% !important;
    margin-top: -5px !important;

    width: 0 !important;
    height: 0 !important;

    border-width: 5px !important;
    border-style: solid !important;
    border-color: transparent transparent transparent #333 !important;
}

/* Show tooltip on hover */
body .lg-toolbar .tooltip:hover .tooltiptext {
    visibility: visible !important;
    opacity: 1 !important;
}

/* =========================================
   Counter - Top Left Position
   ========================================= */
body .lg-outer .lg-counter,
body .lg-container .lg-counter,
body #lg-counter-1 {
    position: fixed !important;
    top: 30px !important;
    left: 30px !important;
    right: auto !important;
    bottom: auto !important;

    display: block !important;

    margin: 0 !important;
    padding: 8px 16px !important;

    background: rgba(0, 0, 0, 0.6) !important;
    background-color: rgba(0, 0, 0, 0.6) !important;
    border-radius: 4px !important;

    color: #fff !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;

    opacity: 0.9 !important;

    z-index: 99998 !important;
}

/* =========================================
   Close Button - Keep at top of toolbar
   ========================================= */
body .lg-toolbar .lg-close {
    order: -1 !important;
}

/* =========================================
   Loading State
   ========================================= */
body .lg-toolbar .loading {
    pointer-events: none !important;
    opacity: 0.5 !important;
}

body .lg-toolbar .loading::after {
    content: '' !important;
    position: absolute !important;
    width: 16px !important;
    height: 16px !important;
    top: 50% !important;
    left: 50% !important;
    margin: -8px 0 0 -8px !important;

    border: 2px solid rgba(0, 0, 0, 0.2) !important;
    border-top-color: #333 !important;
    border-radius: 50% !important;

    animation: mpusi-spin 0.6s linear infinite !important;
}

@keyframes mpusi-spin {
    to { transform: rotate(360deg); }
}

/* =========================================
   Navigation Arrows
   ========================================= */
body .lg-outer .lg-prev,
body .lg-outer .lg-next,
body #lg-prev-1,
body #lg-next-1 {
    background: rgba(255, 255, 255, 0.9) !important;
    border-radius: 4px !important;
    width: 48px !important;
    height: 48px !important;
    opacity: 0.8 !important;
    transition: all 0.2s ease !important;
    color: #333 !important;
}

body .lg-next {
    right: clamp(10px, calc(50% - 45vw - 50px), 25%);
}

body .lg-prev {
    left: clamp(10px, calc(50% - 45vw - 50px), 25%);
}

body .lg-outer .lg-prev:hover,
body .lg-outer .lg-next:hover {
    background: #fff !important;
    opacity: 1 !important;
    transform: scale(1.05) !important;
}

/* =========================================
   Backdrop
   ========================================= */
body .lg-backdrop,
body #lg-backdrop-1 {
    background-color: rgba(0, 0, 0, 0.85) !important;
    opacity: 1 !important;
}

/* =========================================
   Thumbnails - Bottom Position
   ========================================= */
body .lg-outer .lg-thumb-outer {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;

    width: 100% !important;
    padding: 10px 0 !important;

    background: rgba(0, 0, 0, 0.8) !important;
}

/* =========================================
   Sub HTML / Caption
   ========================================= */
body .lg-outer .lg-sub-html {
    position: fixed !important;
    bottom: 70px !important;
    left: 50% !important;
    right: auto !important;
    top: auto !important;

    transform: translateX(-50%) !important;

    max-width: 80% !important;
    padding: 10px 20px !important;
    margin: 0 !important;

    background: rgba(0, 0, 0, 0.7) !important;
    border-radius: 4px !important;

    color: #fff !important;
    text-align: center !important;
}

/* =========================================
   Ensure Proper Z-Index Layering
   ========================================= */
body .lg-backdrop { z-index: 99996 !important; }
body .lg-outer { z-index: 99997 !important; }
body .lg-counter { z-index: 99998 !important; }
body .lg-toolbar { z-index: 99999 !important; }

/* =========================================
   Accessibility Improvements
   ========================================= */
body .lg-toolbar .lg-icon:focus,
body .lg-toolbar .lg-toolbar-icon:focus {
    outline: 2px solid #26A0DA !important;
    outline-offset: 2px !important;
}

@media (min-width: 1920px) {
  /* Very large screens - arrows closer to edges */
  .lg-prev {
    left: clamp(10px, calc(50% - 45vw - 60px), 20%);
  }
  .lg-next {
    right: clamp(10px, calc(50% - 45vw - 60px), 20%);
  }
}

@media (max-width: 1440px) {
  /* Medium screens - balanced positioning */
  .lg-prev {
    left: clamp(10px, calc(50% - 45vw - 40px), 20%);
  }
  .lg-next {
    right: clamp(10px, calc(50% - 45vw - 40px), 20%);
  }
}

@media (max-width: 1024px) {
  /* Tablets - arrows closer to image */
  .lg-prev {
    left: clamp(10px, calc(50% - 45vw - 30px), 15%);
  }
  .lg-next {
    right: clamp(10px, calc(50% - 45vw - 30px), 15%);
  }
}

/* =========================================
   Responsive Design - Mobile
   ========================================= */
@media (max-width: 767px) {
    /* Toolbar - horizontal layout at top center for mobile */
    body .lg-outer .lg-toolbar,
    body #lg-outer-1 .lg-toolbar,
    body .lg-container .lg-outer .lg-toolbar {
        top: 10px !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;

        flex-direction: row-reverse !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;

        padding: 8px 12px !important;
        background: transparent !important;
        border-radius: 24px !important;
    }

    body .lg-outer .lg-dropdown {
        right: 0;
    }

    /* Close button order - keep on the left (flex-direction is row-reverse) */
    body .lg-toolbar .lg-close {
        order: 999 !important;
    }

    body .lg-toolbar .lg-icon,
    body .lg-toolbar .lg-toolbar-icon,
    body .lg-toolbar button.lg-icon,
    body .lg-toolbar a.lg-toolbar-icon {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        max-width: 40px !important;
        max-height: 40px !important;
        background: rgba(255, 255, 255, 0.9) !important;
    }

    body .lg-toolbar .lg-icon:hover,
    body .lg-toolbar .lg-toolbar-icon:hover,
    body .lg-toolbar button.lg-icon:hover,
    body .lg-toolbar a.lg-toolbar-icon:hover {
        background: #fff !important;
        transform: none !important;
    }

    body .lg-toolbar .button-label {
        display: none !important;
    }

    /* Navigation arrows - vertically centered relative to viewport/image */
    body .lg-outer .lg-prev,
    body #lg-prev-1 {
        left: 10px !important;
        right: auto !important;
    }

    body .lg-outer .lg-next,
    body #lg-next-1 {
        right: 10px !important;
        left: auto !important;
    }

    body .lg-outer .lg-prev,
    body .lg-outer .lg-next {
        width: 44px !important;
        height: 44px !important;
        top: calc(50% + 34px) !important;
        transform: translateY(-50%) !important;
    }

    /* Prevent arrows from shifting on hover/click */
    body .lg-outer .lg-prev:hover,
    body .lg-outer .lg-next:hover,
    body .lg-outer .lg-prev:active,
    body .lg-outer .lg-next:active {
        transform: translateY(-50%) !important;
    }

    body .lg-toolbar .lg-icon svg,
    body .lg-toolbar .lg-toolbar-icon svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Counter - same level as toolbar on the left */
    body .lg-outer .lg-counter,
    body .lg-container .lg-counter,
    body #lg-counter-1 {
        top: 10px !important;
        left: 15px !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        background: rgba(0, 0, 0, 0.6) !important;
        border-radius: 24px !important;
    }

    /* Tooltips - Show below on mobile */
    body .lg-toolbar .tooltip .tooltiptext {
        right: auto !important;
        left: 50% !important;
        top: calc(100% + 8px) !important;
        transform: translateX(-50%) !important;
    }

    body .lg-toolbar .tooltip .tooltiptext::after {
        top: -10px !important;
        left: 50% !important;
        margin-left: -5px !important;
        margin-top: 0 !important;
        border-color: transparent transparent #333 transparent !important;
    }

    /* Caption - SHOW on mobile but adjust position */
    body .lg-outer .lg-sub-html {
        display: block !important;
        bottom: 100px !important;
        max-width: 100% !important;
        width: 100%;
        padding: 8px 15px !important;
        font-size: 13px !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 480px) {
    body .lg-outer .lg-toolbar,
    body #lg-outer-1 .lg-toolbar,
    body .lg-container .lg-outer .lg-toolbar {
        top: 8px !important;
        padding: 6px 10px !important;
        gap: 6px !important;
        flex-direction: row-reverse !important;
    }

    /* Close button order - keep on the left */
    body .lg-toolbar .lg-close {
        order: 999 !important;
    }

    body .lg-toolbar .lg-icon,
    body .lg-toolbar .lg-toolbar-icon,
    body .lg-toolbar button.lg-icon,
    body .lg-toolbar a.lg-toolbar-icon {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        max-width: 36px !important;
        max-height: 36px !important;
    }

    body .lg-toolbar .button-label {
        display: none !important;
    }

    /* Navigation arrows - FIXED positioning for small screens */
    body .lg-outer .lg-next,
    body #lg-next-1 {
        right: 8px !important;
        left: auto !important;
    }

    body .lg-outer .lg-prev,
    body #lg-prev-1 {
        left: 8px !important;
        right: auto !important;
    }

    body .lg-outer .lg-prev,
    body .lg-outer .lg-next {
        width: 40px !important;
        height: 40px !important;
        top: calc(50% + 34px) !important;
    }

    /* Prevent arrows from shifting on hover/click for small screens */
    body .lg-outer .lg-prev:hover,
    body .lg-outer .lg-next:hover,
    body .lg-outer .lg-prev:active,
    body .lg-outer .lg-next:active {
        transform: translateY(-50%) !important;
    }

    body .lg-toolbar .lg-icon svg,
    body .lg-toolbar .lg-toolbar-icon svg {
        width: 18px !important;
        height: 18px !important;
    }

    body .lg-outer .lg-counter,
    body .lg-container .lg-counter,
    body #lg-counter-1 {
        top: 8px !important;
        left: 10px !important;
        padding: 6px 10px !important;
        font-size: 12px !important;
        background: rgba(0, 0, 0, 0.6) !important;
        border-radius: 20px !important;
    }

    body .lg-outer .lg-sub-html {
        bottom: 100px !important;
        max-width: 100% !important;
        width: 100%;
        padding: 6px 12px !important;
        font-size: 12px !important;
    }
}

/* =========================================
   Custom Go to Article Icon - Replace with PNG
   ========================================= */
/* Hide the default icon content for Go to Article button */
body .lg-toolbar .lg-go-to-article-btn svg,
body .lg-toolbar .lg-go-to-article-btn::after {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Add custom PNG icon using ::before pseudo-element */
body .lg-toolbar .lg-go-to-article-btn::before {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 22px !important;
    height: 22px !important;
    background-image: url('../images/go-to-article.png') !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    display: block !important;
    z-index: 1 !important;
}

/* =========================================
   Print Styles
   ========================================= */
@media print {
    body .lg-outer,
    body .lg-backdrop {
        display: none !important;
    }
}
