/**
 * SITVI - Toponomastica Panel Styles
 *
 * Stili per il pannello di ricerca toponomastica nel WebGIS viewer.
 * Design glassmorphic coerente con gli altri pannelli (catasto, legend, info, map-tools).
 *
 * Classi principali:
 *  .sitvi-topo-panel         - Container principale
 *  .sitvi-topo-header        - Header con drag handle
 *  .sitvi-topo-search        - Input ricerca vie
 *  .sitvi-topo-via-list      - Lista risultati vie
 *  .sitvi-topo-civici-grid   - Griglia chip civici
 *  .sitvi-topo-actions       - Bottoni azione
 *  .sitvi-topo-results       - Area risultati scrollabile
 *
 * @version 1.0.0
 */

/* ============================================
   PANEL CONTAINER
   ============================================ */

.sitvi-topo-panel {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 10px;
    left: 10px;
    width: 390px;
    max-height: calc(100% - 20px);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.06);
    z-index: 90;
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.sitvi-topo-panel.open {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   RESIZE HANDLE
   ============================================ */

.sitvi-topo-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 14px 0;
}

.sitvi-topo-resize::before {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    border-right: 2px solid #94a3b8;
    border-bottom: 2px solid #94a3b8;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.sitvi-topo-resize:hover::before {
    opacity: 1;
}

.sitvi-topo-panel.resizing {
    transition: none !important;
    user-select: none;
}

/* ============================================
   HEADER
   ============================================ */

.sitvi-topo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

.sitvi-topo-header:active {
    cursor: grabbing;
}

.sitvi-topo-title {
    font-weight: 700;
    font-size: 14px;
    color: #1e293b;
}

.sitvi-topo-title i {
    color: #0ea5e9;
    margin-right: 4px;
}

.sitvi-topo-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.sitvi-topo-close:hover {
    background: #f1f5f9;
    color: #475569;
}

.sitvi-topo-close:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

/* ============================================
   BODY SCROLLABLE
   ============================================ */

.sitvi-topo-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 0;
}

.sitvi-topo-body::-webkit-scrollbar {
    width: 4px;
}

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

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

/* ============================================
   SEARCH INPUT
   ============================================ */

.sitvi-topo-search-wrap {
    position: relative;
    margin-bottom: 10px;
}

.sitvi-topo-search-wrap i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 14px;
    pointer-events: none;
}

.sitvi-topo-search {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

.sitvi-topo-search:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
    background: #fff;
}

/* ============================================
   VIE LIST (risultati ricerca)
   ============================================ */

.sitvi-topo-via-list {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
}

.sitvi-topo-via-list:empty {
    display: none;
}

.sitvi-topo-via-list::-webkit-scrollbar {
    width: 4px;
}

.sitvi-topo-via-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.sitvi-topo-via-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.12s;
}

.sitvi-topo-via-item:last-child {
    border-bottom: none;
}

.sitvi-topo-via-item:hover {
    background: #f0f9ff;
}

.sitvi-topo-via-item.active {
    background: #e0f2fe;
    font-weight: 600;
}

.sitvi-topo-via-item.highlighted {
    background: #e0f2fe;
    outline: 2px solid #0ea5e9;
    outline-offset: -2px;
}

.sitvi-topo-via-item mark {
    background: #fef08a;
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

.sitvi-topo-via-code {
    font-family: monospace;
    font-size: 11px;
    color: #64748b;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.sitvi-topo-via-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   SELECTED VIA HEADER
   ============================================ */

.sitvi-topo-via-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid #bae6fd;
    gap: 6px;
}

.sitvi-topo-via-header.visible {
    display: flex;
}

.sitvi-topo-via-header-name {
    font-weight: 600;
    font-size: 13px;
    color: #0369a1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.sitvi-topo-via-header-name i {
    margin-right: 4px;
}

.sitvi-topo-via-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ============================================
   CIVICI FILTER INPUT
   ============================================ */

.sitvi-topo-civici-filter-wrap {
    display: none;
    position: relative;
    margin-bottom: 8px;
}

.sitvi-topo-civici-filter-wrap.visible {
    display: block;
}

.sitvi-topo-civici-filter {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    color: #1e293b;
    background: #fff;
    outline: none;
    transition: border-color 0.15s;
}

.sitvi-topo-civici-filter:focus {
    border-color: #0ea5e9;
}

/* ============================================
   CIVICI GRID (chip)
   ============================================ */

.sitvi-topo-civici-grid {
    display: none;
    flex-direction: column;
    margin-bottom: 12px;
    max-height: 180px;
    overflow-y: auto;
    padding: 2px;
}

.sitvi-topo-civici-grid.visible {
    display: flex;
}

/* Colonne pari/dispari */
.sitvi-topo-civici-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sitvi-topo-civici-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sitvi-topo-civici-col-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    padding: 0 2px 2px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 2px;
}

.sitvi-topo-civici-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* Sezione singola (tutti pari o tutti dispari) */
.sitvi-topo-civici-section .sitvi-topo-civici-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.sitvi-topo-civici-grid::-webkit-scrollbar {
    width: 4px;
}

.sitvi-topo-civici-grid::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.sitvi-topo-civico-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    padding: 4px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.sitvi-topo-civico-chip:hover {
    background: #f0f9ff;
    border-color: #0ea5e9;
    color: #0369a1;
}

.sitvi-topo-civico-chip.active {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: #fff;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.3);
}

.sitvi-topo-civico-chip:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

/* ============================================
   SECTION DETTAGLIO CIVICO
   ============================================ */

.sitvi-topo-civico-detail {
    display: none;
}

.sitvi-topo-civico-detail.visible {
    display: block;
}

/* ============================================
   ACTION BUTTONS
   ============================================ */

.sitvi-topo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    padding: 8px 0;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
}

.sitvi-topo-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.sitvi-topo-btn:hover {
    background: #f0f9ff;
    border-color: #0ea5e9;
    color: #0369a1;
}

.sitvi-topo-btn.active {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: #fff;
}

.sitvi-topo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sitvi-topo-btn i {
    font-size: 13px;
}

.sitvi-topo-btn:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

.sitvi-topo-btn-catasto {
    border-color: #c4b5fd;
    color: #7c3aed;
}

.sitvi-topo-btn-catasto:hover {
    background: #f5f3ff;
    border-color: #8b5cf6;
    color: #6d28d9;
}

/* ============================================
   RESULTS AREA
   ============================================ */

.sitvi-topo-results {
    margin-top: 4px;
}

/* ============================================
   CARD (edificio, anagrafe)
   ============================================ */

.sitvi-topo-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #334155;
}

.sitvi-topo-card-title {
    font-weight: 700;
    font-size: 12px;
    color: #0369a1;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sitvi-topo-card-title i {
    font-size: 14px;
}

.sitvi-topo-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 12px;
}

.sitvi-topo-card-label {
    color: #64748b;
    font-size: 11px;
}

.sitvi-topo-card-value {
    font-weight: 600;
    color: #1e293b;
    font-size: 12px;
}

/* Card anagrafe */
.sitvi-topo-card-anagrafe {
    background: #fefce8;
    border-color: #fde68a;
}

.sitvi-topo-card-anagrafe .sitvi-topo-card-title {
    color: #a16207;
}

/* ============================================
   TABLE (interni)
   ============================================ */

.sitvi-topo-table-wrap {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}

.sitvi-topo-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.sitvi-topo-table th {
    background: #f1f5f9;
    padding: 7px 10px;
    font-weight: 600;
    color: #475569;
    font-size: 11px;
    text-align: left;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.sitvi-topo-table td {
    padding: 6px 10px;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px;
}

.sitvi-topo-table tr:last-child td {
    border-bottom: none;
}

.sitvi-topo-table tr:hover td {
    background: #f0f9ff;
}

.sitvi-topo-table tr.clickable {
    cursor: pointer;
}

.sitvi-topo-table tr.clickable:hover td {
    background: #e0f2fe;
}

.sitvi-topo-table tr.selected td {
    background: #dbeafe;
    font-weight: 500;
}

/* ============================================
   DETTAGLIO INTERNO ESPANDIBILE
   ============================================ */

.sitvi-topo-interno-detail {
    background: #f5f3ff;
    border: 1px solid #c4b5fd;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 4px 0 8px;
    font-size: 12px;
    animation: sitviTopoSlideDown 0.2s ease;
}

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

.sitvi-topo-interno-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 10px;
    margin-bottom: 6px;
}

.sitvi-topo-interno-detail-label {
    font-size: 10px;
    color: #7c3aed;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.sitvi-topo-interno-detail-value {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

/* ============================================
   LOADING SPINNER
   ============================================ */

.sitvi-topo-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    color: #64748b;
    font-size: 12px;
}

.sitvi-topo-loading i {
    animation: sitviTopoSpin 1s linear infinite;
}

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

/* ============================================
   EMPTY STATE / MESSAGES
   ============================================ */

.sitvi-topo-empty {
    text-align: center;
    padding: 16px 12px;
    color: #94a3b8;
    font-size: 12px;
    font-style: italic;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px dashed #e2e8f0;
    margin: 4px 0;
}

.sitvi-topo-empty i {
    display: block;
    font-size: 20px;
    margin-bottom: 4px;
    font-style: normal;
}

.sitvi-topo-error {
    text-align: center;
    padding: 8px 12px;
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-size: 12px;
    margin-bottom: 8px;
}

/* ============================================
   SEPARATOR
   ============================================ */

.sitvi-topo-separator {
    height: 1px;
    background: #e2e8f0;
    margin: 10px 0;
}

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

/* ============================================
   TABLET (< 768px)
   ============================================ */

@media (max-width: 768px) {
    .sitvi-topo-panel {
        width: 320px;
    }
}

/* ============================================
   MOBILE (< 576px) — Bottom sheet mode
   ============================================ */

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

    .sitvi-topo-panel.open {
        transform: translateY(0);
    }

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

    .sitvi-topo-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
    }

    /* Touch targets >= 44px */
    .sitvi-topo-close {
        min-width: 44px;
        min-height: 44px;
    }

    .sitvi-topo-actions .btn,
    .sitvi-topo-btn {
        min-height: 44px;
        font-size: 13px;
        padding: 8px 12px;
    }

    .sitvi-topo-search-input {
        min-height: 44px;
        font-size: 14px;
    }

    .sitvi-topo-civici-grid {
        max-height: 100px;
    }

    .sitvi-topo-via-list {
        max-height: 120px;
    }

    .sitvi-topo-civico-chip {
        min-width: 44px;
        min-height: 36px;
    }

    .sitvi-topo-interno-detail-grid {
        grid-template-columns: 1fr 1fr;
    }

    .sitvi-topo-table th,
    .sitvi-topo-table td {
        padding: 8px 6px;
        font-size: 12px;
    }
}
