:root {
    --portal-ink: #172033;
    --portal-muted: #697386;
    --portal-muted-soft: #9ba5b5;
    --portal-canvas: #f5f7fb;
    --portal-surface: #ffffff;
    --portal-surface-soft: #f9faff;
    --portal-line: #e5e9f2;
    --portal-line-strong: #d6ddea;
    --portal-brand: #4f46e5;
    --portal-brand-dark: #3730a3;
    --portal-brand-soft: #eef0ff;
    /* Il lilla tenue distingue il menu dal contenuto e riprende il colore del logo. */
    --portal-sidebar: #f1eef8;
    --portal-sidebar-muted: #70687d;
    --portal-sidebar-line: #e0daed;
    --portal-success: #16835d;
    --portal-success-soft: #eaf8f1;
    --portal-warning: #aa6708;
    --portal-warning-soft: #fff5de;
    --portal-danger: #bd3c4a;
    --portal-danger-soft: #fff0f1;
    --portal-radius-lg: 1.25rem;
    --portal-radius-md: .875rem;
    --portal-shadow: 0 12px 32px rgba(23, 32, 51, .055);
    --portal-shadow-lifted: 0 16px 36px rgba(23, 32, 51, .10);
}

/* Un invio numeroso non deve allungare indefinitamente la pagina. */
[data-upload-results] {
    max-height: 16rem;
    overflow-y: auto;
    overflow-wrap: anywhere;
    padding-right: .75rem;
}

[data-upload-progress] {
    accent-color: var(--portal-brand);
}

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.portal-body {
    background: radial-gradient(circle at 82% -8%, rgba(99, 102, 241, .10), transparent 28rem), var(--portal-canvas);
    color: var(--portal-ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: .9375rem;
    line-height: 1.55;
    max-width: 100%;
    overflow-x: hidden;
}

.portal-main {
    min-height: 100vh;
    min-width: 0;
    overflow-x: hidden;
}

.portal-content {
    max-width: 1440px;
    min-width: 0;
    width: 100%;
}

/* Un solo marchio per login, navigazione e icona della scheda del browser. */
.portal-brand {
    align-items: center;
    display: flex;
    gap: .75rem;
    min-width: 0;
}

.portal-brand-mark {
    flex: 0 0 3rem;
    height: 3rem;
    width: 3rem;
}

.portal-brand-copy strong,
.portal-brand-copy > span {
    display: block;
}

.portal-brand-copy strong {
    color: inherit;
    font-size: 1.3rem;
    font-weight: 750;
    letter-spacing: -.04em;
    line-height: 1.2;
}

.portal-brand-copy > span {
    font-size: .75rem;
    margin-top: .2rem;
}

.portal-sidebar-label,
.portal-page-eyebrow {
    color: var(--portal-muted);
    font-size: .6875rem;
    font-weight: 800;
    letter-spacing: .09em;
    line-height: 1.2;
    text-transform: uppercase;
}

.portal-panel,
.portal-stat-card {
    background: var(--portal-surface);
    border: 1px solid var(--portal-line);
    border-radius: var(--portal-radius-lg);
}

.portal-upload-panel {
    background: linear-gradient(135deg, #ffffff, #f5f6ff);
    border-color: #d9dcff;
}

/* Titoli uniformi per lingua e caricamento, conservando le frecce native di apertura. */
.portal-documents .portal-document-section-title {
    font-size: 1.15rem;
}

.portal-document-section-title > .portal-content-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-inline: .25rem;
    vertical-align: -.2em;
    color: var(--portal-brand);
}

.portal-upload-file-field {
    align-items: center;
    background: #fff;
    border: 1px dashed #aaa8ed;
    border-radius: .85rem;
    display: flex;
    height: 3.76rem;
    padding: .45rem;
}

.portal-upload-file-field .form-control {
    border: 0;
    height: 100%;
    box-shadow: none;
}

.portal-upload-delivery-field {
    height: 3.76rem;
}

.portal-upload-delivery-field .portal-upload-delivery-select {
    height: 100%;
    min-height: 100%;
}

.portal-upload-submit {
    min-height: 3.76rem;
}

.portal-toolbar {
    align-items: center;
    background: rgba(255, 255, 255, .74);
    border: 1px solid var(--portal-line);
    border-radius: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    justify-content: space-between;
    padding: .75rem;
}

.portal-toolbar-copy {
    color: var(--portal-muted);
    font-size: .84rem;
}

.portal-search-disabled {
    align-items: flex-start;
    background: linear-gradient(135deg, #fff9e9, #fff3d3);
    border: 1px solid #f0d28b;
    border-radius: var(--portal-radius-lg);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 1.2rem 1.3rem;
}

.portal-search-disabled h3 {
    color: #6f4705;
    font-size: 1rem;
    font-weight: 750;
    margin: 0 0 .35rem;
}

.portal-search-disabled p {
    color: #805d1d;
    margin: 0;
    max-width: 48rem;
}

.portal-page-heading {
    max-width: 760px;
}

.portal-page-heading h2,
.portal-page-heading .h3 {
    color: var(--portal-ink);
    font-size: clamp(1.55rem, 2vw, 2rem);
    font-weight: 750;
    letter-spacing: -.035em;
}

.portal-page-heading > p {
    color: var(--portal-muted) !important;
    max-width: 680px;
}

.portal-panel {
    box-shadow: var(--portal-shadow);
    display: flex;
    flex-direction: column;
    padding: clamp(1rem, 2vw, 1.45rem);
}

.portal-panel-title {
    color: var(--portal-ink);
    font-size: 1rem;
    font-weight: 750;
    letter-spacing: -.012em;
    margin-bottom: .75rem;
}

.portal-collaborators-header {
    align-items: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.portal-member-avatar {
    align-items: center;
    background: linear-gradient(135deg, #e7e7ff, #d8f0ff);
    border: 1px solid #d1d3f8;
    border-radius: .8rem;
    color: #4542a3;
    display: inline-flex;
    flex: 0 0 2.5rem;
    font-size: .9rem;
    font-weight: 800;
    height: 2.5rem;
    justify-content: center;
    width: 2.5rem;
}

.portal-role-badge {
    background: #f2f1ff;
    border: 1px solid #dfddff;
    border-radius: 999px;
    color: #5550ab;
    display: inline-flex;
    font-size: .72rem;
    font-weight: 750;
    padding: .38rem .62rem;
    white-space: nowrap;
}

.portal-modal {
    border: 0;
    border-radius: 1rem;
    box-shadow: 0 1.25rem 3.5rem rgba(23, 32, 51, .18);
}

.portal-modal .modal-header,
.portal-modal .modal-footer {
    border-color: var(--portal-line);
    padding: 1rem 1.25rem;
}

.portal-modal .modal-body {
    padding: 1.25rem;
}

.portal-section-kicker {
    color: var(--portal-brand);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .075em;
    text-transform: uppercase;
}

.portal-empty-state {
    align-items: flex-start;
    background: linear-gradient(135deg, #f8f8ff, #f2f4ff);
    border: 1px dashed #bbb8ff;
    border-radius: var(--portal-radius-md);
    display: flex;
    flex-direction: column;
    gap: .8rem;
    padding: 1.25rem;
}

.portal-empty-state h4 {
    color: var(--portal-ink);
    font-size: 1rem;
    font-weight: 750;
    margin: 0;
}

.portal-empty-state p {
    color: var(--portal-muted);
    margin: 0;
    max-width: 38rem;
}

.portal-form-panel {
    max-width: 760px;
}

.portal-command-panel {
    background:
        radial-gradient(circle at 100% 0%, rgba(137, 132, 255, .34), transparent 26rem),
        linear-gradient(120deg, #1e1b4b, #2a276b);
    border: 1px solid rgba(129, 124, 255, .25);
    border-radius: var(--portal-radius-lg);
    box-shadow: 0 16px 32px rgba(30, 27, 75, .16);
    color: #fff;
    overflow: hidden;
    padding: clamp(1.25rem, 2.5vw, 1.75rem);
    position: relative;
}

.portal-command-panel::after {
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 50%;
    content: "";
    height: 15rem;
    pointer-events: none;
    position: absolute;
    right: -7rem;
    top: -8rem;
    width: 15rem;
}

.portal-command-panel .portal-page-eyebrow,
.portal-command-panel .text-secondary {
    color: #c8c8f9 !important;
}

.portal-command-action {
    background: rgba(255, 255, 255, .075);
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 1rem;
    color: #fff;
    display: block;
    height: 100%;
    min-height: 118px;
    padding: 1rem;
    position: relative;
    text-decoration: none;
    transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}

.portal-command-action::after {
    color: #bfbcff;
    content: "→";
    font-size: 1.25rem;
    line-height: 1;
    position: absolute;
    right: 1rem;
    top: .85rem;
    transition: transform .18s ease;
}

.portal-command-action:hover {
    background: rgba(255, 255, 255, .13);
    border-color: rgba(191, 188, 255, .65);
    color: #fff;
    transform: translateY(-2px);
}

.portal-command-action:hover::after {
    transform: translateX(3px);
}

.portal-command-action span {
    color: #c2c0ff;
    display: block;
    font-size: .6875rem;
    font-weight: 800;
    letter-spacing: .08em;
    margin-bottom: .55rem;
    text-transform: uppercase;
}

.portal-command-action strong,
.portal-command-action .small {
    color: inherit;
}

.portal-stat-card {
    box-shadow: 0 5px 18px rgba(23, 32, 51, .035);
    display: flex;
    flex-direction: column;
    min-height: 142px;
    overflow: hidden;
    padding: 1.15rem;
    position: relative;
}

.portal-stat-card::before {
    background: var(--portal-brand);
    border-radius: 99px;
    content: "";
    height: .45rem;
    position: absolute;
    right: 1.05rem;
    top: 1.15rem;
    width: .45rem;
}

.portal-stat-value {
    font-size: 2.1rem;
    font-weight: 780;
    letter-spacing: -.05em;
    line-height: 1;
}

.portal-stat-success::before {
    background: var(--portal-success);
}

.portal-stat-warning::before {
    background: var(--portal-warning);
}

.portal-stat-success {
    border-color: #d8eddf;
}

.portal-stat-warning {
    border-color: #f3e4bf;
}

.portal-table {
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--portal-line);
    margin-bottom: 0;
}

.portal-table thead th {
    background: var(--portal-surface-soft);
    border-bottom-width: 1px;
    color: var(--portal-muted);
    font-size: .6875rem;
    font-weight: 800;
    letter-spacing: .075em;
    text-transform: uppercase;
}

.portal-table td,
.portal-table th {
    padding: .95rem 1rem;
    vertical-align: middle;
}

.portal-table tbody tr {
    transition: background-color .16s ease;
}

.portal-table tbody tr:hover {
    --bs-table-bg: #fafbff;
}

.status-pill {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    font-size: .72rem;
    font-weight: 750;
    letter-spacing: .01em;
    line-height: 1;
    padding: .43rem .68rem;
    white-space: nowrap;
}

.status-pill::before {
    background: currentColor;
    border-radius: 50%;
    content: "";
    height: .38rem;
    margin-right: .38rem;
    opacity: .75;
    width: .38rem;
}

.status-pill-success {
    background: var(--portal-success-soft);
    color: var(--portal-success);
}

.status-pill-warning {
    background: var(--portal-warning-soft);
    color: var(--portal-warning);
}

.status-pill-danger {
    background: var(--portal-danger-soft);
    color: var(--portal-danger);
}

.status-pill-muted {
    background: #eef1f6;
    color: #667085;
}

.portal-progress {
    background: #ecebff;
    border-radius: 999px;
    height: .35rem;
    max-width: 12rem;
    overflow: hidden;
}

.portal-progress span {
    background: linear-gradient(90deg, #7773e8, #5b8def);
    border-radius: inherit;
    display: block;
    height: 100%;
    min-width: .35rem;
    transition: width .3s ease;
}

.workspace-fact,
.workspace-role-panel,
.workspace-tile,
.role-tile,
.document-event-row,
.portal-rail-card {
    background: var(--portal-surface-soft);
    border: 1px solid var(--portal-line);
    border-radius: var(--portal-radius-md);
}

.workspace-fact {
    min-height: 92px;
    padding: .95rem;
}

.workspace-fact span {
    color: var(--portal-muted);
    display: block;
    font-size: .72rem;
    font-weight: 700;
    margin-bottom: .38rem;
}

.workspace-fact strong {
    color: var(--portal-ink);
    display: block;
    font-size: .92rem;
    overflow-wrap: anywhere;
}

.workspace-role-panel {
    padding: .9rem;
}

.workspace-tile,
.role-tile {
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.workspace-tile.is-current {
    background: #f5f5ff;
    border-color: #bab6ff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .07);
}

.capability-row {
    border-bottom: 1px solid var(--portal-line);
    min-height: 38px;
    padding-bottom: .55rem;
}

.capability-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.role-dot {
    background: var(--portal-brand);
    border-radius: 50%;
    flex: 0 0 .48rem;
    height: .48rem;
    width: .48rem;
}

.document-event-row {
    background: #fff;
    padding: .9rem;
}

.document-event-row:hover {
    border-color: #c9c8ff;
}

.portal-rail-card {
    background: var(--portal-surface-soft);
    padding: 1rem;
}

.portal-spacer-top {
    margin-top: auto;
}

.form-label {
    color: #344054;
    font-size: .8125rem;
    font-weight: 700;
    margin-bottom: .4rem;
}

.form-control,
.form-select {
    background-color: #fff;
    border-color: var(--portal-line-strong);
    border-radius: .7rem;
    color: var(--portal-ink);
    min-height: 2.7rem;
    padding: .55rem .75rem;
    transition: border-color .16s ease, box-shadow .16s ease;
}

.form-control::placeholder {
    color: #a0a8b6;
}

.form-control:focus,
.form-select:focus {
    border-color: #908bff;
    box-shadow: 0 0 0 .22rem rgba(79, 70, 229, .12);
}

.form-check-input:checked {
    background-color: var(--portal-brand);
    border-color: var(--portal-brand);
}

.form-text {
    color: var(--portal-muted);
    font-size: .75rem;
}

.btn {
    align-items: center;
    border-radius: .7rem;
    display: inline-flex;
    font-size: .86rem;
    font-weight: 700;
    justify-content: center;
    min-height: 2.55rem;
    padding: .52rem .9rem;
    transition: box-shadow .16s ease, transform .16s ease, background-color .16s ease, border-color .16s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--portal-brand);
    border-color: var(--portal-brand);
    box-shadow: 0 4px 10px rgba(79, 70, 229, .18);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--portal-brand-dark);
    border-color: var(--portal-brand-dark);
    box-shadow: 0 7px 16px rgba(79, 70, 229, .26);
}

.btn-outline-primary {
    border-color: #c9c6ff;
    color: var(--portal-brand);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: var(--portal-brand-soft);
    border-color: #aaa5ff;
    color: var(--portal-brand-dark);
}

.btn-outline-secondary {
    border-color: var(--portal-line-strong);
    color: #4b5565;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background: #f4f6f9;
    border-color: #c7cfdb;
    color: var(--portal-ink);
}

.btn-outline-danger {
    border-color: #f0c2c7;
    color: var(--portal-danger);
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
    background: var(--portal-danger-soft);
    border-color: #e6a4ac;
    color: #9e2634;
}

.btn-sm {
    border-radius: .6rem;
    font-size: .76rem;
    min-height: 2.15rem;
    padding: .35rem .65rem;
}

.badge {
    font-weight: 700;
}

.alert {
    border-radius: var(--portal-radius-md);
    font-size: .875rem;
    padding: .9rem 1rem;
}

.alert-light {
    background: #fafbfe;
    border-color: var(--portal-line) !important;
    color: #4b5565;
}

.alert-success {
    background: var(--portal-success-soft);
    border-color: #c5e9d4;
    color: #126345;
}

.alert-danger {
    background: var(--portal-danger-soft);
    border-color: #f1c6ca;
    color: #982a38;
}

.alert-warning {
    background: var(--portal-warning-soft);
    border-color: #efd99e;
    color: #855006;
}

.list-group-item {
    border-color: var(--portal-line);
}

code {
    background: #f0efff;
    border-radius: .35rem;
    color: #4b43c6;
    font-size: .82em;
    padding: .12rem .3rem;
}

.field-help {
    align-items: center;
    background: var(--portal-surface, #fff);
    border: 1px solid #b7b4d8;
    border-radius: 50%;
    color: #514caf;
    display: inline-flex;
    font-size: .7rem;
    font-weight: 700;
    height: 1.15rem;
    justify-content: center;
    line-height: 1;
    margin-left: .15rem;
    padding: 0;
    vertical-align: middle;
    width: 1.15rem;
}

.field-help:hover,
.field-help:focus-visible {
    background: #514caf;
    color: #fff;
}

.diff-summary-item {
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 750;
    line-height: 1;
    padding: .5rem .7rem;
    white-space: nowrap;
}

.diff-summary-added {
    background: var(--portal-success-soft);
    color: var(--portal-success);
}

.diff-summary-removed {
    background: var(--portal-danger-soft);
    color: var(--portal-danger);
}

.diff-summary-unchanged {
    background: #eef1f6;
    color: #667085;
}

.diff-view {
    background: #fbfcfe;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: .78rem;
    max-height: 42rem;
    overflow: auto;
}

.diff-line {
    align-items: stretch;
    border-left: .25rem solid transparent;
    display: grid;
    grid-template-columns: 3.2rem 3.2rem 1.7rem minmax(max-content, 1fr);
    min-width: 48rem;
    white-space: pre;
}

.diff-line-number {
    background: rgba(23, 32, 51, .035);
    border-right: 1px solid var(--portal-line);
    color: var(--portal-muted-soft);
    padding: .2rem .45rem;
    text-align: right;
    user-select: none;
}

.diff-line-marker {
    font-weight: 800;
    padding: .2rem .45rem;
    text-align: center;
    user-select: none;
}

.diff-line code {
    color: var(--portal-ink);
    padding: .2rem .7rem .2rem .15rem;
    white-space: pre;
}

.diff-line-added {
    background: #effaf3;
    border-left-color: var(--portal-success);
}

.diff-line-added .diff-line-marker {
    color: var(--portal-success);
}

.diff-line-removed {
    background: #fff3f3;
    border-left-color: var(--portal-danger);
}

.diff-line-removed .diff-line-marker {
    color: var(--portal-danger);
}

.diff-line-unchanged {
    border-left-color: transparent;
}

@media (max-width: 575.98px) {
    .portal-content {
        padding: 1rem !important;
    }

    .portal-panel,
    .portal-command-panel {
        border-radius: 1rem;
    }

    .portal-table td,
    .portal-table th {
        padding: .8rem .7rem;
    }

}

/* Documenti: la larghezza disponibile decide se usare una tabella o schede verticali.
   I testi lunghi vanno a capo; nessuna informazione viene tagliata per nascondere lo scroll. */
.portal-documents {
    min-width: 0;
    overflow-wrap: anywhere;
}

.portal-documents details > .row {
    margin-left: 0;
    margin-right: 0;
}

.portal-documents summary {
    cursor: pointer;
    font-weight: 650;
}

.portal-documents summary:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 4px;
}

.portal-documents .portal-page-heading,
.portal-documents .portal-toolbar > *,
.portal-documents .row > * {
    min-width: 0;
}

.portal-documents .btn,
.portal-documents .status-pill {
    white-space: normal;
}

.portal-documents .status-pill {
    line-height: 1.35;
}

.portal-documents .status-pill::before {
    flex-shrink: 0;
}

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

.document-table th,
.document-table td {
    overflow-wrap: anywhere;
    padding: .85rem .65rem;
}

.document-table td {
    vertical-align: top;
}

.document-table .document-selection-column {
    width: 2.5rem;
}

.document-archive-table th:nth-child(2) { width: 34%; }
.document-archive-table th:nth-child(3) { width: 20%; }
.document-archive-table th:nth-child(4) { width: 19%; }

.document-row-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
    text-align: left;
}

.document-row-actions .btn {
    width: 100%;
}

/* Le azioni secondarie si aprono nella riga, senza menu sovrapposti o tagliati. */
.document-more-actions {
    font-size: .85rem;
    padding: .4rem 0;
}

.document-more-actions summary {
    color: var(--bs-primary);
}

.portal-documents .portal-upload-file-field,
.portal-documents .portal-upload-delivery-field {
    height: auto;
    min-height: 0;
}

.portal-documents .portal-upload-submit {
    min-height: 2.5rem;
}

/* Nei confronti anche le righe di testo lunghe si leggono senza scorrere lateralmente. */
.portal-documents .diff-line {
    grid-template-columns: 2.5rem 2.5rem 1.5rem minmax(0, 1fr);
    min-width: 0;
}

.portal-documents .diff-line code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    min-width: 0;
}

@media (max-width: 1199.98px) {
    .document-table,
    .document-table tbody,
    .document-table tr,
    .document-table td {
        display: block;
        width: 100%;
    }

    /* Conserviamo le intestazioni per le tecnologie assistive. */
    .document-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .document-table tbody tr {
        border: 1px solid var(--portal-line);
        border-radius: .85rem;
        padding: .6rem;
        margin-bottom: 1rem;
    }

    .document-table td {
        border: 0;
        padding: .45rem .35rem;
        text-align: left !important;
    }

    .document-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        color: var(--portal-muted);
        font-size: .72rem;
        font-weight: 750;
        margin-bottom: .2rem;
    }

    .document-table td[data-label="Selezione"]::before {
        display: inline;
        margin-right: .5rem;
    }

    .document-table td[data-label="Selezione"]:not(:has(input)) {
        display: none;
    }

    .document-table .justify-content-end {
        justify-content: flex-start !important;
    }

    .document-row-actions {
        align-items: flex-start;
    }

    .document-row-actions .btn {
        width: auto;
    }
}

/* Diamo più spazio al titolo nelle tabelle dei permessi. */
@media (min-width: 1200px) {
    .document-access-table th:nth-child(2) { width: 22%; }
}

/* La paginazione può andare su più righe, ma ogni pulsante resta intero.
   Il conteggio occupa una riga propria e non sottrae spazio ai comandi. */
.portal-pagination .pagination {
    flex-wrap: wrap;
    row-gap: .5rem;
}

.portal-pagination .page-item {
    flex: 0 0 auto;
}

.portal-pagination .page-link {
    white-space: nowrap;
    overflow-wrap: normal;
}

/* Le associazioni restano leggibili anche con nomi lunghi e su telefono. */
.portal-bot-contents {
    min-width: 0;
    overflow-wrap: anywhere;
}

.portal-bot-contents .badge,
.portal-bot-contents .btn,
.portal-bot-contents .status-pill {
    white-space: normal;
    text-align: left;
    line-height: 1.4;
}

.portal-bot-contents summary {
    cursor: pointer;
}

/* Robot, freccia e cartelle rendono visibile l'associazione senza leggere una guida. */
.portal-content-icon {
    width: 1.4rem;
    height: 1.4rem;
    flex: 0 0 auto;
}

.portal-panel.portal-bot-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 4rem minmax(0, 1.6fr);
    gap: 1.25rem;
    align-items: start;
}

.portal-bot-identity {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem;
    border-radius: var(--portal-radius-md);
    background: var(--portal-brand-soft);
    border: 1px solid #dcdfff;
    min-width: 0;
}

.portal-bot-avatar {
    display: grid;
    place-items: center;
    width: 4rem;
    height: 4rem;
    border-radius: 1.1rem;
    background: var(--portal-brand);
    color: white;
    flex: 0 0 auto;
}

.portal-bot-avatar .portal-content-icon { width: 2.65rem; height: 2.65rem; }
.portal-bot-identity > div { flex: 1 1 9rem; min-width: 0; }
.portal-bot-label { color: var(--portal-brand-dark); font-size: .75rem; font-weight: 700; }
.portal-bot-name { margin: .35rem 0 0; font-size: 1.2rem; line-height: 1.35; font-weight: 750; }

.portal-bot-connector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding-top: 2rem;
    color: var(--portal-muted);
    font-size: .75rem;
}

.portal-bot-connector .portal-content-icon { width: 3rem; height: 2rem; }
.portal-bot-areas { min-width: 0; padding: .5rem 0; }
.portal-area-count { border-radius: 2rem; background: var(--portal-brand-soft); color: var(--portal-brand-dark); padding: .1rem .55rem; font-size: .8rem; font-weight: 700; }
.portal-area-list { display: grid; gap: .65rem; }

.portal-area-tile,
.portal-area-empty {
    display: flex;
    align-items: center;
    gap: .75rem;
    border: 1px solid var(--portal-line);
    border-radius: .65rem;
    padding: .75rem 1rem;
    background: var(--portal-surface-soft);
}

.portal-area-tile .portal-content-icon,
.portal-area-option .portal-content-icon { color: var(--portal-brand); }
.portal-area-tile span { min-width: 0; font-weight: 600; }
.portal-area-empty { color: var(--portal-muted); border-style: dashed; }

/* Le cartelle salvate restano visibili; il selettore nativo funziona anche senza JavaScript. */
.portal-area-picker { border: 1px solid var(--portal-line-strong); border-radius: .75rem; }
.portal-area-picker > summary {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .85rem 1rem;
    list-style: none;
    color: var(--portal-brand-dark);
    font-weight: 650;
    border-radius: .75rem;
}

.portal-area-picker > summary::-webkit-details-marker { display: none; }
.portal-area-picker > summary:hover { background: var(--portal-brand-soft); }
.portal-picker-chevron { margin-left: auto; }
.portal-area-picker[open] > summary .portal-picker-chevron { transform: rotate(180deg); }
.portal-area-picker[open] > summary { border-bottom: 1px solid var(--portal-line); border-radius: .75rem .75rem 0 0; }
.portal-area-form { padding: 1rem; }
.portal-area-form fieldset { min-width: 0; }
.portal-area-options { display: grid; gap: .5rem; }

.portal-area-option {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    padding: .75rem;
    border: 1px solid var(--portal-line);
    border-radius: .6rem;
    cursor: pointer;
}

.portal-area-option .form-check-input { flex: 0 0 auto; margin-top: .2rem; }
.portal-area-option span { min-width: 0; }
.portal-area-option:has(input:checked) { border-color: var(--portal-brand); background: var(--portal-brand-soft); }
.portal-area-option:hover { border-color: var(--portal-brand); }
.portal-area-picker > summary:focus-visible,
.portal-area-option:focus-within { outline: 3px solid var(--portal-brand); outline-offset: 3px; }

/* Su schermi stretti il flusso diventa verticale: bot, freccia, aree. */
@media (max-width: 1199.98px) {
    .portal-panel.portal-bot-card { grid-template-columns: minmax(0, 1fr); gap: .75rem; }
    .portal-bot-connector { flex-direction: row; justify-content: center; padding-top: 0; }
    .portal-bot-connector .portal-content-icon { width: 1.5rem; height: 1.5rem; transform: rotate(90deg); }
    .portal-bot-areas { padding: 0; }
}

/* Panoramica: la stessa sequenza si legge in orizzontale o dall'alto sui telefoni. */
.portal-dashboard-flow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2rem;
    list-style: none;
    margin: 0;
    padding: 0;
}
.portal-dashboard-flow li { min-width: 0; position: relative; }
.portal-dashboard-flow li + li::before {
    content: '→';
    color: #c8c8f9;
    position: absolute;
    left: -1.55rem;
    top: .55rem;
}
.portal-dashboard-step-icon {
    align-items: center;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: .8rem;
    display: inline-flex;
    height: 2.8rem;
    justify-content: center;
    margin-bottom: 1rem;
    width: 2.8rem;
}
.portal-dashboard-step-icon .portal-content-icon { width: 1.65rem; height: 1.65rem; }
.portal-dashboard-step-label { color: #c8c8f9; font-size: .8rem; display: block; margin-bottom: .4rem; }
.portal-dashboard-flow h4 { font-size: 1.05rem; line-height: 1.4; }
.portal-dashboard-flow p { color: #e2e2fa; font-size: .9rem; margin-bottom: .8rem; }
.portal-dashboard-flow a { color: white; text-underline-offset: .25em; font-weight: 650; font-size: .9rem; }
.portal-dashboard a:focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; border-radius: .15rem; }
.portal-dashboard-notice, .portal-dashboard-check {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem;
    border: 1px solid #edcf91;
    border-radius: 1rem;
    background: #fff9ec;
}
.portal-dashboard-check { border-color: var(--portal-line); background: white; }
.portal-dashboard-notice .btn, .portal-dashboard-check .btn { flex-shrink: 0; }
.portal-dashboard-document { display: flex; align-items: center; gap: .85rem; padding: 1rem 0; }
.portal-dashboard-document + .portal-dashboard-document { border-top: 1px solid var(--portal-line); }
.portal-dashboard-document > .portal-content-icon { flex: 0 0 1.4rem; }
.portal-dashboard-document-title { flex: 1; min-width: 0; }
.portal-dashboard-document-title a { text-decoration: underline; text-underline-offset: .2em; }
.portal-dashboard-document .status-pill { flex-shrink: 0; }
.portal-dashboard-empty { display: flex; gap: 1rem; align-items: center; padding: 1rem 0; }
.portal-dashboard-empty > .portal-content-icon { width: 2rem; height: 2rem; flex-shrink: 0; color: var(--portal-brand); }
.portal-dashboard { overflow-wrap: anywhere; }
@media (max-width: 1199.98px) {
    .portal-dashboard-flow { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
    .portal-dashboard-flow li { display: flex; align-items: flex-start; gap: 1rem; }
    .portal-dashboard-step-icon { flex-shrink: 0; margin-bottom: 0; }
    .portal-dashboard-flow li + li::before { content: '↓'; left: 1.1rem; top: -1.45rem; }
}
@media (max-width: 575.98px) {
    .portal-dashboard-notice, .portal-dashboard-check { flex-direction: column; align-items: flex-start; }
    .portal-dashboard-document { flex-wrap: wrap; }
    .portal-dashboard-document-title { flex-basis: calc(100% - 2.5rem); }
    .portal-dashboard-document .status-pill { margin-left: 2.25rem; }
}

/* Stato e avvisi: schede leggibili anche con titoli e riferimenti lunghi, senza tabelle da scorrere. */
.portal-monitoring { overflow-wrap: anywhere; }
.portal-monitoring-section-heading, .portal-monitoring-record-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.portal-monitoring-records { display: grid; gap: .8rem; }
.portal-monitoring-record { background: #f8f9fd; border: 1px solid var(--portal-line); border-radius: .85rem; padding: 1rem; min-width: 0; }
.portal-monitoring-record-heading h4 { flex: 1 1 15rem; min-width: 0; }
.portal-monitoring .status-pill { white-space: normal; }
.portal-monitoring-reference span { font-family: ui-monospace, monospace; }
.portal-monitoring-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem; }
.portal-monitoring-help { border-left: 3px solid var(--portal-brand); padding: .25rem 1rem; }
.portal-monitoring a:focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; }

/* Integrazioni: evidenzia lo spazio e separa il riepilogo dall'azione occasionale di sostituzione. */
.portal-integrations { overflow-wrap: anywhere; }
.portal-connection-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
.portal-connection-diagram { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 1rem; padding: 1.5rem 0; }
.portal-connection-endpoint { display: flex; align-items: center; gap: .85rem; padding: 1rem; border: 1px solid #dddafa; border-radius: .85rem; background: #f5f3ff; min-width: 0; }
.portal-connection-endpoint > .portal-content-icon { width: 2rem; height: 2rem; flex-shrink: 0; color: var(--portal-brand); }
.portal-connection-endpoint span, .portal-connection-action div span { display: block; color: var(--portal-muted); font-size: .85rem; margin-top: .25rem; }
.portal-connection-bridge { display: flex; flex-direction: column; align-items: center; gap: .3rem; font-size: .8rem; color: var(--portal-brand-dark); }
.portal-connection-bridge .portal-content-icon { width: 2.5rem; height: 1.5rem; }
.portal-connection-saved { background: #f8f9fd; border-radius: .85rem; padding: 1rem; }
.portal-connection-metadata { display: flex; flex-wrap: wrap; gap: .75rem 2rem; font-size: .85rem; }
.portal-connection-metadata > div { min-width: 0; }
.portal-connection-metadata dt { color: var(--portal-muted); font-weight: 400; }
.portal-connection-metadata dd { margin: .2rem 0 0; font-weight: 600; }
.portal-connection-editor { border: 1px solid var(--portal-line); border-radius: .85rem; }
.portal-connection-editor > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem; color: var(--portal-brand-dark); font-weight: 650; cursor: pointer; }
.portal-connection-editor > summary::-webkit-details-marker { display: none; }
.portal-connection-editor > summary .portal-content-icon { flex-shrink: 0; }
.portal-connection-editor[open] > summary { border-bottom: 1px solid var(--portal-line); }
.portal-connection-editor[open] > summary .portal-content-icon { transform: rotate(180deg); }
.portal-connection-editor-body { padding: 1rem; }
.portal-connection-steps { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .75rem; }
.portal-connection-steps li { display: flex; align-items: flex-start; gap: .75rem; }
.portal-connection-steps li > span { flex: 0 0 1.7rem; height: 1.7rem; display: grid; place-items: center; border-radius: 50%; color: var(--portal-brand-dark); background: #eeeaff; font-size: .8rem; font-weight: 700; }
.portal-connection-steps p { color: var(--portal-muted); font-size: .9rem; margin: .25rem 0 0; }
.portal-connection-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.portal-connection-action { display: flex; align-items: center; gap: .85rem; border: 1px solid var(--portal-line); border-radius: 1rem; padding: 1rem; background: white; text-decoration: none; color: var(--portal-ink); }
.portal-connection-action > .portal-content-icon { flex-shrink: 0; color: var(--portal-brand); width: 1.75rem; height: 1.75rem; }
.portal-connection-action div { flex: 1; min-width: 0; }
.portal-connection-action:hover { border-color: var(--portal-brand); }
.portal-integrations :is(a, summary):focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; }
@media (max-width: 767.98px) {
    .portal-connection-diagram, .portal-connection-actions { grid-template-columns: minmax(0, 1fr); }
    .portal-connection-bridge { flex-direction: row; justify-content: center; }
    .portal-connection-bridge .portal-content-icon { transform: rotate(90deg); }
}

/* Collaboratori: persone e azioni restano leggibili senza una tabella orizzontale. */
.portal-collaborators { overflow-wrap: anywhere; }
.portal-collaborator-list { display: grid; gap: .75rem; }
.portal-collaborator-card { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; border: 1px solid var(--portal-line); border-radius: .85rem; padding: 1rem; }
.portal-collaborator-identity { display: flex; align-items: center; gap: .8rem; flex: 1 1 16rem; min-width: 0; }
.portal-collaborator-identity > div { min-width: 0; }
.portal-collaborator-identity .portal-member-avatar { flex-shrink: 0; }
.portal-collaborator-role { flex: 0 1 12rem; }
.portal-collaborator-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.portal-collaborator-roles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.portal-collaborator-role-info { border: 1px solid var(--portal-line); border-radius: .75rem; padding: .85rem; background: #f8f9fd; min-width: 0; }
.portal-collaborator-role-info summary { cursor: pointer; color: var(--portal-brand-dark); }
.portal-collaborator-role-info li + li { margin-top: .4rem; }
.portal-collaborators .modal-title { min-width: 0; }
.portal-collaborators .modal-body { min-height: 0; }
.portal-collaborators .modal-content { max-height: 100%; }
.portal-collaborators .modal-header .btn-close { flex-shrink: 0; }
.portal-collaborators summary:focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; }
@media (max-width: 767.98px) {
    .portal-collaborator-roles { grid-template-columns: minmax(0, 1fr); }
    .portal-collaborator-actions { flex-basis: 100%; }
}

/* Limitazioni: ogni scheda lega una persona al documento e all'effetto concreto del blocco. */
.portal-access { overflow-wrap: anywhere; }
.portal-access-heading, .portal-access-record-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .85rem; }
.portal-access-diagram { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: .75rem; }
.portal-access-diagram > span:nth-child(odd) { padding: 1rem; border: 1px solid #dddafa; border-radius: .8rem; background: #f5f3ff; }
.portal-access-diagram small { display: block; color: var(--portal-muted); margin-top: .25rem; }
.portal-access-diagram > span:nth-child(even) { color: var(--portal-brand); }
.portal-access-guide > summary { cursor: pointer; color: var(--portal-brand-dark); font-weight: 600; }
.portal-access :is(summary, a):focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; }
.portal-access-effects { display: grid; gap: .75rem; }
.portal-access-effects dd { margin: .2rem 0 0; color: var(--portal-muted); }
.portal-access-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.portal-access-filters > div { min-width: 0; }
.portal-access-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.portal-access-records { display: grid; gap: 1rem; }
.portal-access-record { border: 1px solid var(--portal-line); border-radius: .85rem; padding: 1rem; min-width: 0; }
.portal-access-person { display: flex; align-items: flex-start; gap: .75rem; min-width: 0; }
.portal-access-person input { flex-shrink: 0; }
.portal-access-person small { display: block; color: var(--portal-muted); }
.portal-access .status-pill { white-space: normal; }
.portal-access-document, .portal-access-empty { display: flex; align-items: flex-start; gap: .75rem; margin: 1rem 0; }
.portal-access-document > .portal-content-icon, .portal-access-empty > .portal-content-icon { flex: 0 0 1.5rem; width: 1.5rem; height: 1.5rem; color: var(--portal-brand); }
.portal-access-confirm-list { padding-left: 1.25rem; }
.portal-access-confirm-list li + li { margin-top: .75rem; }
.portal-access .modal-body { min-height: 0; }
.portal-access .modal-content { max-height: 100%; }
.portal-access .modal-header .btn-close { flex-shrink: 0; }
@media (max-width: 991.98px) {
    .portal-access-filters { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 575.98px) {
    .portal-access-diagram { grid-template-columns: minmax(0, 1fr); gap: .35rem; }
    .portal-access-diagram > span:nth-child(even) { justify-self: center; transform: rotate(90deg); }
    .portal-access-dates { grid-template-columns: minmax(0, 1fr); }
}

/* Cronologia: sequenza temporale senza colonne rigide, leggibile anche con nomi molto lunghi. */
.portal-audit { overflow-wrap: anywhere; }
.portal-audit-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; }
.portal-audit-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.portal-audit-filters > div { min-width: 0; }
.portal-audit summary { cursor: pointer; color: var(--portal-brand-dark); }
.portal-audit :is(summary, a):focus-visible { outline: 3px solid #9690ff; outline-offset: 4px; }
.portal-audit-note { padding: .75rem 1rem; border-left: 3px solid var(--portal-brand); background: #f5f3ff; border-radius: 0 .65rem .65rem 0; }
.portal-audit-timeline { list-style: none; margin: 1.5rem 0 0; padding: 0; }
.portal-audit-entry { position: relative; margin-left: .4rem; border-left: 2px solid #dddafa; padding: 0 0 1.25rem 1.35rem; }
.portal-audit-entry::before { content: ''; position: absolute; width: .7rem; height: .7rem; left: -.4rem; top: 1.3rem; background: var(--portal-brand); border-radius: 50%; }
.portal-audit-entry:last-child { padding-bottom: 0; }
.portal-audit-entry article { padding: 1rem; border: 1px solid var(--portal-line); border-radius: .85rem; min-width: 0; }
.portal-audit .status-pill { white-space: normal; }
.portal-audit-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1.5rem; font-size: .875rem; }
.portal-audit-facts dt { color: var(--portal-muted); font-weight: 400; margin-bottom: .2rem; }
.portal-audit-facts dd { margin: 0; }
.portal-audit-reference { font-size: .85rem; }
.portal-audit-empty { display: flex; align-items: flex-start; gap: 1rem; padding: 1rem 0; }
.portal-audit-empty > .portal-content-icon { flex: 0 0 1.75rem; height: 1.75rem; color: var(--portal-brand); }
@media (max-width: 767.98px) {
    .portal-audit-filters, .portal-audit-facts { grid-template-columns: minmax(0, 1fr); }
    .portal-audit-entry { padding-left: .85rem; }
}

.portal-bot-summary { min-width: 0; }
.portal-bot-usage { min-width: 0; padding: 1rem; border: 1px solid var(--portal-line); border-radius: var(--portal-radius-md); }
.portal-bot-usage .form-select { padding-right: 2rem; }

/* Riepilogo compatto del budget condiviso nella pagina Assistenti. */
.portal-budget { background: #fff; border: 1px solid #e0e5f1; border-radius: 18px; overflow: hidden; }
.portal-budget-metrics { display: flex; flex-wrap: wrap; padding: 18px 22px; gap: 16px 24px; }
.portal-budget-metric { flex: 1; min-width: 0; }
.portal-budget-metric + .portal-budget-metric { border-left: 1px solid #e5e9f2; padding-left: 24px; }
.portal-budget-metric h3 { color: #58647c; font-size: .82rem; font-weight: 600; margin: 0 0 4px; }
.portal-budget-amount { display: block; color: #25324b; font-size: 1.4rem; line-height: 1.3; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.portal-budget-metric p { margin: 5px 0 0; color: #69758b; font-size: .78rem; line-height: 1.5; }
.portal-budget-metric p b { color: #43516a; font-weight: 600; }
.portal-budget-notice { padding: 10px 22px; background: #fff8e7; border-top: 1px solid #f2e6c8; color: #77530c; font-size: .82rem; line-height: 1.55; }
.portal-budget-help { padding: 9px 22px; border-top: 1px solid #edf0f6; color: #67738a; font-size: .78rem; }
.portal-budget-help summary { cursor: pointer; width: fit-content; color: #526078; font-weight: 600; }
.portal-budget-help summary:focus-visible { outline: 2px solid #6552e8; outline-offset: 4px; border-radius: 2px; }
.portal-budget-help > div { padding-top: 10px; max-width: 90ch; line-height: 1.6; }
.portal-budget-help p { margin: 0 0 8px; }
@media (max-width: 575.98px) {
    .portal-budget-metrics { flex-direction: column; padding: 16px; gap: 14px; }
    .portal-budget-metric + .portal-budget-metric { border-left: 0; border-top: 1px solid #e5e9f2; padding: 14px 0 0; }
    .portal-budget-notice { padding: 10px 16px; }
    .portal-budget-help { padding: 9px 16px; }
}
