/**
 * EGB Cart System - Frontend Styles
 */

/* ==========================================================================
   Cart Add Button
   ========================================================================== */

.egb-cart-add-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.egb-cart-add-button:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.egb-cart-add-button--hidden {
    display: none !important;
}

.egb-cart-add-button--loading {
    pointer-events: none;
}

.egb-cart-add-button--loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: egb-spin 0.8s linear infinite;
}

.egb-cart-add-button .egb-btn-icon {
    font-size: inherit;
    line-height: 1;
}

.egb-cart-add-button .egb-btn-text {
    line-height: 1;
}

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

@keyframes egb-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes egb-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes egb-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes egb-scale {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.egb-anim-pulse {
    animation: egb-pulse 0.4s ease;
}

.egb-anim-shake {
    animation: egb-shake 0.4s ease;
}

.egb-anim-bounce {
    animation: egb-bounce 0.4s ease;
}

.egb-anim-scale {
    animation: egb-scale 0.4s ease;
}

/* ==========================================================================
   Dynamic Cart
   ========================================================================== */

.egb-dynamic-cart {
    display: inline-block;
    position: relative;
}

.egb-dynamic-cart--hidden {
    display: none !important;
}

.egb-dynamic-cart--empty.egb-dynamic-cart--hide-empty {
    display: none !important;
}

.egb-cart-icon-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.egb-cart-icon-wrapper:hover {
    transform: scale(1.05);
}

.egb-cart-icon {
    display: inline-block;
    line-height: 1;
}

.egb-cart-svg svg {
    width: 100%;
    height: 100%;
}

/* Badge */
.egb-cart-badge {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.egb-cart-badge--hidden {
    display: none !important;
}

@keyframes egb-badge-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.egb-cart-badge--animate {
    animation: egb-badge-pop 0.3s ease;
}

/* Dropdown */
.egb-dynamic-cart {
    position: relative;
    display: inline-block;
}

.egb-cart-dropdown {
    position: absolute;
    top: 100%;
    z-index: 9999;
    margin-top: 8px;
    overflow: hidden;
    display: none;
}

.egb-cart-dropdown.egb-cart-dropdown--open {
    display: block !important;
}

.egb-cart-dropdown-content {
    padding: 12px;
    overflow-y: auto;
}

/* Empty State */
.egb-cart-empty {
    text-align: center;
    padding: 20px;
    color: #666;
}

/* Items List */
.egb-cart-items-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.egb-cart-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.egb-cart-item:last-child {
    border-bottom: none;
}

.egb-cart-item:hover {
    background-color: #f9f9f9;
}

.egb-cart-item-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 12px;
    flex-shrink: 0;
}

.egb-cart-item-details {
    flex: 1;
    min-width: 0;
}

.egb-cart-item-title {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

.egb-cart-item-price {
    font-size: 12px;
    color: #666;
}

.egb-cart-item-sku,
.egb-cart-item-qty {
    font-size: 11px;
    color: #999;
}

.egb-cart-item-remove {
    background: none;
    border: none;
    color: #e74c3c;
    font-size: 20px;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
}

.egb-cart-item-remove:hover {
    opacity: 1;
}

/* Total */
.egb-cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-top: 1px solid #eee;
    font-weight: bold;
}

.egb-cart-total-label {
    color: #333;
}

.egb-cart-total-value {
    color: #000;
}

/* Action Button Wrapper */
.egb-cart-action-wrapper {
    padding: 12px;
    border-top: 1px solid #eee;
}

.egb-cart-action-btn {
    width: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.egb-cart-action-btn:hover {
    opacity: 0.9;
}

/* ==========================================================================
   Cart Checkout Button
   ========================================================================== */

.egb-cart-checkout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.egb-cart-checkout-button:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.egb-cart-checkout-button--hidden,
.egb-checkout--hidden {
    display: none !important;
}

.egb-cart-checkout-button--loading {
    pointer-events: none;
}

.egb-cart-checkout-button--loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 12px;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: egb-spin 0.8s linear infinite;
}

.egb-cart-checkout-button--success {
    background-color: #27ae60 !important;
}

.egb-cart-checkout-button--error {
    background-color: #e74c3c !important;
}

.egb-cart-checkout-button .egb-btn-icon {
    font-size: inherit;
    line-height: 1;
}

.egb-cart-checkout-button .egb-btn-text {
    line-height: 1;
}

/* ==========================================================================
   Messages
   ========================================================================== */

.egb-cart-message {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 99999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: egb-slide-in 0.3s ease;
}

@keyframes egb-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.egb-cart-message--success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.egb-cart-message--error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.egb-cart-message--info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

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

@media (max-width: 768px) {
    .egb-cart-dropdown {
        position: fixed;
        top: auto !important;
        bottom: 0;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: none !important;
        border-radius: 16px 16px 0 0 !important;
        transform: none !important;
        margin-top: 0;
    }
    
    .egb-cart-dropdown-content {
        max-height: 60vh;
    }
    
    .egb-cart-item-image {
        width: 40px;
        height: 40px;
    }
    
    .egb-cart-message {
        left: 20px;
        right: 20px;
        bottom: 20px;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .egb-cart-dropdown {
        background-color: #1e1e1e;
        border-color: #333;
    }
    
    .egb-cart-item {
        border-color: #333;
    }
    
    .egb-cart-item:hover {
        background-color: #2a2a2a;
    }
    
    .egb-cart-item-title {
        color: #fff;
    }
    
    .egb-cart-item-price,
    .egb-cart-item-sku,
    .egb-cart-item-qty {
        color: #aaa;
    }
    
    .egb-cart-empty {
        color: #aaa;
    }
    
    .egb-cart-total {
        border-color: #333;
    }
    
    .egb-cart-total-label,
    .egb-cart-total-value {
        color: #fff;
    }
    
    .egb-cart-action-wrapper {
        border-color: #333;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .egb-dynamic-cart,
    .egb-cart-add-button,
    .egb-cart-checkout-button {
        display: none !important;
    }
}

/* ==========================================================================
   Quantity Badge on Add Button
   ========================================================================== */

.egb-btn-qty-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: bold;
    line-height: 20px;
    text-align: center;
    color: #fff;
    background-color: #e74c3c;
    border-radius: 10px;
    z-index: 1;
}

.egb-cart-btn--max-reached {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==========================================================================
   Quantity Controls in Cart
   ========================================================================== */

.egb-cart-item-qty-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.egb-cart-item-qty-controls.egb-cart-qty--max-reached .egb-cart-qty-plus {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.egb-cart-qty-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.egb-cart-qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    color: #333;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.egb-cart-qty-btn:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
}

.egb-cart-qty-btn:active {
    background-color: #d0d0d0;
    transform: scale(0.95);
}

.egb-cart-qty-input {
    width: 50px;
    height: 28px;
    padding: 0 4px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    color: #333;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    -moz-appearance: textfield;
}

.egb-cart-qty-input::-webkit-outer-spin-button,
.egb-cart-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.egb-cart-qty-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

/* Price display with quantity */
.egb-cart-item-unit-price {
    font-size: 0.9em;
    color: #666;
}

.egb-cart-item-total-price {
    font-weight: 600;
}

/* Dark mode quantity controls */
@media (prefers-color-scheme: dark) {
    .egb-cart-qty-btn {
        color: #fff;
        background-color: #444;
        border-color: #555;
    }
    
    .egb-cart-qty-btn:hover {
        background-color: #555;
        border-color: #666;
    }
    
    .egb-cart-qty-input {
        color: #fff;
        background-color: #333;
        border-color: #555;
    }
    
    .egb-cart-item-unit-price {
        color: #999;
    }
}

/* ==========================================================================
   Messages
   ========================================================================== */

.egb-cart-message {
    display: inline-block;
    margin-left: 10px;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    animation: egb-message-fade-in 0.3s ease;
}

.egb-cart-message--success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.egb-cart-message--error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@keyframes egb-message-fade-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   WooCommerce Cart Blocks
   ========================================================================== */

/* WooCommerce Add to Cart Button */
.egb-woo-add-to-cart {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    background-color: #0073aa;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.egb-woo-add-to-cart:hover {
    background-color: #005a87;
}

.egb-woo-add-to-cart.egb-woo-btn--loading {
    opacity: 0.7;
    cursor: wait;
}

.egb-woo-add-to-cart.egb-woo-btn--added {
    background-color: #27ae60;
}

.egb-woo-btn-icon {
    font-size: inherit;
}

.egb-woo-btn-text {
    font-size: inherit;
}

@keyframes egb-woo-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.egb-woo-anim--pulse {
    animation: egb-woo-pulse 0.3s ease;
}

/* WooCommerce Mini Cart */
.egb-woo-mini-cart {
    position: relative;
    display: inline-block;
}

.egb-woo-cart-icon-wrapper {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.egb-woo-cart-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    border-radius: 50%;
    background-color: #e74c3c;
    color: #ffffff;
}

.egb-woo-cart-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 300px;
    max-width: 400px;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 10px;
    visibility: hidden;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.egb-woo-cart-dropdown.egb-woo-cart-dropdown--open {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.egb-woo-cart-items {
    max-height: 300px;
    overflow-y: auto;
    padding: 12px;
}

.egb-woo-cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.egb-woo-cart-item:last-child {
    border-bottom: none;
}

.egb-woo-cart-item-image {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}

.egb-woo-cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.egb-woo-cart-item-details {
    flex: 1;
    min-width: 0;
}

.egb-woo-cart-item-name {
    font-weight: 500;
    font-size: 14px;
    color: #333;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.egb-woo-cart-item-price {
    font-size: 13px;
    color: #666;
}

.egb-woo-cart-item-quantity {
    font-size: 12px;
    color: #999;
}

.egb-woo-cart-item-remove {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.egb-woo-cart-item-remove:hover {
    background-color: #ffebee;
    color: #e74c3c;
}

.egb-woo-cart-empty {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.egb-woo-cart-total {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    border-top: 1px solid #e0e0e0;
    font-weight: 600;
}

.egb-woo-cart-total-value {
    color: #e74c3c;
}

.egb-woo-cart-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e0e0e0;
}

.egb-woo-cart-view-cart,
.egb-woo-cart-checkout {
    flex: 1;
    padding: 10px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.egb-woo-cart-view-cart {
    background-color: #f5f5f5;
    color: #333;
}

.egb-woo-cart-view-cart:hover {
    background-color: #e0e0e0;
    color: #333;
}

.egb-woo-cart-checkout {
    background-color: #0073aa;
    color: #ffffff;
}

.egb-woo-cart-checkout:hover {
    background-color: #005a87;
    color: #ffffff;
}

/* WooCommerce Checkout Button */
.egb-woo-checkout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    background-color: #27ae60;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.egb-woo-checkout-button:hover {
    background-color: #219a52;
    color: #ffffff;
}

.egb-woo-checkout-button.egb-woo-checkout--hidden {
    display: none;
}

/* Hide WooCommerce "View Cart" link when option is enabled */
.egb-woo-hide-view-cart + .added_to_cart,
.egb-woo-hide-view-cart + a.added_to_cart,
.egb-woo-hide-view-cart ~ .added_to_cart,
.egb-woo-hide-view-cart ~ a.added_to_cart {
    display: none !important;
}

/* Also hide any WC message that appears after the button */
.egb-woo-add-to-cart.egb-woo-hide-view-cart + .wc-forward,
.egb-woo-add-to-cart.egb-woo-hide-view-cart ~ .woocommerce-message {
    display: none !important;
}

/* Mini Cart Quantity Controls */
.egb-woo-cart-item-qty-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.egb-woo-qty-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
}

.egb-woo-qty-btn:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
}

.egb-woo-qty-btn:active {
    background-color: #d0d0d0;
    transform: scale(0.95);
}

.egb-woo-qty-value {
    min-width: 24px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

/* Loading state for cart item */
.egb-woo-cart-item--loading {
    opacity: 0.6;
    pointer-events: none;
}

.egb-woo-cart-item--loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #ddd;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: egb-woo-spin 0.6s linear infinite;
}

.egb-woo-cart-item {
    position: relative;
}

@keyframes egb-woo-spin {
    to { transform: rotate(360deg); }
}
