/**
 * SITVI - Legend Panel CSS
 *
 * Stili per il pannello legenda interattivo (SitviLegendPanel).
 * Organizzato in sezioni: container, floating, docked, header, search,
 * overlay moduli, body, gruppi, layer, simbologia, opacity, azioni,
 * animazioni, dock utility (wrapper), responsive.
 *
 * @package SITVI
 * @version 2.1.0
 */

/* =============================================
   1. PANEL CONTAINER (base)
   ============================================= */

.sitvi-legend-panel {
    display: none;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.06);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    color: #1a1a2e;
    overflow: hidden;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.sitvi-legend-panel.show {
    opacity: 1;
    transform: translateY(0);
}

/* =============================================
   2. FLOATING STATE
   ============================================= */

.sitvi-legend-floating {
    position: fixed;
    z-index: 1000;
    width: 300px;
    min-width: 260px;
    max-width: 420px;
    max-height: calc(100vh - 120px);
    resize: both;
}

/* =============================================
   3. DOCKED STATE (left / right)
   ============================================= */

.sitvi-legend-docked-right,
.sitvi-legend-docked-left {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 300px;
    max-height: none;
    border-radius: 0;
    resize: none;
    z-index: 10;
    border: none;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: rgba(255, 255, 255, 0.97);
}

.sitvi-legend-docked-right {
    right: 0;
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.06);
}

.sitvi-legend-docked-left {
    left: 0;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.06);
}

/* =============================================
   4. DOCK UTILITY
   Il posizionamento del contenitore mappa e dei
   controlli viene gestito via JS per compatibilita'
   con tutte le strutture DOM (webgis3, mappa-condivisa).
   ============================================= */

/* =============================================
   5. HEADER
   ============================================= */

.sitvi-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
    min-height: 42px;
}

.sitvi-legend-docked-left .sitvi-legend-header,
.sitvi-legend-docked-right .sitvi-legend-header {
    cursor: default;
}

.sitvi-legend-title {
    font-weight: 600;
    font-size: 13px;
    color: #334155;
    letter-spacing: -0.01em;
}

.sitvi-legend-title i {
    margin-right: 6px;
    color: #3b82f6;
    font-size: 14px;
}

.sitvi-legend-header-actions {
    display: flex;
    gap: 2px;
    align-items: center;
}

.sitvi-legend-btn {
    background: none;
    border: none;
    padding: 5px 6px;
    cursor: pointer;
    color: #94a3b8;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.sitvi-legend-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #475569;
}

.sitvi-legend-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

/* =============================================
   6. SEARCH BAR
   ============================================= */

.sitvi-legend-search {
    position: relative;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

/* ===== Overlay moduli (voci runtime registrate dai moduli viewer) ===== */

.sitvi-legend-module-overlays {
    padding: 6px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.sitvi-legend-module-overlays-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 4px;
}

.sitvi-legend-module-overlay-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    margin-bottom: 0;
    cursor: pointer;
}

.sitvi-legend-search-icon {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 12px;
    pointer-events: none;
}

.sitvi-legend-search-input {
    width: 100%;
    padding: 6px 10px 6px 30px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 12px;
    outline: none;
    background: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    box-sizing: border-box;
    color: #334155;
}

.sitvi-legend-search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: #fff;
}

.sitvi-legend-search-input::placeholder {
    color: #94a3b8;
}

/* =============================================
   7. BODY (scrollable)
   ============================================= */

.sitvi-legend-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
}

.sitvi-legend-body::-webkit-scrollbar {
    width: 5px;
}

.sitvi-legend-body::-webkit-scrollbar-track {
    background: transparent;
}

.sitvi-legend-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.sitvi-legend-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* =============================================
   8. GROUP NODES
   ============================================= */

.sitvi-legend-group {
    /* contenitore */
}

.sitvi-legend-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 6px;
    margin: 0 4px;
    transition: background 0.15s;
}

.sitvi-legend-group-header:hover {
    background: rgba(59, 130, 246, 0.06);
}

.sitvi-legend-group-toggle {
    font-size: 11px;
    color: #94a3b8;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.sitvi-legend-group.collapsed > .sitvi-legend-group-header .sitvi-legend-group-toggle {
    transform: rotate(-90deg);
}

.sitvi-legend-group.collapsed > .sitvi-legend-group-body {
    display: none;
}

.sitvi-legend-group-check {
    accent-color: #3b82f6;
    cursor: pointer;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

.sitvi-legend-group-icon {
    font-size: 13px;
    color: #f59e0b;
    flex-shrink: 0;
}

.sitvi-legend-group-name {
    font-weight: 600;
    font-size: 12px;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sitvi-legend-group-body {
    /* Linea-guida verticale allineata al chevron del gruppo (--sitvi-guide-x
       impostata inline dal render in base alla profondita'): rende immediata
       la lettura di quali layer appartengono al gruppo */
    position: relative;
}

.sitvi-legend-group-body::before {
    content: '';
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: var(--sitvi-guide-x, 13px);
    width: 1px;
    background: rgba(100, 116, 139, 0.25);
    pointer-events: none;
}

/* Basemap group: nascosto nella legenda interattiva */
.sitvi-legend-basemap-group {
    display: none;
}

/* =============================================
   9. LAYER NODES
   ============================================= */

.sitvi-legend-layer {
    padding: 3px 10px;
    margin: 0 4px;
    border-radius: 6px;
    transition: background 0.15s;
}

.sitvi-legend-layer:hover {
    background: rgba(59, 130, 246, 0.04);
}

.sitvi-legend-layer-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
}

.sitvi-legend-layer-check {
    accent-color: #3b82f6;
    cursor: pointer;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

.sitvi-legend-layer-name {
    flex: 1;
    font-size: 12px;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}

/* Basemap layer: nascosto */
.sitvi-legend-basemap-layer {
    display: none;
}

/* =============================================
   10. SYMBOLOGY SWATCHES
   ============================================= */

/* Swatch inline (stile singolo).
   Lasciamo che le dimensioni dipendano dall'SVG dentro: il container aveva
   width/height/border/border-radius propri che strozzavano l'SVG e
   spostavano il testo verticalmente rispetto all'icona. Ora il box
   "rispetta" l'SVG e si allinea con il middle del testo del layer. */
.sitvi-legend-swatch-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    /* width/height auto = adottano quelle dell'SVG figlio (16x16, 20x10) */
    line-height: 0; /* evita gap baseline */
}
.sitvi-legend-swatch-inline > svg {
    display: block;
}
/* Allinea verticalmente con la label adiacente (font 12-13px ~ 16px box) */
.sitvi-legend-swatch-inline.sitvi-legend-swatch-line {
    /* La line ha viewBox 20x10: alziamo leggermente per centrare con il testo */
    margin: 3px 0;
}

/* Sezione simbologia espandibile */
.sitvi-legend-symbology {
    padding: 2px 0 2px 32px;
    transition: max-height 0.2s ease;
}

.sitvi-legend-symbology.collapsed {
    display: none;
}

/* Riga swatch */
.sitvi-legend-swatch-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 0;
}

.sitvi-legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.sitvi-legend-swatch-label {
    font-size: 11px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* WMS GetLegendGraphic */
.sitvi-legend-wms-legend {
    padding: 2px 0;
}

.sitvi-legend-wms-img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Barra gradiente */
.sitvi-legend-gradient-bar {
    height: 10px;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    margin: 4px 0 2px 0;
}

/* Heatmap: gradient bar identica alla graduated ma piu' alta per evidenza */
.sitvi-legend-heatmap {
    height: 14px;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    margin: 4px 0 2px 0;
}

.sitvi-legend-gradient-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #94a3b8;
    margin-bottom: 4px;
}

/* =============================================
   11. OPACITY SLIDER ROW
   ============================================= */

.sitvi-legend-opacity-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 32px;
}

.sitvi-legend-opacity-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #e2e8f0;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.sitvi-legend-opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.sitvi-legend-opacity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.sitvi-legend-opacity-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #3b82f6;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.sitvi-legend-opacity-value {
    font-size: 11px;
    color: #94a3b8;
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* =============================================
   12. LAYER ACTIONS (icone)
   ============================================= */

.sitvi-legend-layer-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.sitvi-legend-layer:hover .sitvi-legend-layer-actions {
    opacity: 1;
}

.sitvi-legend-layer-actions i {
    font-size: 13px;
    color: #94a3b8;
    cursor: pointer;
    padding: 3px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}

.sitvi-legend-layer-actions i:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.sitvi-legend-symbology-toggle {
    font-size: 11px !important;
    transition: transform 0.2s !important;
}

.sitvi-legend-symbology-toggle.bi-chevron-up {
    transform: rotate(0deg);
}

/* =============================================
   13. ANIMATIONS
   ============================================= */

/* Dock transition */
.sitvi-legend-docked-left,
.sitvi-legend-docked-right {
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.sitvi-legend-docked-right.show {
    transform: translateX(0);
}

.sitvi-legend-docked-left.show {
    transform: translateX(0);
}

/* =============================================
   14. RESPONSIVE (mobile)
   ============================================= */

@media (max-width: 576px) {
    .sitvi-legend-panel.sitvi-legend-floating {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 60vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
        resize: none;
    }

    .sitvi-legend-panel.sitvi-legend-floating.show {
        transform: translateY(0);
    }

    /* Nascondi bottoni dock su mobile */
    .sitvi-legend-dock-left-btn,
    .sitvi-legend-dock-right-btn {
        display: none !important;
    }

    .sitvi-legend-header {
        cursor: default;
        padding: 12px 16px;
    }

    /* Azioni sempre visibili su mobile (no hover) */
    .sitvi-legend-layer-actions {
        opacity: 1;
    }

    .sitvi-legend-layer-actions i {
        padding: 4px;
        font-size: 15px;
    }

    .sitvi-legend-layer-check {
        width: 18px;
        height: 18px;
    }

    .sitvi-legend-group-check {
        width: 18px;
        height: 18px;
    }

    .sitvi-legend-layer {
        padding: 5px 12px;
    }

    .sitvi-legend-layer-row {
        min-height: 34px;
    }
}

@media (max-width: 768px) {
    .sitvi-legend-docked-left,
    .sitvi-legend-docked-right {
        width: 260px;
    }
}
