/**
 * Archives Advanced Search - CSS CORRIGÉ
 * - Pas d'espace à droite du bouton
 * - Responsive mobile optimisé
 * - Style similaire à single-archives
 * 
 * @version 2.0
 */

/* ================================================
   CONTENEUR PRINCIPAL
   ================================================ */

.archives-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
}

/* ================================================
   FORMULAIRE DE RECHERCHE
   ================================================ */

.archives-search-form {
    position: relative;
    width: 100%;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: stretch; /* CORRECTION: stretch au lieu de center */
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px; /* Plus simple comme single-archives */
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.search-input-wrapper:focus-within {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* Icône de recherche */
.search-icon {
    font-size: 18px;
    padding: 0 12px;
    color: #999;
    display: flex;
    align-items: center;
    flex-shrink: 0; /* CORRECTION: empêche la compression */
}

/* Champ de saisie */
.archives-search-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 12px; /* CORRECTION: padding égal */
    font-size: 15px;
    background: transparent;
    color: #333;
    min-width: 0; /* CORRECTION: permet la réduction */
}

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

/* Bouton de soumission */
.search-submit-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 24px; /* CORRECTION: padding réduit */
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0; /* CORRECTION: empêche la compression */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.search-submit-btn:hover {
    background: #5568d3;
}

.search-submit-btn:active {
    transform: scale(0.98);
}

/* Icône dans le bouton (mobile) */
.search-submit-btn .btn-icon {
    display: none;
}

.search-submit-btn .btn-text {
    display: inline;
}

/* ================================================
   DROPDOWN DES RÉSULTATS
   ================================================ */

.archives-search-results {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
    animation: slideDown 0.3s ease;
    border: 1px solid #e0e0e0;
}

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

.search-results-content {
    max-height: 500px;
    overflow-y: auto;
}

/* Scrollbar personnalisée */
.search-results-content::-webkit-scrollbar {
    width: 6px;
}

.search-results-content::-webkit-scrollbar-track {
    background: #f5f5f5;
}

.search-results-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.search-results-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ================================================
   LISTE DES RÉSULTATS
   ================================================ */

.search-results-list {
    padding: 4px 0;
}

/* Item de résultat */
.result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f5f5f5;
}

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

.result-item:hover,
.result-item.active {
    background: #f8f9fa;
}

/* Image miniature */
.result-thumbnail {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 6px;
    overflow: hidden;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.result-thumbnail.no-image {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.result-thumbnail .placeholder-icon {
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
}

/* Contenu du résultat */
.result-content {
    flex: 1;
    min-width: 0;
}

.result-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Surlignage du terme recherché */
.result-title mark {
    background: #fff3cd;
    color: #856404;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 700;
}

/* Métadonnées */
.result-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #666;
}

.result-meta span {
    display: inline-flex;
    align-items: center;
}

.result-type {
    background: #e8f0fe;
    color: #1a73e8;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.result-date,
.result-author {
    color: #999;
    font-size: 11px;
}

/* ================================================
   LIEN "VOIR TOUS LES RÉSULTATS"
   ================================================ */

.search-view-all {
    padding: 12px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.search-view-all a {
    color: #667eea;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.search-view-all a:hover {
    color: #5568d3;
}

/* ================================================
   ÉTATS DE CHARGEMENT ET MESSAGES
   ================================================ */

/* État de chargement */
.search-loading {
    text-align: center;
    padding: 30px 20px;
    color: #666;
}

.loading-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid #f0f0f0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Aucun résultat */
.search-no-results {
    text-align: center;
    padding: 30px 20px;
}

.no-results-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}

.search-no-results p {
    margin: 8px 0;
    color: #666;
    font-size: 14px;
}

.search-no-results strong {
    color: #333;
}

.search-tips {
    font-size: 12px;
    color: #999;
    font-style: italic;
    margin-top: 8px;
}

/* Lien vers page de filtrage */
.search-filter-link {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 20px;
    background: #667eea;
    color: white !important;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.3s ease;
}

.search-filter-link:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Message d'erreur */
.search-error {
    text-align: center;
    padding: 30px 20px;
    color: #dc3545;
}

.error-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
}

/* Message caractères minimum */
.search-min-chars {
    text-align: center;
    padding: 16px;
    color: #999;
    font-size: 13px;
}

/* ================================================
   STYLE SINGLE-ARCHIVES (Intégration)
   ================================================ */

.single-archive_doc .archives-search-wrapper {
    max-width: 100%;
    margin-bottom: 30px;
}

.single-archive_doc .search-input-wrapper {
    background: #f8f9fa;
    border-color: #ddd;
}

.single-archive_doc .archives-search-input {
    background: transparent;
}

/* ================================================
   RESPONSIVE - MOBILE
   ================================================ */

@media (max-width: 768px) {
    .archives-search-wrapper {
        max-width: 100%;
    }
    
    /* Version mobile : Bouton icône seulement */
    .search-submit-btn {
        padding: 12px 16px;
        min-width: auto;
    }
    
    .search-submit-btn .btn-text {
        display: none; /* Cache le texte */
    }
    
    .search-submit-btn .btn-icon {
        display: inline; /* Affiche l'icône */
        font-size: 16px;
    }
    
    /* OU Version alternative : Bouton en bas */
    .archives-search-wrapper.mobile-button-bottom .search-input-wrapper {
        flex-direction: column;
    }
    
    .archives-search-wrapper.mobile-button-bottom .search-submit-btn {
        width: 100%;
        padding: 12px;
        border-radius: 0 0 8px 8px;
    }
    
    .archives-search-wrapper.mobile-button-bottom .search-submit-btn .btn-text {
        display: inline;
    }
    
    .archives-search-wrapper.mobile-button-bottom .search-submit-btn .btn-icon {
        display: none;
    }
    
    /* Résultats */
    .result-item {
        padding: 8px 12px;
        gap: 10px;
    }
    
    .result-thumbnail {
        width: 45px;
        height: 45px;
    }
    
    .result-title {
        font-size: 13px;
    }
    
    .result-meta {
        font-size: 11px;
    }
    
    .archives-search-results {
        border-radius: 8px;
    }
    
    .search-results-content {
        max-height: 400px;
    }
}

@media (max-width: 480px) {
    .search-icon {
        padding: 0 10px;
        font-size: 16px;
    }
    
    .archives-search-input {
        padding: 10px 8px;
        font-size: 14px;
    }
    
    .search-submit-btn {
        padding: 10px 14px;
    }
    
    .result-thumbnail {
        width: 40px;
        height: 40px;
    }
    
    .result-thumbnail .placeholder-icon {
        font-size: 20px;
    }
    
    .result-title {
        font-size: 12px;
    }
    
    .result-meta {
        font-size: 10px;
        gap: 4px;
    }
    
    .result-type {
        font-size: 9px;
        padding: 1px 5px;
    }
}

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

.result-item {
    animation: fadeIn 0.2s ease;
}

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

/* ================================================
   ACCESSIBILITÉ
   ================================================ */

.archives-search-input:focus {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.result-item:focus {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.search-submit-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Réduire les animations si préférence utilisateur */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ================================================
   PRINT
   ================================================ */

@media print {
    .archives-search-wrapper {
        display: none;
    }
}