/**
 * ============================================================================
 * Legende V3 Finale - Bouton Flottant Droit
 * ============================================================================
 *
 * @projet     Province de Zagora - Plateforme Territoriale Integree
 * @fichier    legende-v3-final.css
 * @version    3.0 (finale)
 *
 * @description
 * Styles du bouton flottant et du panneau de legende V3 :
 *   - Bouton fixe a droite de l'ecran (50% vertical)
 *   - Panneau coulissant avec animation
 *   - Selection unique de categorie (highlight actif)
 *   - !important utilise pour surcharger les styles inline Leaflet
 *
 * @utilise_par  carte-interactive.html (avec legende-v3-final.js)
 * ============================================================================
 */

/* Bouton flottant - FORCÉ À DROITE */
.legend-toggle-btn {
    position: fixed !important;
    right: 15px !important;
    left: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 50px;
    height: 50px;
    background: linear-gradient(145deg, #1e3a5f, #0f2744);
    border: 2px solid #f97316;
    border-radius: 12px;
    color: #f97316;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.legend-toggle-btn:hover {
    transform: translateY(-50%) scale(1.1) !important;
}

.legend-toggle-btn span {
    font-size: 8px;
    font-weight: 600;
}

.legend-toggle-btn.hidden {
    display: none !important;
}

/* Panneau - FORCÉ À DROITE */
.legend-v3 {
    position: fixed !important;
    right: -360px !important;
    left: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 340px;
    max-height: 85vh;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    border-radius: 16px 0 0 16px;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-right: none;
    overflow: hidden;
    z-index: 1001 !important;
    display: flex;
    flex-direction: column;
    font-family: 'Segoe UI', system-ui, sans-serif;
    transition: right 0.35s ease !important;
}

.legend-v3.open {
    right: 0 !important;
}

/* Header */
.legend-v3-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-v3-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
}

.legend-v3-title i { color: #f97316; }

.legend-v3-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.legend-v3-close:hover { background: rgba(239, 68, 68, 0.4); }

/* Basemap */
.legend-v3-basemap {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.basemap-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.basemap-btn.active { background: #f97316; border-color: #f97316; color: #fff; }

/* Actions */
.legend-v3-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.action-btn {
    padding: 7px 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.action-show { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.action-hide { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.action-reset { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }

.legend-v3-total { margin-left: auto; font-size: 0.75rem; color: rgba(255,255,255,0.5); }
.legend-v3-total strong { color: #f97316; }

/* Grille */
.legend-v3-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 10px;
}

.category-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 4px;
    border: 2px solid var(--cat-color, #666);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--cat-color, #fff);
    cursor: pointer;
    min-height: 70px;
}

.category-btn:hover { background: rgba(255, 255, 255, 0.08); }
.category-btn.active { background: var(--cat-color); color: #fff; }
.category-btn i { font-size: 1.2rem; margin-bottom: 3px; }
.category-btn .cat-label { font-size: 0.65rem; font-weight: 600; }
.category-btn .cat-count { font-size: 0.6rem; opacity: 0.7; }

/* Douars */
.legend-v3-douars {
    padding: 10px 12px;
    background: rgba(255, 87, 34, 0.1);
    border-top: 1px solid rgba(255, 87, 34, 0.2);
}

.douars-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    border: 2px solid #FF5722;
    border-radius: 10px;
    background: transparent;
    color: #FF5722;
    cursor: pointer;
    font-weight: 600;
}

.douars-btn:hover { background: rgba(255, 87, 34, 0.2); }
.douars-btn.active { background: #FF5722; color: #fff; }

/* Sous-catégories */
.legend-v3-subcats { flex: 1; overflow-y: auto; background: rgba(0, 0, 0, 0.2); }
.subcat-panel { display: none; padding: 10px; }
.subcat-panel.active { display: block; }

.subcat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--cat-color);
}

.subcat-header i { color: var(--cat-color); }
.subcat-header .subcat-title { flex: 1; font-weight: 600; color: #fff; font-size: 0.9rem; }
.subcat-header .subcat-toggle-all {
    padding: 5px 10px;
    border: 1px solid var(--cat-color);
    border-radius: 5px;
    background: transparent;
    color: var(--cat-color);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.subcat-header .subcat-toggle-all:hover { background: rgba(255,255,255,0.1); }
.subcat-header .subcat-toggle-all.active { background: var(--cat-color); color: #fff; }

.subcat-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.subcat-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.85);
    transition: all 0.2s;
    min-height: 70px;
}

.subcat-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--cat-color);
    transform: translateY(-2px);
}
.subcat-btn.active {
    background: var(--cat-color);
    color: #fff;
    border-color: var(--cat-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.subcat-btn .subcat-icon {
    font-size: 1.4rem;
    color: var(--cat-color);
    margin-bottom: 2px;
}
.subcat-btn.active .subcat-icon { color: #fff; }
.subcat-btn .subcat-name {
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
}
.subcat-btn .subcat-count {
    opacity: 0.6;
    font-size: 0.65rem;
}
.subcat-btn.active .subcat-count { opacity: 0.9; }

/* Mobile */
@media (max-width: 768px) {
    .legend-v3 {
        width: 100% !important;
        right: -100% !important;
        left: auto !important;
        top: auto !important;
        bottom: 0 !important;
        transform: none !important;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
    }
    .legend-v3.open { right: 0 !important; }
    .legend-toggle-btn { bottom: 80px !important; top: auto !important; transform: none !important; right: 15px !important; left: auto !important; }
}

/* Cacher anciennes légendes */
.right-panel#legend-panel, #new-legend-panel, .legend-panel, .legend-v2, #legend-v2-container { display: none !important; }
