/* --- BASE & LAYOUT --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f4f4f9;
    color: #333;
}

/* --- HEADER --- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 10px;
}

/* --- NAVIGAZIONE (TABS) --- */
.tabs {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    background: #ffffff;
    padding: 10px;
    border-bottom: 2px solid #2c3e50;
    position: sticky;
    top: 0;
    z-index: 1000;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    flex: 0 0 auto;
    padding: 10px 20px;
    margin-right: 5px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
}

.tab-btn.active {
    background: #2c3e50;
    color: white;
    border-color: #2c3e50;
}

/* --- CONTENUTO SCHEDE --- */
.tab-content {
    display: none;
    padding: 20px;
    background: white;
    border: 1px solid #ddd;
    margin-top: 10px;
    border-radius: 8px;
}

/* Regola fondamentale per mostrare la scheda attiva */
.tab-content.active {
    display: block !important;
}

/* --- GRIGLIA E CAMPI --- */
.data-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
}

.campo {
    display: flex;
    flex-direction: column;
}

.campo label {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.campo input, .campo select, .campo textarea {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    height: 44px;
    max-width: 100%;
    box-sizing: border-box;
}

/* Campi precompilati dall'importazione PDF: da verificare prima di salvare.
   L'evidenziazione sparisce non appena l'utente interviene sul campo (controllato/corretto). */
.campo-importato-pdf {
    background-color: #fff9c4 !important;
}

/* --- HEADER / LOGOUT --- */
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-logout {
    padding: 6px 14px;
    background: transparent;
    color: inherit;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
}

/* --- BOTTONI --- */
.btn-nuovo {
    padding: 12px 20px;
    background-color: #2c3e50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

/* --- GRIGLIA TABELLE --- */
table {
    border: 1px solid #c3c2b7;
}
th, td {
    border: 1px solid #c3c2b7;
    padding: 8px 10px;
    text-align: left;
}
thead th {
    background: #f4f4f9;
}
tbody tr:nth-child(even) {
    background: #fafaf9;
}

/* --- OTTIMIZZAZIONE MOBILE (iPhone) --- */
@media only screen and (max-width: 600px) {
    body { padding: 10px; }
    
    .data-grid { 
        grid-template-columns: 1fr !important;
    }

    .btn-nuovo {
        width: 100%; 
    }

    /* Ottimizzazione tabelle Dashboard */
    table, thead, tbody, th, td, tr {
        display: block;
    }
    thead { display: none; }
    tr { margin-bottom: 15px; border: 1px solid #ccc; padding: 10px; }
    td { text-align: right; padding-left: 50%; position: relative; }
    td::before { content: attr(data-label); position: absolute; left: 10px; font-weight: bold; }
}

/* Regole globali */
table {
    width: 100%;
    border-collapse: collapse;
}
.grid-anteprime {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    min-height: 100px;
    padding: 10px 0;
}
@media (max-width: 900px) {
    .grid-anteprime {
        grid-template-columns: repeat(2, 1fr);
    }
}
.card-allegato {
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border: 1px solid #ccc;
    padding: 10px;
    border-radius: 8px;
}

/* --- DASHBOARD --- */
.dashboard-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.chart-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
}
.chart-card h3 {
    margin-top: 0;
    font-size: 1em;
}
.chart-card canvas {
    max-height: 240px;
}
.chart-tabella {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    font-size: 0.85em;
    color: #52514e;
}
.chart-tabella li {
    padding: 3px 0;
    border-top: 1px solid #e1e0d9;
}
.dashboard-nav {
    display: flex;
    gap: 12px;
    margin-top: 25px;
    flex-wrap: wrap;
}
.dashboard-nav a {
    text-decoration: none;
}

/* --- NUOVO SOGGETTO: pulsante rapido + modale --- */
.campo-con-azione {
    display: flex;
    gap: 6px;
}
.campo-con-azione select, .campo-con-azione input {
    flex: 1;
    min-width: 0;
}
.btn-aggiungi-soggetto {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    color: #2c3e50;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.btn-aggiungi-soggetto:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.modale-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modale-box {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
}