/**
 * GB Precious Metals - Frontend Styles
 *
 * Improved CSS with proper specificity and minimal !important usage
 * Following CSS best practices for maintainability and theme compatibility
 */

/* ==========================================================================
   "FROM" PRICE PREFIX (Shop/Archive Pages)
   ========================================================================== */

.gbpm-from-price-prefix {
    font-weight: 400;
    font-size: 0.85em;
    color: #6b7280;
    margin-right: 2px;
}

/* ==========================================================================
   QUANTITY BREAKS TABLE
   ========================================================================== */

.gbpm-quantity-breaks-table-container {
    margin: 0;
    overflow-x: hidden; /* Prevent horizontal scroll */
    width: 100%;
}

.gbpm-quantity-breaks-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    border: 1px solid #ddd;
}

/* Use auto table layout for taxable tables to allow minimum-width columns */
.gbpm-quantity-breaks-table.gbpm-taxable-table {
    table-layout: auto !important;
}

/* Remove any minimum width constraints to allow aggressive compression */

.gbpm-quantity-breaks-table th,
.gbpm-quantity-breaks-table td {
    padding: 8px;
    text-align: left;
    vertical-align: middle;
    border: 1px solid #ddd;
    border-collapse: collapse;
}

/* ==========================================================================
   COLUMN LAYOUTS - NON-TAXABLE (2-column) vs TAXABLE (4-column)
   ========================================================================== */

/* Non-taxable table (2-column layout) */
.gbpm-quantity-breaks-table.gbpm-non-taxable-table th:first-child,
.gbpm-quantity-breaks-table.gbpm-non-taxable-table td:first-child {
    width: 60%;
}

.gbpm-quantity-breaks-table.gbpm-non-taxable-table th:last-child,
.gbpm-quantity-breaks-table.gbpm-non-taxable-table td:last-child {
    width: 40%;
    text-align: center !important;
    white-space: nowrap;
}

/* Taxable table (4-column layout) */
.gbpm-quantity-breaks-table.gbpm-taxable-table th,
.gbpm-quantity-breaks-table.gbpm-taxable-table td {
    text-align: center !important;
    white-space: nowrap;
}

/* Price columns - use min-width to fit content exactly */
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(2),
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(2),
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(3),
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(3),
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(4),
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(4) {
    width: 1px !important; /* Forces minimum width */
    white-space: nowrap !important;
    text-align: center !important;
}

/* Minimal padding for price columns */
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(2),
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(3),
.gbpm-quantity-breaks-table.gbpm-taxable-table td:nth-child(4) {
    padding-left: 4px !important;
    padding-right: 4px !important;
}

/* Minimal padding for price headers */
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(2),
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(3),
.gbpm-quantity-breaks-table.gbpm-taxable-table th:nth-child(4) {
    padding-left: 4px !important;
    padding-right: 4px !important;
    font-size: 0.9em;
}

/* First column (Qty) takes all available space */
.gbpm-quantity-breaks-table.gbpm-taxable-table th:first-child,
.gbpm-quantity-breaks-table.gbpm-taxable-table td:first-child {
    width: auto !important; /* Takes remaining space */
    max-width: 0; /* Forces column to respect table width */
    text-align: left !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   PRICE CELL STYLING - Common styles for all price columns
   ========================================================================== */

.gbpm-quantity-breaks-table .gbpm-tier-price,
.gbpm-quantity-breaks-table .gbpm-tier-vat,
.gbpm-quantity-breaks-table .gbpm-tier-net {
    /* Reset any potential conflicting styles */
    display: table-cell !important;
    width: 100% !important;
    text-align: center !important;
    padding: 8px !important;
    margin: 0 !important;
    vertical-align: middle;
    border: 1px solid #ddd !important;
    /* Ensure consistent borders */
}

/* VAT column specific styling */
.gbpm-quantity-breaks-table .gbpm-tier-vat {
    font-size: 0.95em;
}

/* Net column specific styling */
.gbpm-quantity-breaks-table .gbpm-tier-net {
    /* Remove default font-weight to allow row highlighting to apply bold */
}

/* Remove background colors when row is highlighted */
.gbpm-quantity-breaks-table tbody tr.highlighted-tier .gbpm-tier-vat,
.gbpm-quantity-breaks-table tbody tr.highlighted-tier .gbpm-tier-net {
    background-color: transparent;
}

.gbpm-quantity-breaks-table .gbpm-tier-price .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-price .amount,
.gbpm-quantity-breaks-table .gbpm-tier-vat .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-vat .amount,
.gbpm-quantity-breaks-table .gbpm-tier-net .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-net .amount {
    display: inline-block !important;
    text-align: center !important;
    padding: 2px 5px !important;
    margin: 0 !important;
    white-space: nowrap !important;
    border-radius: 3px;
    transition: background-color 0.3s ease;
    border: none !important;
    box-shadow: none !important;
    width: auto !important;
}

.gbpm-quantity-breaks-table .gbpm-tier-price .woocommerce-Price-currencySymbol,
.gbpm-quantity-breaks-table .gbpm-tier-vat .woocommerce-Price-currencySymbol,
.gbpm-quantity-breaks-table .gbpm-tier-net .woocommerce-Price-currencySymbol {
    display: inline !important;
}

.gbpm-quantity-breaks-table th {
    background-color: #f8f8f8;
    font-weight: bold;
}

.gbpm-quantity-breaks-table tbody tr {
    transition: background-color 0.2s ease, border-left 0.2s ease;
}

.gbpm-quantity-breaks-table tbody tr.current-tier {
    background-color: #f5f5f5;
    font-weight: bold;
}

/* Special highlighting for packaging options */
.gbpm-quantity-breaks-table tbody tr.tube-option,
.gbpm-quantity-breaks-table tbody tr.monster-box-option {
    background-color: rgba(194, 159, 94, 0.15);
    border-left: 3px solid #c29f5e;
    font-weight: 500;
    position: relative;
}

/* Ensure all cells in packaging rows have the same background */
.gbpm-quantity-breaks-table tbody tr.tube-option td,
.gbpm-quantity-breaks-table tbody tr.monster-box-option td {
    background-color: rgba(194, 159, 94, 0.15) !important;
}

/* Add subtle icon or indicator for packaging */
.gbpm-quantity-breaks-table tbody tr.tube-option td:first-child::before {
    content: "📦 ";
    font-size: 14px;
    margin-right: 5px;
}

.gbpm-quantity-breaks-table tbody tr.monster-box-option td:first-child::before {
    content: "📦 ";
    font-size: 16px;
    margin-right: 5px;
}

/* When packaging rows are selected as current tier, use normal highlight */
.gbpm-quantity-breaks-table tbody tr.tube-option.current-tier,
.gbpm-quantity-breaks-table tbody tr.monster-box-option.current-tier,
.gbpm-quantity-breaks-table tbody tr.tube-option.highlighted-tier,
.gbpm-quantity-breaks-table tbody tr.monster-box-option.highlighted-tier {
    background-color: #f5f5f5;
    border-left: 3px solid #999;
    font-weight: bold;
}

/* Ensure all cells use the highlighted background */
.gbpm-quantity-breaks-table tbody tr.tube-option.highlighted-tier td,
.gbpm-quantity-breaks-table tbody tr.monster-box-option.highlighted-tier td {
    background-color: #f5f5f5 !important;
}

/* Hover effect for packaging options */
.gbpm-quantity-breaks-table tbody tr.tube-option:hover,
.gbpm-quantity-breaks-table tbody tr.monster-box-option:hover {
    background-color: rgba(194, 159, 94, 0.25);
    cursor: pointer;
}

/* ==========================================================================
   TAX DISPLAY ELEMENTS
   ========================================================================== */

/* Tax suffix styling in table headers */
.gbpm-quantity-breaks-table th .gbpm-tax-suffix {
    font-size: 0.85em;
    font-weight: normal;
    color: #666;
    font-style: italic;
    margin-left: 4px;
    white-space: nowrap;
}

/* Tax information styling for price cells */
.gbpm-tier-price[data-is-taxable="true"] {
    position: relative;
}

/* Tax status indicators for the table */
.gbpm-quantity-breaks-table[data-tax-status="taxable"][data-tax-display="incl"] th:last-child::after {
    content: "";
    /* Visual indicator for tax-inclusive pricing could be added here if needed */
}

/* Tax amount display (for future use if needed) */
.gbpm-tax-amount {
    font-size: 0.8em;
    color: #666;
    font-style: italic;
    display: block;
    margin-top: 2px;
}


/* ==========================================================================
   PRICE ANIMATIONS - Product Page & Shortcodes (White Background Optimized)
   ========================================================================== */

/* Price container animations - target product page and shortcode elements only */
.gbpm-product-price .woocommerce-Price-amount,
.gbpm-tier-price .woocommerce-Price-amount,
.gbpm-tier-vat .woocommerce-Price-amount,
.gbpm-tier-net .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-price .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-vat .woocommerce-Price-amount,
.gbpm-quantity-breaks-table .gbpm-tier-net .woocommerce-Price-amount,
.gbpm-shortcode .woocommerce-Price-amount,
.gbpm-shortcode-price .woocommerce-Price-amount {
    display: inline-block;
    padding: 2px 5px;
    border-radius: 3px;
    transition: background-color 0.3s ease;
    border: none !important;
    box-shadow: none !important;
}

/* Ensure shop/archive price amounts remain inline so the animation only hugs the number */
.woocommerce ul.products li.product .price .woocommerce-Price-amount,
.woocommerce div.product p.price .woocommerce-Price-amount {
    display: inline-block !important;
    width: auto !important;
}

/* Don't block animations on VAT and Net cells - let them work normally */

/* Animation classes applied by JavaScript - only up/down, no neutral */
.gbpm-price-up,
.price-up {
    animation: gbpm-price-flash-green 4s ease-out !important;
}

/* Fix typo: ensure scoped class also works */
.gbpm-price-down,
.price-down {
    animation: gbpm-price-flash-red 4s ease-out !important;
}

/* White background optimized animations */
@keyframes gbpm-price-flash-green {
    0% { background-color: rgba(76, 175, 80, 0.3); }
    50% { background-color: rgba(76, 175, 80, 0.3); }
    100% { background-color: transparent; }
}

@keyframes gbpm-price-flash-red {
    0% { background-color: rgba(244, 67, 54, 0.3); }
    50% { background-color: rgba(244, 67, 54, 0.3); }
    100% { background-color: transparent; }
}

/* ==========================================================================
   QUANTITY BUTTONS - Simplified with proper cascading
   ========================================================================== */

/* Base quantity button styles - use CSS custom properties for easy theming */
.gbpm-qty-btn {
    --gbpm-btn-width: 30px;
    --gbpm-btn-height: 40px;
    --gbpm-btn-bg: #c29f5e;
    --gbpm-btn-color: #ffffff;
    --gbpm-btn-border: none;
    
    display: inline-block;
    width: var(--gbpm-btn-width);
    height: var(--gbpm-btn-height);
    line-height: calc(var(--gbpm-btn-height) - 2px);
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    background: var(--gbpm-btn-bg);
    color: var(--gbpm-btn-color);
    border: var(--gbpm-btn-border);
    box-shadow: none;
    padding: 0;
    vertical-align: middle;
    border-radius: 0;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

/* Button variants */
.gbpm-qty-minus {
    border-radius: 3px 0 0 3px;
    margin-right: -1px;
}

.gbpm-qty-plus {
    border-radius: 0 3px 3px 0;
    margin-left: -1px;
}

/* Hover states */
.gbpm-qty-btn:hover {
    background: #c19543;
}

.gbpm-qty-btn:active {
    background: #c19543;
}

/* ==========================================================================
   PRODUCT FORM LAYOUT - Horizontal cart layout
   ========================================================================== */

/* Use a scoped approach for better maintainability */
.woocommerce .gbpm-cart-layout,
.woocommerce-page .gbpm-cart-layout {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: row;
    width: 100%;
    margin-bottom: 20px;
    gap: 10px;
}

/* Quantity container in horizontal layout */
.gbpm-cart-layout .quantity {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
    float: none;
}

/* Add to cart button in horizontal layout */
.gbpm-cart-layout .single_add_to_cart_button,
.woocommerce .gbpm-cart-layout .single_add_to_cart_button,
.woocommerce-page .gbpm-cart-layout .single_add_to_cart_button {
    flex: 1 !important;
    height: 40px !important;
    min-width: 150px;
    align-items: center !important;
    box-sizing: border-box;
    text-align: center !important;
    padding: 0 15px !important;
}

/* ==========================================================================
   QUANTITY INPUT STYLING
   ========================================================================== */

/* Quantity input field */
.gbpm-cart-layout .quantity .qty,
.quantity .qty[data-gbpm-styled] {
    height: 40px;
    text-align: center;
    width: 60px;
    margin: 0;
    padding: 0 8px;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 0;
    -moz-appearance: textfield;
    appearance: textfield;
    vertical-align: middle;
    line-height: normal;
}

/* Hide spin buttons on quantity input */
.quantity .qty[data-gbpm-styled]::-webkit-inner-spin-button,
.quantity .qty[data-gbpm-styled]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

/* ==========================================================================
   LOADING STATES
   ========================================================================== */

/* Loading state for price cells */
.gbpm-tier-price.gbpm-loading {
    position: relative;
    opacity: 0.6;
}

.gbpm-tier-price.gbpm-loading::after {
    content: "Updating...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    color: #666;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 5px;
    border-radius: 2px;
}

/* Pulse animation for loading elements */
@keyframes gbpm-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.gbpm-loading {
    animation: gbpm-pulse 1.5s infinite ease-in-out;
}

/* ==========================================================================
   THEME COMPATIBILITY OVERRIDES
   ========================================================================== */

/* 
 * Only use !important for critical layout issues that cannot be solved
 * with proper specificity. Keep these to an absolute minimum.
 */

/* Ensure quantity buttons are always visible regardless of theme */
.quantity .gbpm-qty-btn {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Prevent theme CSS from completely hiding our price elements */
.gbpm-product-price,
.gbpm-tier-price {
    display: inline-block !important;
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

/* Highlighted tier in quantity breaks table */
.gbpm-tier.highlighted-tier {
    background-color: #f5f5f5 !important;
    font-weight: 600;
}

/* Ensure all cells in highlighted row have the same background and inherit bold */
.gbpm-tier.highlighted-tier td {
    background-color: #f5f5f5 !important;
    font-weight: inherit !important;
}

/* Price display utilities */
.gbpm-price-display {
    font-weight: bold;
    display: inline-block;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

/* From price styling - inherits text color from parent */
.gbpm-from-price {
    font-weight: bold;
}

/* Last update timestamp styling */
.gbpm-last-update-text {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
    margin-top: 10px;
}

#gbpm-last-update-display {
    font-weight: bold;
}

/* ==========================================================================
   TOTAL PRICE DISPLAY
   ========================================================================== */

.gbpm-total-price-container {
    display: block;
    margin-top: -5px;
    line-height: 1.4;
    color: #000;
}

.gbpm-total-label {
    font-weight: 600;
    font-size: 14px;
    padding-left: 5px;
    color: #000;
}

.gbpm-total-price {
    display: inline-block;
    font-size: 16px;
    color: #000;
    font-weight: 600;
}

/* Total price container styling */
p.price .gbpm-total-price-container {
    font-size: inherit;
    font-weight: normal;
}

/* Price container spacing */
p.price {
    margin: 0;
    padding: 0;
    line-height: inherit;
}

/* ==========================================================================
   PRODUCT BADGES
   ========================================================================== */

/* CSS custom properties for badge theming */
:root {
    --gbpm-badge-gap: 4px;
    --gbpm-badge-margin-bottom: -3em;
    --gbpm-badge-padding: 6px 12px;
    --gbpm-badge-font-size: 12px;
    --gbpm-badge-border-radius: 4px;
}

/* Badge container above product image */
.gbpm-product-badges-container {
    display: flex;
    gap: var(--gbpm-badge-gap);
    margin-bottom: var(--gbpm-badge-margin-bottom);
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    /* Ensure badges don't inherit unwanted spacing from theme */
    line-height: 1;
    box-sizing: border-box;
    z-index: 99;
}

/* Base badge styling - now using external SVG files */
.gbpm-product-badge {
    display: inline-block;
    width: 70px;
    height: 70px;
    margin: 0;
    vertical-align: bottom;
    position: relative;
    cursor: help;
}

/* Tooltip styling */
.gbpm-product-badge::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    max-width: 300px;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    text-align: left;
    line-height: 1.3;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.1s ease-in, visibility 0.1s ease-in;
    transition-delay: 1s;
    z-index: 1000;
    pointer-events: none;
    margin-bottom: 5px;
}

.gbpm-product-badge::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.1s ease-in, visibility 0.1s ease-in;
    transition-delay: 1s;
    z-index: 1000;
    pointer-events: none;
}

.gbpm-product-badge:hover::after,
.gbpm-product-badge:hover::before {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */

/* Responsive adjustments for tablet and mobile */
@media (max-width: 1024px) {
    :root {
        --gbpm-badge-gap: 3px;
        --gbpm-badge-margin-bottom: 0.02em;
    }

    /* Ensure badges are visible on mobile */
    .gbpm-product-badges-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .gbpm-product-badge {
        display: inline-block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Smaller tooltips on mobile */
    .gbpm-product-badge::after {
        font-size: 11px;
        max-width: 220px;
        padding: 6px 10px;
    }
}