/* 1. FORCE TOOLTIP TO HIDE & PREVENT LEAKAGE */
.ai-btn-container .ai-tooltip {
    display: block !important;
    visibility: hidden !important; /* Prevents rendering even if parent card overrides opacity */
    opacity: 0 !important;
    position: absolute !important;
    bottom: 135% !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(4px) !important;
    background-color: #0f172a !important;
    color: #f8fafc !important;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    font-size: 0.75rem !important;
    font-family: system-ui, sans-serif !important;
    white-space: nowrap !important;
    transition: opacity 0.2s ease, transform 0.2s ease !important;
    border: 1px solid #475569 !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2) !important;
    z-index: 99999 !important;
    width: auto !important;
    height: auto !important;
}

/* Tooltip Arrow */
.ai-btn-container .ai-tooltip::after {
    content: "" !important;
    position: absolute !important;
    top: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    border-width: 5px !important;
    border-style: solid !important;
    border-color: #0f172a transparent transparent transparent !important;
}

/* Show Tooltip cleanly on Hover */
.ai-btn-containeroramax:hover .ai-tooltip,
.ai-btn-container:hover .ai-tooltip {
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateX(-50%) translateY(0) !important;
}

/* 2. STRIP EXTERNAL BUTTON STYLES & FORCE HORIZONTAL LAYOUT */
.ai-btn-container .ai-explain-btn {
    all: unset !important; /* Strips default button styles and card leaks */
    box-sizing: border-box !important;
    position: relative !important;
    
    /* Strict Horizontal Row Orientation */
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    
    /* Fixed Dimensions to Stop Talling/Stretching */
    width: max-content !important;
    height: 38px !important; 
    padding: 0 20px !important;
    
    /* Purple Linear Gradient Force */
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%) !important;
    background-size: 200% auto !important;
    border-radius: 8px !important;
    
    /* Typography */
    font-size: 0.9rem !important;
    font-weight: 600 !important;
    font-family: system-ui, sans-serif !important;
    color: #ffffff !important;
    
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.25) !important;
}

/* Hover States */
.ai-btn-container .ai-explain-btn:hover {
    background-position: right center !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4) !important;
}

.ai-btn-container .ai-explain-btn:active {
    transform: translateY(0) !important;
}

/* Icon Dimensions Setup */
.ai-btn-container .ai-icon {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    fill: #ffffff !important;
    display: inline-block !important;
}

.ai-btn-container .ai-btn-text {
    display: inline !important;
    color: #ffffff !important;
    white-space: nowrap !important;
}.ai-btn-container {
    position: relative;
    display: inline-block;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-sizing: border-box;
}

.ai-btn-container *, 
.ai-btn-container *::before, 
.ai-btn-container *::after {
    box-sizing: border-box;
}

/* Button Design */
.ai-btn-container .ai-explain-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #ffffff;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    background-size: 200% auto;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.25);
    margin: 0;
}

/* Glowing Outer Ring border effect */
.ai-btn-container .ai-explain-btn::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
    border-radius: 10px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Hover States */
.ai-btn-container .ai-explain-btn:hover {
    background-position: right center;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
}

.ai-btn-container .ai-explain-btn:hover::before {
    opacity: 1;
}

/* Active Press States */
.ai-btn-container .ai-explain-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.4);
}

/* Icon Animation setup */
.ai-btn-container .ai-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
    transition: transform 0.3s ease;
}

.ai-btn-container .ai-explain-btn:hover .ai-icon {
    transform: rotate(15deg) scale(1.1);
}

/* Self-Contained Tooltip CSS */
.ai-btn-container .ai-tooltip {
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background-color: #0f172a;
    color: #f8fafc;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    border: 1px solid #475569;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* Tooltip Arrow */
.ai-btn-container .ai-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: #0f172a transparent transparent transparent;
}

/* Tooltip trigger */
.ai-btn-container:hover .ai-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* JavaScript Loading/Processing Overrides */
.ai-btn-container .ai-explain-btn.is-loading {
    pointer-events: none;
    background: #334155;
    color: #94a3b8;
    box-shadow: none;
}

.ai-btn-container .ai-explain-btn.is-loading .ai-icon {
    animation: aiPulse 1.5s infinite ease-in-out;
}

@keyframes aiPulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 1; }
}
