/*
  Theme-agnostic variables with sensible fallbacks.
  Will automatically adapt when themes define WP CSS vars (e.g., Gutenberg presets).
*/
:root {
    --wc-sub-primary: var(--wp--preset--color--primary, #2271b1);
    --wc-sub-accent: var(--wp--preset--color--accent, #2271b1);
    --wc-sub-success: var(--wp--preset--color--vivid-green-cyan, #28a745);
    --wc-sub-text: var(--global--color-primary, currentColor);
    --wc-sub-bg: var(--global--color-background, #ffffff);
    --wc-sub-surface: var(--global--color-secondary, #f7f7f7);
    --wc-sub-border: var(--global--color-border, #e5e5e5);
    --wc-sub-shadow: rgba(0,0,0,.08);
    --wc-sub-radius: var(--global--border-radius, 8px);
}
/**
 * WooCommerce Subscription Frontend Styles
 */

/* Subscription button in product loops */
.woocommerce ul.products li.product .subscription-button,
.woocommerce-page ul.products li.product .subscription-button {
    display: block;
    width: 100%;
    margin-top: 10px;
    text-align: center;
    background-color: #4CAF50;
    color: #fff !important;
    border: none;
    padding: 8px 15px;
    border-radius: 3px;
    font-size: 0.9em;
    text-decoration: none;
    transition: all 0.3s ease;
    line-height: 1.5;
    cursor: pointer;
}

.woocommerce ul.products li.product .subscription-button:hover,
.woocommerce-page ul.products li.product .subscription-button:hover {
    background-color: #45a049;
    color: #fff;
    text-decoration: none;
}

/* Loading state */
.woocommerce ul.products li.product .subscription-button.loading,
.woocommerce-page ul.products li.product .subscription-button.loading {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
}

.woocommerce ul.products li.product .subscription-button.loading:after,
.woocommerce-page ul.products li.product .subscription-button.loading:after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 5px;
    vertical-align: middle;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: wc-subscription-spin 0.6s linear infinite;
}

/* Disabled state */
.woocommerce ul.products li.product .subscription-button:disabled,
.woocommerce-page ul.products li.product .subscription-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Success state */
.woocommerce ul.products li.product .subscription-button.added,
.woocommerce-page ul.products li.product .subscription-button.added {
    background-color: #4CAF50;
}

/* Animation for button states */
@keyframes wc-subscription-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .woocommerce ul.products li.product .subscription-button,
    .woocommerce-page ul.products li.product .subscription-button {
        font-size: 0.8em;
        padding: 6px 10px;
    }
}

/* Subscription option on product page */
.wc-subscription-option {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #f9f9f9;
}

.wc-subscription-checkbox-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
}

.wc-subscription-checkbox-label input[type="checkbox"] {
    margin-right: 10px;
    margin-top: 2px;
}

.wc-subscription-checkbox-text {
    font-weight: 600;
    color: #333;
}

.wc-subscription-description {
    margin-top: 10px;
    font-size: 14px;
    color: #666;
}

/* Subscription checkbox on checkout */
.wc-subscription-checkout-field {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #f9f9f9;
}

.wc-subscription-checkout-field .checkbox {
    font-weight: normal;
}

/* Subscription status colors */
.subscription-status.active {
    color: #008000;
    font-weight: bold;
}

.subscription-status.pending {
    color: #ffa500;
    font-weight: bold;
}

.subscription-status.cancelled {
    color: #808080;
    font-weight: bold;
}

.subscription-status.expired {
    color: #ff0000;
    font-weight: bold;
}

/* My Account subscriptions table */
.my_account_subscriptions .subscription-id,
.my_account_subscriptions .subscription-product,
.my_account_subscriptions .subscription-status,
.my_account_subscriptions .subscription-start-date,
.my_account_subscriptions .subscription-next-payment,
.my_account_subscriptions .subscription-actions {
    vertical-align: top;
}

@media screen and (max-width: 768px) {
    .my_account_subscriptions tr:not(.woocommerce-orders-table__header) {
        display: block;
        margin-bottom: 20px;
        padding: 15px;
        border: 1px solid #ddd;
        border-radius: 4px;
    }
    
    .my_account_subscriptions td {
        display: block;
        text-align: right;
        padding: 5px 0;
    }
    
    .my_account_subscriptions td:before {
        content: attr(data-title) ": ";
        float: left;
        font-weight: bold;
        color: #333;
    }
}

/* Cart subscription options */
.wc-cart-subscription-option {
    margin: 10px 0;
    padding: 12px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.wc-cart-subscription-option.loading {
    opacity: 0.6;
    pointer-events: none;
}

.wc-cart-subscription-checkbox-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
}

.wc-cart-subscription-checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-grow: 1;
}

.wc-cart-subscription-checkbox-label input[type="checkbox"] {
    margin-right: 8px;
    margin-top: 0;
}

.wc-cart-subscription-checkbox-text {
    font-weight: 500;
    color: #495057;
    font-size: 14px;
}

.wc-cart-subscription-active-badge {
    background-color: #28a745;
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wc-cart-subscription-description {
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
    font-style: italic;
}

/* Cart subscription option hover effect */
.wc-cart-subscription-option:hover {
    background-color: #e9ecef;
    border-color: #dee2e6;
}

/* Loading animation */
.wc-cart-subscription-option.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Subscription discount styling */
.subscription-discount-badge {
    background-color: #dc3545;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 5px;
}

.wc-cart-subscription-discount-preview {
    color: #28a745;
    font-size: 12px;
    font-weight: 500;
    font-style: italic;
}

/* Discount price styling */
.wc-cart-subscription-checkbox-text del {
    color: #999;
    text-decoration: line-through;
}

.wc-cart-subscription-checkbox-text ins {
    color: #28a745;
    text-decoration: none;
    font-weight: 600;
}

/* Cart item discount styling */
.woocommerce-cart-form .cart_item .product-price del,
.woocommerce-cart-form .cart_item .product-subtotal del {
    color: #999;
    font-size: 0.9em;
}

.woocommerce-cart-form .cart_item .product-price ins,
.woocommerce-cart-form .cart_item .product-subtotal ins {
    color: #28a745;
    text-decoration: none;
    font-weight: 600;
}

/* Subscription Duration Modal */
.wc-subscription-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99999;
}

.wc-subscription-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--wc-sub-bg);
    width: 90%;
    max-width: 420px;
    border-radius: var(--wc-sub-radius);
    box-shadow: 0 10px 30px var(--wc-sub-shadow);
    overflow: hidden;
    z-index: 100000;
}

.wc-subscription-modal-header {
    padding: 12px 16px;
    background: var(--wc-sub-surface);
    border-bottom: 1px solid var(--wc-sub-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wc-subscription-modal-header h3 {
    margin: 0;
    font-size: 16px;
}
.wc-subscription-modal-header .close {
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.wc-subscription-modal-body {
    padding: 12px 16px;
}

.wc-subscription-modal-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.wc-subscription-modal-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 2px solid var(--wc-sub-border);
    border-radius: var(--wc-sub-radius);
    cursor: pointer;
    background: var(--wc-sub-bg);
    transition: all .18s ease-in-out;
}
.wc-subscription-modal-option input[type="radio"] {
    margin: 0;
}

.wc-subscription-modal-option span {
    font-weight: 600;
    color: var(--wc-sub-text);
}

.wc-subscription-modal-option:hover {
    border-color: var(--wc-sub-primary);
    box-shadow: 0 2px 8px var(--wc-sub-shadow);
}

.wc-subscription-modal-option.selected,
.wc-subscription-modal-option input[type="radio"]:checked + span {
    color: var(--wc-sub-primary);
}

.wc-subscription-modal-option.selected {
    border-color: var(--wc-sub-primary);
    background: color-mix(in srgb, var(--wc-sub-primary) 8%, #ffffff);
}

/* Lock body scroll while modal open */
body.wc-subscription-modal-open {
    overflow: hidden;
}

.wc-subscription-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--wc-sub-border);
    background: var(--wc-sub-surface);
}

/* Respect dark mode automatically */
@media (prefers-color-scheme: dark) {
    :root {
        --wc-sub-bg: #1e1f21;
        --wc-sub-surface: #2a2b2e;
        --wc-sub-border: #3a3b3e;
        --wc-sub-text: #e6e6e6;
        --wc-sub-shadow: rgba(0,0,0,.3);
    }
    .wc-subscription-modal-option.selected {
        background: color-mix(in srgb, var(--wc-sub-primary) 12%, #1e1f21);
    }
}