.ctb-table-wrapper {
    margin-top: 20px !important;
    background: #fff !important;
    border-radius: 4px !important;
    overflow: visible !important;
    position: relative !important;
}

/* Create isolation context when modal is active */
.ctb-condition-help.active .ctb-table-wrapper {
    isolation: isolate !important;
    z-index: 1 !important;
}

.ctb-table-wrapper .table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 0 !important;
    overflow: visible !important;
}

.ctb-table-wrapper .table td {
    padding: 10px 12px !important;
    vertical-align: top !important;
    border: 1px solid #e5e5e5 !important;
    position: relative !important;
    overflow: visible !important;
    z-index: 1 !important;
}

.ctb-table-wrapper .table span {
    display: block !important;
}

.ctb-table-wrapper .table .ctb-label {
    font-family: Montserrat, sans-serif !important;
    font-size: 8px !important;
    font-weight: 400 !important;
    line-height: 10px !important;
    color: #666 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.4px !important;
    margin-top: 4px !important;
    display: inline-flex !important;
    align-items: center !important;
    position: relative !important;
}

.ctb-table-wrapper .table .ctb-value {
    font-family: Montserrat, sans-serif !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    text-transform: none !important;
    line-height: 16px !important;
    color: #000 !important;
    margin-top: 0!important;
    margin-bottom: 4px !important;
    display: block !important;
}

.ctb-table-wrapper .table .condition-value {
    text-align: center !important;
    font-weight: 700 !important;
    font-size: 11px !important;
}

/* Condition color coding - Maximum specificity */
.ctb-table-wrapper .table .ctb-value.condition-value.condition-new,
.ctb-table-wrapper .table .condition-new,
body .ctb-table-wrapper .condition-new,
.ctb-table-wrapper .table .ctb-value.condition-value.condition-like-new,
.ctb-table-wrapper .table .condition-like-new,
body .ctb-table-wrapper .condition-like-new,
.ctb-table-wrapper .table .ctb-value.condition-value.condition-excellent,
.ctb-table-wrapper .table .condition-excellent,
body .ctb-table-wrapper .condition-excellent {
    color: #0B9919 !important; /* Green for excellent conditions */
}

.ctb-table-wrapper .table .ctb-value.condition-value.condition-very-good,
.ctb-table-wrapper .table .condition-very-good,
body .ctb-table-wrapper .condition-very-good,
.ctb-table-wrapper .table .ctb-value.condition-value.condition-good,
.ctb-table-wrapper .table .condition-good,
body .ctb-table-wrapper .condition-good {
    color: #28A745 !important; /* Light green for good conditions */
}

.ctb-table-wrapper .table .ctb-value.condition-value.condition-fair,
.ctb-table-wrapper .table .condition-fair,
body .ctb-table-wrapper .condition-fair,
.ctb-table-wrapper .table .ctb-value.condition-value.condition-used,
.ctb-table-wrapper .table .condition-used,
body .ctb-table-wrapper .condition-used {
    color: #FFA500 !important; /* Orange for fair/used */
}

.ctb-table-wrapper .table .ctb-value.condition-value.condition-poor,
.ctb-table-wrapper .table .condition-poor,
body .ctb-table-wrapper .condition-poor {
    color: #DC3545 !important; /* Red for poor condition */
}

.ctb-table-wrapper .table .ctb-value.condition-value.condition-refurbished,
.ctb-table-wrapper .table .condition-refurbished,
body .ctb-table-wrapper .condition-refurbished {
    color: #007BFF !important; /* Blue for refurbished */
}

.ctb-table-wrapper .table .ctb-value.condition-value.condition-n-a,
.ctb-table-wrapper .table .condition-n-a,
body .ctb-table-wrapper .condition-n-a {
    color: #999 !important; /* Gray for N/A */
}

/* Ensure Year value stays black */
.ctb-table-wrapper .table .ctb-value:not(.condition-value),
body .ctb-table-wrapper .table .ctb-value:not(.condition-value) {
    color: #000 !important;
}

/* WooCommerce sidebar styling */
.woocommerce-page .ctb-table-wrapper,
.single-product .ctb-table-wrapper,
.woocommerce .ctb-table-wrapper,
.product .ctb-table-wrapper,
body.single-product .ctb-table-wrapper {
    margin: 0 0 20px 0 !important;
    padding: 0 !important;
}

.woocommerce-page .ctb-table-wrapper .table,
.single-product .ctb-table-wrapper .table,
.woocommerce .ctb-table-wrapper .table,
.product .ctb-table-wrapper .table,
body.single-product .ctb-table-wrapper .table {
    margin-bottom: 0 !important;
}

/* Ensure condition colors work on frontend */
body.single-product .ctb-table-wrapper .table .ctb-value.condition-value,
.woocommerce .ctb-table-wrapper .table .ctb-value.condition-value,
.product .ctb-table-wrapper .table .ctb-value.condition-value {
    text-align: center !important;
    font-weight: 700 !important;
    font-size: 11px !important;
}

/* ========================================
   Apple-Style Condition Help Tooltip
   ======================================== */

.ctb-condition-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f5f5f7;
    border: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 11px;
    line-height: 15px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    margin-left: 6px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.ctb-condition-help:hover,
.ctb-condition-help.active {
    background: #fff ;
    border-color: rgba(0, 113, 227, 0.3);
    color: #0071e3;
}

.ctb-condition-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    right: -10px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 12px 14px;
    min-width: 260px;
    max-width: 300px;
    box-shadow: 
        0 8px 24px rgba(0, 0, 0, 0.12),
        0 2px 6px rgba(0, 0, 0, 0.08),
        0 0 0 0.5px rgba(0, 0, 0, 0.04);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999999 !important;
    pointer-events: none;
}

.ctb-condition-help.active .ctb-condition-tooltip {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
    display: block !important;
}

/* Active button styling */
.ctb-condition-help.active {
    background: #fff !important;
    border-color: rgba(0, 113, 227, 0.3) !important;
    color: #0071e3 !important;
}

/* Modal backdrop positioning */
.ctb-condition-help.active::after {
    z-index: 999998 !important;
}

/* Modal tooltip positioning */
.ctb-condition-help.active .ctb-condition-tooltip {
    z-index: 999999 !important;
}

/* Tooltip arrow */
.ctb-condition-tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    right: 18px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(255, 255, 255, 0.98);
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.05));
}

.ctb-condition-tooltip strong {
    display: block;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #1d1d1f;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.ctb-tooltip-item {
    display: flex;
    margin-bottom: 6px;
    line-height: 1.3;
    gap: 6px;
}

.ctb-tooltip-item:last-child {
    margin-bottom: 0;
}

.ctb-tooltip-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    font-size: 11px;
    font-weight: 600;
    color: #1d1d1f;
    min-width: 70px;
    flex-shrink: 0;
}

.ctb-tooltip-desc {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    font-size: 11px;
    font-weight: 400;
    color: #6e6e73;
    line-height: 1.4;
}

/* Highlight current condition */
.ctb-tooltip-item.current-condition {
    background: rgba(0, 113, 227, 0.08);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 2px -4px;
    border-left: 3px solid #0071e3;
}

.ctb-tooltip-item.current-condition .ctb-tooltip-label {
    color: #0071e3;
    font-weight: 700;
}

.ctb-tooltip-item.current-condition .ctb-tooltip-desc {
    color: #1d1d1f;
    font-weight: 500;
}

/* Modal backdrop for active state */
.ctb-condition-help.active::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999998 !important;
    opacity: 0;
    animation: fadeInBackdrop 0.3s ease forwards;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

@keyframes fadeInBackdrop {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Close button for modal */
.ctb-condition-help.active .ctb-condition-tooltip::after {
    content: '×';
    position: absolute;
    top: 8px;
    right: 12px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 300;
    color: #999;
    cursor: pointer;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.ctb-condition-help.active .ctb-condition-tooltip::after:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #666;
}

/* Mobile modal tooltip */
@media screen and (max-width: 1024px) {
    .ctb-condition-tooltip {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translate(-50%, -50%) scale(0.9) !important;
        min-width: 300px;
        max-width: calc(100vw - 30px);
        max-height: calc(100vh - 60px);
        overflow-y: auto;
        padding: 20px;
        border-radius: 12px;
        box-shadow: 
            0 20px 40px rgba(0, 0, 0, 0.25),
            0 8px 16px rgba(0, 0, 0, 0.15);
    }
    
    .ctb-condition-help.active .ctb-condition-tooltip {
        transform: translate(-50%, -50%) scale(1) !important;
    }
    
    /* Remove arrow on mobile */
    .ctb-condition-tooltip::before {
        display: none !important;
    }
    
    /* Compact mobile layout */
    .ctb-tooltip-item {
        margin-bottom: 8px;
        flex-direction: row;
        gap: 8px;
        align-items: flex-start;
    }
    
    .ctb-tooltip-label {
        min-width: 70px;
        font-size: 11px;
        font-weight: 600;
        flex-shrink: 0;
    }
    
    .ctb-tooltip-desc {
        font-size: 11px;
        line-height: 1.4;
        flex: 1;
    }
    
    .ctb-condition-tooltip strong {
        font-size: 14px;
        text-align: center;
        margin-bottom: 12px;
        padding-bottom: 8px;
    }
}

/* Desktop modal positioning when active */
@media screen and (min-width: 1025px) {
    .ctb-condition-help.active .ctb-condition-tooltip {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translate(-50%, -50%) scale(1) !important;
        min-width: 320px;
        max-width: 400px;
        padding: 20px;
        border-radius: 12px;
        box-shadow: 
            0 20px 40px rgba(0, 0, 0, 0.25),
            0 8px 16px rgba(0, 0, 0, 0.15);
    }
    
    /* Remove arrow on desktop modal */
    .ctb-condition-help.active .ctb-condition-tooltip::before {
        display: none !important;
    }
}

/* Extra small mobile devices */
@media screen and (max-width: 480px) {
    .ctb-condition-help {
        width: 14px;
        height: 14px;
        font-size: 10px;
    }
    
    .ctb-condition-tooltip {
        min-width: 260px;
        max-width: calc(100vw - 30px);
        padding: 12px 14px;
    }
    
    .ctb-tooltip-item {
        margin-bottom: 6px;
    }
}

/* Responsive improvements */
@media screen and (max-width: 768px) {
    .ctb-table-wrapper .table .ctb-label {
        font-size: 7px !important;
        line-height: 9px !important;
    }
    
    .ctb-table-wrapper .table .ctb-value {
        font-size: 11px !important;
        line-height: 14px !important;
    }
    
    .ctb-table-wrapper .table .condition-value {
        font-size: 10px !important;
    }
    
    .ctb-table-wrapper .table td {
        padding: 8px 10px !important;
    }
}
