:root {
    color-scheme: light;
    --ink: #10233f;
    --muted: #4e6079;
    --blue: #174eb3;
    --blue-hover: #123c8f;
    --navy: #10274b;
    --paper: #fff;
    --canvas: #f3f6fb;
    --line: #d9e2ef;
    --field-line: #788da7;
    --focus: #2871e5;
    --radius: 14px;
    font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
    line-height: 1.55;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }

body { margin: 0; }

a { color: var(--blue); }

a:hover { color: var(--blue-hover); }

p, h1, h2 { margin-block: 0; }

h1, h2 {
    line-height: 1.13;
    letter-spacing: -0.035em;
}

h1 { font-size: clamp(2rem, 1.7rem + 1vw, 2.75rem); }

h2 { font-size: 1.3rem; }

button, input, select { font: inherit; }

button { cursor: pointer; }

ul { margin: 0; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.sr-only, .skip-link:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link:focus {
    position: fixed;
    z-index: 3;
    inset: 12px auto auto 12px;
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--paper);
}

.brand-signature {
    display: inline-flex;
    align-items: center;
    gap: .875rem;
    width: fit-content;
    color: white;
    font-size: .9375rem;
    line-height: 1.2;
    font-weight: 650;
    text-decoration: none;
}

.brand-signature:hover { color: #deeaff; }

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background: #dce9ff;
    color: #14346f;
    font-size: 1.65rem;
    line-height: 1;
    font-weight: 750;
}

.auth-shell {
    display: grid;
    min-height: 100svh;
    grid-template-columns: minmax(320px, 42%) minmax(0, 1fr);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    gap: clamp(3rem, 12vh, 9rem);
    padding: clamp(2rem, 5.5vw, 5.25rem);
    min-height: 100%;
    color: #fff;
    background:
        repeating-radial-gradient(circle at 104% 106%, transparent 0 89px, rgb(154 195 255 / 18%) 90px 91px, transparent 92px 100px),
        linear-gradient(155deg, #112746 12%, #183d76 55%, #2055a5 100%);
}

.brand-display {
    font-size: clamp(3.2rem, 6.25vw, 6.9rem);
    line-height: .94;
    letter-spacing: -.047em;
    font-weight: 700;
}

.auth-main {
    display: grid;
    place-items: center;
    min-width: 0;
    padding: 56px clamp(1.5rem, 5vw, 5rem);
    background: var(--paper);
}

.auth-content {
    width: min(100%, 406px);
}

.auth-content > p:not(.notice):not(.form-footer) { margin-block: 0 1.25rem; }

.auth-exit { margin-top: 1.5rem; }

.view-heading { margin-bottom: 1.75rem; }

.view-heading p {
    margin-top: .65rem;
    color: var(--muted);
}

.form-stack { display: grid; gap: 1.15rem; }

.form-stack > .button { margin-top: .25rem; }

.field {
    min-width: 0;
    display: grid;
    gap: .4rem;
}

.field label {
    font-size: .9375rem;
    font-weight: 650;
}

.field input,
.field select {
    min-height: 48px;
    width: 100%;
    border: 1px solid var(--field-line);
    border-radius: 8px;
    padding: .65rem .8rem;
    color: var(--ink);
    background: var(--paper);
}

.field input[aria-invalid="true"] { border-color: #ae2a44; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    min-height: 46px;
    padding: .6rem 1.05rem;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: .9375rem;
    text-decoration: none;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
}

.button-primary {
    background: var(--blue);
    color: white;
}

.button-primary:hover {
    background: var(--blue-hover);
    color: white;
}

.button-secondary {
    border-color: var(--field-line);
    color: var(--ink);
    background: var(--paper);
}

.button-secondary:hover { background: var(--canvas); }

.text-button {
    min-height: 44px;
    padding: .4rem 0;
    border: 0;
    color: var(--blue);
    text-decoration: underline;
    text-underline-offset: 3px;
    background: none;
}

.form-footer {
    margin-top: 1.4rem;
    font-size: .9375rem;
}

.notice {
    padding: .75rem .95rem;
    margin: 0 0 1rem;
    border: 1px solid;
    border-radius: 9px;
    font-size: .9375rem;
    overflow-wrap: anywhere;
}

.notice ul { padding-inline-start: 1.3rem; }

.notice-error {
    color: #8e1734;
    background: #fff3f6;
    border-color: #ecb3c2;
}

.notice-success {
    color: #185343;
    background: #edf9f4;
    border-color: #afd8c9;
}

.code-input {
    font-family: ui-monospace, monospace;
    letter-spacing: .15em;
}

.recovery-details {
    padding-top: 1rem;
    margin-top: 1.4rem;
    border-top: 1px solid var(--line);
}

.recovery-details summary {
    width: fit-content;
    padding-block: .45rem;
    color: var(--blue);
    cursor: pointer;
}

.recovery-details .form-stack { margin-block: .65rem 1.2rem; }

.qr-code {
    display: grid;
    justify-content: start;
    padding: .75rem;
    width: fit-content;
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: white;
}

.qr-code svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.setup-key code {
    display: block;
    overflow-wrap: anywhere;
    margin-top: .35rem;
}

.app-shell {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: 100svh;
}

.app-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2.4rem;
    min-width: 0;
    padding: 1.5rem;
    color: #fff;
    background: var(--navy);
    /* Ferma mentre la pagina scorre, così utente ed «Esci» restano sempre in vista.
       Se lo schermo è troppo basso scorre la sola sidebar. */
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    height: 100svh;
    overflow-y: auto;
}

.app-nav { display: grid; gap: .25rem; }

.app-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .875rem;
    border-radius: 8px;
    color: #dce7fa;
    font-size: .9375rem;
    font-weight: 600;
    text-decoration: none;
}

.app-nav a i {
    flex: none;
    width: 1.25em;
    color: #9fb6da;
    text-align: center;
}

.app-nav a:hover { color: #fff; background: #1a3860; }

.app-nav a[aria-current] { color: #fff; background: #214471; }

.app-nav a:hover i,
.app-nav a[aria-current] i { color: #96bdff; }

.app-sidebar :focus-visible { outline-color: #a7caff; }

.session {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .65rem;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #456381;
}

.session-person {
    display: grid;
    gap: 2px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.session-name { font-weight: 650; }

.session-role {
    color: #cedcf4;
    font-size: .875rem;
}

.session .text-button { color: #dce7fa; }

.app-main {
    justify-self: center;
    /* Il margine interno era il vero limite alla larghezza (fino a 72 px per lato):
       ridotto, così le tabelle hanno più spazio anche sugli schermi da 1366-1440 px. */
    width: min(100%, 1480px);
    min-width: 0;
    padding: clamp(1.25rem, 3vw, 2.75rem);
}

.heading-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.panel {
    padding: clamp(1.125rem, 3vw, 1.75rem);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}

.panel p:not(.notice) { color: var(--muted); }

.panel h2 + p { margin-top: .5rem; }

.dashboard-grid,
.role-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}

.dashboard-link {
    display: block;
    color: var(--ink);
    text-decoration: none;
}

.dashboard-link:hover {
    border-color: var(--focus);
    color: var(--blue);
}

.role-panel ul {
    display: grid;
    gap: .5rem;
    margin-top: 1.15rem;
    padding-inline-start: 1.25rem;
}

.role-panel li::marker { color: var(--blue); }

.form-panel, .security-panel { max-width: 660px; }

.security-panel h2 { margin-bottom: .75rem; }

.security-panel p { margin-block: .75rem; }

.recovery-list {
    display: flex;
    flex-wrap: wrap;
    gap: .55rem;
    padding: 0;
    margin-block: 1rem;
    list-style: none;
}

.recovery-list code,
.setup-key code {
    padding: .4rem .6rem;
    border-radius: 6px;
    background: #eff4fc;
    color: var(--navy);
}

.form-role {
    display: grid;
    gap: .25rem;
    margin: 0;
}

.form-role dt {
    font-size: .9375rem;
    font-weight: 650;
}

.form-role dd {
    width: fit-content;
    margin: 0;
    padding: .15rem .55rem;
    border-radius: 6px;
    color: var(--blue-hover);
    background: #eff4fc;
}

.field-pair {
    display: grid;
    gap: 1.15rem;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}

.field-pair .form-role dd { max-width: 100%; overflow-wrap: anywhere; }

.field-note { margin: 0; font-size: .875rem; }

.profile-panel h2 { margin-bottom: 1rem; }

.profile-panel + .profile-panel { margin-top: 1.5rem; }

.form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }

.table-frame {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.users-table th,
.users-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--line);
    /* break-word e non anywhere: anywhere riduce la larghezza minima delle
       colonne a una lettera e spezza le parole anche quando c'è spazio. */
    overflow-wrap: break-word;
}

.users-table thead th {
    color: var(--muted);
    background: #f8faff;
    font-size: .875rem;
}

.users-table tbody tr:last-child > * { border-bottom: 0; }

/* Link nelle celle (per esempio il nome che apre il dettaglio): senza
   sottolineatura, riconoscibili da colore e grassetto; la sottolineatura
   torna al passaggio del mouse e con la tastiera. */
.table-link { text-decoration: none; }

.table-link:hover,
.table-link:focus-visible { text-decoration: underline; }

/* Badge di stato, validi in tutta la piattaforma. Ogni variante ha colore,
   bordo e icona propri: lo stato resta leggibile anche senza distinguere i colori. */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .4em;
    padding: .125rem .55rem;
    border: 1px solid #cdd5df;
    border-radius: 6px;
    color: #44505f;
    background: #eef1f5;
    font-size: .875rem;
    font-weight: 650;
    line-height: 1.5;
    white-space: nowrap;
    overflow-wrap: normal;
}

.badge i { font-size: .85em; }

.badge.is-success { color: #0f5c3b; background: #dcf5e8; border-color: #8fd3b1; }

.badge.is-warning { color: #7a3e00; background: #fdeccb; border-color: #efbd62; }

.badge.is-danger { color: #9b1c1c; background: #fde4e4; border-color: #efa3a3; }

.badge.is-info { color: #1546a0; background: #e1eaff; border-color: #a6c0f4; }

.badge.is-neutral { color: #44505f; background: #eef1f5; border-color: #cdd5df; }

.row-actions { text-align: right; }

.action-group {
    display: flex;
    justify-content: flex-end;
    gap: .375rem;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--blue);
    background: var(--paper);
    /* Serve quando il pulsante a icona è un link <a> (per esempio «Vedi i dettagli»). */
    text-decoration: none;
}

.icon-button:hover { background: var(--canvas); }

.icon-button.is-enabled { color: #157356; }

.icon-button.is-disabled { color: #58677b; }

.mail-icon {
    display: block;
    position: relative;
    width: 18px;
    height: 14px;
    overflow: hidden;
    border: 2px solid currentColor;
    border-radius: 3px;
}

.mail-icon::before {
    content: "";
    position: absolute;
    inset: -7px 0 auto;
    width: 10px;
    height: 10px;
    margin: auto;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.power-icon {
    display: block;
    position: relative;
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    margin-top: 2px;
}

.power-icon::before {
    content: "";
    position: absolute;
    inset: -3px 0 auto;
    width: 2px;
    height: 8px;
    border-radius: 2px;
    margin: auto;
    background: currentColor;
}

.pager {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .75rem;
    margin-top: 1.15rem;
    color: var(--muted);
    font-size: .875rem;
}

.pager > div:last-child { text-align: right; }

.filter-bar {
    display: grid;
    grid-template-columns: minmax(min(100%, 260px), 2fr) repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.filter-actions { min-height: 48px; }

.list-summary {
    margin-bottom: .65rem;
    color: var(--muted);
    font-size: .875rem;
}

.cell-detail {
    display: block;
    color: var(--muted);
    font-size: .875rem;
}

.users-table .nowrap {
    white-space: nowrap;
    overflow-wrap: normal;
}

.cell-code {
    font-family: ui-monospace, monospace;
    font-size: .875rem;
}

.back-link {
    margin-bottom: 1rem;
    font-size: .9375rem;
}

.detail-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    align-items: start;
}

.detail-list {
    display: grid;
    grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
    gap: .55rem 1rem;
    margin: 1rem 0 0;
}

.detail-list dt {
    color: var(--muted);
    font-size: .9375rem;
}

.detail-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.address-lines { display: grid; }

.detail-footnote {
    margin-top: 1.25rem;
    color: var(--muted);
    font-size: .875rem;
}

@media (max-width: 760px) {
    .auth-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }

    .auth-brand {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: .9rem;
        padding: 1.35rem 1.5rem;
    }

    .brand-display { font-size: clamp(1.4rem, 5.5vw, 2rem); }

    .auth-main { align-items: start; padding-block: 2.5rem 3rem; }

    .app-shell { grid-template-columns: minmax(0, 1fr); }

    /* Su mobile la sidebar è l'intestazione della pagina: fissa toglierebbe troppo spazio. */
    .app-sidebar { position: static; height: auto; overflow-y: visible; gap: 1rem; padding: 1rem 1.25rem; }

    .app-nav { display: flex; flex-wrap: wrap; }

    .app-nav a { padding-inline: .65rem; }

    .session { margin-top: 0; padding-top: .4rem; }

    .users-table { min-width: 580px; }

    .filter-bar { grid-template-columns: minmax(0, 1fr); }

    /* Su schermi stretti i due pulsanti e la pagina corrente non stanno in una riga. */
    .pager { grid-template-columns: 1fr 1fr; }

    .pager > span { grid-column: 1 / -1; grid-row: 1; text-align: center; }

    .detail-list { grid-template-columns: minmax(0, 1fr); gap: .15rem; }

    .detail-list dd + dt { margin-top: .55rem; }
}

@media (max-width: 370px) {
    .auth-brand { padding-inline: 1rem; }
    .auth-main { padding-inline: 1rem; }
}
