/**
 * Frontend Styles
 *
 * @package AdvancedCoupons
 * @since 1.0.0
 */

/* CSS Variables */
:root {
    --acfw-space-xs: 8px;
    --acfw-space-sm: 12px;
    --acfw-space-md: 16px;
    --acfw-space-lg: 20px;
    --acfw-space-xl: 24px;
    --acfw-radius-md: 8px;
    --acfw-radius-lg: 14px;
    --acfw-transition-fast: 0.15s ease;
    --acfw-transition-base: 0.2s ease;
    --acfw-transition-slow: 0.3s ease;
    --acfw-shadow-lg: var(--wp--preset--shadow--natural, 0 12px 28px rgba(0, 0, 0, 0.18));
    --acfw-z-tooltip: 100;
    --acfw-z-notification: 999;
}

/* Animations */
@keyframes acfw-spin {
    to { transform: rotate(360deg); }
}

@keyframes acfw-scale-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Available Coupons Widget */
details.acfw-available-coupons {
    margin: var(--acfw-space-lg) 0;
}

summary.acfw-coupons-toggle {
    display: flex;
    align-items: center;
    padding: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
    list-style: none;
}

summary.acfw-coupons-toggle::-webkit-details-marker {
    display: none;
}

summary.acfw-coupons-toggle:hover {
    opacity: 0.85;
}

summary.acfw-coupons-toggle .acfw-count {
    margin-left: 0.5em;
}

summary.acfw-coupons-toggle::after {
    content: '';
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.3s ease;
}

details.acfw-available-coupons[open] summary.acfw-coupons-toggle::after {
    transform: rotate(-135deg);
}

details.acfw-available-coupons .acfw-coupons-content {
    padding: 1em;
    max-height: 350px;
    overflow-y: auto;
}

.acfw-available-coupons .acfw-ac-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--acfw-space-md);
    align-items: start;
    container-type: inline-size;
}

@container (max-width: 350px) {
    .acfw-available-coupons .acfw-ac-list {
        grid-template-columns: 1fr;
        gap: var(--acfw-space-xs);
    }
    
    .acfw-available-coupons .acfw-ac-list .acfw-coupon {
        width: 100%;
        min-width: auto;
    }
}

.wc-block-components-sidebar-layout .acfw-available-coupons .acfw-ac-list,
.wp-block-woocommerce-checkout-fields-block .acfw-available-coupons .acfw-ac-list,
.wp-block-woocommerce-cart .acfw-available-coupons .acfw-ac-list,
.woocommerce-checkout .acfw-available-coupons .acfw-ac-list,
.woocommerce-cart .acfw-available-coupons .acfw-ac-list {
    grid-template-columns: repeat(2, 1fr);
}

.wc-block-components-sidebar .acfw-available-coupons .acfw-ac-list,
.woocommerce-checkout-review-order .acfw-available-coupons .acfw-ac-list {
    grid-template-columns: 1fr;
}

.acfw-ac-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    opacity: 0.6;
    font-style: italic;
}

/* Coupon Card Click-to-Apply */
.acfw-ac-card-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--acfw-radius-lg);
    transition: transform var(--acfw-transition-base);
}

.acfw-ac-card-wrapper .acfw-coupon {
    position: relative;
    transition: box-shadow var(--acfw-transition-base);
}

.acfw-ac-card-wrapper:hover {
    transform: translateY(-4px);
}

.acfw-ac-card-wrapper:hover .acfw-coupon {
    box-shadow: var(--acfw-shadow-lg);
}

.acfw-ac-card-wrapper:active {
    transform: translateY(-2px);
}

.acfw-ac-card-wrapper::before {
    content: 'Click to apply';
    position: absolute;
    bottom: calc(100% + var(--acfw-space-xs));
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 6px var(--acfw-space-sm);
    font-size: 12px;
    font-weight: 500;
    background: var(--wp--preset--color--foreground, #1f2937);
    color: var(--wp--preset--color--background, #ffffff);
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--acfw-transition-base);
    pointer-events: none;
    z-index: var(--acfw-z-tooltip);
}

.acfw-ac-card-wrapper::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--wp--preset--color--foreground, #1f2937);
    opacity: 0;
    visibility: hidden;
    transition: all var(--acfw-transition-base);
    pointer-events: none;
    z-index: var(--acfw-z-tooltip);
}

.acfw-ac-card-wrapper:hover::before,
.acfw-ac-card-wrapper:hover::after {
    opacity: 1;
    visibility: visible;
}

.acfw-ac-card-wrapper:hover::before {
    transform: translateX(-50%) translateY(0);
}

.acfw-ac-card-wrapper.acfw-applying {
    pointer-events: none;
    opacity: 0.7;
}

.acfw-ac-card-wrapper.acfw-applying .acfw-coupon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: acfw-spin 0.8s linear infinite;
    z-index: 20;
}

.acfw-ac-card-wrapper.acfw-applying::before,
.acfw-ac-card-wrapper.acfw-applying::after {
    display: none;
}

.acfw-ac-card-wrapper.acfw-applied {
    pointer-events: none;
}

.acfw-ac-card-wrapper.acfw-applied .acfw-coupon::after {
    content: '✓ Applied!';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    background: var(--wc-green, currentColor);
    color: var(--wp--preset--color--background, inherit);
    border-radius: inherit;
    animation: acfw-scale-in var(--acfw-transition-slow) forwards;
    z-index: 15;
}

.acfw-ac-card-wrapper.acfw-applied::before,
.acfw-ac-card-wrapper.acfw-applied::after {
    display: none;
}

/* My Account Coupons Page */
.acfw-myaccount-coupons {
    margin: 0;
}

.acfw-myaccount-section {
    margin-bottom: 30px;
}

.acfw-myaccount-section:last-child {
    margin-bottom: 0;
}

.acfw-myaccount-section h3 {
    margin: 0 0 15px;
    padding-bottom: 10px;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid currentColor;
    opacity: 0.2;
}

.acfw-myaccount-coupons .acfw-ac-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.acfw-total-credit {
    margin-top: 15px;
    padding: var(--acfw-space-sm) 15px;
    background: var(--wc-green-bg, transparent);
    color: var(--wc-green, inherit);
    border-radius: var(--acfw-radius-md);
    font-size: 14px;
}

.acfw-total-credit strong {
    margin-right: var(--acfw-space-xs);
}

/* Store Notice Bar */
.acfw-store-notice {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--acfw-space-sm);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
}

.acfw-store-notice.acfw-notice-top {
    position: relative;
    width: 100%;
}

.acfw-store-notice.acfw-notice-top-fixed {
    position: sticky;
    top: 0;
    width: 100%;
    z-index: var(--acfw-z-notification);
}

.acfw-store-notice.acfw-notice-bottom {
    position: relative;
    width: 100%;
}

.acfw-store-notice.acfw-notice-bottom-fixed {
    position: sticky;
    bottom: 0;
    width: 100%;
    z-index: var(--acfw-z-notification);
}

.acfw-store-notice p {
    margin: 0;
    flex: 1;
    text-align: center;
}

.acfw-store-notice p a {
    color: inherit;
    text-decoration: underline;
    margin-left: 4px;
}

.acfw-store-notice p a:hover {
    opacity: 0.9;
}

.acfw-store-notice .acfw-notice-dismiss {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    opacity: 0.8;
    transition: opacity var(--acfw-transition-fast);
}

.acfw-store-notice .acfw-notice-dismiss:hover {
    opacity: 1;
}

.acfw-store-notice .acfw-notice-dismiss svg {
    fill: currentColor;
}

body.admin-bar .acfw-store-notice.acfw-notice-top-fixed {
    top: 32px;
}

/* WooCommerce Blocks Compatibility */
.wc-block-cart .acfw-available-coupons,
.wc-block-checkout .acfw-available-coupons {
    margin: var(--acfw-space-lg) 0;
}

/* BOGO Free Item Styles */
.acfw-bogo-badge {
    display: inline-block;
    padding: 4px 10px;
    margin-top: 5px;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    background: #27ae60;
    border-radius: 4px;
    letter-spacing: 0.3px;
}

.acfw-bogo-quantity {
    display: inline-block;
    padding: 4px 8px;
    font-weight: 600;
    opacity: 0.7;
}

/* FREE item price strikethrough styling */
.woocommerce-cart-form__cart-item .product-price del,
.woocommerce-cart-form__cart-item .product-subtotal del {
    opacity: 0.6;
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    .acfw-coupons-toggle {
        padding: var(--acfw-space-sm) 15px;
    }
    
    .acfw-coupons-content {
        padding: var(--acfw-space-sm);
    }
    
    .acfw-amount-buttons {
        justify-content: center;
    }
    
    .acfw-amount-buttons .button {
        flex: 1 1 calc(33.333% - 10px);
        min-width: 60px;
    }
}

@media screen and (max-width: 600px) {
    .acfw-store-notice {
        height: auto;
        min-height: 40px;
        padding: var(--acfw-space-xs) var(--acfw-space-sm);
    }
    
    .acfw-store-notice p {
        font-size: 13px;
    }
}

@media screen and (max-width: 599px) {
    .acfw-ac-list,
    .acfw-available-coupons .acfw-ac-list,
    .acfw-myaccount-coupons .acfw-ac-list,
    .wc-block-components-sidebar-layout .acfw-available-coupons .acfw-ac-list,
    .wp-block-woocommerce-checkout-fields-block .acfw-available-coupons .acfw-ac-list,
    .wp-block-woocommerce-cart .acfw-available-coupons .acfw-ac-list,
    .woocommerce-checkout .acfw-available-coupons .acfw-ac-list,
    .woocommerce-cart .acfw-available-coupons .acfw-ac-list {
        grid-template-columns: 1fr;
    }
    
    .acfw-ac-card-wrapper .acfw-coupon {
        width: 100%;
        min-width: unset;
    }
}

@media screen and (max-width: 480px) {
    .acfw-amount-buttons .button {
        flex: 1 1 calc(50% - 10px);
    }
}

/* Print Styles */
@media print {
    .acfw-ac-apply-btn,
    .acfw-apply-coupon-btn,
    .acfw-dismiss-notice,
    .button {
        display: none;
    }
}
