/* ============================================
   CHART BUILDER - CSS COMPLETO
   Adattato da Palermo-Incidenti per ANNCSU
   ============================================ */

/* ==================== TRIGGER BUTTON ==================== */
.chart-builder-trigger {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: linear-gradient(135deg, #ff9900 0%, #e68800 100%);
    color: white;
    border: none;
    padding: 14px 22px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 153, 0, 0.45);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Titillium Web', sans-serif;
    overflow: hidden;
    white-space: nowrap;
}

.chart-builder-trigger:not(:disabled):hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 153, 0, 0.6);
}

.chart-builder-trigger i { font-size: 16px; }

/* Stato: caricamento dati in corso */
.chart-builder-trigger.loading {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
    cursor: wait;
    opacity: 0.85;
}

.chart-builder-trigger.loading .pulse-ring1 { display: none; }

/* Stato: errore caricamento */
.chart-builder-trigger.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.pulse-ring1 {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 100%; height: 100%;
    border-radius: 50px;
    border: 3px solid #ff9900;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) 4;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
}

/* ==================== MODAL OVERLAY ==================== */
.chart-builder-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 20px;                   /* mobile: padding uniforme */
}

@media (min-width: 700px) {
    .chart-builder-modal { padding: 20px 10%; }
}

@media (min-width: 1100px) {
    .chart-builder-modal { padding: 20px 20%; }
}

.chart-builder-modal.show {
    display: flex;
}

.chart-builder-content {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 100%;                 /* si adatta al padding del modal */
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==================== TIP BAR ==================== */
.chart-builder-tip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    background: #fff7ed;
    border-bottom: 1px solid #fed7aa;
    font-size: 12px;
    color: #92400e;
    flex-shrink: 0;
}

.chart-builder-tip i.fa-lightbulb { color: #f59e0b; font-size: 14px; flex-shrink: 0; }

.chart-builder-tip span { flex: 1; line-height: 1.4; }

.chart-builder-tip-btn {
    flex-shrink: 0;
    background: none;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    color: #92400e;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'Titillium Web', sans-serif;
    transition: all 0.2s;
    white-space: nowrap;
}

.chart-builder-tip-btn:hover {
    background: #f59e0b;
    color: white;
    border-color: #f59e0b;
}

/* ==================== HEADER ==================== */
.chart-builder-header {
    background: linear-gradient(135deg, #ff9900 0%, #e68800 50%, #cc7700 100%);
    color: white;
    padding: 20px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chart-builder-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-builder-title i { font-size: 24px; }

.chart-builder-title h2 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    color: #ffffff !important;
}

.chart-builder-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 38px; height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
}

.chart-builder-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg);
}

/* ==================== BODY ==================== */
.chart-builder-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ==================== LEFT PANEL ==================== */
.chart-builder-config {
    width: 380px;
    flex-shrink: 0;
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    padding: 20px;
}

.chart-builder-config::-webkit-scrollbar { width: 6px; }
.chart-builder-config::-webkit-scrollbar-track { background: #e5e7eb; }
.chart-builder-config::-webkit-scrollbar-thumb { background: #9ca3af; border-radius: 4px; }

/* ==================== CONFIG SECTIONS ==================== */
.config-section {
    background: white;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
    border: 2px solid #e5e7eb;
    transition: border-color 0.2s;
}

.config-section:hover { border-color: #ff9900; }

.config-section h3 {
    font-size: 14px;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 14px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-section h3 i { color: #ff9900; font-size: 16px; }

/* ==================== FORM CONTROLS ==================== */
.config-group { margin-bottom: 16px; }

.config-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.config-label i { color: #ff9900; font-size: 13px; }

.config-select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Titillium Web', sans-serif;
    background: white;
    color: #1f2937;
    cursor: pointer;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.config-select:hover { border-color: #ff9900; }
.config-select:focus { outline: none; border-color: #ff9900; box-shadow: 0 0 0 3px rgba(255, 153, 0, 0.15); }

/* ==================== CHART TYPE GRID ==================== */
.chart-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.chart-type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Titillium Web', sans-serif;
}

.chart-type-btn i { font-size: 20px; color: #6b7280; transition: color 0.2s; }
.chart-type-btn span { font-size: 10px; font-weight: 600; color: #6b7280; transition: color 0.2s; }

.chart-type-btn:hover {
    border-color: #ff9900;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 153, 0, 0.2);
}

.chart-type-btn:hover i,
.chart-type-btn:hover span { color: #ff9900; }

.chart-type-btn.active {
    background: linear-gradient(135deg, #ff9900 0%, #e68800 100%);
    border-color: #e68800;
}

.chart-type-btn.active i,
.chart-type-btn.active span { color: white; }

.chart-type-btn[data-type="mixed"] {
    background: linear-gradient(135deg, #ffd080 0%, #ffb833 100%);
    border-color: #ffb833;
}

.chart-type-btn[data-type="mixed"] span,
.chart-type-btn[data-type="mixed"] i { color: #7a4800; }

.chart-type-btn[data-type="mixed"].active {
    background: linear-gradient(135deg, #ff9900 0%, #cc6600 100%);
    border-color: #cc6600;
}

.chart-type-btn[data-type="mixed"].active span,
.chart-type-btn[data-type="mixed"].active i { color: #ffffff; }

/* ==================== TIPOLOGIE / TIPI ==================== */
.tipologie-checkboxes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.tipologie-checkboxes .tipologia-checkbox:last-child {
    grid-column: span 2;
}

.tipologia-checkbox {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background: #f8f9fa;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.tipologia-checkbox:hover { border-color: #ff9900; background: #f3f4f6; }
.tipologia-checkbox.checked {
    border-color: #ff9900;
    background: rgba(255, 153, 0, 0.1);
}

.tipologia-checkbox input[type="checkbox"] {
    width: 16px; height: 16px;
    margin-right: 8px;
    cursor: pointer;
    accent-color: #ff9900;
}

.tipologia-checkbox label {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 5px;
}

.tipologia-icon { font-size: 13px; }

/* ==================== MIXED CHART CONFIG ==================== */
.mixed-config-section {
    background: rgba(124, 58, 237, 0.04);
    border: 1px solid rgba(124, 58, 237, 0.18);
    border-radius: 8px;
    padding: 12px;
}

.mixed-config-section .config-label i { color: #7c3aed; }

#mixed-config-group {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
}

.config-row { display: flex; gap: 12px; margin-top: 8px; }
.config-col-half { flex: 1; }

.sub-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 5px;
    text-transform: uppercase;
}

/* ==================== COLOR CONTROLS ==================== */
.color-mode-group { margin-bottom: 14px; }

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.color-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.color-input-wrapper label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="color"] {
    width: 100%;
    height: 44px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    padding: 4px;
    transition: border-color 0.2s;
}

input[type="color"]:hover { border-color: #ff9900; }

/* ==================== RANGE SLIDERS ==================== */
.range-group { margin-bottom: 14px; }

.range-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.range-label-text {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.range-value {
    background: linear-gradient(135deg, #ff9900, #e68800);
    color: white;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    min-width: 44px;
    text-align: center;
}

input[type="range"] {
    width: 100%;
    height: 5px;
    border-radius: 5px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff9900, #e68800);
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff9900, #e68800);
    cursor: pointer;
    border: none;
}

/* ==================== PRESET BUTTONS ==================== */
.preset-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.preset-btn {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-family: 'Titillium Web', sans-serif;
}

.preset-btn:hover {
    background: linear-gradient(135deg, #ff9900 0%, #e68800 100%);
    color: white;
    border-color: #ff9900;
    transform: translateY(-1px);
}

/* ==================== CHECKBOXES ==================== */
.checkbox-group {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.checkbox-group:hover { background: #f3f4f6; border-color: #e5e7eb; }

.checkbox-group input[type="checkbox"] {
    width: 18px; height: 18px;
    margin-right: 10px;
    cursor: pointer;
    accent-color: #ff9900;
}

.checkbox-group label { cursor: pointer; font-size: 12px; color: #1f2937; font-weight: 500; }

/* ==================== DIVIDER ==================== */
.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, #e5e7eb, transparent);
    margin: 14px 0;
}

/* ==================== INFO BOX ==================== */
.info-box {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid #3b82f6;
    border-radius: 6px;
    display: flex;
    gap: 8px;
    font-size: 11px;
    line-height: 1.5;
    color: #1e293b;
}

.info-box i { color: #2563eb; font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.info-box strong { color: #1e40af; }

/* ==================== ACTION BUTTONS ==================== */
.config-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 20px;
}

.btn-generate {
    grid-column: span 2;
    padding: 13px 20px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    font-family: 'Titillium Web', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn-reset-builder {
    padding: 11px 16px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    font-family: 'Titillium Web', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-reset-builder:hover { transform: translateY(-2px); }

/* ==================== ACTIVE FILTERS BOX ==================== */
.active-filters-box {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    min-height: 50px;
    max-height: 110px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.no-filters {
    display: block;
    text-align: center;
    color: #9ca3af;
    font-size: 12px;
    font-style: italic;
    padding: 8px;
}

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: linear-gradient(135deg, #fff7ed, #ffedd5);
    border: 1px solid #f59e0b;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    color: #92400e;
    margin: 3px;
}

.filter-badge i { font-size: 10px; }

/* ==================== RIGHT PANEL - PREVIEW ==================== */
.chart-builder-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    min-width: 0;
}

.preview-header {
    padding: 12px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9fafb;
    flex-shrink: 0;
}

.preview-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Toggle Grafico / Tabella */
.view-toggle {
    display: flex;
    background: #e5e7eb;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.view-toggle-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Titillium Web', sans-serif;
    background: transparent;
    color: #6b7280;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.view-toggle-btn.active {
    background: white;
    color: #ff9900;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* Pulsante CSV */
.btn-download-csv {
    padding: 9px 16px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    font-family: 'Titillium Web', sans-serif;
}

.btn-download-csv:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4); }

/* ==================== TABELLA DATI ==================== */
.table-wrapper-custom {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 16px;
    box-sizing: border-box;
}

.data-table {
    width: 100%;
    min-width: max-content;   /* scroll orizzontale per tabelle multi-colonna */
    border-collapse: collapse;
    font-family: 'Titillium Web', sans-serif;
    font-size: 12px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    background: linear-gradient(135deg, #ff9900 0%, #e68800 100%);
    color: white;
    padding: 10px 14px;
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.data-table th:first-child { border-radius: 8px 0 0 0; }
.data-table th:last-child  { border-radius: 0 8px 0 0; }

.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

.data-table tr:nth-child(even) td { background: #fafafa; }
.data-table tr:hover td { background: #fff7ed; }

.data-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.data-table td.ok-val  { color: #059669; }
.data-table td.err-val { color: #dc2626; }
.data-table tfoot td {
    font-weight: 700;
    background: #f9fafb;
    border-top: 2px solid #e5e7eb;
    padding: 10px 14px;
}
}

.preview-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-header h3 i { color: #ff9900; }

.btn-download-chart {
    padding: 9px 16px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-download-chart:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4); }
.btn-download-chart:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.preview-container {
    flex: 1;
    padding: 20px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
}

.preview-placeholder {
    text-align: center;
    color: #9ca3af;
}

.preview-placeholder i {
    font-size: 70px;
    color: #d1d5db;
    margin-bottom: 14px;
    display: block;
}

.preview-placeholder p {
    font-size: 16px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 6px;
}

.preview-placeholder small { font-size: 13px; color: #9ca3af; }

.chart-wrapper-custom {
    width: 100%;
    height: 100%;
    min-height: 380px;
    position: relative;
    display: none;
    background: white;
    padding: 16px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.chart-wrapper-custom.active { display: block; }

/* ==================== FOOTER ==================== */
.chart-builder-footer {
    padding: 14px 24px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 24px;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.footer-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
}

.footer-stat i { color: #ff9900; font-size: 14px; }

/* ==================== FILTRI GEOGRAFICI ==================== */

/* Titolo sezione con pulsante reset inline */
.config-section h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ==================== GEO LEVEL RADIO SELECTOR ==================== */
.geo-level-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 5px;
}

.geo-level-option {
    flex: 1;
    cursor: pointer;
}

.geo-level-option input[type="radio"] {
    display: none;
}

.geo-level-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 5px;
    border-radius: 7px;
    font-size: 10px;
    font-weight: 700;
    color: #6b7280;
    font-family: 'Titillium Web', sans-serif;
    transition: all 0.2s;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    text-align: center;
}

.geo-level-option input[type="radio"]:checked + span {
    background: white;
    color: #ff9900;
    box-shadow: 0 1px 5px rgba(0,0,0,0.12);
}

.geo-level-option:hover span {
    color: #ff9900;
}

/* Pulsante "Seleziona tutte" inline nella label */
.btn-sel-all {
    margin-left: auto;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: all 0.2s;
    font-family: 'Titillium Web', sans-serif;
    flex-shrink: 0;
}

.btn-sel-all:hover {
    background: #fff7ed;
    border-color: #ff9900;
    color: #ff9900;
}

.btn-reset-geo-filters {
    margin-left: auto;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    font-family: 'Titillium Web', sans-serif;
}

.btn-reset-geo-filters:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #dc2626;
}

/* Badge conteggio selezioni */
.geo-filter-count {
    font-size: 10px;
    font-weight: 700;
    color: #ff9900;
    margin-left: 4px;
}

/* Input di ricerca sopra il select */
.geo-search-input {
    width: 100%;
    padding: 7px 10px;
    border: 2px solid #e5e7eb;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-size: 12px;
    font-family: 'Titillium Web', sans-serif;
    background: white;
    color: #1f2937;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.geo-search-input:focus {
    outline: none;
    border-color: #ff9900;
}

.geo-search-input::placeholder { color: #9ca3af; }

/* Multi-select per filtri geo */
.geo-filter-select {
    width: 100%;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Titillium Web', sans-serif;
    background: white;
    color: #1f2937;
    cursor: pointer;
    box-sizing: border-box;
    overflow-y: auto;
    transition: border-color 0.2s;
    /* Quando preceduto da geo-search-input */
}

.geo-search-input + .geo-filter-select {
    border-top: none;
    border-radius: 0 0 6px 6px;
}

.geo-filter-select:focus { outline: none; border-color: #ff9900; }

.geo-filter-select option {
    padding: 5px 8px;
    font-size: 12px;
}

.geo-filter-select option:checked,
.geo-filter-select option:hover {
    background: linear-gradient(135deg, #ff9900, #e68800);
    color: white;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
    .chart-builder-body { flex-direction: column; }

    .chart-builder-config {
        width: 100%;
        max-height: 320px;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .chart-type-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 600px) {
    .chart-builder-modal { padding: 10px; }

    .chart-builder-header { padding: 14px 16px; }
    .chart-builder-title h2 { font-size: 16px; }

    .chart-type-grid { grid-template-columns: repeat(3, 1fr); }

    .config-actions { grid-template-columns: 1fr; }
    .btn-generate { grid-column: span 1; }

    .tipologie-checkboxes { grid-template-columns: 1fr; }
    .tipologie-checkboxes .tipologia-checkbox:last-child { grid-column: span 1; }

    .color-picker-grid { grid-template-columns: 1fr; }

    .chart-builder-trigger {
        top: 10px;
        padding: 10px 14px;
        font-size: 12px;
        gap: 0;
        z-index: 8;
    }

    .chart-builder-trigger span:not(.pulse-ring1) {
        display: none;
    }
}

/* ============================================================
   TEMA SCURO  (:root default = dark, [data-theme="light"] = light)
   Tutti gli override si applicano quando NON è attivo il tema chiaro
   ============================================================ */
:root:not([data-theme="light"]) {

    /* Contenitore principale */
    .chart-builder-content {
        background: #1e1e1e;
        box-shadow: 0 20px 60px rgba(0,0,0,0.7);
    }

    /* Header già colorato (#ff9900) — invariato */

    /* Tip bar */
    .chart-builder-tip {
        background: #2a2000;
        border-bottom-color: #4a3800;
        color: #f5c96a;
    }
    .chart-builder-tip-btn {
        border-color: #f59e0b;
        color: #f5c96a;
    }
    .chart-builder-tip-btn:hover { background: #f59e0b; color: #1e1e1e; }

    /* Pannello config (sinistra) */
    .chart-builder-config {
        background: #1a1a1a;
        border-right-color: #333;
    }

    .config-section {
        background: #252525;
        border-color: #333;
    }
    .config-section:hover { border-color: #ff9900; }
    .config-section h3 {
        color: #e0e0e0;
        border-bottom-color: #2d2d2d;
    }

    .config-label { color: #ccc; }

    .config-select {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    .config-select:focus { border-color: #ff9900; }
    .config-select option { background: #2d2d2d; color: #e0e0e0; }

    /* Type buttons */
    .chart-type-btn {
        background: #2d2d2d;
        border-color: #444;
        color: #aaa;
    }
    .chart-type-btn:hover { background: #3a3a3a; border-color: #ff9900; color: #ff9900; }
    .chart-type-btn.active { background: linear-gradient(135deg, #ff9900, #e68800); color: #fff; border-color: transparent; }
    .chart-type-btn span { color: inherit; }

    /* Checkbox tipologie */
    .tipologia-checkbox {
        background: #2d2d2d;
        border-color: #444;
    }
    .tipologia-checkbox:hover { background: #333; border-color: #ff9900; }
    .tipologia-checkbox.checked { background: rgba(255,153,0,0.12); border-color: #ff9900; }
    .tipologia-checkbox label { color: #ccc; }

    /* Info box */
    .info-box {
        background: rgba(255,255,255,0.04);
        border-color: #333;
        color: #999;
    }

    /* Mixed config */
    .mixed-config-section {
        background: rgba(124,58,237,0.08);
        border-color: rgba(124,58,237,0.3);
    }
    #mixed-config-group {
        background: rgba(59,130,246,0.08);
        border-color: rgba(59,130,246,0.25);
    }

    /* Color pickers */
    input[type="color"] { border-color: #444; background: #2d2d2d; }
    input[type="color"]:hover { border-color: #ff9900; }

    /* Range slider */
    input[type="range"] { accent-color: #ff9900; }
    .range-value {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    .range-label-text { color: #aaa; }

    /* Sub-label */
    .sub-label { color: #888; }

    /* Pulsanti azione */
    .btn-reset {
        background: #2d2d2d;
        border-color: #444;
        color: #aaa;
    }
    .btn-reset:hover { background: #3a3a3a; color: #ef4444; border-color: #ef4444; }

    /* Preset buttons */
    .preset-btn {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }
    .preset-btn:hover { border-color: #ff9900; color: #ff9900; }

    /* Geo level selector */
    .geo-level-selector { background: #252525; }
    .geo-level-option span { color: #888; }
    .geo-level-option input[type="radio"]:checked + span {
        background: #2d2d2d;
        color: #ff9900;
        box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    }

    /* Geo filter selects */
    .geo-filter-select {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    .geo-filter-select:focus { border-color: #ff9900; }
    .geo-filter-select option { background: #2d2d2d; color: #e0e0e0; }
    .geo-filter-select option:checked { background: #ff9900; color: #fff; }

    .geo-search-input {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    .geo-search-input::placeholder { color: #666; }
    .geo-search-input:focus { border-color: #ff9900; }
    .geo-search-input + .geo-filter-select { border-top: none; }

    .btn-sel-all { border-color: #444; color: #888; }
    .btn-sel-all:hover { background: rgba(255,153,0,0.1); border-color: #ff9900; color: #ff9900; }
    .btn-reset-geo-filters { border-color: #444; color: #888; }
    .btn-reset-geo-filters:hover { background: rgba(239,68,68,0.12); border-color: #ef4444; color: #ef4444; }

    /* Pannello preview (destra) */
    .chart-builder-preview { background: #1a1a1a; }

    .preview-header {
        background: #212121;
        border-bottom-color: #333;
    }
    .preview-header h3 { color: #e0e0e0; }

    /* View toggle */
    .view-toggle { background: #2d2d2d; }
    .view-toggle-btn { color: #888; }
    .view-toggle-btn.active { background: #3a3a3a; color: #ff9900; box-shadow: 0 1px 4px rgba(0,0,0,0.4); }

    /* Placeholder */
    .preview-placeholder          { color: #666; }
    .preview-placeholder i        { color: #444; }
    .preview-placeholder p        { color: #888; }
    .preview-placeholder small    { color: #666; }
    .preview-container            { background: #1a1a1a; }

    /* Footer */
    .chart-builder-footer {
        background: #212121;
        border-top-color: #333;
    }
    .footer-stat        { color: #aaa; }
    .footer-stat i      { color: #888; }
    #custom-chart-total { color: #e0e0e0; }
    #custom-chart-period{ color: #888; }

    /* Tabella */
    .table-wrapper-custom { background: #1a1a1a; }
    .data-table { color: #e0e0e0; }
    .data-table th {
        background: linear-gradient(135deg, #cc7700 0%, #b36600 100%);
    }
    .data-table td {
        border-bottom-color: #2d2d2d;
        color: #ccc;
    }
    .data-table tr:nth-child(even) td { background: #212121; }
    .data-table tr:hover td { background: rgba(255,153,0,0.06); }
    .data-table td.ok-val  { color: #4c9b82; }
    .data-table td.err-val { color: #e63946; }
    .data-table tfoot td {
        background: #212121;
        border-top-color: #333;
        color: #ccc;
    }

    /* Download buttons */
    .btn-download-chart:hover { box-shadow: 0 4px 12px rgba(59,130,246,0.4); }
    .btn-download-csv:hover   { box-shadow: 0 4px 12px rgba(16,185,129,0.4); }

    /* Filter badges */
    .filter-badge {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }

    /* Active filters box */
    .active-filters-box {
        background: #252525;
        border-color: #333;
    }

    /* Chart wrapper (canvas container) */
    .chart-wrapper-custom {
        background: #252525;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }

    /* Checkbox groups (opzioni visualizzazione, ecc.) */
    .checkbox-group {
        background: #2d2d2d;
    }
    .checkbox-group:hover { background: #333; border-color: #444; }
    .checkbox-group label { color: #ccc; }

    /* Divider */
    .divider { background: linear-gradient(90deg, transparent, #333, transparent); }

    /* Scrollbar nella colonna config */
    .chart-builder-config::-webkit-scrollbar-track { background: #252525; }
    .chart-builder-config::-webkit-scrollbar-thumb { background: #444; }

    /* Range slider track */
    input[type="range"] { background: #444; }

    /* Color input labels */
    .color-input-wrapper label { color: #888; }
}
