/**
 * Advanced Promo Kit - Frontend Styles
 *
 * @since 1.0.0
 * @package APK
 */

/* ==========================================================================
   Image Wrapper - Contains product image and labels
   ========================================================================== */

.apk-image-wrapper {
    position: relative;
    display: block;
    width: 100%;
    margin: 0 auto 1.618em; /* Inherit WooCommerce image margin */
}

.apk-image-wrapper img {
    display: block;
    width: 100%;
    height: auto;
    margin: 0 !important; /* Remove margin from image, applied to wrapper instead */
}

/* ==========================================================================
   Labels Wrapper
   ========================================================================== */

.apk-labels-wrapper {
    position: absolute;
    height: min-content;
    display: flex;
    flex-flow: column nowrap;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
    overflow: visible;
}

/* Out-of-image placement wrapper - displayed below the product image */
.apk-labels-wrapper.apk-placement-out-of-image {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
    pointer-events: auto;
}

.apk-labels-wrapper.apk-placement-out-of-image .apk-label {
    position: relative;
    inset: auto;
}

/* On-image placement: the wrapper must span the full product image so each label
   can anchor to any edge (top/right/bottom/left) via its own inset styles, mirroring
   the admin live preview. Without this the wrapper is height:min-content pinned at
   the top, so "Bottom" labels render at the top of the image. See issue #92. */
.apk-labels-wrapper.apk-placement-on-image {
    height: auto;
}

/* Each on-image label item becomes a transparent full-image layer, giving the label
   inside the image itself as its positioning context. This overrides .apk-stacked so
   on-image labels honour their configured position instead of stacking at the top. */
.apk-labels-wrapper.apk-placement-on-image .apk-label-item {
    position: absolute !important;
    inset: 0;
    width: auto;
}

.apk-labels-wrapper.apk-placement-on-image .apk-label {
    position: absolute !important;
}

/* ==========================================================================
   Single Label Styles
   ========================================================================== */

.apk-label {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    box-sizing: border-box;
    z-index: 10;
    /* Default badge styling - can be overridden by inline styles from database */
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
}

.apk-stacked {
    position: relative !important;
}

/* Label link wrapper */
.apk-label-link {
    pointer-events: auto;
    text-decoration: none;
    display: inline-block;
}

.apk-label-link:hover .apk-label {
    opacity: 0.9;
}

/* Shadow wrapper for clipped shapes */
.apk-label-shadow-wrapper {
    position: relative;
    pointer-events: auto;
}

/* ==========================================================================
   Placement Positions
   ========================================================================== */

/* Top Left */
.apk-placement-top-left {
    top: 10px;
    left: 10px;
}

/* Top Center */
.apk-placement-top-center {
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
}

/* Top Right */
.apk-placement-top-right {
    top: 10px;
    right: 10px;
}

/* Middle Left */
.apk-placement-middle-left {
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
}

/* Middle Center */
.apk-placement-middle-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Middle Right */
.apk-placement-middle-right {
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
}

/* Bottom Left */
.apk-placement-bottom-left {
    bottom: 10px;
    left: 10px;
}

/* Bottom Center */
.apk-placement-bottom-center {
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
}

/* Bottom Right */
.apk-placement-bottom-right {
    bottom: 10px;
    right: 10px;
}

.apk-label-item {
    display: flex;
    width: 100%;
    position: absolute;
}

.apk-position-item-right {
    justify-content: flex-end;
}

/* ==========================================================================
   Badge Types
   ========================================================================== */

/* Text badge type */
.apk-badge-type-text .apk-label-text {
    display: block;
}

/* Image badge type */
.apk-badge-type-image {
    padding: 0;
    background: transparent !important;
}

.apk-badge-type-image .apk-label-image {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Icon badge type */
.apk-badge-type-icon {
    padding: 8px;
}

.apk-badge-type-icon .apk-label-icon {
    display: block;
    font-size: 1.2em;
}

/* ==========================================================================
   Tooltip Support
   ========================================================================== */

.apk-label[data-tooltip],
.apk-label-shadow-wrapper[data-tooltip] {
    cursor: help;
}

/* Lift the hovered badge above its siblings. Every .apk-label is positioned with
   z-index:10, which makes it its own stacking context, so the tooltip's z-index
   below cannot lift it past a sibling badge — sibling badges tie at z-index:10 and
   are painted in DOM order, letting a later badge cover an earlier badge's tooltip.
   Promoting the host itself is what actually gets the tooltip on top. See issue #49. */
.apk-label[data-tooltip]:hover,
.apk-label-shadow-wrapper[data-tooltip]:hover {
    z-index: 100;
}

/* Makes the labels wrapper a query container so the tooltip can cap its width to
   the product image (100cqw) rather than running off the card. See issue #49. */
.apk-labels-wrapper {
    container-type: inline-size;
}

.apk-label[data-tooltip]:hover::after,
.apk-label-shadow-wrapper[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 5px;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 11px;
    font-weight: normal;
    /* Wrap instead of running off the card edge: shrink to the text, but never wider
       than the product image less the badge's edge offset on either side. border-box
       keeps the padding inside that cap. The px value is the fallback for browsers
       without container query units. */
    box-sizing: border-box;
    white-space: normal;
    width: max-content;
    max-width: 200px;
    max-width: calc(100cqw - 20px);
    border-radius: 3px;
    /* The tooltip is never a hit target. Wrapping makes it tall enough to cover the
       badge below it, and without this it would swallow that badge's own hover. */
    pointer-events: none;
    z-index: 100;
}

/* Align the tooltip to the badge's own side so it grows inward from the card edge
   instead of overhanging it. Centre-positioned badges keep the centred default. */
.apk-position-item-left .apk-label[data-tooltip]:hover::after,
.apk-position-item-left .apk-label-shadow-wrapper[data-tooltip]:hover::after {
    left: 0;
    right: auto;
    transform: none;
}

.apk-position-item-right .apk-label[data-tooltip]:hover::after,
.apk-position-item-right .apk-label-shadow-wrapper[data-tooltip]:hover::after {
    left: auto;
    right: 0;
    transform: none;
}

/* ==========================================================================
   Context-specific Styles
   ========================================================================== */

/* Archive/Loop pages - smaller labels */
.apk-labels-loop .apk-label {
    font-size: 11px;
    padding: 3px 8px;
}

/* Single product page - can be larger */
.apk-labels-single .apk-label {
    font-size: 13px;
    padding: 5px 12px;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media screen and (max-width: 768px) {
    .apk-label {
        font-size: 10px;
        padding: 3px 6px;
    }

    .apk-labels-loop .apk-label {
        font-size: 9px;
        padding: 2px 5px;
    }
}

@media screen and (max-width: 480px) {
    .apk-label {
        font-size: 9px;
        padding: 2px 5px;
    }
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes apk-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
  
@keyframes apk-flash {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0; }
}
  
@keyframes apk-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
  
@keyframes apk-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
  
@keyframes apk-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
  
@keyframes apk-swing {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(15deg); }
    40% { transform: rotate(-10deg); }
    60% { transform: rotate(5deg); }
    80% { transform: rotate(-5deg); }   
}

.apk-animation-pulse { animation: apk-pulse 2s ease-in-out infinite; }
.apk-animation-flash { animation: apk-flash 2s ease-in-out infinite; }
.apk-animation-shake { animation: apk-shake 2s ease-in-out infinite; }
.apk-animation-bounce { animation: apk-bounce 2s ease-in-out infinite; }
.apk-animation-rotate { animation: apk-rotate 2s ease-in-out infinite; }
.apk-animation-swing { animation: apk-swing 2s ease-in-out infinite; }

/* ==========================================================================
   Custom Image Badge
   ========================================================================== */

.apk-label-custom-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ==========================================================================
   Single Product Override Styles
   ========================================================================== */

.product {
    overflow: visible !important;
}

/* ==========================================================================
   Theme Compatibility
   ========================================================================== */

/* Generic wrapper resets for theme link wrappers */
a > .apk-image-wrapper,
.products .apk-image-wrapper {
    position: relative;
    display: block;
    overflow: visible;
}

/* Storefront */
.storefront .apk-image-wrapper,
.theme-storefront .apk-image-wrapper {
    overflow: visible;
    position: relative;
}

/* Astra */
.ast-woocommerce-container .apk-image-wrapper,
.astra-shop-thumbnail-wrap .apk-image-wrapper {
    overflow: visible;
    position: relative;
    z-index: 1;
}

.ast-woocommerce-container .products .product {
    overflow: visible;
}

/* Flatsome */
.product-small .apk-image-wrapper,
.product-large .apk-image-wrapper {
    overflow: visible;
    position: relative;
    flex-shrink: 0;
}

/* OceanWP */
.oceanwp-theme .apk-image-wrapper,
.woo-entry-image .apk-image-wrapper {
    overflow: visible;
    position: relative;
    z-index: 1;
}

/* Kadence */
.wp-site-blocks .apk-image-wrapper,
.entry-content .apk-image-wrapper {
    overflow: visible;
    position: relative;
}

/* GeneratePress */
.generate-columns-container .apk-image-wrapper {
    overflow: visible;
    position: relative;
}

/* Divi theme */
.et_shop_image .apk-image-wrapper {
    overflow: visible;
    position: relative;
}

/* Avada */
.fusion-woo-product-image .apk-image-wrapper {
    overflow: visible;
    position: relative;
    z-index: 1;
}

.fusion-woo-product-image {
    overflow: visible !important;
}
