* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f4f5f7;
    color: #1f2328;
}

a {
    color: inherit;
}

h1 {
    margin: 0 0 4px;
}

h2 {
    margin: 0;
    font-size: 1.05rem;
}

.sottotitolo {
    color: #6b7280;
    margin-top: 0;
    margin-bottom: 24px;
}

.messaggio-errore {
    background: #fde8e8;
    color: #9b1c1c;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.messaggio-successo {
    background: #dcfce7;
    color: #166534;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

/* --- Pagina profilo --- */
.griglia-profilo {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    align-items: start;
}

.suggerimento-campo {
    font-size: 0.78rem;
    color: #6b7280;
}

.opzione-mostra-password {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #4b5563;
    cursor: pointer;
}

.opzione-mostra-password input {
    width: auto;
}

.vuoto {
    color: #6b7280;
    text-align: center;
    padding: 16px 0;
}

/* --- Layout applicazione con barra di navigazione in alto --- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar {
    width: 100%;
    flex-shrink: 0;
    background: #fff;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-brand {
    grid-column: 1;
    justify-self: start;
    display: flex;
    align-items: center;
    padding: 10px 0;
}

.sidebar-logo {
    height: 40px;
    width: auto;
    max-width: 150px;
    display: block;
}

.sidebar-nav {
    grid-column: 2;
    justify-self: center;
    display: flex;
    flex-direction: row;
    padding: 0;
    gap: 4px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: #4b5563;
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
}

.sidebar-nav a:hover {
    background: #f3f4f6;
    color: #111827;
}

.sidebar-nav a.attivo {
    background: #163D8A;
    color: #fff;
}

.icona {
    font-size: 1rem;
}

.sidebar-footer {
    grid-column: 3;
    justify-self: end;
    padding: 10px 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
}

.utente-corrente {
    font-size: 0.85rem;
    color: #6b7280;
    white-space: nowrap;
}

a.utente-corrente {
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 6px;
}

a.utente-corrente:hover,
a.utente-corrente.attivo {
    background: #eef2ff;
    color: #163D8A;
}

.link-logout {
    font-size: 0.82rem;
    color: #dc2626;
    text-decoration: none;
    white-space: nowrap;
}

.link-logout:hover {
    text-decoration: underline;
}

.contenuto-principale {
    flex: 1;
    width: 100%;
    padding: 32px 40px 60px;
    max-width: 1200px;
    margin: 0 auto;
}

.intestazione-pagina {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}

/* --- Piè di pagina --- */
.piede-pagina {
    text-align: center;
    font-size: 0.78rem;
    color: #9ca3af;
    padding: 14px 20px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.piede-pagina-login {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: transparent;
    border-top: none;
    padding: 16px 20px;
    color: rgba(255, 255, 255, 0.75);
}

/* --- Pagina di login --- */
.pagina-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a8a, #111827);
}

.scheda-login {
    background: #fff;
    border-radius: 12px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo {
    max-width: 100%;
    height: auto;
    margin-bottom: 10px;
}

.login-brand p {
    margin: 0;
    color: #6b7280;
    font-size: 0.88rem;
}

.modulo-login {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modulo-login button {
    margin-top: 6px;
}

/* --- Elementi di modulo comuni --- */
.campo {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.campo label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
}

.riga-campi {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.riga-campi .campo {
    flex: 1;
    min-width: 180px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    width: 100%;
}

button {
    align-self: flex-start;
    background: #163D8A;
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

button:hover {
    background: #123271;
}

.azioni-modulo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

/* --- Pannelli --- */
.pannello {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
}

.modulo-pannello {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modulo-dati {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.pannello-titolo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}

.link-vedi-tutti {
    font-size: 0.85rem;
    color: #163D8A;
    text-decoration: none;
}

.link-vedi-tutti:hover {
    text-decoration: underline;
}

/* --- Statistiche dashboard --- */
.griglia-statistiche {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

@media (max-width: 900px) {
    .griglia-statistiche {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 520px) {
    .griglia-statistiche {
        grid-template-columns: 1fr;
    }
}

.scheda-stat {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-etichetta {
    font-size: 0.8rem;
    color: #6b7280;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-valore {
    font-size: 1.6rem;
    font-weight: 700;
    color: #111827;
}

.griglia-doppia {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

/* --- Grafici dashboard --- */
.griglia-grafici {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.scheda-grafico {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scheda-grafico h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.grafico-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.grafico-svg text {
    font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.grafico-etichetta {
    font-size: 8px;
    fill: #4b5563;
}

.grafico-valore {
    font-size: 8px;
    font-weight: 600;
    fill: #111827;
}

.grafico-tick {
    font-size: 7px;
    fill: #9ca3af;
}

.grafico-tick-centrato {
    text-anchor: middle;
}

.grafico-griglia {
    stroke: #eef0f2;
    stroke-width: 1;
}

.grafico-asse {
    stroke: #e5e7eb;
    stroke-width: 1;
}

.legenda-grafico {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: #4b5563;
}

.legenda-punto {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: middle;
}

/* --- Righe/badge di scadenza (dashboard) --- */
.riga-in-scadenza {
    background: #fffbeb;
}

.riga-urgente {
    background: #fff1f0;
}

.riga-scaduto {
    background: #fef2f2;
}

.badge-in-scadenza {
    background: #fef3c7;
    color: #92400e;
}

.badge-urgente {
    background: #ffe4d5;
    color: #9a3412;
}

.badge-scaduto {
    background: #fde2e2;
    color: #991b1b;
}

/* --- Banner avvisi scadenze (dashboard) --- */
.pannello-avvisi {
    border-color: #fcd9b6;
    background: #fffaf5;
}

.lista-avvisi {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.avviso-scadenza {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: 0.88rem;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 500;
}

.avviso-scadenza strong {
    font-size: 1.05rem;
    font-weight: 700;
}

.avviso-scaduto {
    background: #fde2e2;
    color: #991b1b;
}

.avviso-urgente {
    background: #ffe4d5;
    color: #9a3412;
}

.avviso-in-scadenza {
    background: #fef3c7;
    color: #92400e;
}

/* --- Tabelle --- */
.tabella-dati {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.tabella-dati th {
    text-align: left;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6b7280;
    padding: 8px 10px;
    border-bottom: 2px solid #e5e7eb;
}

.tabella-dati td {
    padding: 10px;
    border-bottom: 1px solid #f0f1f3;
    vertical-align: middle;
}

.tabella-dati tr:last-child td {
    border-bottom: none;
}

.col-descrizione {
    color: #4b5563;
}

.azioni {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    text-decoration: none;
    font-size: 0.82rem;
    padding: 6px 10px;
    border-radius: 5px;
    white-space: nowrap;
    display: inline-block;
}

.btn-modifica {
    background: #dbeafe;
    color: #1e40af;
}

.btn-elimina {
    background: #fde2e2;
    color: #991b1b;
}

.btn-annulla {
    background: #e5e7eb;
    color: #374151;
}

.btn-pdf {
    background: #e0e7ff;
    color: #3730a3;
}

/* --- Popup modale (riutilizzato da preventivi e consuntivi) --- */
.btn-nuovo-elemento {
    background: #163D8A;
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 0.92rem;
    cursor: pointer;
    align-self: flex-start;
}

.btn-nuovo-elemento:hover {
    background: #123271;
}

.finestra-modale {
    position: relative;
    border: none;
    border-radius: 14px;
    padding: 0;
    width: min(720px, calc(100vw - 48px));
    max-width: 720px;
    max-height: calc(100vh - 110px);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
    flex-direction: column;
    animation: comparsa-modale 0.16s ease-out;
}

/* Il display va forzato solo quando il dialog è effettivamente aperto (attributo [open]):
   altrimenti la regola sovrascrive "dialog:not([open]) { display: none }" dello user-agent
   e il popup resta visibile anche senza showModal(). */
.finestra-modale[open] {
    display: flex;
}

.finestra-modale::backdrop {
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(1px);
}

/* Variante larga: usata dal popup preventivo per contenere la tabella voci */
.finestra-modale--larga {
    width: min(1180px, calc(100vw - 48px));
    max-width: 1180px;
}

@keyframes comparsa-modale {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.modale-intestazione {
    padding: 18px 52px 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 14px 14px 0 0;
    background: #f9fafb;
    flex-shrink: 0;
}

.modale-intestazione h2 {
    font-size: 1rem;
    color: #111827;
}

.btn-chiudi-modale {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef0f2;
    border: none;
    border-radius: 50%;
    font-size: 1.15rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-chiudi-modale:hover {
    background: #e5e7eb;
    color: #111827;
}

.modale-corpo {
    padding: 20px 24px 24px;
    overflow-y: auto;
}

.modale-corpo .modulo-dati {
    gap: 12px;
}

/* --- Tabella voci di preventivo --- */
.contenitore-tabella-voci {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.tabella-voci {
    width: 100%;
    table-layout: fixed;
}

.tabella-voci th,
.tabella-voci td {
    text-align: right;
    white-space: normal;
    word-break: break-word;
    padding: 8px 6px;
}

.tabella-voci th:first-child,
.tabella-voci td:first-child {
    text-align: left;
}

.tabella-voci th:nth-child(1) { width: 21%; }
.tabella-voci th:nth-child(2) { width: 7%; }
.tabella-voci th:nth-child(3) { width: 11%; }
.tabella-voci th:nth-child(4) { width: 11%; }
.tabella-voci th:nth-child(5) { width: 11%; }
.tabella-voci th:nth-child(6) { width: 11%; }
.tabella-voci th:nth-child(7) { width: 10%; }
.tabella-voci th:nth-child(8) { width: 10%; }
.tabella-voci th:nth-child(9) { width: 8%; }

.tabella-voci input {
    padding: 6px 6px;
    font-size: 0.85rem;
}

.tabella-voci .valore-calcolato {
    font-variant-numeric: tabular-nums;
    color: #374151;
    font-weight: 600;
}

.tabella-voci tfoot td {
    font-weight: 700;
    border-top: 2px solid #e5e7eb;
    background: #f9fafb;
}

.btn-rimuovi-voce {
    background: #fde2e2;
    color: #991b1b;
    border: none;
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-rimuovi-voce:hover {
    background: #fbcaca;
}

/* --- Tabella ore di lavoro (consuntivo) --- */
.tabella-ore th:nth-child(1) { width: 70%; }
.tabella-ore th:nth-child(2) { width: 20%; }
.tabella-ore th:nth-child(3) { width: 10%; }

.tabella-ore td {
    vertical-align: middle;
}

.tabella-ore input {
    padding: 6px 6px;
    font-size: 0.85rem;
}

.tabella-ore tfoot td {
    font-weight: 700;
    border-top: 2px solid #e5e7eb;
    background: #f9fafb;
}

/* --- Tabella SAL (consuntivo) --- */
.tabella-sal th:nth-child(1) { width: 5%; }
.tabella-sal th:nth-child(2) { width: 15%; }
.tabella-sal th:nth-child(3) { width: 28%; }
.tabella-sal th:nth-child(4) { width: 10%; }
.tabella-sal th:nth-child(5) { width: 10%; }
.tabella-sal th:nth-child(6) { width: 12%; }
.tabella-sal th:nth-child(7) { width: 13%; }
.tabella-sal th:nth-child(8) { width: 7%; }

.riga-sal--oltre-previsto .dato-percentuale-sal,
.riga-sal--oltre-previsto .input-ore-sal {
    color: #b45309;
}

.avviso-sal {
    background: #fef3c7;
    color: #92400e;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin: 10px 0 0;
}

.tabella-sal th:nth-child(3),
.tabella-sal td:nth-child(3) {
    text-align: left;
}

.tabella-sal select {
    padding: 6px 4px;
    font-size: 0.85rem;
    width: 100%;
}

.barra-avanzamento {
    height: 8px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

.barra-avanzamento-riempimento {
    height: 100%;
    width: 0;
    background: #163D8A;
    border-radius: 999px;
    transition: width 0.2s ease;
}

.barra-avanzamento--compatta {
    height: 6px;
    min-width: 70px;
    margin-bottom: 3px;
}

.btn-aggiungi-voce {
    background: #eef2ff;
    color: #3730a3;
    border: none;
    align-self: flex-start;
    margin-top: 8px;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.88rem;
    cursor: pointer;
}

.btn-aggiungi-voce:hover {
    background: #e0e7ff;
}

/* --- Riepilogo totali preventivo (voci + manodopera) --- */
.riepilogo-preventivo {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.riepilogo-riga {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #4b5563;
}

.riepilogo-riga--totale {
    border-top: 1px solid #e5e7eb;
    margin-top: 4px;
    padding-top: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #111827;
}

/* --- Filtri di stato --- */
.filtri-stato {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.filtri-stato a {
    text-decoration: none;
    font-size: 0.82rem;
    padding: 5px 12px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #4b5563;
}

.filtri-stato a.attivo {
    background: #163D8A;
    color: #fff;
}

/* --- Badge di stato --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-bozza {
    background: #e5e7eb;
    color: #374151;
}

.badge-inviato {
    background: #fef3c7;
    color: #92400e;
}

.badge-accettato {
    background: #dcfce7;
    color: #166534;
}

.badge-rifiutato {
    background: #fde2e2;
    color: #991b1b;
}

.badge-in_corso {
    background: #dbeafe;
    color: #1e40af;
}

.badge-completato {
    background: #dcfce7;
    color: #166534;
}

.badge-fatturato {
    background: #ede9fe;
    color: #5b21b6;
}

@media (max-width: 720px) {
    .sidebar {
        display: flex;
        flex-wrap: wrap;
        row-gap: 8px;
        padding: 10px 16px;
    }

    .sidebar-nav {
        order: 3;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .sidebar-footer {
        margin-left: auto;
    }

    .contenuto-principale {
        padding: 20px;
    }
}
