/**
 * AI Search Block frontend styles
 */

.ai-search-block {
    margin: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

.ai-search-charts {
    display: grid;
    gap: 20px;
    /* Mobile first - one column */
    grid-template-columns: 1fr;
    grid-auto-columns: 1fr; /* Force equal width columns */
    width: 100%;
}

/* Tablet - two columns */
@media (min-width: 768px) {
    .ai-search-charts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Desktop - three columns */
@media (min-width: 1024px) {
    .ai-search-charts {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.ai-search-chart-container {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    background-color: #f9f9f9;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 250px;
    transform: translateZ(0); /* Force hardware acceleration */
    min-height: 200px;
    transition: transform 0.3s ease;
    contain: layout style;
}

/* Ensure animation optimizations for all child elements */
.ai-search-chart-container,
.ai-search-chart-container * {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Chart wrapper to contain the canvas */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 200px; /* Ensure minimum height */
    visibility: visible !important; /* Always keep visible */
    transform: translateZ(0); /* Force hardware acceleration */
    backface-visibility: hidden; /* Prevent flickering */
    will-change: transform; /* Hint to browser that this element will change */
    contain: strict; /* Improve performance */
    cursor: pointer; /* Show hand cursor to indicate clickability */
    transition: all 0.3s ease; /* Smooth transitions for hover effects */
}

/* Add an overlay to keep charts interactive even during transitions */
.chart-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    background: transparent;
    transition: all 0.3s ease;
}

/* Hover effect to indicate chart is clickable */
.chart-wrapper:hover::after {
    background: rgba(255, 159, 0, 0.05); /* Very subtle orange highlight on hover */
    box-shadow: inset 0 0 0 2px #FF9F00; /* Add border on hover */
}
}

.ai-search-chart {
    display: block !important; /* Force display even during transitions */
    width: 100% !important;
    height: 100% !important;
    visibility: visible !important; /* Force visibility */
    opacity: 1 !important; /* Force opacity */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    perspective: 1000px;
    contain: strict;
}

.ai-search-chart-container:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.ai-search-chart-title {
    text-align: center;
    margin-bottom: 15px;
    /* Prevent long titles from expanding containers */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Action section styles */
.chart-actions {
    margin-top: 15px;
    display: flex;
    justify-content: center;
}

.ai-search-download-btn {
    background-color: #4b4fcb;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: center;
    font-weight: 500;
}

.ai-search-download-btn:hover {
    background-color: #3a3e9d;
}

.ai-search-download-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(75, 79, 203, 0.4);
}

/* Enhanced Modal styles with animations */
.ai-search-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    transition: background-color 0.4s ease, backdrop-filter 0.4s ease;
}

/* Modal active state */
.ai-search-modal.active {
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ai-search-modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    transform: scale(0.7);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
                opacity 0.35s ease,
                margin 0.35s ease;
}

/* Modal content active state */
.ai-search-modal.active .ai-search-modal-content {
    transform: scale(1);
    opacity: 1;
    margin: 5% auto;
}

.ai-search-modal-close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.2s ease;
    transform-origin: center;
}

.ai-search-modal-close:hover,
.ai-search-modal-close:focus {
    color: #000;
    text-decoration: none;
    transform: rotate(90deg);
}

.ai-search-modal-chart-container {
    margin-top: 20px;
    height: 400px;
    position: relative;
    width: 100%;
    overflow: hidden; /* Contains any overflow from canvas */
}

.ai-search-timeline-chart {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    opacity: 0;
    transition: opacity 0.5s ease 0.2s; /* Delayed fade-in for chart */
}

.ai-search-modal.active .ai-search-timeline-chart {
    opacity: 1;
}

/* Force canvas to stay rendered during transitions */
@media (max-width: 1200px) {
    canvas.ai-search-chart {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(75, 79, 203, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(75, 79, 203, 0); }
    100% { box-shadow: 0 0 0 0 rgba(75, 79, 203, 0); }
}

/* Industry Filter Styles */
.ai-search-industry-filter,
.ai-industry-filter {
    margin-bottom: 30px;
    padding: 15px;
    background-color: #f0f0f0;
    border-radius: 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ai-search-industry-filter form,
.ai-industry-filter form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
}

.ai-search-industry-filter label,
.ai-industry-filter label {
    margin-right: 15px;
    font-weight: 600;
    min-width: 120px;
    color: #333;
}

.ai-search-industry-filter select,
.ai-industry-filter select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    flex-grow: 1;
    max-width: 300px;
    background-color: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    transition: all 0.2s ease;
}

/* Add a focus state for accessibility */
.ai-search-industry-filter select:focus,
.ai-industry-filter select:focus {
    outline: 2px solid #4b4fcb;
    border-color: #4b4fcb;
    box-shadow: 0 0 0 3px rgba(75, 79, 203, 0.2);
}

/* Add hover effect */
.ai-search-industry-filter select:hover,
.ai-industry-filter select:hover {
    border-color: #999;
}

/* Make sure the filter works well on mobile */
@media (max-width: 576px) {
    .ai-search-industry-filter,
    .ai-industry-filter {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .ai-search-industry-filter label,
    .ai-industry-filter label {
        margin-bottom: 8px;
    }
    
    .ai-search-industry-filter select,
    .ai-industry-filter select {
        width: 100%;
        max-width: 100%;
    }
}