/* Ricerca Avanzata Plugin - Stili v3.1 FIXED */

/* Reset e container principale */
.ra-container * {
    box-sizing: border-box;
}

.ra-container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 0;
    overflow: visible; /* Cambiato da hidden per l'autocomplete */
    position: relative;
}

/* Header con search bar */
.ra-search-header {
    /* background: #0066cc; */
    border-bottom: 3px solid #0066cc;
    position: relative;
    border-radius: 0;
}

.ra-search-bar-wrapper {
    background: white;
    border-radius: 0;
    display: flex;
    align-items: center;
    padding: 0;
    overflow: hidden;
    min-height: 48px;
    position: relative;
}

.ra-search-icon {
    padding: 12px 15px;
    color: #0072DA;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ra-search-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    padding: 12px 0 !important;
    font-size: 16px;
    color: #333;
    background: transparent !important;
    min-width: 200px;
    box-shadow: none !important;
}

.ra-search-input::placeholder {
    color: #999;
}

.ra-search-input:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* Toggle button per aprire/chiudere la sezione */
.ra-toggle-section {
    padding: 10px 10px;
    background: #0072DA;
    border-radius: 0;
    cursor: pointer;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    height: 48px;
    width: 48px;
    border: 0;
}

.ra-toggle-section:hover, .ra-toggle-section:focus {
    background: #0072DA;
    color: white;
}

.ra-toggle-section:focus {
    outline: none;
}

.ra-chevron-icon {
    transition: transform 0.3s ease;
    pointer-events: none;
}

.ra-toggle-section.active .ra-chevron-icon {
    transform: rotate(180deg);
}

/* Selected tags */
.ra-selected-tags {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    flex-wrap: wrap;
}

.ra-selected-tag {
    background: #ECECEC;
    color: #0066cc;
    padding: 8px 10px;
    border-radius: 0;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0px solid #b3d9ff;
    white-space: nowrap;
    animation: tagFadeIn 0.2s ease;
    font-weight: 600;
    text-transform: uppercase;
}

@keyframes tagFadeIn {
    from { 
        opacity: 0;
        transform: scale(0.9);
    }
    to { 
        opacity: 1;
        transform: scale(1);
    }
}

.ra-remove-tag {
    cursor: pointer;
    width: 16px;
    height: 16px;
    background: none;
    color: #0072DA;
    border-radius: 0%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
}

.ra-remove-tag:hover {
    background: #fff;
}

.ra-clear-all {
    padding: 8px 15px;
    background: transparent;
    color: #666;
    border: none;
    cursor: pointer;
    font-size: 14px;
    margin-right: 10px;
    flex-shrink: 0;
    display: none;
}

.ra-clear-all:hover {
    color: #333;
    background: none;
}

/* Content area - FIXED */
.ra-content-wrapper {
    display: none;
    flex-direction: row;
    min-height: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    border-radius: 0 0 12px 12px;
}

/* Stato aperto - IMPORTANTE: usa display flex inline */
.ra-content-wrapper.open {
    display: flex !important;
    max-height: 400px !important;
    min-height: 300px;
    opacity: 1;
    overflow: visible;
    position: absolute;
    width: 100%;
    z-index: 200;
}

/* Sidebar con tags */
.ra-tags-sidebar {
    width: 300px;
    background: #F1F2FC;
    padding: 20px 16px;
    border-right: 1px solid #e0e0e0;
    max-height: 600px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Scrollbar personalizzata per la sidebar */
.ra-tags-sidebar::-webkit-scrollbar {
    width: 6px;
}

.ra-tags-sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.ra-tags-sidebar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.ra-tags-sidebar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.ra-sidebar-section {
    margin-bottom: 20px;
}

.ra-section-title {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 15px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid #e0e0e0;
}

.ra-tags-list {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex-wrap: wrap;
}

.ra-tag-filter {
    padding: 8px 16px;
    background: none;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 20px;
    color: #6557B8;
    border: none;
    position: relative;
    user-select: none;
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    text-transform: uppercase;
}

.ra-tag-count {
    background: #e0e0e0;
    color: #666;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    min-width: 20px;
    text-align: center;
    display: none;
}

.ra-tag-filter:hover {
    background: #e8f4ff;
    border-color: #b3d9ff;
    transform: translateX(2px);
}

.ra-tag-filter:hover .ra-tag-count {
    background: #b3d9ff;
    color: #0066cc;
}

.ra-tag-filter.active {
    background: #9c8fe8;
    color: white;
    border-color: #8b7dd6;
    transform: translateX(0);
}

.ra-tag-filter.active .ra-tag-count {
    background: rgba(255,255,255,0.3);
    color: white;
}

.ra-tag-filter.active::after {
    content: none;
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
}

/* Sidebar footer con opzioni */
.ra-sidebar-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.ra-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
}

.ra-checkbox-label input[type="checkbox"] {
    cursor: pointer;
}

.ra-no-tags {
    color: #999;
    font-style: italic;
    padding: 20px;
    text-align: center;
}

/* Results area */
.ra-search-results {
    flex: 1;
    padding: 25px;
    background: white;
    overflow-y: auto;
    max-height: 600px;
}

.ra-results-placeholder {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.ra-results-placeholder h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: #666;
    font-weight: 600;
}

.ra-results-placeholder p {
    margin: 0;
    font-size: 14px;
}

.ra-results-content {
    animation: fadeIn 0.3s ease-in;
}

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

.ra-result-item {
    padding: 0px 0 0 8px;
    border-left: 3px solid transparent;
    margin-bottom: 15px;
    background: none;
    border-radius: 0;
    transition: all 0.2s;
    cursor: pointer;
}

.ra-result-item:hover {
    background: #f1f2fc;
    border-left-color: #8a75db;
    transform: translateX(3px);
}

.ra-result-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    display: none;
}

.ra-result-category {
    background: #0066cc;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: inline-block;
}

.ra-result-date {
    color: #999;
    font-size: 12px;
}

.ra-result-item h3 {
    color: #101720;
    font-size: 20px;
    margin: 8px 0;
    font-weight: 400;
}

.ra-result-item h3 a {
    color: inherit;
    text-decoration: none;
}

.ra-result-item h3 a:hover {
    color: #0066cc;
}

.ra-result-item p {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
    margin: 8px 0 0 0;
    display: none;
}

.ra-result-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
    display: none;
}

.ra-result-tag {
    background: #f0f0f0;
    color: #666;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
}

/* Loading state */
.ra-loading {
    text-align: center;
    padding: 60px;
    color: #666;
}

.ra-loading::after {
    content: '';
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid #e0e0e0;
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

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

/* Autocomplete dropdown */
.ra-autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 20px;
    right: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
}

.ra-autocomplete-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    color: #333;
}

.ra-autocomplete-item:hover {
    background: #f8f9fa;
}

.ra-autocomplete-item:last-child {
    border-bottom: none;
}

.ra-autocomplete-item .highlight {
    background: #ffeb3b;
    font-weight: bold;
    padding: 0 2px;
}

/* No results */
.ra-no-results {
    text-align: center;
    padding: 40px;
    color: #999;
}

.ra-no-results h4 {
    color: #666;
    margin-bottom: 10px;
}

/* Responsive design */
@media (max-width: 768px) {
    .ra-content-wrapper.open {
        flex-direction: column;
        min-height: auto;
    }
    
    .ra-tags-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        padding: 15px;
        max-height: 300px;
    }
    
    .ra-tags-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .ra-tag-filter {
        font-size: 13px;
        padding: 8px 10px;
    }
    
    .ra-search-bar-wrapper {
        flex-wrap: wrap;
    }
    
    .ra-search-input {
        width: 100%;
        min-width: auto;
        padding: 10px !important;
    }
    
    .ra-selected-tags {
        width: 100%;
        order: 3;
        padding: 10px 0;
    }
    
    .ra-toggle-section {
        order: 2;
    }
}

/* WordPress admin bar fix */
.admin-bar .ra-autocomplete-dropdown {
    top: calc(100% + 10px);
    display: none;
}

/* Compatibilità con temi WordPress */
.ra-container input[type="text"]:focus {
    outline: none !important;
    box-shadow: none !important;
    border-color: transparent !important;
}

/* Fix per alcuni temi che sovrascrivono display flex */
.ra-content-wrapper[style*="display: flex"] {
    display: flex !important;
}

/* Debug - puoi rimuovere in produzione */
.ra-debug-info {
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 99999;
    display: none;
}

body.ra-debug .ra-debug-info {
    display: block;
}