:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f3f6f8;
    color: #16232d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 0.75rem 1.5rem;
    background: #123b52;
}

.brand {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
}

.account-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem 1rem;
    color: #dcecf3;
    font-size: 0.9rem;
}

.account-actions a {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.account-actions form {
    margin: 0;
}

.company-switcher {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.company-switcher label {
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.company-switcher select {
    width: auto;
    max-width: 220px;
    padding: 0.45rem 0.6rem;
    border-color: #7896a7;
    background: #fff;
    color: #123b52;
}

.switch-button {
    padding: 0.48rem 0.65rem;
    border: 1px solid #a9c1ce;
    border-radius: 7px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 750;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

/* Layout da applicazione: il contenuto usa tutta la larghezza disponibile. */
.page-shell {
    padding: 1.25rem 1.5rem 2rem;
}

.welcome-card,
.auth-card {
    margin: 8vh auto 0;
}

.welcome-card {
    width: min(680px, 100%);
    padding: clamp(2rem, 6vw, 4rem);
    border: 1px solid #dce5ea;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 24px 70px rgb(30 66 87 / 12%);
}

.auth-card {
    width: min(440px, 100%);
    padding: 2rem;
    border: 1px solid #dce5ea;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 24px 70px rgb(30 66 87 / 12%);
}

.form-field {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 1rem;
}

.form-field label {
    font-size: 0.88rem;
    font-weight: 700;
}

.auth-card .form-field input {
    min-height: 2.8rem;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.primary-button {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 0;
    border-radius: 9px;
    background: #176b67;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
}

.field-error {
    margin: 0;
    color: #a52323;
    font-size: 0.82rem;
}

.flash-stack {
    display: grid;
    gap: 0.5rem;
    margin: 1rem 1.5rem 0;
}

.flash {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    background: #e7eef2;
}

.flash-success {
    background: #dff3e8;
    color: #145b39;
}

.flash-danger,
.flash-warning {
    background: #fde7e7;
    color: #8a1f1f;
}

.admin-shell {
    width: 100%;
}

.section-title {
    font-size: clamp(1.6rem, 2.4vw, 2.1rem);
}

.section-description {
    margin: 0.4rem 0 1.25rem;
    color: #5a6b75;
}

.admin-nav {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.admin-nav a {
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    background: #e5edf1;
    color: #123b52;
    font-weight: 750;
    text-decoration: none;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.7fr);
    gap: 1.5rem;
    align-items: start;
}

.panel {
    padding: 1.35rem;
    border: 1px solid #dce5ea;
    border-radius: 14px;
    background: #fff;
    /* Le tabelle più larghe del riquadro scorrono invece di uscirne. */
    overflow-x: auto;
}

.panel h1,
.panel h2 {
    margin-top: 0;
    color: #123b52;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem 0.55rem;
    border-bottom: 1px solid #e2e9ed;
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: #536772;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.data-table tr.row-invalid td {
    background: #fdecec;
    color: #a52323;
}

.row-invalid-note {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
}

.data-table a {
    color: #176b67;
    font-weight: 700;
}

.badge {
    display: inline-flex;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: #dff3e8;
    color: #145b39;
    font-size: 0.78rem;
    font-weight: 800;
}

.badge-inactive {
    background: #edf0f2;
    color: #6b747a;
}

.secondary-button {
    display: inline-flex;
    justify-content: center;
    padding: 0.7rem 1rem;
    border: 1px solid #9db0ba;
    border-radius: 9px;
    background: #fff;
    color: #123b52;
    cursor: pointer;
    font: inherit;
    font-weight: 750;
    text-decoration: none;
}

.danger-button {
    padding: 0.7rem 1rem;
    border: 0;
    border-radius: 9px;
    background: #a52323;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 750;
}

.inline-edit-form {
    display: flex;
    gap: 0.6rem;
    min-width: 320px;
}

.counter-form {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) minmax(90px, 1fr) auto;
    gap: 0.5rem;
    min-width: 330px;
}

.counter-form input[type="number"] {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid #b8c8d1;
    border-radius: 9px;
    font: inherit;
}

.muted-text {
    color: #6b747a;
    font-size: 0.82rem;
}

.page-heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 1rem;
}

.primary-link {
    display: inline-flex;
    padding: 0.8rem 1rem;
    border-radius: 9px;
    background: #176b67;
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.table-actions form {
    margin: 0;
}

/* Una cella in flex smette di essere una cella di tabella e disallinea le righe. */
td.table-actions {
    display: table-cell;
    white-space: nowrap;
}

td.table-actions > * {
    display: inline-block;
    margin-right: 0.75rem;
    vertical-align: middle;
}

td.table-actions > :last-child {
    margin-right: 0;
}

.danger-link {
    padding: 0;
    border: 0;
    background: transparent;
    color: #a52323;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
}

.config-panel { margin-top: 1rem; }
.config-row, .config-form, .config-category, .config-option { display: flex; align-items: center; gap: 0.65rem; margin: 0.5rem 0; }
.config-row { justify-content: space-between; }
.config-form > input, .config-form > select { min-width: 110px; }
.config-category, .config-option { justify-content: space-between; }
.config-category > .config-form, .config-option > .config-form { flex: 1; }

/* Schede di dettaglio: sezioni a tutta larghezza, campi in colonne automatiche. */
.record-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.record-header .eyebrow {
    margin-bottom: 0.35rem;
}

.record-meta {
    margin: 0.35rem 0 0;
    color: #5a6b75;
}

.employee-form-grid {
    display: grid;
    gap: 1rem;
}

.employee-fieldset {
    min-width: 0;
    margin: 0;
    padding: 1rem 1.25rem 0.25rem;
}

/* Il legend fluttuante resta dentro il riquadro invece di tagliarne il bordo. */
.employee-fieldset legend {
    float: left;
    width: 100%;
    margin: 0 0 0.85rem;
    padding: 0;
    color: #123b52;
    font-size: 0.95rem;
    font-weight: 800;
}

.employee-fieldset legend + * {
    clear: both;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0 1rem;
}

.field-grid .form-field {
    gap: 0.3rem;
    margin-bottom: 0.85rem;
}

.field-grid .form-field label {
    color: #3d505b;
    font-size: 0.8rem;
}

@media (min-width: 761px) {
    .field-grid .field-wide {
        grid-column: span 2;
    }
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 1rem -1.5rem -2rem;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid #dce5ea;
    background: rgb(243 246 248 / 95%);
}

.deadline-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.deadline-stats .panel { display: grid; gap: 0.25rem; }
.deadline-stats strong { font-size: 1.8rem; }
.state-expired, .status-scaduto { color: #a52323; }
.state-warning, .status-in_scadenza { color: #9a6500; }
.state-valid, .status-valido { color: #1f6b4f; }
.status-ok, .status-inviato { color: #1f6b4f; }
.status-email_mancante, .status-non_trovato, .status-errore { color: #a52323; }
.smtp-state { display: grid; gap: 0.25rem; }

.deadline-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    gap: 1rem;
}

.deadline-form .primary-button { margin-bottom: 1rem; }
.filter-form, .deadline-template { display: flex; align-items: center; gap: 0.65rem; }
.deadline-template { justify-content: space-between; padding: 0.65rem 0; border-bottom: 1px solid #dfe7eb; }
.deadline-template .config-form { flex: 1; }
.deadline-template.is-inactive { opacity: 0.55; }
.status-badge { display: inline-block; font-weight: 700; white-space: nowrap; }
.nav-count { display: inline-block; min-width: 1.4rem; padding: 0.1rem 0.35rem; border-radius: 999px; background: #a52323; color: #fff; text-align: center; }
.home-deadlines { margin-top: 1rem; }

.document-selection, .document-template-form {
    display: flex;
    align-items: end;
    gap: 1rem;
}

.document-selection .form-field { flex: 1; }
.document-template-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid #dfe7eb; }
.document-template-row .document-template-form { flex: 1; }
.placeholder-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.placeholder-list code { padding: 0.35rem 0.55rem; border: 1px solid #cbd8de; border-radius: 6px; background: #f5f8f9; }
.document-context-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }

.employee-toolbar { display: grid; gap: 1rem; margin-bottom: 1rem; }
.employee-filters, .employee-report-actions { display: flex; align-items: end; gap: 1rem; }
.employee-filters .form-field { flex: 1; margin: 0; }
.employee-filters .primary-button { width: auto; }
.employee-report-actions { flex-wrap: wrap; }
.employee-report-actions a { font-weight: 700; }
.employee-toolbar a { color: #176b67; font-weight: 700; }
.employee-filters .form-field + .form-field { flex: 0 1 260px; }
.copy-options { margin: 1rem 0; border: 1px solid #dfe7eb; border-radius: 9px; padding: 1rem; }
.copy-options legend { color: #123b52; font-weight: 800; }
.copy-preview { margin-top: 1rem; }
.company-setting-form { display: grid; grid-template-columns: 0.7fr 1fr 1.5fr auto; align-items: end; gap: 1rem; }
.company-setting-form .form-field { margin: 0; }
.company-setting-form .primary-button { width: auto; margin-bottom: 0; }
.company-setting-row { display: grid; grid-template-columns: minmax(220px, 0.8fr) minmax(0, 2fr) auto; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid #dfe7eb; }
.company-setting-edit { display: grid; grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 2fr) auto; align-items: center; gap: 0.75rem; }
.company-setting-edit textarea { width: 100%; resize: vertical; }

@media (max-width: 760px) {
    .employee-form-grid,
    .field-grid,
    .deadline-stats,
    .deadline-form {
        grid-template-columns: 1fr;
    }

    .filter-form, .deadline-template { align-items: stretch; flex-direction: column; }
    .document-selection, .document-template-form, .document-template-row {
        align-items: stretch;
        flex-direction: column;
    }
    .document-context-grid { grid-template-columns: 1fr; }
    .employee-filters, .employee-report-actions { align-items: stretch; flex-direction: column; }
    .company-setting-form, .company-setting-row, .company-setting-edit { grid-template-columns: 1fr; }
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.form-actions .primary-button {
    width: auto;
}

/* Stile unico per tutti i campi; :where() non aggiunge specificità, così le
   regole dei singoli componenti continuano a prevalere. */
:where(
    input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="file"], [type="submit"]),
    select,
    textarea
) {
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid #b8c8d1;
    border-radius: 8px;
    background: #fff;
    color: #16232d;
    font: inherit;
    font-size: 0.95rem;
}

:where(textarea) {
    min-height: 5rem;
    resize: vertical;
}

:where(input, select, textarea):focus {
    border-color: #176b67;
    outline: 2px solid rgb(23 107 103 / 25%);
    outline-offset: 0;
}

@media (max-width: 760px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    .account-actions span {
        display: none;
    }

    .company-switcher label {
        display: none;
    }
}

.eyebrow {
    margin: 0 0 0.75rem;
    color: #247a74;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    color: #123b52;
    font-size: clamp(2.4rem, 8vw, 4.6rem);
    line-height: 1;
}

.status {
    margin-top: 2rem;
    color: #5a6b75;
}
