/* Reset base e Stili Globali */
body { 
    font-family: 'Titillium Web', "Helvetica Neue", Helvetica, Arial, sans-serif; 
    margin: 0; 
    background-color: #f0f0f0;
    color: #333;
    font-size: 1rem; /* Base 16px di default */
    line-height: 1.5;
    padding-bottom: 80px;
}

.container {
    width: 95%;
    max-width: 1400px; 
    margin: 0 auto;
    padding: 0 15px;
}

/* Header */
.main-header {
    background-color: #343a40;
    color: #fff;
    padding: 12px 0;
    margin-bottom: 25px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
.header-content { 
    display: flex;
    align-items: center; 
}
.header-logo {
    height: 80px;
    width: auto;
    margin-right: 15px;
}
.header-text {
    line-height: 1.3;
}
.main-title { 
    font-size: 1.9em; 
    margin: 0;
    font-weight: 600; 
    color: #fff;
}
.main-title .location-name {
    font-weight: 400; 
    font-size: 0.9em; 
}
.sub-title {
    font-size: 1.2em; 
    margin: 0; 
    font-weight: 300; 
    color: #ced4da; 
}
.header-nav {
    margin-left: auto; 
    display: flex; 
    align-items: center;
}
.header-nav a {
    color: #ced4da; 
    text-decoration: none;
    padding: 8px 15px; 
    border-radius: 4px;
    font-weight: 500; 
    font-size: 0.95rem; /* Leggermente più piccolo di 1.1rem per bilanciare */
    transition: background-color 0.2s, color 0.2s;
}
.header-nav a:hover {
    background-color: #495057; 
    color: #fff; 
}

/* Controlli Pagina */
.page-controls-bar {
    background-color: #f7f7f7;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px; 
}
.page-controls-bar .list-info {
    font-size: 0.95rem;
    font-weight: bold;
    color: #333;
    white-space: nowrap;
    margin-right: 5px; 
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
}
.control-button-style {
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem; /* Unificato font-size per bottoni di controllo */
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    white-space: nowrap;
    text-align: center;
}
/* Hover specifici per bottoni Applica/Reset/Cerca sono definiti sotto */

/* Dropdown "Aggiungi Filtro" */
.filter-dropdown-container { position: relative; display: inline-block; }
.dropdown-content {
    display: none; 
    position: absolute;
    background-color: #fff;
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    border: 1px solid #ccc;
    border-radius: 4px;
    z-index: 10;
    margin-top: 2px;
}
.dropdown-content a { color: black; padding: 8px 12px; text-decoration: none; display: block; font-size: 0.9em; }
.dropdown-content a:hover { background-color: #f1f1f1; }
.dropdown-content a.disabled { color: #aaa; cursor: not-allowed; background-color: #f9f9f9; }
.dropdown-content a.disabled:hover { background-color: #f9f9f9; }

.main-search-input {
    flex-grow: 1;
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}
.search-button { /* Pulsante "Cerca" nella barra superiore */
    background-color: #6c757d; 
    color: white;
    border-color: #545b62;
    font-weight: bold;
}
.search-button:hover { background-color: #5a6268; border-color: #545b62; }

/* Area Filtri Attivi e Pulsanti Azione */
#active-filters-area {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; 
    gap: 20px; 
    margin-bottom: 15px;
    padding-top: 10px;
}
#active-filters-container {
    display: flex;
    flex-direction: column; 
    gap: 10px; 
    flex-grow: 1; 
}
.action-buttons-for-filters {
    display: flex;
    flex-direction: column; 
    gap: 8px; 
    align-items: stretch; 
}
.apply-button {
    background-color: #007bff; color: white; border-color: #007bff; font-weight: bold;
}
.apply-button:hover { background-color: #0056b3; border-color: #0056b3; }
#reset-all-filters-button {
    background-color: #6c757d; color: white; border-color: #545b62;
}
#reset-all-filters-button:hover { background-color: #5a6268; border-color: #545b62; }

.active-filter-item {
    display: flex; align-items: center; gap: 5px; font-size: 0.9em;
}
.filter-name-tag {
    background-color: #6c757d; color: white; border: 1px solid #545b62;
    padding: 6px 10px; border-radius: 4px; cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    font-weight: 500; font-size: 0.875em;
}
.filter-name-tag .remove-icon { font-weight: bold; font-size: 1.1em; line-height: 1; }
.filter-name-tag:hover { background-color: #5a6268; }
.filter-operator-select, .filter-value-input {
    padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px;
    font-size: 0.875em; background-color: #fff; box-sizing: border-box;
}
.filter-operator-select { min-width: 110px; }
.filter-value-input { width: 150px; }
.filter-value-input[type="number"] { width: 100px; }
.filter-value-input::placeholder { color: #999; }

/* Status Messages */
.status-messages { 
    margin-bottom: 15px; background-color: #fff; padding: 10px 15px;
    border: 1px solid #e3e3e3; border-radius: 4px; font-size: 0.9em;
}
.status-messages p { margin: 5px 0; }
#error-message { color: #dc3545 !important; font-weight: bold; }

/* Tabella e Ordinamento */
.table-responsive-wrapper {
    overflow-x: auto; width: 100%; margin-bottom: 20px; 
}
table { 
    width: 100%; border-collapse: collapse; margin-bottom: 0; /* Rimosso margin-bottom dalla tabella, gestito dal wrapper */
    background-color: #fff; border: 1px solid #ddd; font-size: 0.875em;
}
th, td { 
    border-bottom: 1px solid #eee; border-left: 1px solid #eee; 
    padding: 9px 10px; text-align: left; vertical-align: top; 
}
th:first-child, td:first-child { border-left: none; }
th { 
    background-color: #f7f7f7; font-weight: bold; color: #333;
    border-bottom-width: 1px; border-bottom-color: #ddd;
}
table > thead > tr > th { border-top: none; }
td { color: #212529; }
/* Larghezze colonne (come le avevi) */
#results-table th:nth-child(1), #results-table td:nth-child(1) { width: 60px; }
#results-table th:nth-child(2), #results-table td:nth-child(2) { width: 90px; }
#results-table th:nth-child(4), #results-table td:nth-child(4) { text-align: right; width: 110px; }
#results-table th:nth-child(6), #results-table td:nth-child(6) { width: 90px; }
#results-table td:nth-child(3) { min-width: 180px; }
#results-table td:nth-child(5) { min-width: 220px; }

.sortable-header {
    cursor: pointer; position: relative; user-select: none;
    /* font-size: 1rem; Rimosso, eredita da th */
}
.sortable-header:hover { background-color: #e8e8e8; }
.sort-arrow {
    display: inline-block; width: 0; height: 0;
    margin-left: 7px; vertical-align: middle; 
    opacity: 0.4; transition: opacity 0.2s, transform 0.2s;
}
.sortable-header.sort-asc .sort-arrow {
    border-left: 5px solid transparent; border-right: 5px solid transparent;
    border-bottom: 6px solid #333; opacity: 1; transform: translateY(-2px);
}
.sortable-header.sort-desc .sort-arrow {
    border-left: 5px solid transparent; border-right: 5px solid transparent;
    border-top: 6px solid #333; opacity: 1; transform: translateY(1px);
}

/* Paginazione */
.pagination {
    margin-top: 20px; margin-bottom: 30px; text-align: center;
    background-color: #fff; padding: 12px 15px; border: 1px solid #e3e3e3;
    border-radius: 4px; display: flex; justify-content: center;
    align-items: center; flex-wrap: wrap; gap: 5px;
}
.pagination button, .pagination input[type="number"], .pagination select {
    margin: 0 2px; padding: 6px 10px; font-size: 0.9rem; /* Coerenza font-size */
    border: 1px solid #ccc; border-radius: 4px; vertical-align: middle; 
}
.pagination input[type="number"]#page-input { width: 50px; text-align: center; }
.pagination select#rows-per-page { padding-right: 25px; }
.pagination button { background-color: #fff; color: #007bff; cursor: pointer; transition: background-color 0.15s ease-in-out; }
.pagination button:hover { background-color: #e9ecef; }
.pagination button:disabled { color: #6c757d; background-color: #f8f9fa; opacity: 0.65; cursor: not-allowed; }
.pagination .page-indicator, .pagination .rows-per-page-label { 
    padding: 6px 0; font-size: 0.9rem; color: #495057; margin: 0 5px; 
}
.pagination .rows-per-page-label { margin-left: 15px; }

#loading-spinner { 
    display: flex; /* Usato da JS per mostrarlo. Flex per centrare lo spinner figlio. */
    justify-content: center; /* Centra lo spinner orizzontalmente */
    align-items: center; /* Centra lo spinner verticalmente */
    width: 100%; /* Occupa la larghezza per una centratura efficace */
    min-height: 70px; /* Altezza minima per dare spazio verticale quando è visibile, aggiusta se necessario */
    padding: 15px 0; /* Un po' di padding verticale */
    box-sizing: border-box;
}

/* Lo spinner effettivo (il cerchio che ruota) */
.spinner {
  border: 5px solid #f3f3f3; 
  border-top: 5px solid #007bff; /* Blu per coerenza con i pulsanti */
  border-radius: 50%;
  width: 20px; 
  height: 20px;
  animation: spin 1s linear infinite;
  /* margin: 0 auto; Non più necessario se #loading-spinner usa flex per centrare */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Classe per disabilitare interazioni (già presente e corretta) */
.controls-disabled {
    pointer-events: none;
    opacity: 0.6;
}

/* Stili Specifici Pagina Dati (dati.html) */
.page-navigation { margin-bottom: 20px; font-size: 0.9em; }
.page-navigation a { color: #007bff; text-decoration: none; /* Rimosso margin-bottom, gestisci con gap o padding se serve */ }
.page-navigation a:hover { text-decoration: underline; }
.download-links {
    margin-top: 30px; margin-bottom: 30px; display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;
}
.download-item {
    background-color: #fff; padding: 20px; border: 1px solid #e0e0e0;
    border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.download-item h3 { margin-top: 0; color: #333; }
.download-item p { font-size: 0.95rem; color: #555; line-height: 1.6; }
.download-button {
    display: inline-block; margin-top: 15px; padding: 10px 20px;
    background-color: #007bff; color: white; text-decoration: none;
    border-radius: 4px; font-weight: 600; transition: background-color 0.2s;
    font-size: 0.9rem; /* Coerenza con altri bottoni */
}
.download-button:hover { background-color: #0056b3; }

.main-footer {
    position: fixed; 
    left: 0; 
    bottom: 0; 
    width: 100%;
    padding: 20px 0; 
    background: #f8f9fa;
    text-align: center; 
    border-top: 1px solid #e0e0e0;
    z-index: 100; /* È buona norma avere uno z-index per elementi fissi */
}

/* --- RESPONSIVE DESIGN --- */
/* Breakpoint Medio (es. tablet portrait, mobile landscape) */
@media (max-width: 768px) {
    .container { padding: 0 10px; }
    .main-header .header-content {
        flex-direction: column; align-items: center; text-align: center; gap: 10px;
    }
    .header-logo { height: 60px; margin-right: 0; margin-bottom: 8px; }
    .main-title { font-size: 1.7em; } /* Relativo al font-size del body (1rem) */
    .sub-title { font-size: 1.1em; }
    .header-nav { margin-left: 0; margin-top: 10px; width: 100%; justify-content: center; }
    .header-nav a { font-size: 1rem; padding: 8px 12px; }

    .page-controls-bar { flex-direction: column; align-items: stretch; }
    .page-controls-bar > * { margin-bottom: 10px; width: 100%; box-sizing: border-box; }
    .page-controls-bar .list-info { margin-right: 0; text-align: center; }
    .main-search-input { min-width: 0; }

    #active-filters-area { flex-direction: column; align-items: stretch; }
    .action-buttons-for-filters {
        margin-left: 0; margin-top: 15px; flex-direction: row; 
        justify-content: space-around; /* O space-between per spingerli ai lati */
    }
    .action-buttons-for-filters button { flex-basis: 48%; text-align: center; }
    .active-filter-item { flex-wrap: wrap; }
    .filter-value-input, .filter-value-input[type="number"] { width: 100%; }
}

/* Breakpoint Piccolo (Smartphone portrait) */
@media (max-width: 480px) {
    body { font-size: 0.875rem; /* 14px se il base è 16px */ }
    .main-title { font-size: 1.5em; }
    .sub-title { font-size: 1em; }
    .header-logo { height: 50px; }
    .header-nav a { font-size: 0.95rem; } /* Riduci ancora un po' se necessario */
    
    .download-links { grid-template-columns: 1fr; gap: 15px; }
    .download-item { padding: 15px; }
    .action-buttons-for-filters { flex-direction: column; }
    .action-buttons-for-filters button { width: 100%; flex-basis: auto; }
    .pagination button, .pagination input, .pagination select, 
    .pagination .page-indicator, .pagination .rows-per-page-label {
        font-size: 0.85rem; 
    }
    .control-button-style, .search-button, .apply-button, #reset-all-filters-button, .download-button {
        font-size: 0.85rem; /* Riduci font bottoni */
        padding: 5px 10px; /* Riduci padding bottoni */
    }
    .filter-name-tag { font-size: 0.8rem; padding: 5px 8px; }
    .filter-operator-select, .filter-value-input { font-size: 0.8rem; }
}