/* ============================================
   ACTIONS DU HEADER - STYLES HARMONISÉS
   Boutons : Recherche, Historique, Accessibilité
   ============================================ */

/* ====================================
   STYLES COMMUNS - LES 3 BOUTONS
   ==================================== */

.header-action-btn {
    width: 48px;
    height: 48px;
    padding: 0;
    border: 2px solid #2270b2;
    border-radius: 50%;
    background-color: #fff;
    color: #2270b2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
}

.header-action-btn:hover {
    background-color: #2270b2;
    border-color: #2270b2;
    color: #fff;
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.3);
    transform: translateY(-2px);
}

.header-action-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.2);
}

.header-action-btn:focus-visible {
    outline: 3px solid rgba(13, 110, 253, 0.5);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.header-action-btn .bi,
.header-action-btn .material-icons {
    font-size: 1.25rem;
    line-height: 1;
}

/* ====================================
   RECHERCHE GLOBALE - CONTENEUR
   ==================================== */

#global-search-container {
    position: relative;
    width: 48px;
    height: 48px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#global-search-container.search-active {
    width: 350px;
}

/* ====================================
   RECHERCHE - BOUTON DÉCLENCHEUR
   ==================================== */

#global-search-trigger {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 10;
}

#global-search-container.search-active #global-search-trigger {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* ====================================
   RECHERCHE - FORMULAIRE
   ==================================== */

#global-client-search-form {
    position: absolute;
    top: 0;
    right: 0;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
    transform-origin: right center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9;
}

#global-search-container.search-active #global-client-search-form {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

/* ====================================
   RECHERCHE - INPUT GROUP
   ==================================== */

#global-client-search-form .input-group {
    background-color: #fff;
    border: 2px solid #2270b2;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.2);
    transition: all 0.2s ease;
    height: 48px;
}

#global-client-search-form .input-group:focus-within {
    box-shadow: 0 6px 16px rgba(13, 110, 253, 0.3);
}

#global-client-search-form .input-group-text:first-child {
    background-color: transparent;
    border: none;
    padding-left: 16px;
    padding-right: 8px;
    color: #0d6efd;
}

#global-client-search-input {
    height: 48px;
    font-size: 0.95rem;
    border: none;
    background-color: transparent;
    padding: 0 8px;
    transition: all 0.2s ease;
    color: #212529;
}

#global-client-search-input:focus {
    border: none;
    box-shadow: none;
    outline: none;
}

#global-client-search-input::placeholder {
    color: #6c757d;
    font-style: italic;
}

#global-search-close {
    background-color: transparent;
    border: none;
    padding: 0 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    cursor: pointer;
}

#global-search-close:hover {
    background-color: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
}

#global-search-close:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
    background-color: rgba(13, 110, 253, 0.15);
}

#global-search-spinner {
    background-color: transparent;
    border: none;
    padding-right: 12px;
}

/* ====================================
   RECHERCHE - DROPDOWN RÉSULTATS
   ==================================== */

#global-client-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1050;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    background-color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

#global-client-search-results.show {
    display: block !important;
    animation: slideDown 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.global-search-result-item {
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-radius: 0;
    text-decoration: none;
    color: inherit;
    padding: 0.75rem 1rem;
}

.global-search-result-item:hover,
.global-search-result-item.active {
    background-color: #e9ecef;
    color: inherit;
}

.global-search-result-item:focus-visible {
    background-color: #e9ecef;
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
}

#global-client-search-results .dropdown-header {
    background-color: #f8f9fa;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    color: #495057;
    font-weight: 600;
}

#global-client-search-results .dropdown-divider {
    margin: 0;
}

#global-client-search-results .dropdown-item-text {
    padding: 1rem;
    font-size: 0.9rem;
    color: #6c757d;
}

#global-client-search-results::-webkit-scrollbar {
    width: 8px;
}

#global-client-search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 0 12px 12px 0;
}

#global-client-search-results::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#global-client-search-results::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ====================================
   HISTORIQUE - BOUTON
   ==================================== */

#historyDropdown {
    /* Hérite de .header-action-btn */
}

/* Badge de notification sur l'historique */
#historyDropdown .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #dc3545;
    color: #fff;
    font-size: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ====================================
   HISTORIQUE - DROPDOWN
   ==================================== */

#historyDropdown ~ .dropdown-menu {
    min-width: 20rem;
    max-width: 25rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    margin-top: 8px;
    padding: 0;
    overflow: hidden;
}

#historyDropdown ~ .dropdown-menu .dropdown-header {
    background-color: #f8f9fa;
    font-weight: 600;
    padding: 0.75rem 1rem;
    color: #495057;
    border-bottom: 1px solid #dee2e6;
}

#historyDropdown ~ .dropdown-menu .dropdown-item {
    padding: 0.75rem 1rem;
    transition: background-color 0.15s ease;
    border: none;
}

#historyDropdown ~ .dropdown-menu .dropdown-item:hover {
    background-color: #f8f9fa;
}

#historyDropdown ~ .dropdown-menu .dropdown-item:focus-visible {
    background-color: #e9ecef;
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
}

#historyDropdown ~ .dropdown-menu .dropdown-divider {
    margin: 0;
    border-color: #dee2e6;
}

/* ====================================
   ACCESSIBILITÉ - BOUTON
   ==================================== */

#accessibility-toolbar-toggle {
    /* Hérite de .header-action-btn */
}

/* État actif du bouton accessibilité */
#accessibility-toolbar-toggle[aria-expanded="true"] {
    background-color: #2270b2;
    color: #fff;
}

/* ====================================
   ANIMATIONS
   ==================================== */

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

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

/* ====================================
   RESPONSIVE - TABLETTES
   ==================================== */

@media (max-width: 991px) {
    #global-search-container.search-active {
        width: 300px;
    }

    #global-client-search-form[aria-hidden="true"] {
        display: none !important;
        width: 0 !important;
        overflow: hidden;
    }

    #global-client-search-input {
        font-size: 0.9rem;
    }
    
    #global-client-search-input::placeholder {
        font-size: 0.85rem;
    }
    
    #historyDropdown ~ .dropdown-menu {
        min-width: 18rem;
        max-width: 22rem;
    }
}

/* ====================================
   RESPONSIVE - MOBILES
   ==================================== */

@media (max-width: 767px) {
    .header-action-btn {
        width: 44px;
        height: 44px;
    }
    
    .header-action-btn .bi,
    .header-action-btn .material-icons {
        font-size: 1.125rem;
    }

    #global-search-container {
        max-width: 40px; /* taille du bouton loupe seulement */
        overflow: hidden;
    }

    #global-search-container.search-active {
        position: fixed;
        top: 10px;
        right: 10px;
        left: 10px;
        width: calc(100vw - 20px);
        z-index: 1100;
    }
    
    #global-client-search-form {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 0;
        opacity: 0;
        transition: width 0.3s ease, opacity 0.3s ease;
        overflow: hidden;
        z-index: 1000;
    }
    
    #global-client-search-results {
        max-height: 300px;
    }
    
    /* Backdrop mobile pour la recherche */
    #global-search-container.search-active::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: -1;
        animation: fadeIn 0.3s ease;
    }
    
    #historyDropdown ~ .dropdown-menu {
        min-width: calc(100vw - 40px);
        max-width: calc(100vw - 40px);
    }
}

/* ====================================
   ACCESSIBILITÉ - CONTRASTE ÉLEVÉ
   ==================================== */

@media (prefers-contrast: high) {
    .header-action-btn {
        border-width: 3px;
        border-color: #000;
    }
    
    .header-action-btn:hover {
        background-color: #000;
        border-color: #000;
    }
    
    .header-action-btn:focus-visible {
        outline-width: 4px;
        outline-color: #000;
    }
    
    #global-client-search-form .input-group {
        border-width: 3px;
        border-color: #000;
    }
    
    #global-client-search-input:focus {
        outline: 3px solid #000;
        outline-offset: 2px;
    }
    
    .global-search-result-item.active {
        background-color: #000;
        color: #fff;
    }
}

/* ====================================
   MODE SOMBRE
   ==================================== */

@media (prefers-color-scheme: dark) {
    .header-action-btn {
        background-color: #212529;
        border-color: #495057;
        color: #adb5bd;
    }
    
    .header-action-btn:hover {
        background-color: #0d6efd;
        border-color: #0d6efd;
        color: #fff;
    }
    
    #global-client-search-form .input-group {
        background-color: #212529;
        border-color: #495057;
    }
    
    #global-client-search-input {
        background-color: transparent;
        color: #fff;
    }
    
    #global-client-search-form .input-group-text {
        color: #adb5bd;
    }
    
    #global-search-close {
        color: #adb5bd;
    }
    
    #global-search-close:hover {
        background-color: rgba(173, 181, 189, 0.1);
        color: #fff;
    }
    
    #global-client-search-results {
        background-color: #212529;
        border-color: #495057;
    }
    
    #global-client-search-results .dropdown-header {
        background-color: #343a40;
        color: #adb5bd;
    }
    
    .global-search-result-item {
        color: #fff;
    }
    
    .global-search-result-item:hover,
    .global-search-result-item.active {
        background-color: #495057;
    }
    
    #historyDropdown ~ .dropdown-menu {
        background-color: #212529;
        border-color: #495057;
    }
    
    #historyDropdown ~ .dropdown-menu .dropdown-header {
        background-color: #343a40;
        color: #adb5bd;
        border-bottom-color: #495057;
    }
    
    #historyDropdown ~ .dropdown-menu .dropdown-item {
        color: #fff;
    }
    
    #historyDropdown ~ .dropdown-menu .dropdown-item:hover {
        background-color: #343a40;
    }
    
    #historyDropdown ~ .dropdown-menu .dropdown-divider {
        border-color: #495057;
    }
}

/* ====================================
   RÉDUCTION DU MOUVEMENT
   ==================================== */

@media (prefers-reduced-motion: reduce) {
    .header-action-btn,
    #global-search-container,
    #global-client-search-form,
    #global-client-search-form .input-group,
    .global-search-result-item,
    #historyDropdown ~ .dropdown-menu .dropdown-item {
        transition: none;
        animation: none;
    }
    
    .header-action-btn:hover {
        transform: none;
    }
    
    #global-search-container.search-active::before {
        animation: none;
    }
}