/*
 * Tema dell'interfaccia, sopra Bootstrap 5.3. Nessuno stile inline: la CSP (style-src 'self') non lo consente,
 * quindi colori e misure sono variabili qui e i componenti sono classi riusabili nelle viste.
 */

/* ------------------------------------------------------------------ token */
:root {
    --app-primary: #4f46e5;
    --app-primary-hover: #4338ca;
    --app-primary-active: #3730a3;
    --app-primary-soft: #eef2ff;
    --app-primary-border: #c7d2fe;
    --app-bg: #f4f5f9;
    --app-surface: #fff;
    --app-surface-2: #f9fafb;
    --app-border: #e4e7ec;
    --app-border-strong: #d0d5dd;
    --app-heading: #101828;
    --app-text: #1d2433;
    --app-muted: #667085;
    --app-subtle: #98a2b3;
    --app-radius: .75rem;
    --app-radius-sm: .5rem;
    --app-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --app-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --app-shadow-lg: 0 16px 40px -12px rgba(16, 24, 40, .22);
    --app-ring: 0 0 0 .2rem rgba(99, 102, 241, .2);

    --sidebar-width: 264px;
    --sidebar-bg: #0f172a;
    --sidebar-bg-2: #141d35;
    --sidebar-text: #aab4c8;
    --sidebar-text-strong: #f1f5f9;
    --sidebar-muted: #5f6b85;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-active: rgba(129, 140, 248, .16);

    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-body-font-size: .9375rem;
    --bs-body-color: var(--app-text);
    --bs-emphasis-color: var(--app-heading);
    --bs-secondary-color: var(--app-muted);
    --bs-tertiary-color: var(--app-subtle);
    --bs-tertiary-bg: var(--app-surface-2);
    --bs-border-color: var(--app-border);
    --bs-border-radius: .5rem;
    --bs-border-radius-sm: .375rem;
    --bs-border-radius-lg: .75rem;
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-primary-text-emphasis: #3730a3;
    --bs-primary-bg-subtle: #eef2ff;
    --bs-primary-border-subtle: #c7d2fe;
    --bs-link-color: #4f46e5;
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: #3730a3;
    --bs-link-hover-color-rgb: 55, 48, 163;
    --bs-focus-ring-color: rgba(99, 102, 241, .25);
    --bs-code-color: #6941c6;
}

body {
    background: var(--app-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { color: var(--app-heading); letter-spacing: -.01em; }
a { text-underline-offset: .2em; }
code { font-size: .85em; }

.icon { width: 1.125rem; height: 1.125rem; flex-shrink: 0; vertical-align: -.2em; }
.icon-sm { width: .95rem; height: .95rem; }
.icon-lg { width: 1.5rem; height: 1.5rem; }

/* ------------------------------------------------------------------ shell */
.app-sidebar {
    --bs-offcanvas-width: var(--sidebar-width);
    --bs-offcanvas-bg: var(--sidebar-bg);
    --bs-offcanvas-border-width: 0;
}
.sidebar-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
}
@media (min-width: 992px) {
    .app-sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 1030; display: flex; width: var(--sidebar-width); }
    .app-main { margin-left: var(--sidebar-width); }
}
.app-main { min-height: 100vh; display: flex; flex-direction: column; }
.app-content { flex: 1 0 auto; width: 100%; padding: 1.75rem 2.25rem 3rem; }
.app-footer { padding: 0 2.25rem 1.5rem; color: var(--app-subtle); font-size: .78rem; }
@media (max-width: 991.98px) {
    .app-content { padding: 1.25rem 1rem 2.5rem; }
    .app-footer { padding: 0 1rem 1.25rem; }
}

.sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 1.35rem 1.25rem 1.1rem; }
.brand-link { display: flex; align-items: center; gap: .75rem; min-width: 0; color: var(--sidebar-text-strong); text-decoration: none; }
.brand-link:hover { color: #fff; }
.brand-mark {
    display: grid; place-items: center; flex-shrink: 0;
    width: 2.35rem; height: 2.35rem; border-radius: .65rem;
    color: #fff; background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    box-shadow: 0 8px 18px -8px rgba(99, 102, 241, .9), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-mark .icon { width: 1.3rem; height: 1.3rem; }
.brand-name { display: block; font-weight: 650; font-size: .92rem; line-height: 1.2; }
.brand-sub { display: block; margin-top: .1rem; font-size: .72rem; color: var(--sidebar-muted); }

.sidebar-cta { padding: 0 1rem .75rem; }
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 0 .75rem 1rem; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .12) transparent; }
.sidebar-section { padding: 1.1rem .75rem .4rem; font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--sidebar-muted); }
.sidebar-link {
    position: relative; display: flex; align-items: center; gap: .75rem;
    padding: .55rem .75rem; margin-bottom: .1rem; border-radius: .5rem;
    color: var(--sidebar-text); font-size: .9rem; font-weight: 500; text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}
.sidebar-link .icon { width: 1.15rem; height: 1.15rem; opacity: .8; }
.sidebar-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.sidebar-link:focus-visible { outline: 2px solid #818cf8; outline-offset: -2px; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-link.active .icon { color: #a5b4fc; opacity: 1; }
.sidebar-link.active::before { content: ""; position: absolute; left: -.75rem; top: .45rem; bottom: .45rem; width: 3px; border-radius: 0 3px 3px 0; background: #818cf8; }

.sidebar-user { display: flex; align-items: center; gap: .35rem; padding: .85rem 1rem; border-top: 1px solid rgba(255, 255, 255, .07); }
.user-chip { display: flex; flex: 1; align-items: center; gap: .65rem; min-width: 0; padding: .35rem; border-radius: .55rem; color: var(--sidebar-text-strong); text-decoration: none; }
.user-chip:hover { background: var(--sidebar-hover); color: #fff; }
.user-meta { min-width: 0; }
.user-name { display: block; overflow: hidden; font-size: .85rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.user-role { display: block; font-size: .72rem; color: var(--sidebar-muted); }
.sidebar-icon-btn {
    display: grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0;
    border: 0; border-radius: .5rem; background: transparent; color: var(--sidebar-text);
}
.sidebar-icon-btn:hover, .sidebar-icon-btn:focus-visible { background: var(--sidebar-hover); color: #fff; }

.avatar {
    display: grid; place-items: center; flex-shrink: 0;
    width: 2.25rem; height: 2.25rem; border-radius: 50%;
    font-size: .78rem; font-weight: 650; letter-spacing: .02em;
    color: #e0e7ff; background: linear-gradient(135deg, #4338ca 0%, #7c3aed 100%);
}
.avatar-sm { width: 1.85rem; height: 1.85rem; font-size: .68rem; }
.avatar-alt { color: #ecfeff; background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%); }

.app-topbar {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem;
    background: rgba(255, 255, 255, .92); border-bottom: 1px solid var(--app-border);
    -webkit-backdrop-filter: saturate(180%) blur(8px); backdrop-filter: saturate(180%) blur(8px);
}
.app-topbar .brand-link { color: var(--app-heading); }
.app-topbar .brand-mark { width: 2rem; height: 2rem; }
.app-topbar .brand-mark .icon { width: 1.1rem; height: 1.1rem; }
.topbar-btn { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; padding: 0; border: 1px solid var(--app-border); border-radius: .55rem; background: #fff; color: var(--app-text); }

.demo-banner {
    display: flex; align-items: center; gap: .6rem; margin-bottom: 1.25rem; padding: .55rem .9rem;
    border: 1px dashed #c7d2fe; border-radius: var(--app-radius-sm); background: #f5f6ff; color: #3730a3; font-size: .85rem;
}

/* ------------------------------------------------------------- page header */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem 1.5rem; margin-bottom: 1.5rem; }
.page-header > div:first-child { min-width: 0; }
.page-pretitle { display: flex; align-items: center; gap: .4rem; margin-bottom: .3rem; font-size: .74rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--app-primary); }
.page-title { margin: 0; font-size: 1.6rem; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; color: var(--app-heading); overflow-wrap: anywhere; }
.page-title .count { margin-left: .35rem; font-size: 1rem; font-weight: 500; color: var(--app-subtle); }
.page-subtitle { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .65rem; margin: .4rem 0 0; font-size: .92rem; color: var(--app-muted); }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.page-actions form { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .55rem; font-size: .85rem; font-weight: 500; color: var(--app-muted); text-decoration: none; }
.back-link:hover { color: var(--app-primary); }
.meta-sep { color: var(--app-border-strong); }

/* ------------------------------------------------------------------ cards */
.card {
    --bs-card-border-color: var(--app-border);
    --bs-card-border-radius: var(--app-radius);
    --bs-card-inner-border-radius: calc(var(--app-radius) - 1px);
    --bs-card-cap-bg: transparent;
    --bs-card-cap-padding-y: .85rem;
    --bs-card-cap-padding-x: 1.25rem;
    --bs-card-spacer-x: 1.25rem;
    --bs-card-spacer-y: 1.1rem;
    box-shadow: var(--app-shadow-sm);
}
.card-header { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-weight: 600; color: var(--app-heading); }
.card-header > .icon { color: var(--app-subtle); }
.card-header .header-link { margin-left: auto; font-size: .82rem; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: .2rem; }
.card-header .header-note { margin-left: auto; font-size: .8rem; font-weight: 400; color: var(--app-muted); }
.card > .list-group-flush > .list-group-item { padding-left: 1.25rem; padding-right: 1.25rem; }
.card-collapsible > summary { cursor: pointer; list-style: none; }
.card-collapsible > summary::-webkit-details-marker { display: none; }
.card-collapsible > summary:hover { background: var(--app-surface-2); }
.card-collapsible:not([open]) > summary { border-bottom: 0; border-radius: var(--app-radius); }
.card-collapsible .collapse-chevron { color: var(--app-subtle); transition: transform .15s ease; }
.card-collapsible .header-note + .collapse-chevron { margin-left: .25rem; }
.card-collapsible > summary > .collapse-chevron:only-of-type { margin-left: auto; }
.card-collapsible[open] .collapse-chevron { transform: rotate(90deg); }
.card-danger { border-color: #fecdca; }
.card-danger > .card-header { color: #b42318; background: #fffbfa; border-bottom-color: #fecdca; }

/* ----------------------------------------------------------------- tables */
.table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: #f8f9fc;
    --bs-table-border-color: #eef0f4;
    margin-bottom: 0;
    font-variant-numeric: tabular-nums;
}
.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table-sm > :not(caption) > * > * { padding: .45rem .6rem; }
.table > thead > tr > th, .table > thead > tr > td {
    padding-top: .6rem; padding-bottom: .6rem;
    font-size: .72rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
    color: var(--app-muted); background: var(--app-surface-2); border-bottom-color: var(--app-border);
}
.table > tbody > tr:last-child > * { border-bottom-width: 0; }
.card > .table-responsive > .table > :not(caption) > * > :first-child,
.card > .table > :not(caption) > * > :first-child { padding-left: 1.25rem; }
.card > .table-responsive > .table > :not(caption) > * > :last-child,
.card > .table > :not(caption) > * > :last-child { padding-right: 1.25rem; }
.card > .table-responsive:last-child, .card > .table:last-child { border-bottom-left-radius: var(--app-radius); border-bottom-right-radius: var(--app-radius); }
.card > .table-responsive:first-child > .table > thead > tr:first-child > :first-child { border-top-left-radius: calc(var(--app-radius) - 1px); }
.card > .table-responsive:first-child > .table > thead > tr:first-child > :last-child { border-top-right-radius: calc(var(--app-radius) - 1px); }
.table .row-link { color: var(--app-heading); font-weight: 500; text-decoration: none; }
.table .row-link:hover { color: var(--app-primary); text-decoration: underline; }
.table .cell-muted { color: var(--app-muted); font-size: .82rem; }
.table .cell-error { max-width: 22rem; color: #b42318; font-size: .8rem; }
.table-kv > tbody > tr > th { width: 40%; font-weight: 500; color: var(--app-muted); }

.doc-cell { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.doc-cell > div { min-width: 0; }
.doc-name { display: block; overflow: hidden; max-width: 28rem; font-weight: 500; color: var(--app-heading); text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
a.doc-name:hover { color: var(--app-primary); text-decoration: underline; }
.doc-meta { display: block; font-size: .78rem; color: var(--app-muted); white-space: nowrap; }
.doc-meta.wrap { white-space: normal; overflow-wrap: anywhere; }
.code-pill { display: inline-block; padding: .1rem .45rem; border-radius: .35rem; background: #f2f4f7; color: #344054; font-family: var(--bs-font-monospace); font-size: .78rem; font-weight: 500; }

.filetype {
    display: inline-grid; place-items: center; flex-shrink: 0;
    width: 2.25rem; height: 2.25rem; border-radius: .5rem;
    font-size: .58rem; font-weight: 750; letter-spacing: .03em;
}
.filetype-pdf { color: #d92d20; background: #fef3f2; box-shadow: inset 0 0 0 1px #fee4e2; }
.filetype-xls { color: #079455; background: #ecfdf3; box-shadow: inset 0 0 0 1px #dcfae6; }
.filetype-csv { color: #0086c9; background: #f0f9ff; box-shadow: inset 0 0 0 1px #e0f2fe; }
.filetype-other { color: #475467; background: #f2f4f7; box-shadow: inset 0 0 0 1px #e4e7ec; }

/* ----------------------------------------------------------------- badges */
.badge-soft {
    --dot: currentColor;
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .28rem .6rem .28rem .5rem;
    border: 1px solid transparent; border-radius: 999px;
    font-size: .75rem; font-weight: 600; line-height: 1.1; letter-spacing: 0; white-space: nowrap;
}
.badge-soft::before { content: ""; flex-shrink: 0; width: .42rem; height: .42rem; border-radius: 50%; background: var(--dot); }
.badge-soft.badge-success { color: #067647; background: #ecfdf3; border-color: #abefc6; --dot: #17b26a; }
.badge-soft.badge-warning { color: #b54708; background: #fffaeb; border-color: #fedf89; --dot: #f79009; }
.badge-soft.badge-danger { color: #b42318; background: #fef3f2; border-color: #fecdca; --dot: #f04438; }
.badge-soft.badge-info { color: #175cd3; background: #eff8ff; border-color: #b2ddff; --dot: #2e90fa; }
.badge-soft.badge-primary { color: #3730a3; background: #eef2ff; border-color: #c7d2fe; --dot: #6366f1; }
.badge-soft.badge-secondary { color: #344054; background: #f2f4f7; border-color: #e4e7ec; --dot: #98a2b3; }
.badge-soft.badge-dark { color: #344054; background: #e4e7ec; border-color: #d0d5dd; --dot: #475467; }
.badge-soft.badge-light { color: #475467; background: #fff; border-color: #d0d5dd; --dot: #d0d5dd; }
.badge-soft[data-poll-url]::before { animation: pulse-dot 1.4s ease-in-out infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
@media (prefers-reduced-motion: reduce) { .badge-soft[data-poll-url]::before { animation: none; } }

/* ---------------------------------------------------------------- buttons */
.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-border-radius: .5rem;
    --bs-btn-focus-box-shadow: var(--app-ring);
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
}
.btn-sm { --bs-btn-border-radius: .45rem; gap: .35rem; }
.btn .icon { width: 1.05em; height: 1.05em; }
.btn-primary {
    --bs-btn-bg: #4f46e5; --bs-btn-border-color: #4f46e5;
    --bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
    --bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
    --bs-btn-disabled-bg: #4f46e5; --bs-btn-disabled-border-color: #4f46e5;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .1), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-success {
    --bs-btn-bg: #079455; --bs-btn-border-color: #079455;
    --bs-btn-hover-bg: #067647; --bs-btn-hover-border-color: #067647;
    --bs-btn-active-bg: #085d3a; --bs-btn-active-border-color: #085d3a;
    --bs-btn-disabled-bg: #079455; --bs-btn-disabled-border-color: #079455;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .1), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-danger {
    --bs-btn-bg: #d92d20; --bs-btn-border-color: #d92d20;
    --bs-btn-hover-bg: #b42318; --bs-btn-hover-border-color: #b42318;
    --bs-btn-active-bg: #912018; --bs-btn-active-border-color: #912018;
}
.btn-outline-primary {
    --bs-btn-bg: #fff; --bs-btn-color: #4338ca; --bs-btn-border-color: #c7d2fe;
    --bs-btn-hover-color: #3730a3; --bs-btn-hover-bg: #eef2ff; --bs-btn-hover-border-color: #a5b4fc;
    --bs-btn-active-color: #3730a3; --bs-btn-active-bg: #e0e7ff; --bs-btn-active-border-color: #a5b4fc;
    --bs-btn-disabled-color: #4338ca; --bs-btn-disabled-border-color: #c7d2fe;
}
.btn-outline-secondary {
    --bs-btn-bg: #fff; --bs-btn-color: #344054; --bs-btn-border-color: #d0d5dd;
    --bs-btn-hover-color: #1d2939; --bs-btn-hover-bg: #f9fafb; --bs-btn-hover-border-color: #d0d5dd;
    --bs-btn-active-color: #1d2939; --bs-btn-active-bg: #f2f4f7; --bs-btn-active-border-color: #d0d5dd;
    --bs-btn-disabled-color: #98a2b3; --bs-btn-disabled-border-color: #e4e7ec;
    box-shadow: var(--app-shadow-sm);
}
.btn-outline-success {
    --bs-btn-bg: #fff; --bs-btn-color: #067647; --bs-btn-border-color: #abefc6;
    --bs-btn-hover-color: #067647; --bs-btn-hover-bg: #ecfdf3; --bs-btn-hover-border-color: #75e0a7;
    --bs-btn-active-color: #085d3a; --bs-btn-active-bg: #dcfae6; --bs-btn-active-border-color: #75e0a7;
}
.btn-outline-danger {
    --bs-btn-bg: #fff; --bs-btn-color: #b42318; --bs-btn-border-color: #fecdca;
    --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #d92d20; --bs-btn-hover-border-color: #d92d20;
    --bs-btn-active-color: #fff; --bs-btn-active-bg: #b42318; --bs-btn-active-border-color: #b42318;
}
.btn-outline-warning {
    --bs-btn-bg: #fff; --bs-btn-color: #b54708; --bs-btn-border-color: #fedf89;
    --bs-btn-hover-color: #93370d; --bs-btn-hover-bg: #fffaeb; --bs-btn-hover-border-color: #fec84b;
    --bs-btn-active-color: #93370d; --bs-btn-active-bg: #fef0c7; --bs-btn-active-border-color: #fec84b;
}
.btn-link { --bs-btn-font-weight: 500; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ forms */
.form-label { margin-bottom: .35rem; font-size: .875rem; font-weight: 500; color: #344054; }
.form-text { font-size: .8rem; color: var(--app-muted); }
.form-control, .form-select { border-color: var(--app-border-strong); box-shadow: var(--app-shadow-sm); }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: var(--app-ring); }
.form-control::placeholder { color: var(--app-subtle); }
.form-control:disabled, .form-select:disabled { background-color: var(--app-surface-2); }
.form-check-input { border-color: var(--app-border-strong); }
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.form-check-input:focus { border-color: #a5b4fc; box-shadow: var(--app-ring); }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; top: 50%; left: .8rem; width: 1rem; height: 1rem; color: var(--app-subtle); transform: translateY(-50%); pointer-events: none; }
.input-icon > .form-control { padding-left: 2.35rem; }

.bulk-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem 1.25rem;
    border-bottom: 1px solid var(--app-border); background: var(--app-surface-2);
    border-top-left-radius: calc(var(--app-radius) - 1px); border-top-right-radius: calc(var(--app-radius) - 1px);
    font-size: .85rem; color: var(--app-muted);
}
.bulk-bar [data-bulk-count] { margin-right: .25rem; font-weight: 500; }
.bulk-bar.has-selection [data-bulk-count] { color: var(--app-primary); }
.bulk-note { flex-basis: 100%; font-size: .78rem; }
.check-cell { width: 2.75rem; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.filter-bar > * { flex: 0 1 auto; }
.filter-bar .grow { flex: 1 1 14rem; max-width: 22rem; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 10rem; }
.filter-bar .filter-reset { font-size: .85rem; }

.form-section + .form-section { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--app-border); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: 1.5rem; }

/* ----------------------------------------------------------------- alerts */
.alert { --bs-alert-border-radius: var(--app-radius-sm); --bs-alert-padding-y: .75rem; --bs-alert-padding-x: 1rem; font-size: .9rem; }
.alert-icon { display: flex; align-items: flex-start; gap: .65rem; }
.alert-icon > .icon { width: 1.15rem; height: 1.15rem; margin-top: .05rem; }
.alert-icon > div { flex: 1; min-width: 0; }
.alert-dismissible.alert-icon { padding-right: 3rem; }
.alert-warning { --bs-alert-color: #93370d; --bs-alert-bg: #fffcf5; --bs-alert-border-color: #fedf89; --bs-alert-link-color: #93370d; }
.alert-danger { --bs-alert-color: #912018; --bs-alert-bg: #fffbfa; --bs-alert-border-color: #fecdca; --bs-alert-link-color: #912018; }
.alert-success { --bs-alert-color: #085d3a; --bs-alert-bg: #f6fef9; --bs-alert-border-color: #abefc6; --bs-alert-link-color: #085d3a; }
.alert-info { --bs-alert-color: #194185; --bs-alert-bg: #f5faff; --bs-alert-border-color: #b2ddff; --bs-alert-link-color: #194185; }
.alert-secondary { --bs-alert-color: #344054; --bs-alert-bg: #f9fafb; --bs-alert-border-color: #e4e7ec; }
.alert-warning > .icon { color: #dc6803; }
.alert-danger > .icon { color: #d92d20; }
.alert-success > .icon { color: #079455; }
.alert-info > .icon { color: #1570ef; }
.alert-heading { font-size: .95rem; font-weight: 600; color: inherit; margin-bottom: .35rem; }
.notice-list { display: grid; gap: .5rem; margin-bottom: 1.25rem; }
.notice-list .alert { margin: 0; padding-top: .6rem; padding-bottom: .6rem; font-size: .85rem; }

/* ------------------------------------------------------------- navigation */
.segmented { display: inline-flex; flex-wrap: wrap; gap: .15rem; padding: .25rem; border-radius: .6rem; background: #eaecf2; }
.segmented a { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .8rem; border-radius: .45rem; font-size: .85rem; font-weight: 500; color: #475467; text-decoration: none; }
.segmented a:hover { color: var(--app-heading); }
.segmented a.active { background: #fff; color: var(--app-heading); box-shadow: var(--app-shadow); }
.segmented .seg-count { padding: 0 .4rem; border-radius: 999px; background: rgba(16, 24, 40, .07); font-size: .72rem; font-weight: 600; }
.pagination {
    --bs-pagination-color: #344054; --bs-pagination-bg: #fff; --bs-pagination-border-color: var(--app-border);
    --bs-pagination-hover-color: var(--app-heading); --bs-pagination-hover-bg: var(--app-surface-2); --bs-pagination-hover-border-color: var(--app-border);
    --bs-pagination-active-bg: var(--app-primary); --bs-pagination-active-border-color: var(--app-primary);
    --bs-pagination-focus-box-shadow: var(--app-ring); --bs-pagination-border-radius: .5rem; --bs-pagination-font-size: .875rem;
}
.dropdown-menu {
    --bs-dropdown-border-color: var(--app-border); --bs-dropdown-border-radius: .65rem; --bs-dropdown-box-shadow: var(--app-shadow-lg);
    --bs-dropdown-link-active-bg: var(--app-primary); --bs-dropdown-font-size: .9rem;
    padding: .35rem; box-shadow: var(--bs-dropdown-box-shadow);
}
.dropdown-item { display: flex; align-items: center; gap: .55rem; padding: .45rem .7rem; border-radius: .4rem; }

/* -------------------------------------------------------------- dashboard */
.stat-card { height: 100%; }
.stat-card .card-body { display: flex; align-items: flex-start; gap: 1rem; }
.stat-icon { display: grid; place-items: center; flex-shrink: 0; width: 2.75rem; height: 2.75rem; border-radius: .75rem; }
.stat-icon .icon { width: 1.35rem; height: 1.35rem; }
.stat-label { font-size: .85rem; font-weight: 500; color: var(--app-muted); }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; color: var(--app-heading); font-variant-numeric: tabular-nums; }
.stat-link { display: inline-flex; align-items: center; gap: .2rem; margin-top: .15rem; font-size: .8rem; font-weight: 500; text-decoration: none; }
.stat-link:hover { text-decoration: underline; }
.stat-card.is-alert { border-color: #fecdca; }
.stat-card.is-alert .stat-value { color: #b42318; }
.tone-primary { color: #4f46e5; background: #eef2ff; }
.tone-success { color: #079455; background: #ecfdf3; }
.tone-warning { color: #dc6803; background: #fffaeb; }
.tone-danger { color: #d92d20; background: #fef3f2; }
.tone-info { color: #1570ef; background: #eff8ff; }
.tone-secondary { color: #475467; background: #f2f4f7; }

.welcome { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.welcome-date { font-size: .85rem; font-weight: 500; color: var(--app-muted); }
.welcome-date::first-letter { text-transform: uppercase; }
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; }
.quick-action {
    display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem;
    border: 1px solid var(--app-border); border-radius: var(--app-radius); background: #fff; box-shadow: var(--app-shadow-sm);
    color: var(--app-heading); text-decoration: none; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.quick-action:hover { border-color: #c7d2fe; color: var(--app-heading); box-shadow: var(--app-shadow); transform: translateY(-1px); }
.quick-action strong { display: block; font-size: .9rem; font-weight: 600; }
.quick-action span { display: block; font-size: .78rem; color: var(--app-muted); }
.quick-action .stat-icon { width: 2.4rem; height: 2.4rem; border-radius: .65rem; }
.quick-action > .icon:last-child { margin-left: auto; color: var(--app-subtle); }

.status-bar { overflow: hidden; height: .7rem; border-radius: 999px; background: #f2f4f7; }
.status-bar svg { display: block; width: 100%; height: 100%; }
.fill-secondary { fill: #98a2b3; } .fill-info { fill: #2e90fa; } .fill-primary { fill: #6366f1; } .fill-warning { fill: #f79009; }
.fill-success { fill: #17b26a; } .fill-danger { fill: #f04438; } .fill-dark { fill: #475467; }
.status-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .25rem .75rem; margin-top: 1rem; }
.status-legend a { display: flex; align-items: center; gap: .55rem; padding: .4rem .55rem; border-radius: .5rem; color: var(--app-text); font-size: .86rem; text-decoration: none; }
.status-legend a:hover { background: var(--app-surface-2); }
.status-legend .legend-count { margin-left: auto; font-weight: 650; color: var(--app-heading); font-variant-numeric: tabular-nums; }
.legend-dot { flex-shrink: 0; width: .6rem; height: .6rem; border-radius: 3px; }
.dot-secondary { background: #98a2b3; } .dot-info { background: #2e90fa; } .dot-primary { background: #6366f1; } .dot-warning { background: #f79009; }
.dot-success { background: #17b26a; } .dot-danger { background: #f04438; } .dot-dark { background: #475467; }

.activity-list { margin: 0; padding: 0; list-style: none; }
.activity-item { display: flex; gap: .8rem; padding: .7rem 1.25rem; border-bottom: 1px solid #f2f4f7; }
.activity-item:last-child { border-bottom: 0; }
.activity-dot { flex-shrink: 0; width: .55rem; height: .55rem; margin-top: .45rem; border-radius: 50%; box-shadow: 0 0 0 3px #fff, 0 0 0 4px #eaecf0; }
.activity-text { min-width: 0; font-size: .875rem; }
.activity-title { font-weight: 500; color: var(--app-heading); }
.activity-meta { font-size: .78rem; color: var(--app-muted); }

.empty-state { padding: 2.25rem 1.25rem; text-align: center; color: var(--app-muted); }
.empty-state .empty-icon { display: inline-grid; place-items: center; width: 3rem; height: 3rem; margin-bottom: .75rem; border-radius: 50%; background: #f2f4f7; color: var(--app-subtle); box-shadow: 0 0 0 6px #f9fafb; }
.empty-state .empty-icon .icon { width: 1.35rem; height: 1.35rem; }
.empty-state .empty-title { margin-bottom: .2rem; font-weight: 600; color: #344054; }
.empty-state p { margin: 0 auto; max-width: 28rem; font-size: .875rem; }
.empty-state .btn { margin-top: 1rem; }
.empty-state-sm { padding: 1.25rem; }

/* ---------------------------------------------------------- key / value */
.kv { display: grid; grid-template-columns: minmax(7.5rem, 38%) minmax(0, 1fr); gap: .6rem 1rem; margin: 0; font-size: .875rem; }
.kv dt { font-weight: 500; color: var(--app-muted); }
.kv dd { margin: 0; color: var(--app-heading); overflow-wrap: anywhere; }
.min-w-0 { min-width: 0; }

/* ----------------------------------------------------------------- stepper */
.stepper { display: flex; margin: 0; padding: 0; list-style: none; }
.stepper li { position: relative; display: flex; flex: 1; flex-direction: column; align-items: center; gap: .4rem; text-align: center; font-size: .8rem; font-weight: 500; color: var(--app-muted); }
.stepper li::before { content: ""; position: absolute; top: 1rem; left: -50%; z-index: 0; width: 100%; height: 2px; background: var(--app-border); }
.stepper li:first-child::before { display: none; }
.stepper .step-icon { position: relative; z-index: 1; display: grid; place-items: center; width: 2rem; height: 2rem; border: 2px solid var(--app-border); border-radius: 50%; background: #fff; color: var(--app-subtle); font-size: .78rem; font-weight: 700; }
.stepper .step-icon .icon { width: 1rem; height: 1rem; }
.stepper li.done, .stepper li.current { color: var(--app-heading); }
.stepper li.done::before, .stepper li.current::before { background: var(--app-primary); }
.stepper li.done .step-icon { border-color: var(--app-primary); background: var(--app-primary); color: #fff; }
.stepper li.current .step-icon { border-color: var(--app-primary); color: var(--app-primary); box-shadow: 0 0 0 4px #e0e7ff; }
.stepper li.error .step-icon { border-color: #f04438; background: #fef3f2; color: #d92d20; box-shadow: 0 0 0 4px #fee4e2; }
.stepper li.error { color: #b42318; }
.step-note { display: block; font-size: .72rem; font-weight: 400; color: var(--app-muted); }

/* ------------------------------------------------------------------ upload */
.dropzone {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
    padding: 2.5rem 1.5rem; border: 2px dashed #c7d2fe; border-radius: var(--app-radius);
    background: linear-gradient(180deg, #fbfbff 0%, #f5f6ff 100%); text-align: center; cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: #6366f1; background: #eef2ff; }
.dropzone:focus-within { outline: 2px solid #6366f1; outline-offset: 2px; }
.dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone-icon { display: grid; place-items: center; width: 3.25rem; height: 3.25rem; margin-bottom: .5rem; border-radius: 50%; background: #fff; color: var(--app-primary); box-shadow: var(--app-shadow); }
.dropzone-icon .icon { width: 1.5rem; height: 1.5rem; }
.dropzone-title { font-weight: 600; color: var(--app-heading); }
.dropzone-title span { color: var(--app-primary); }
.dropzone-hint { font-size: .82rem; color: var(--app-muted); }
.file-list { display: grid; gap: .4rem; margin: .85rem 0 0; padding: 0; list-style: none; }
.file-list:empty { display: none; }
.file-list li { display: flex; align-items: center; gap: .65rem; padding: .45rem .75rem; border: 1px solid var(--app-border); border-radius: .55rem; background: #fff; font-size: .85rem; }
.file-list .file-name { overflow: hidden; min-width: 0; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { margin-left: auto; color: var(--app-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-list .filetype { width: 1.9rem; height: 1.9rem; font-size: .52rem; }
.steps-list { margin: 0; padding: 0; list-style: none; counter-reset: steps; }
.steps-list li { position: relative; padding: 0 0 .9rem 2.4rem; font-size: .875rem; counter-increment: steps; }
.steps-list li:last-child { padding-bottom: 0; }
.steps-list li::before {
    content: counter(steps); position: absolute; top: -.05rem; left: 0;
    display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
    background: var(--app-primary-soft); color: var(--app-primary); font-size: .75rem; font-weight: 700;
}
.steps-list strong { display: block; color: var(--app-heading); font-weight: 600; }
.steps-list span { color: var(--app-muted); }

/* -------------------------------------------------------- review e varie */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.toolbar-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; font-size: .82rem; color: var(--app-muted); }
.table-review td { vertical-align: top; }
.table-review input.form-control-sm { min-width: 7rem; }
.table-review input.input-wide { min-width: 16rem; }
.table-review .form-control-sm, .table-review .form-select-sm { box-shadow: none; }
.table-review .excerpt { min-width: 16rem; max-width: 24rem; font-size: .75rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.table-review .record-issue { min-width: 12rem; }
.table-review .row-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: .3rem; }
.table-review .row-actions form { display: contents; }
.table-review tr.row-pending > td:first-child { box-shadow: inset 3px 0 0 #f79009; }
.table-review tr.row-validated > td:first-child { box-shadow: inset 3px 0 0 #17b26a; }
.table-review tr.row-discarded > td:first-child { box-shadow: inset 3px 0 0 #d0d5dd; }
.table-review tr.row-discarded > td { color: var(--app-subtle); background: #fcfcfd; }
.table-review .row-num { font-weight: 600; color: var(--app-subtle); }
.record-issue { display: flex; gap: .35rem; margin-bottom: .2rem; font-size: .75rem; line-height: 1.35; }
.record-issue .icon { width: .85rem; height: .85rem; margin-top: .1rem; }
.issue-error { color: #b42318; }
.issue-warning { color: #b54708; }
.original-value { display: block; margin-top: .2rem; font-size: .72rem; color: #b54708; }
.is-invalid-cell { background-color: var(--bs-danger-bg-subtle) !important; }

.qr-code { width: 220px; height: 220px; padding: 10px; border: 1px solid var(--app-border); border-radius: var(--app-radius); background: #fff; image-rendering: pixelated; }
.code-input { font-family: var(--bs-font-monospace); letter-spacing: .3em; }
.secret-box { padding: .6rem .75rem; border: 1px dashed var(--app-border-strong); border-radius: var(--app-radius-sm); background: var(--app-surface-2); font-family: var(--bs-font-monospace); font-size: .9rem; text-align: center; word-break: break-all; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: 0; padding: 0; list-style: none; }
.recovery-grid li { padding: .55rem .75rem; border: 1px solid var(--app-border); border-radius: .5rem; background: var(--app-surface-2); font-family: var(--bs-font-monospace); font-size: 1rem; text-align: center; }

.text-mono-sm { font-family: var(--bs-font-monospace); font-size: .8rem; }
.text-truncate-20 { display: inline-block; overflow: hidden; max-width: 20rem; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.preview-table { font-size: .8rem; }
.preview-table td, .preview-table th { overflow: hidden; max-width: 14rem; text-overflow: ellipsis; white-space: nowrap; }
.preview-table > thead > tr > th { text-transform: none; letter-spacing: 0; }
.extracted-text { overflow: auto; max-height: 24rem; margin: 0; padding: 1rem; border-radius: var(--app-radius-sm); background: #0f172a; color: #cbd5e1; font-size: .75rem; white-space: pre-wrap; }
.diag-status { width: 7.5rem; }
.diag-label { width: 34%; }

/* ---------------------------------------------------------- accesso (guest) */
.auth-body { min-height: 100vh; background: #fff; }
.auth-shell { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; }
@media (min-width: 992px) { .auth-shell { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }
.auth-aside {
    position: relative; overflow: hidden; flex-direction: column; justify-content: space-between; gap: 2rem;
    padding: 3rem 3.5rem; color: #c7d2fe;
    background:
        radial-gradient(1100px 680px at -5% -5%, rgba(99, 102, 241, .75) 0%, transparent 62%),
        radial-gradient(800px 560px at 110% 110%, rgba(139, 92, 246, .65) 0%, transparent 62%),
        #0b1022;
}
.auth-aside::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
    background-size: 36px 36px;
    -webkit-mask-image: radial-gradient(ellipse at 30% 40%, #000 0%, transparent 75%);
    mask-image: radial-gradient(ellipse at 30% 40%, #000 0%, transparent 75%);
}
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside .brand-link { color: #fff; }
.auth-aside .brand-sub { color: #a5b4fc; }
.auth-headline { max-width: 30rem; margin: 0; font-size: 2.15rem; font-weight: 700; line-height: 1.15; letter-spacing: -.025em; color: #fff; }
.auth-lead { max-width: 29rem; margin: 1rem 0 0; font-size: 1rem; color: #c7d2fe; }
.auth-features { display: grid; gap: 1.1rem; max-width: 29rem; margin: 2.25rem 0 0; padding: 0; list-style: none; }
.auth-features li { display: flex; align-items: flex-start; gap: .9rem; }
.auth-feature-icon { display: grid; place-items: center; flex-shrink: 0; width: 2.35rem; height: 2.35rem; border: 1px solid rgba(255, 255, 255, .14); border-radius: .65rem; background: rgba(255, 255, 255, .07); color: #c7d2fe; }
.auth-features strong { display: block; font-size: .95rem; font-weight: 600; color: #fff; }
.auth-features span { font-size: .85rem; color: #a5b4fc; }
.auth-foot { font-size: .78rem; color: #818cf8; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 2.5rem 1.25rem; }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand-link { color: var(--app-heading); margin-bottom: 2rem; }
.auth-card .brand-sub { color: var(--app-muted); }
.auth-icon { display: grid; place-items: center; width: 3rem; height: 3rem; margin-bottom: 1.25rem; border: 1px solid var(--app-border); border-radius: .8rem; background: #fff; color: var(--app-primary); box-shadow: var(--app-shadow); }
.auth-icon .icon { width: 1.4rem; height: 1.4rem; }
.auth-title { margin-bottom: .4rem; font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.auth-lead-text { margin-bottom: 1.75rem; color: var(--app-muted); }
.auth-card .form-control { padding: .6rem .85rem; }
.auth-card .btn-lg { --bs-btn-padding-y: .65rem; --bs-btn-font-size: 1rem; }
.auth-help { margin: 1.5rem 0 0; font-size: .85rem; text-align: center; color: var(--app-muted); }
.auth-help a { display: inline-flex; align-items: center; gap: .3rem; text-decoration: none; }
.auth-help a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------- guida */
.guide-toc { position: sticky; top: 1.5rem; font-size: .875rem; }
.guide-toc .card-body { padding: 1rem 1.1rem; }
.guide-toc a { display: block; padding: .3rem .5rem; border-radius: .4rem; color: #475467; text-decoration: none; }
.guide-toc a:hover { background: var(--app-surface-2); color: var(--app-primary); }
.guide section { scroll-margin-top: 1.5rem; }
.guide h2 { margin-top: 2.25rem; padding-bottom: .45rem; border-bottom: 1px solid var(--app-border); font-size: 1.3rem; font-weight: 650; }
.guide h3 { margin-top: 1.35rem; font-size: 1.02rem; font-weight: 600; }
.guide .table { font-size: .9rem; }
.guide p, .guide li { line-height: 1.6; }

/* --------------------------------------------------------------- telefono */
@media (max-width: 575.98px) {
    .page-title { font-size: 1.35rem; }
    .page-actions { width: 100%; }
    .page-actions > .btn, .page-actions > form { flex: 1 1 auto; }
    .page-actions > form > .btn { width: 100%; }
    .stat-card .card-body { flex-direction: column; gap: .6rem; padding: 1rem; }
    .stat-icon { width: 2.4rem; height: 2.4rem; }
    .stat-value { font-size: 1.55rem; }
    .stepper li { font-size: .72rem; }
    .stepper .step-note { display: none; }
    .filter-bar > *, .filter-bar .grow { flex: 1 1 100%; max-width: none; }
    .filter-bar .w-auto { width: 100% !important; }
}

/* ------------------------------------------------------------------ stampa */
@media print {
    body { background: #fff; }
    .app-sidebar, .app-topbar, .app-footer, .guide-toc, .no-print, .demo-banner { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }
    .card { box-shadow: none; }
    .guide { font-size: 10.5pt; }
    .guide h2 { break-after: avoid; }
    .guide .card, .guide table { break-inside: avoid; }
    main.container, .container { max-width: 100% !important; }
}
