/* G2 Secure Vault — stile Fluent 2 (g2-auth/UI-STYLE.md): gradienti chiari, superfici acriliche,
   angoli e contorni disciplinati, movimenti brevi (150–300 ms). */

:root {
    color-scheme: light dark;
    --bg: linear-gradient(160deg, #eaf1fb 0%, #f6f8fc 45%, #eef3fa 100%);
    --surface: rgba(255, 255, 255, .82);
    --surface-solid: #ffffff;
    --surface-2: #f5f7fa;
    --hover: rgba(15, 108, 189, .07);
    --selected: rgba(15, 108, 189, .12);
    --border: #e1e5ec;
    --border-strong: #c9cfd9;
    --text: #1b1a19;
    --muted: #5b6370;
    --faint: #8a919c;
    --brand: #0f6cbd;
    --brand-hover: #115ea3;
    --brand-press: #0c3b5e;
    --brand-soft: #ebf3fc;
    --on-brand: #ffffff;
    --danger: #c42b1c;
    --danger-soft: #fdf0ee;
    --success: #0e7a0d;
    --success-soft: #ecf7ec;
    --warning: #8a5a00;
    --warning-soft: #fff6dd;
    --virtual: #6b4fbb;
    --virtual-soft: #f1edfb;
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --shadow-1: 0 1px 2px rgba(15, 30, 60, .06), 0 1px 3px rgba(15, 30, 60, .08);
    --shadow-2: 0 4px 14px rgba(15, 30, 60, .10), 0 1px 3px rgba(15, 30, 60, .08);
    --shadow-3: 0 16px 48px rgba(15, 30, 60, .22), 0 2px 8px rgba(15, 30, 60, .10);
    --ease: cubic-bezier(.33, 0, .1, 1);
    --topbar-h: 56px;
    --sidebar-w: 292px;
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: linear-gradient(160deg, #141a24 0%, #171b22 50%, #131821 100%);
        --surface: rgba(38, 43, 52, .82);
        --surface-solid: #262b34;
        --surface-2: #1e232b;
        --hover: rgba(120, 180, 240, .10);
        --selected: rgba(120, 180, 240, .18);
        --border: #363d49;
        --border-strong: #4a5362;
        --text: #f1f3f6;
        --muted: #b3bac6;
        --faint: #8a93a1;
        --brand: #479ef5;
        --brand-hover: #62abf5;
        --brand-press: #96c6fa;
        --brand-soft: #1b2c40;
        --on-brand: #0b1a2b;
        --danger: #f1707b;
        --danger-soft: #3a1f22;
        --success: #54b054;
        --success-soft: #1b2e1c;
        --warning: #f2c661;
        --warning-soft: #3a2f12;
        --virtual: #b3a0f0;
        --virtual-soft: #2a2440;
        --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-2: 0 4px 14px rgba(0, 0, 0, .45);
        --shadow-3: 0 16px 48px rgba(0, 0, 0, .6);
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg) fixed;
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--radius-sm); }
.only-narrow, .icon-btn.only-narrow { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--brand); color: var(--on-brand); padding: 8px 12px; border-radius: var(--radius); z-index: 1000; }
.skip-link:focus { left: 8px; }

/* ── Pulsanti ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface-solid); color: var(--text);
    font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
    transition: background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); background: var(--danger); border-color: var(--danger); }
.btn-subtle { border-color: transparent; background: transparent; }
.btn-subtle:hover { background: var(--hover); border-color: transparent; }
.btn-lg { height: 40px; padding: 0 20px; font-size: 15px; }
.btn .bi { font-size: 16px; }
.icon-btn {
    width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; border-radius: var(--radius-sm);
    background: transparent; cursor: pointer; color: var(--muted); font-size: 17px; flex: none;
    transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn { border: 0; background: none; padding: 0; color: var(--brand); cursor: pointer; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

/* ── Campi ────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; }
.input, .select, .textarea {
    height: 32px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    border-bottom-color: var(--faint); background: var(--surface-solid); width: 100%;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 64px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: inset 0 -1px 0 var(--brand); }
.input.invalid { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: 12.5px; }

/* ── Ingresso (authenticator) ─────────────────────────────────────────── */
.gate {
    position: fixed; inset: 0; z-index: 400; display: grid; place-items: center; padding: 24px;
    background: var(--bg); overflow: auto;
    /* minmax(0, …): senza, la colonna si allarga al contenuto più largo della scheda e su un telefono
       la scheda esce dallo schermo invece di stringersi. */
    grid-template-columns: minmax(0, 1fr);
}
.gate.over-app { background: rgba(20, 30, 50, .45); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%); }
.gate-card {
    width: min(460px, 100%); background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-3); padding: 32px;
    backdrop-filter: blur(30px) saturate(150%); -webkit-backdrop-filter: blur(30px) saturate(150%);
    animation: rise .25s var(--ease);
}
.gate-card.wide { width: min(560px, 100%); }
.gate-loading { text-align: center; padding: 16px 0; color: var(--muted); display: grid; gap: 14px; justify-items: center; }
.gate-icon {
    width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 16px;
    background: var(--brand-soft); color: var(--brand); font-size: 28px;
}
.gate-icon.danger { background: var(--danger-soft); color: var(--danger); }
.gate h1 { font-size: 20px; font-weight: 600; text-align: center; letter-spacing: -.01em; }
.gate .lead { text-align: center; color: var(--muted); margin-top: 6px; }
.gate-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; }
.gate-foot a { color: var(--muted); }
.steps { list-style: none; margin: 22px 0 0; padding: 0; display: grid; gap: 18px; counter-reset: step; }
.steps > li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; counter-increment: step; }
.steps > li::before {
    content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
    background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 13px;
}
.steps h2 { font-size: 14.5px; font-weight: 600; }
.steps p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.qr-box { margin-top: 10px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
/* Il margine bianco lo dà la quiet zone del QR stesso: niente padding. crispEdges evita le righe
   sottili fra i moduli quando la scala non è intera. */
.qr { width: min(200px, 100%); aspect-ratio: 1; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); flex: none; overflow: hidden; }
.qr svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; }
.secret { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; letter-spacing: .04em; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; word-break: break-all; }
.otp { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
/* min-width: 0 lascia stringere le caselle sui telefoni più piccoli invece di spingere la scheda fuori. */
.otp input {
    width: 46px; min-width: 0; height: 56px; text-align: center; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums;
    border-radius: var(--radius); border: 1px solid var(--border-strong); border-bottom: 2px solid var(--faint); background: var(--surface-solid);
    transition: border-color .15s var(--ease), transform .15s var(--ease);
}
.otp input:focus { outline: none; border-color: var(--brand); border-bottom-color: var(--brand); transform: translateY(-1px); }
.otp.error input { border-color: var(--danger); animation: shake .3s var(--ease); }
.otp-gap { width: 6px; flex: none; }
.gate-msg { min-height: 20px; margin-top: 12px; text-align: center; font-size: 13px; color: var(--danger); }
.gate-msg.info { color: var(--muted); }

/* ── Struttura ────────────────────────────────────────────────────────── */
.shell { height: 100%; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 12px; padding: 0 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    backdrop-filter: blur(24px) saturate(150%); -webkit-backdrop-filter: blur(24px) saturate(150%);
    position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex: none; }
.brand-name { font-weight: 600; font-size: 15.5px; letter-spacing: -.01em; }
.search { flex: 1; max-width: 520px; margin: 0 auto; position: relative; }
.search .bi { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input {
    width: 100%; height: 34px; padding: 0 12px 0 36px; border-radius: 17px; border: 1px solid var(--border);
    background: var(--surface-solid); transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--selected); }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex: none; margin-left: auto; }
.lock-chip {
    display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 15px;
    border: 1px solid var(--border); background: var(--surface-solid); cursor: pointer; font-size: 13px; color: var(--muted);
    transition: all .15s var(--ease); font-variant-numeric: tabular-nums;
}
.lock-chip:hover { border-color: var(--brand); color: var(--brand); }
.lock-chip.soon { background: var(--warning-soft); border-color: transparent; color: var(--warning); font-weight: 600; }
.menu-wrap { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px; border: 0; background: transparent; border-radius: var(--radius); cursor: pointer; transition: background .15s var(--ease); }
.user-btn:hover { background: var(--hover); }
.user-btn .bi { font-size: 11px; color: var(--faint); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; background-size: cover; background-position: center; flex: none; }
.user-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 13px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11.5px; color: var(--muted); }

.menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 216px; padding: 4px; z-index: 60;
    background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2);
    animation: pop .15s var(--ease); transform-origin: top right;
}
.menu.fixed { position: fixed; right: auto; top: auto; }
.menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: var(--radius-sm);
    text-align: left; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); }
.menu-item .bi { color: var(--muted); font-size: 16px; width: 18px; text-align: center; }
.menu-item.danger, .menu-item.danger .bi { color: var(--danger); }
.menu-item[disabled] { opacity: .45; cursor: not-allowed; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.app-launcher-menu { width: 280px; max-height: 60vh; overflow: auto; }
.app-launcher-menu img { width: 20px; height: 20px; object-fit: contain; border-radius: 4px; }

.body { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
    width: var(--sidebar-w); flex: none; display: flex; flex-direction: column; min-height: 0;
    background: var(--surface); border-right: 1px solid var(--border);
    backdrop-filter: blur(24px) saturate(150%); -webkit-backdrop-filter: blur(24px) saturate(150%);
}
.sidebar-scroll { flex: 1; overflow: auto; padding: 12px 8px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 8px; display: grid; gap: 2px; }
.side-title { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.side-title + .tree-empty { padding: 4px 8px 12px; color: var(--faint); font-size: 12.5px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 2px; }
.tree-row {
    display: flex; align-items: center; gap: 2px; height: 30px; border-radius: var(--radius-sm); padding-right: 6px; cursor: pointer;
    color: var(--text); text-decoration: none; transition: background .12s var(--ease);
}
.tree-link { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--selected); font-weight: 600; }
.tree-row.active .tree-ico { color: var(--brand); }
.tree-row.dim .tree-name { color: var(--muted); }
.tree-toggle { width: 22px; height: 22px; border: 0; background: none; display: grid; place-items: center; color: var(--faint); cursor: pointer; border-radius: 3px; flex: none; font-size: 10px; transition: transform .15s var(--ease); }
.tree-toggle:hover { background: var(--hover); color: var(--text); }
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }
.tree-ico { color: #d39b1b; font-size: 15px; flex: none; margin-right: 6px; }
.tree-ico.virtual { color: var(--virtual); }
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-badge { color: var(--faint); font-size: 12px; flex: none; }
.side-link { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--text); transition: background .12s var(--ease); }
.side-link:hover { background: var(--hover); }
.side-link.active { background: var(--selected); font-weight: 600; }
.side-link .bi { color: var(--muted); font-size: 16px; }
.side-link.active .bi { color: var(--brand); }
.scrim { position: absolute; inset: 0; background: rgba(10, 20, 40, .35); z-index: 19; }

.main { flex: 1; min-width: 0; overflow: auto; padding: 20px 28px 48px; outline: none; }
.page { max-width: 1280px; margin: 0 auto; animation: fade .2s var(--ease); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); min-height: 22px; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 1px 4px; border-radius: 3px; }
.crumbs a:hover { background: var(--hover); color: var(--text); }
.crumbs .bi { font-size: 10px; color: var(--faint); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 6px 0 16px; flex-wrap: wrap; }
.page-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.page-title h1 { font-size: 24px; font-weight: 600; letter-spacing: -.015em; overflow-wrap: anywhere; }
.page-title .bi-folder-fill { color: #d39b1b; font-size: 24px; }
.page-title .bi-folder-symlink-fill { color: var(--virtual); font-size: 24px; }
.page-sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip.virtual { background: var(--virtual-soft); color: var(--virtual); border-color: transparent; }
.chip.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.chip.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius); background: var(--brand-soft); color: var(--text); margin-bottom: 14px; font-size: 13.5px; }
.note .bi { color: var(--brand); font-size: 16px; margin-top: 1px; }
.note.warn { background: var(--warning-soft); }
.note.warn .bi { color: var(--warning); }
.note.ok { background: var(--success-soft); }
.note.ok .bi { color: var(--success); }
.note.danger { background: var(--danger-soft); }
.note.danger .bi { color: var(--danger); }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
    backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%);
}
.card-pad { padding: 20px; }

/* ── Elenco di cartelle e documenti ───────────────────────────────────── */
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.list td { padding: 0 12px; height: 44px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr { transition: background .12s var(--ease); }
.list tbody tr.row-click { cursor: pointer; }
.list tbody tr:hover { background: var(--hover); }
.list .col-ico { width: 44px; padding-right: 0; }
.list .col-actions { width: 96px; text-align: right; white-space: nowrap; }
.list .col-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.list .muted { color: var(--muted); white-space: nowrap; }
.row-actions { opacity: 0; transition: opacity .12s var(--ease); display: inline-flex; gap: 2px; }
tr:hover .row-actions, tr:focus-within .row-actions, .row-actions.open { opacity: 1; }
.name-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name-btn { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.name-btn:hover { color: var(--brand); text-decoration: underline; }
.name-btn.plain { cursor: default; font-weight: 500; }
.name-btn.plain:hover { color: var(--text); text-decoration: none; }
.file-ico { font-size: 22px; display: block; }
.fam-folder { color: #d39b1b; } .fam-vfolder { color: var(--virtual); }
.fam-pdf { color: #d93025; } .fam-word { color: #2b579a; } .fam-excel { color: #1d6f42; } .fam-powerpoint { color: #c43e1c; }
.fam-image { color: #8a3ffc; } .fam-text, .fam-file, .fam-archive, .fam-signed, .fam-mail { color: var(--muted); }
@media (prefers-color-scheme: dark) { .fam-word { color: #6ea0e8; } .fam-excel { color: #4fbf82; } .fam-pdf { color: #f1707b; } }

.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty .bi { font-size: 44px; color: var(--faint); display: block; margin-bottom: 12px; }
.empty h2 { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.empty .actions { justify-content: center; margin-top: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile {
    display: flex; gap: 12px; align-items: center; padding: 16px; text-decoration: none; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
    transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.tile .bi { font-size: 28px; }
.tile-name { font-weight: 600; overflow-wrap: anywhere; }
.tile-sub { color: var(--muted); font-size: 12.5px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 24px 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.dropzone { position: relative; }
.dropzone.dragging::after {
    content: "Rilascia per caricare in questa cartella"; position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
    background: color-mix(in srgb, var(--brand-soft) 88%, transparent); border: 2px dashed var(--brand); border-radius: var(--radius-lg);
    color: var(--brand); font-weight: 600; font-size: 16px; pointer-events: none;
}

/* ── Finestre, pannelli, avvisi ───────────────────────────────────────── */
.backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(15, 25, 45, .42); display: grid; place-items: center; padding: 24px; animation: fade .15s var(--ease); backdrop-filter: blur(2px); }
.dialog {
    width: min(480px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column;
    background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
    animation: rise .2s var(--ease);
}
.dialog.md { width: min(640px, 100%); } .dialog.lg { width: min(880px, 100%); }
.dialog-head { padding: 20px 24px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 18px; font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.dialog-head p { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.dialog-body { padding: 16px 24px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.dialog-foot { padding: 14px 24px 20px; display: flex; justify-content: flex-end; gap: 8px; align-items: center; flex-wrap: wrap; }
.dialog-foot .grow { margin-right: auto; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 190; background: var(--surface-solid); border-left: 1px solid var(--border); box-shadow: var(--shadow-3); display: flex; flex-direction: column; animation: slide-in .22s var(--ease); }
.drawer-head { padding: 18px 20px 12px; display: flex; gap: 12px; align-items: flex-start; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; flex: 1; }
.drawer-body { flex: 1; overflow: auto; padding: 16px 20px 24px; display: grid; gap: 20px; align-content: start; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.drawer h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.vlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.vitem { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.vitem-main { flex: 1; min-width: 0; }
.vitem-title { font-weight: 600; font-size: 13px; }
.vitem-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 13px; }
.timeline li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; }
.timeline .bi { color: var(--muted); margin-top: 2px; }
.timeline .when { color: var(--muted); font-size: 12px; }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 500; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: var(--radius); background: #1f2a3a; color: #fff; box-shadow: var(--shadow-3); font-size: 13.5px; animation: rise .2s var(--ease); max-width: min(560px, 92vw); }
.toast.error { background: #8e1f14; }
.toast .bi { font-size: 16px; }
.toast button { border: 0; background: none; color: #9fd0ff; font-weight: 600; cursor: pointer; padding: 0 0 0 6px; }

.uploads { position: fixed; right: 20px; bottom: 20px; width: min(380px, calc(100vw - 40px)); z-index: 150; background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); overflow: hidden; animation: rise .2s var(--ease); }
.uploads-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--border); }
.uploads-list { max-height: 260px; overflow: auto; }
.upload { padding: 10px 14px; border-bottom: 1px solid var(--border); display: grid; gap: 6px; }
.upload:last-child { border-bottom: 0; }
.upload-top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.upload-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
.upload.done .upload-state { color: var(--success); } .upload.failed .upload-state { color: var(--danger); white-space: normal; }
.bar { height: 3px; border-radius: 2px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s var(--ease); }
.upload.done .bar > span { background: var(--success); } .upload.failed .bar > span { background: var(--danger); }

/* ── Permessi ─────────────────────────────────────────────────────────── */
.switch-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.switch { position: relative; width: 40px; height: 20px; flex: none; margin-top: 2px; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 10px; border: 1px solid var(--faint); background: transparent; transition: all .15s var(--ease); }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: all .15s var(--ease); }
.switch input:checked + span { background: var(--brand); border-color: var(--brand); }
.switch input:checked + span::after { left: 23px; background: var(--on-brand); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.grant { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); align-items: center; }
.grant + .grant { margin-top: 8px; }
.grant.readonly { background: var(--surface-2); }
.subject { display: flex; align-items: center; gap: 10px; min-width: 0; }
.subject-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.subject-ico.person { background: var(--virtual-soft); color: var(--virtual); }
.subject-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caps { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.cap { position: relative; }
.cap input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.cap span { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--border-strong); font-size: 12.5px; color: var(--muted); background: var(--surface-solid); transition: all .12s var(--ease); user-select: none; }
.cap input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.cap input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.cap input:disabled + span { opacity: .75; cursor: default; }
.cap.static span { cursor: default; }
.cap.static.on span { background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 600; }
.grant .reason { grid-column: 1 / -1; }
.picker { position: relative; }
.picker-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; max-height: 280px; overflow: auto; background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 4px; }
.picker-group { padding: 6px 10px 2px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.picker-item { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.picker-item:hover, .picker-item:focus-visible { background: var(--hover); }
.sub-head { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inherited-from { font-size: 12.5px; color: var(--muted); margin: 10px 0 6px; display: flex; gap: 6px; align-items: center; }
.struck { opacity: .55; }

/* ── Scelta di cartelle e documenti ───────────────────────────────────── */
.choose-tree { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; max-height: 340px; overflow: auto; }
.choose-row { display: flex; align-items: center; gap: 4px; height: 30px; border-radius: var(--radius-sm); padding-right: 8px; cursor: pointer; }
.choose-row:hover { background: var(--hover); }
.choose-row.selected { background: var(--selected); font-weight: 600; }
.choose-row.disabled { opacity: .45; cursor: not-allowed; }
.two-pane { display: grid; grid-template-columns: 250px 1fr; gap: 12px; min-height: 320px; }
.doc-check { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.doc-check:hover { background: var(--hover); }
.doc-check input { width: 16px; height: 16px; accent-color: var(--brand); }
.pane { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; overflow: auto; max-height: 360px; }

/* ── Visualizzatore ───────────────────────────────────────────────────── */
.viewer { position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column; background: #20242b; color: #f1f3f6; animation: fade .15s var(--ease); }
.viewer-bar { height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: #2a2f38; border-bottom: 1px solid #3a404b; }
.viewer-bar .icon-btn { color: #c9cfd9; }
.viewer-bar .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.viewer-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.viewer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.viewer-page { font-variant-numeric: tabular-nums; color: #c9cfd9; font-size: 13px; padding: 0 8px; white-space: nowrap; }
.viewer-zoom { font-variant-numeric: tabular-nums; min-width: 48px; text-align: center; font-size: 13px; color: #c9cfd9; }
.viewer-sep { width: 1px; height: 22px; background: #454c59; margin: 0 6px; }
.viewer .chip { background: #3a404b; border-color: transparent; color: #dfe4ec; }
.viewer .select { background: #353b46; border-color: #4a5260; color: #f1f3f6; height: 30px; width: auto; }
.viewer .btn { background: #353b46; border-color: #4a5260; color: #f1f3f6; }
.viewer .btn:hover { background: #404754; }
.viewer-body { flex: 1; overflow: auto; padding: 20px 16px 64px; scroll-behavior: smooth; }
.pages { display: grid; gap: 16px; justify-items: center; }
.pg { background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .45); border-radius: 2px; position: relative; overflow: hidden; width: 100%; }
.pg img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.pg.loading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, #f1f3f6 30%, #e4e8ee 50%, #f1f3f6 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.pg.failed { display: grid; place-items: center; color: #5b6370; font-size: 13px; }
.viewer-state { height: 100%; display: grid; place-items: center; text-align: center; padding: 24px; }
.viewer-state .box { max-width: 420px; display: grid; gap: 12px; justify-items: center; color: #c9cfd9; }
.viewer-state .bi { font-size: 44px; color: #8a93a1; }
.viewer-state h2 { font-size: 17px; color: #fff; font-weight: 600; }

/* ── Registro, amministrazione ────────────────────────────────────────── */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px; align-items: end; }
.table-wrap { overflow: auto; }
.audit td { height: auto; padding: 9px 12px; vertical-align: top; font-size: 13px; }
.audit .act { display: flex; gap: 8px; align-items: baseline; white-space: nowrap; }
.audit .act .bi { color: var(--muted); }
.audit tr.denied .act, .audit tr.denied .act .bi { color: var(--danger); }
.audit td:nth-child(2) { min-width: 210px; }
.audit td:nth-child(2) .detail { overflow-wrap: normal; white-space: nowrap; }
.audit .target { overflow-wrap: anywhere; min-width: 220px; }
.audit .detail { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.role-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.role-card h2 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.role-card p { color: var(--muted); font-size: 13px; margin: 4px 0 12px; min-height: 38px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; min-height: 26px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: 13px; background: var(--brand-soft); color: var(--brand); font-size: 12.5px; font-weight: 600; }
.tag button { width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer; display: grid; place-items: center; font-size: 12px; }
.tag button:hover { background: var(--selected); }
.row-inline { display: flex; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 8px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab:hover { color: var(--text); background: var(--hover); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.skeleton { height: 44px; border-bottom: 1px solid var(--border); background: linear-gradient(100deg, transparent 30%, var(--hover) 50%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.center { display: grid; place-items: center; padding: 48px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ── Schermi stretti ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .only-narrow, .icon-btn.only-narrow { display: inline-grid; }
    .sidebar { position: absolute; top: 0; bottom: 0; left: 0; z-index: 20; transform: translateX(-102%); transition: transform .22s var(--ease); background: var(--surface-solid); }
    .sidebar.open { transform: none; box-shadow: var(--shadow-3); }
    .main { padding: 16px 14px 40px; }
    .brand-name, .user-text, .user-btn .bi-chevron-down { display: none; }
    .list .hide-narrow { display: none; }
    .row-actions { opacity: 1; }
    .two-pane { grid-template-columns: 1fr; }
    .page-title h1 { font-size: 20px; }
}
@media (max-width: 560px) {
    .lock-chip span { display: none; }
    .otp { gap: 6px; }
    .otp input { width: 40px; height: 50px; font-size: 21px; }
    .gate { padding: 12px; }
    .gate-card { padding: 24px 18px; }
    .viewer-name { font-size: 13px; }
    .viewer-zoom, .viewer .hide-narrow { display: none; }
}
