/**
 * ============================================================================
 * Legende Interactive - Panneau de Couches
 * ============================================================================
 *
 * @projet     Province de Zagora - Plateforme Territoriale Integree
 * @fichier    legende-styles.css
 *
 * @description
 * Styles du panneau de legende interactif pour la carte :
 *   - Panneau lateral droit avec categories de couches
 *   - Boutons de categorie avec icones et compteurs
 *   - Animation d'ouverture/fermeture
 *   - Sous-categories avec checkboxes
 *
 * @utilise_par  carte-interactive.html
 * ============================================================================
 */

/* ========================================
   PANNEAU DE LÉGENDE
   ======================================== */

.legend-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.98) 0%, rgba(15, 23, 42, 0.98) 100%);
    border: 1px solid rgba(249, 115, 22, 0.3);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    width: 320px;
    max-height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
}

.legend-panel.collapsed {
    width: 56px;
    overflow: hidden;
}

.legend-panel.collapsed .legend-header-title,
.legend-panel.collapsed .legend-content,
.legend-panel.collapsed .legend-footer {
    display: none;
}

/* ========================================
   EN-TÊTE DE LA LÉGENDE
   ======================================== */

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.15) 0%, rgba(249, 115, 22, 0.05) 100%);
    border-bottom: 1px solid rgba(249, 115, 22, 0.3);
    cursor: pointer;
}

.legend-header:hover {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.2) 0%, rgba(249, 115, 22, 0.1) 100%);
}

.legend-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-header-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
}

.legend-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

.legend-toggle-icon {
    color: rgba(255, 255, 255, 0.7);
    transition: transform 0.3s ease;
}

.legend-panel.collapsed .legend-toggle-icon {
    transform: rotate(180deg);
}

/* ========================================
   BARRE DE RECHERCHE
   ======================================== */

.legend-search {
    position: relative;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-search i {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.85rem;
}

.legend-search input {
    width: 100%;
    padding: 10px 36px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: white;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.legend-search input:focus {
    outline: none;
    border-color: #f97316;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.legend-search input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.legend-clear-search {
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.legend-clear-search:hover {
    color: #f97316;
    background: rgba(249, 115, 22, 0.1);
}

/* ========================================
   ACTIONS RAPIDES
   ======================================== */

.legend-actions {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-action-btn {
    flex: 1;
    padding: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.legend-action-btn:hover {
    background: rgba(249, 115, 22, 0.15);
    border-color: #f97316;
    color: #f97316;
}

.legend-action-btn i {
    font-size: 0.85rem;
}

/* ========================================
   CONTENU DE LA LÉGENDE (SCROLLABLE)
   ======================================== */

.legend-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

.legend-content::-webkit-scrollbar {
    width: 6px;
}

.legend-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.legend-content::-webkit-scrollbar-thumb {
    background: rgba(249, 115, 22, 0.4);
    border-radius: 3px;
}

.legend-content::-webkit-scrollbar-thumb:hover {
    background: rgba(249, 115, 22, 0.6);
}

/* ========================================
   CATÉGORIES
   ======================================== */

.legend-categories {
    display: flex;
    flex-direction: column;
}

.legend-category {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.legend-category:last-child {
    border-bottom: none;
}

.legend-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.legend-category-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.legend-category.expanded .legend-category-header {
    background: rgba(249, 115, 22, 0.08);
}

.legend-category-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-expand-btn {
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0.7rem;
}

.legend-expand-btn:hover {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
}

.legend-category.expanded .legend-expand-btn {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
}

.legend-category-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: white;
}

.legend-count {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.3);
    padding: 3px 8px;
    border-radius: 10px;
}

/* ========================================
   CHECKBOX PERSONNALISÉE
   ======================================== */

.legend-checkbox-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.legend-checkbox-wrapper input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.legend-checkbox {
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.legend-checkbox::after {
    content: '';
    display: none;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.legend-checkbox-wrapper input:checked + .legend-checkbox {
    background: #f97316;
    border-color: #f97316;
}

.legend-checkbox-wrapper input:checked + .legend-checkbox::after {
    display: block;
}

/* État partiel (semi-coché) */
.legend-checkbox.partial {
    background: rgba(249, 115, 22, 0.4);
    border-color: #f97316;
}

.legend-checkbox.partial::after {
    display: block;
    width: 8px;
    height: 2px;
    border: none;
    background: white;
    transform: none;
}

.legend-checkbox-wrapper:hover .legend-checkbox {
    border-color: #f97316;
}

/* ========================================
   SOUS-CATÉGORIES
   ======================================== */

.legend-category-content {
    background: rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

.legend-subcategory {
    padding: 6px 16px 6px 48px;
    transition: all 0.2s ease;
}

.legend-subcategory:hover {
    background: rgba(255, 255, 255, 0.03);
}

.legend-subcategory-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-subcategory-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
    flex: 1;
}

.legend-count-small {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
}

/* ========================================
   PIED DE LÉGENDE
   ======================================== */

.legend-footer {
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-total {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

.legend-total strong {
    color: #f97316;
}

.legend-reset-btn {
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    color: #ef4444;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.legend-reset-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
}

/* ========================================
   ICÔNES DES CATÉGORIES
   ======================================== */

.legend-category-header i.fas,
.legend-category-header i.far {
    width: 20px;
    text-align: center;
    font-size: 0.9rem;
}

.legend-subcategory-header i.fas,
.legend-subcategory-header i.far {
    width: 16px;
    text-align: center;
}

/* ========================================
   TOOLTIP
   ======================================== */

.legend-tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(249, 115, 22, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    max-width: 250px;
    pointer-events: none;
    animation: fadeIn 0.2s ease;
}

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

.legend-tooltip-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    margin-bottom: 6px;
}

.legend-tooltip-content {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
}

.legend-tooltip-stat {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-tooltip-stat-label {
    color: rgba(255, 255, 255, 0.5);
}

.legend-tooltip-stat-value {
    color: #f97316;
    font-weight: 600;
}

/* ========================================
   SURLIGNAGE DE RECHERCHE
   ======================================== */

.legend-highlight {
    background: rgba(249, 115, 22, 0.3);
    padding: 0 2px;
    border-radius: 2px;
}

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

@media (max-width: 768px) {
    .legend-panel {
        width: 100%;
        max-width: 100%;
        right: 0;
        left: 0;
        top: auto;
        bottom: 0;
        border-radius: 16px 16px 0 0;
        max-height: 60vh;
    }

    .legend-panel.collapsed {
        width: 100%;
        height: 56px;
    }

    .legend-actions {
        flex-wrap: wrap;
    }

    .legend-action-btn span {
        display: none;
    }
}

/* ========================================
   MODE SOMBRE AMÉLIORÉ
   ======================================== */

.dark-mode .legend-panel {
    background: linear-gradient(135deg, rgba(10, 15, 25, 0.98) 0%, rgba(5, 10, 20, 0.98) 100%);
}

/* ========================================
   ANIMATIONS AU SURVOL
   ======================================== */

.legend-category-header::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 3px;
    height: 100%;
    background: transparent;
    transition: background 0.3s ease;
}

.legend-category:hover .legend-category-header::before {
    background: var(--category-color, #f97316);
}

.legend-category.expanded .legend-category-header::before {
    background: var(--category-color, #f97316);
}

/* ========================================
   BOUTON TOGGLE EXTERNE
   ======================================== */

.legend-external-toggle {
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 72px;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: none;
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.legend-external-toggle:hover {
    width: 44px;
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
}

.legend-external-toggle i {
    color: white;
    font-size: 0.9rem;
}

.legend-external-toggle span {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
}
