/**
 * SELECT2 FRONTEND STYLES - Libreria Sync
 * 
 * Stili personalizzati per Select2 nel frontend WooCommerce
 */

/* ==========================================================================
   BASE SELECT2 FRONTEND STYLING
   ========================================================================== */

/* Container principale per filtri */
.libreria-author-filter-widget .select2-container--open .select2-selection, 
.libreria-publisher-filter-widget .select2-container--open .select2-selection {
     background: #ffffff !important;
}


.libreria-author-filter-widget,
.libreria-publisher-filter-widget {
    margin: 20px 0;
    padding: 15px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.libreria-author-filter-widget h3,
.libreria-publisher-filter-widget h3 {
    margin: 0 0 12px 0 !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    color: #2c3338 !important;
    border-bottom: 2px solid #f0f0f1;
    padding-bottom: 8px;
}

/* Select2 Container Frontend */
.libreria-filter-authors.select2-container,
.libreria-filter-publishers.select2-container {
    width: 100% !important;
    font-family: inherit !important;
}

/* Select2 Selection Frontend */
.libreria-filter-authors .select2-selection,
.libreria-filter-publishers .select2-selection {
    border: 2px solid #ddd !important;
    border-radius: 6px !important;
    min-height: 44px !important;
    padding: 8px 12px !important;
    font-size: 15px !important;
    background: #ffffff !important;
    transition: all 0.3s ease !important;
}

.libreria-filter-authors .select2-selection:hover,
.libreria-filter-publishers .select2-selection:hover {
    border-color: #999 !important;
    box-shadow: 0 0 0 2px rgba(255, 129, 37, 0.1) !important;
}

.libreria-filter-authors .select2-selection:focus,
.libreria-filter-publishers .select2-selection:focus,
.libreria-filter-authors.select2-container--open .select2-selection,
.libreria-filter-publishers.select2-container--open .select2-selection {
    border-color: #FF8125 !important;
    box-shadow: 0 0 0 3px rgba(255, 129, 37, 0.15) !important;
    outline: none !important;
    background: #fff !important;
}

/* Selection Text Frontend */
.libreria-filter-authors .select2-selection__rendered,
.libreria-filter-publishers .select2-selection__rendered {
    line-height: 28px !important;
    padding: 0 !important;
    color: #495057 !important;
    font-weight: 500 !important;
}

.libreria-filter-authors .select2-selection__placeholder,
.libreria-filter-publishers .select2-selection__placeholder {
    color: #6c757d !important;
    font-style: italic !important;
    font-weight: normal !important;
}

/* Arrow Frontend */
.libreria-filter-authors .select2-selection__arrow,
.libreria-filter-publishers .select2-selection__arrow {
    height: 100% !important;
    right: 12px !important;
    width: 20px !important;
}

.libreria-filter-authors .select2-selection__arrow b,
.libreria-filter-publishers .select2-selection__arrow b {
    border-color: #6c757d transparent transparent transparent !important;
    border-style: solid !important;
    border-width: 6px 6px 0 6px !important;
    height: 0 !important;
    left: 50% !important;
    margin-left: -6px !important;
    margin-top: -3px !important;
    position: absolute !important;
    top: 50% !important;
    width: 0 !important;
    transition: transform 0.2s ease !important;
}

.libreria-filter-authors.select2-container--open .select2-selection__arrow b,
.libreria-filter-publishers.select2-container--open .select2-selection__arrow b {
    transform: rotate(180deg) !important;
}

/* Clear Button Frontend */
.libreria-filter-authors .select2-selection__clear,
.libreria-filter-publishers .select2-selection__clear {
    color: #dc3545 !important;
    cursor: pointer !important;
    float: right !important;
    font-size: 18px !important;
    font-weight: bold !important;
    margin-right: 25px !important;
    padding: 0 8px !important;
    transition: color 0.2s ease !important;
}

.libreria-filter-authors .select2-selection__clear:hover,
.libreria-filter-publishers .select2-selection__clear:hover {
    color: #c82333 !important;
    transform: scale(1.1) !important;
}

/* ==========================================================================
   DROPDOWN STYLING
   ========================================================================== */

/* Dropdown Container */
.select2-dropdown {
    border: 1px solid #FF8125 !important;
    border-top: none !important;
    border-radius: 0 0 8px 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    z-index: 9999 !important;
    background: #ffffff !important;
}

/* Search Input */
.select2-search--dropdown .select2-search__field {
    padding: 4px 8px !important;
    width: 100% !important;
    margin: 8px !important;
    height: 20px !important;
    font-size: 15px !important;
    width: calc(100% - 16px) !important;
}
}

.select2-search--dropdown .select2-search__field:focus {
    /*border-color: #FF8125 !important;
    box-shadow: 0 0 0 2px rgba(255, 129, 37, 0.15) !important;*/
    outline: none !important;
}

/* Results Container */
.select2-results {
    max-height: 250px !important;
    padding: 4px 0 !important;
}

/* Individual Results */
.select2-results__option {
    font-size: 15px !important;
    line-height: 1.5 !important;
    padding: 12px 16px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    border-bottom: 1px solid #f8f9fa !important;
}

.select2-results__option:last-child {
    border-bottom: none !important;
}

.select2-results__option--highlighted {
    background: linear-gradient(135deg, #FF8125, #E5742C) !important;
    color: white !important;
    transform: translateX(2px) !important;
}

.select2-results__option--selected {
    background: #FFF4E6 !important;
    color: #E5742C !important;
    font-weight: 600 !important;
}

.select2-results__option[aria-disabled="true"] {
    color: #6c757d !important;
    cursor: default !important;
}

/* ==========================================================================
   CUSTOM RESULT TEMPLATES
   ========================================================================== */

/* Author Filter Results */
.select2-result-author-filter {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.select2-result-author-filter .select2-result-name {
    font-weight: 500;
    color: inherit;
    flex: 1;
}

.select2-result-author-filter .select2-result-count {
    font-size: 12px;
    color: #6c757d;
    padding: 2px 6px;
    font-weight: 600;
    min-width: fit-content;
}

.select2-results__option--highlighted .select2-result-author-filter .select2-result-count {
    background: rgba(255, 255, 255, 0.2) !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

/* Publisher Filter Results */
.select2-result-publisher-filter {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.select2-result-publisher-filter .select2-result-name {
    font-weight: 500;
    color: inherit;
    flex: 1;
}

.select2-result-publisher-filter .select2-result-count {
    font-size: 12px;
    color: #6c757d;
    padding: 2px 6px;
    font-weight: 600;
    min-width: fit-content;
}

.select2-results__option--highlighted .select2-result-publisher-filter .select2-result-count {
    background: rgba(255, 255, 255, 0.2) !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

/* ==========================================================================
   LOADING & MESSAGE STATES
   ========================================================================== */

/* Loading State */
.select2-results__option--loading {
    color: #6c757d !important;
    font-style: italic !important;
    text-align: center !important;
    padding: 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
}

.select2-results__option--loading::before {
    content: "" !important;
    display: inline-block !important;
    width: 16px !important;
    height: 16px !important;
    border: 2px solid #f3f3f3 !important;
    border-top: 2px solid #FF8125 !important;
    animation: spin 1s linear infinite !important;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* No Results */
.select2-results__message {
    color: #6c757d !important;
    font-size:12px !important;
    font-style: italic !important;
    text-align: center !important;
    background: #f8f9fa !important;
    margin: 8px !important;    
}

/* ==========================================================================
   ALPHABET FILTER STYLING
   ========================================================================== */

.libreria-alphabet-filter {
    margin: 20px 0;
    padding: 20px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.libreria-alphabet-filter h3 {
    margin: 0 0 15px 0 !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    color: #2c3338 !important;
    border-bottom: 2px solid #f0f0f1;
    padding-bottom: 8px;
}

.alphabet-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.alphabet-btn {
    display: inline-block;
    padding: 8px 12px;
    color: #495057;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
    border: 1px solid #dee2e6;
    min-width: 40px;
    text-align: center;
}

.alphabet-btn:hover {
    background: #e9ecef;
    color: #495057;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.alphabet-btn.active {
    background: #FF8125;
    color: white;
    border-color: #FF8125;
    font-weight: 600;
}

.alphabet-btn.active:hover {
    background: #E5742C;
    border-color: #E5742C;
    color: white;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 768px) {
    .libreria-author-filter-widget,
    .libreria-publisher-filter-widget {
        margin: 15px 0;
        padding: 12px;
    }
    
    .libreria-filter-authors .select2-selection,
    .libreria-filter-publishers .select2-selection {
        min-height: 50px !important;
        padding: 12px 15px !important;
        font-size: 16px !important;
    }
    
    .select2-results__option {
        padding: 15px 16px !important;
        font-size: 16px !important;
    }
    
    .alphabet-buttons {
        gap: 4px;
    }
    
    .alphabet-btn {
        padding: 10px 8px;
        min-width: 36px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .libreria-author-filter-widget,
    .libreria-publisher-filter-widget,
    .libreria-alphabet-filter {
        margin: 10px -15px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .alphabet-buttons {
        gap: 3px;
    }
    
    .alphabet-btn {
        padding: 8px 6px;
        min-width: 32px;
        font-size: 12px;
    }
}

/* ==========================================================================
   WOOCOMMERCE INTEGRATION
   ========================================================================== */

.widget-area .libreria-author-filter-widget,
.widget-area .libreria-publisher-filter-widget {
    background: inherit;
    border: none;
    box-shadow: none;
    padding: 0;
}

.widget-area .libreria-author-filter-widget h3,
.widget-area .libreria-publisher-filter-widget h3 {
    font-size: inherit !important;
    margin-bottom: 10px !important;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.woocommerce .libreria-author-filter-widget,
.woocommerce .libreria-publisher-filter-widget {
    margin-bottom: 30px;
}

/* ==========================================================================
   ACCESSIBILITY & ANIMATIONS
   ========================================================================== */

.select2-search--dropdown .select2-search__field:focus,
.libreria-filter-authors.select2-container--open .select2-selection,
.libreria-filter-publishers.select2-container--open .select2-selection {
    outline: 1px solid #FF8125 !important;
    outline-offset: 1px !important;
}

.select2-results__option:focus {
    outline: 1px solid #FF8125 !important;
    outline-offset: 1px !important;
}

.select2-dropdown {
    animation: fadeInDown 0.2s ease-out;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.libreria-author-filter-widget,
.libreria-publisher-filter-widget {
    animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .select2-dropdown,
    .libreria-author-filter-widget,
    .libreria-publisher-filter-widget {
        animation: none !important;
    }
}

/* ==========================================================================
   CUSTOM SCROLLBAR
   ========================================================================== */

.select2-results::-webkit-scrollbar {
    width: 8px;
}

.select2-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.select2-results::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.select2-results::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.select2-results {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* ==========================================================================
   UTILITIES
   ========================================================================== */

.libreria-author-filter-widget h3,
.libreria-publisher-filter-widget h3,
.alphabet-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}




.select2-container--default .select2-dropdown {
    max-height: 300px !important;
}

.select2-results__options {
    max-height: 250px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* Fix altezza campo selezione single */
.select2-container--default .select2-selection--single {
/*
    min-height: 38px !important;
    height: 38px !important;
*/
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
}

/* Fix per selezione multipla */
.select2-container--default .select2-selection--multiple {
     
}


/* Fix elementi selezionati (tag) */
.select2-selection__choice {
    height: 28px !important;
    line-height: 26px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #e4e4e4 !important;
    border: 1px solid #444 !important;
    border-radius: 4px !important;
    color: #333;
    cursor: default !important;
    float: left !important;
    margin-right: 5px !important;
    margin-top: 5px !important;
    padding: 4px 14px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    line-height: 20px !important;
    height: auto !important;
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #333 !important;
    cursor: pointer !important;
    display: inline-block !important;
    font-size: 16px !important;
    font-weight: bold !important;
    margin-left: 4px !important;
    transition: color 0.2s ease !important;
    text-decoration: none !important;
    line-height: 1 !important;
    padding: 0 !important;
    background: none !important;
    border: none !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #FF8125 !important;
    background-color: rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    transform: scale(1.1) !important;
}