:root {
    --af-bg: #f0f4f9;
    --af-surface: #ffffff;
    --af-border: #d8e0eb;
    --af-text: #1a2332;
    --af-muted: #5c6b7f;
    --af-accent: #2563eb;
    --af-accent-dim: #1d4ed8;
    --af-danger: #dc2626;
    --af-shadow: 0 1px 3px rgba(26, 35, 50, 0.06);
    --af-shadow-md: 0 4px 14px rgba(26, 35, 50, 0.08);
}

* {
    box-sizing: border-box;
}

body.af-body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", system-ui, sans-serif;
    background:
        radial-gradient(1000px 520px at 8% -8%, rgba(37, 99, 235, 0.08) 0%, transparent 55%),
        radial-gradient(800px 480px at 100% 0%, rgba(99, 102, 241, 0.07) 0%, transparent 50%),
        var(--af-bg);
    color: var(--af-text);
}

.af-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 3rem;
}

.af-app {
    display: grid;
    grid-template-columns: minmax(200px, 240px) 1fr;
    gap: clamp(0.75rem, 1.5vw, 1.25rem);
    align-items: start;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 1.25rem clamp(0.65rem, 1.25vw, 1.25rem) 3rem;
    min-height: 100vh;
}

@media (max-width: 900px) {
    .af-app {
        grid-template-columns: 1fr;
    }

    .af-aside {
        position: static;
        min-height: 0;
        max-height: none;
    }

    .af-aside-toolbar {
        display: none;
    }
}

.af-aside {
    position: sticky;
    top: 1rem;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 2rem);
    max-height: calc(100vh - 2rem);
    border: 1px solid var(--af-border);
    border-radius: 12px;
    background: var(--af-surface);
    padding: 1rem 0.85rem;
    box-shadow: var(--af-shadow);
}

.af-aside-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.af-aside-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: -0.15rem 0 0.5rem;
}

.af-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: 0.35rem;
}

.af-sidebar-toggle-chevron {
    display: block;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.af-app--sidebar-collapsed .af-sidebar-toggle-chevron {
    transform: rotate(180deg);
}

.af-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (min-width: 901px) {
    .af-app--sidebar-collapsed {
        grid-template-columns: 3.5rem 1fr;
    }

    .af-app--sidebar-collapsed .af-aside {
        padding: 0.65rem 0.4rem;
    }

    .af-app--sidebar-collapsed .af-aside-toolbar {
        justify-content: center;
        margin-bottom: 0.35rem;
    }

    .af-app--sidebar-collapsed .af-aside-nav {
        display: none;
    }

    .af-app--sidebar-collapsed .af-aside-footer .af-topbar-branding {
        display: none;
    }

    .af-app--sidebar-collapsed .af-aside-footer .af-topbar-actions > span,
    .af-app--sidebar-collapsed .af-aside-footer .af-topbar-actions > .af-muted-small {
        display: none;
    }

    .af-app--sidebar-collapsed .af-aside-footer {
        margin-top: 0.35rem;
        padding-top: 0.5rem;
        border-top: none;
    }

    .af-app--sidebar-collapsed .af-aside-footer .af-topbar-actions {
        align-items: stretch;
    }

    .af-app--sidebar-collapsed .af-aside-footer .af-btn {
        font-size: 0.72rem;
        padding: 0.3rem 0.35rem;
    }
}

.af-aside-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--af-muted);
    margin: 0.75rem 0.5rem 0.35rem;
    font-weight: 600;
}

.af-aside-nav > .af-aside-title:first-child {
    margin-top: 0;
}

.af-nav-link {
    display: block;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    color: var(--af-text);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
}

.af-nav-link:hover {
    background: rgba(37, 99, 235, 0.08);
    color: var(--af-accent-dim);
}

.af-nav-link.is-active {
    background: rgba(37, 99, 235, 0.12);
    color: var(--af-accent-dim);
    font-weight: 600;
}

.af-main {
    min-width: 0;
}

.af-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.af-btn--danger {
    border-color: rgba(220, 38, 38, 0.35);
    color: #b91c1c;
    background: rgba(254, 226, 226, 0.9);
}

.af-btn--danger:hover {
    background: rgba(254, 202, 202, 0.95);
}

.af-muted-small {
    font-size: 0.82rem;
    color: var(--af-muted);
}

.af-topbar-branding {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    min-width: 0;
}

.af-logo-link {
    text-decoration: none;
    flex-shrink: 0;
}

.af-logo-frame {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: 0;
    box-shadow: none;
}

.af-logo-frame--compact {
    padding: 0;
}

.af-logo-img {
    display: block;
    height: auto;
    max-height: 40px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.af-logo-img--hero {
    max-height: none;
    max-width: min(100%, 300px);
    margin: 0 auto;
}

.af-logo-hero-wrap {
    display: block;
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: 0;
    box-shadow: none;
}

.af-logo-hero-wrap .af-logo-img--hero {
    max-width: 100%;
}

.af-brand-block {
    min-width: 0;
}

.af-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--af-border);
    margin-bottom: 1.5rem;
}

.af-brand {
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: 1.05rem;
    color: var(--af-text);
}

.af-brand span {
    color: var(--af-muted);
    font-weight: 500;
}

.af-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--af-muted);
}

.af-topbar--aside {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-bottom: none;
    margin: 0;
    padding: 0;
    gap: 0.65rem;
}

.af-aside-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--af-border);
}

.af-aside-footer .af-topbar-branding {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
}

.af-aside-footer .af-logo-img {
    max-height: 38px;
    width: auto;
    max-width: min(200px, 100%);
}

.af-aside-footer .af-brand {
    font-size: 0.92rem;
    line-height: 1.3;
}

.af-aside-footer .af-brand span {
    display: block;
    margin-top: 0.08rem;
    font-size: 0.88em;
}

.af-aside-footer .af-topbar-actions {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
    gap: 0.45rem;
}

.af-aside-footer .af-topbar-actions form {
    width: 100%;
}

.af-aside-footer .af-topbar-actions .af-btn {
    width: 100%;
}

.af-card {
    background: var(--af-surface);
    border: 1px solid var(--af-border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: var(--af-shadow);
}

.af-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(37, 99, 235, 0.22);
    background: rgba(37, 99, 235, 0.08);
    color: var(--af-text);
    font-size: 0.85rem;
    line-height: 1.25;
    white-space: nowrap;
}

.af-card h1 {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    color: var(--af-text);
}

.af-sub {
    margin: 0 0 1rem;
    color: var(--af-muted);
    font-size: 0.95rem;
}

.af-table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid var(--af-border);
    background: var(--af-surface);
}

table.af-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

table.af-table th,
table.af-table td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--af-border);
}

table.af-table th {
    color: var(--af-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #f8fafc;
}

table.af-table tr:last-child td {
    border-bottom: none;
}

table.af-table tbody tr:hover td {
    background: rgba(37, 99, 235, 0.04);
}

.af-link {
    color: var(--af-accent);
    text-decoration: none;
    font-weight: 500;
}

.af-link:hover {
    text-decoration: underline;
    color: var(--af-accent-dim);
}

.af-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    border: 1px solid var(--af-border);
    background: #f8fafc;
    color: var(--af-text);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
}

.af-btn:hover {
    background: #eef2f7;
    border-color: #c5d0e0;
}

.af-btn--primary {
    background: linear-gradient(180deg, var(--af-accent), var(--af-accent-dim));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.af-btn--primary:hover {
    filter: brightness(1.05);
    color: #fff;
}

.af-btn--ghost {
    background: transparent;
}

.af-btn--ghost:hover {
    background: rgba(37, 99, 235, 0.06);
}

.af-btn--disabled,
.af-btn--disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    background: transparent;
}

.af-indicizza-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--af-border);
}

.af-sessioni-filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem 1.25rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--af-border);
    align-items: end;
}

.af-sessioni-filters__field {
    margin-bottom: 0;
}

.af-sessioni-filters__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding-bottom: 0.2rem;
}

.af-sessioni-gruppo {
    margin-top: 1.25rem;
}

.af-sessioni-gruppo:first-of-type {
    margin-top: 1rem;
}

.af-sessioni-gruppo__titolo {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--af-text);
}

.af-sessioni-gruppo__meta {
    margin: 0 0 0.5rem;
    font-size: 0.78rem;
    color: var(--af-muted);
    line-height: 1.35;
}

.af-select--wide,
.af-input--wide {
    max-width: 100%;
}

.af-form-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.af-form-row label {
    font-size: 0.85rem;
    color: var(--af-muted);
    font-weight: 500;
}

.af-input,
.af-select {
    width: 100%;
    max-width: 420px;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--af-border);
    background: #fff;
    color: var(--af-text);
    box-shadow: inset 0 1px 2px rgba(26, 35, 50, 0.04);
}

.af-input:focus,
.af-select:focus {
    outline: none;
    border-color: var(--af-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.af-textarea {
    width: 100%;
    max-width: 100%;
    min-height: 6rem;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--af-border);
    background: #fff;
    color: var(--af-text);
    box-shadow: inset 0 1px 2px rgba(26, 35, 50, 0.04);
    font: inherit;
    resize: vertical;
}

.af-textarea:focus {
    outline: none;
    border-color: var(--af-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.af-readonly-box {
    width: 100%;
    max-width: 420px;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px dashed var(--af-border);
    background: rgba(248, 250, 252, 0.9);
    color: var(--af-text);
    font-size: 0.95rem;
}

.af-error {
    color: var(--af-danger);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.af-flash {
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.af-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.af-badge--gray {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.af-badge--yellow {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
}

.af-badge--green {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.af-badge--blue {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.af-badge--violet {
    background: #ede9fe;
    color: #5b21b6;
    border: 1px solid #c4b5fd;
}

.af-split {
    display: grid;
    /* PDF: tutto lo spazio residuo · Metadati: più larghi su monitor grandi (prima max 380px) */
    grid-template-columns: 1fr minmax(280px, min(480px, 34vw));
    gap: clamp(0.65rem, 1vw, 1.1rem);
    min-height: calc(100vh - 88px);
}

@media (max-width: 960px) {
    .af-split {
        grid-template-columns: 1fr;
        min-height: auto;
    }
}

.af-preview {
    border: 1px solid var(--af-border);
    border-radius: 12px;
    overflow: hidden;
    background: #e8ecf2;
    min-height: 600px;
    box-shadow: var(--af-shadow);
}

.af-preview iframe {
    width: 100%;
    height: 80vh;
    min-height: 540px;
    border: none;
    background: #fff;
}

.af-doc-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--af-border);
    background: #f8fafc;
}

.af-doc-tab {
    font-size: 0.8rem;
    padding: 0.25rem 0.55rem;
    border-radius: 6px;
    border: 1px solid transparent;
    color: var(--af-muted);
    cursor: pointer;
    background: transparent;
}

.af-doc-tab:hover {
    color: var(--af-text);
    background: rgba(37, 99, 235, 0.06);
}

.af-doc-tab.is-active {
    border-color: var(--af-border);
    color: var(--af-accent-dim);
    background: #fff;
    font-weight: 600;
    box-shadow: var(--af-shadow);
}

/* Indicizzazione pratica — UX */
.af-indicizza-session {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1.25rem;
    margin-top: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.06);
    border: 1px solid rgba(37, 99, 235, 0.12);
    font-size: 0.88rem;
}

.af-indicizza-session-meta {
    color: var(--af-muted);
    flex: 1 1 200px;
}

.af-indicizza-session-meta strong {
    color: var(--af-text);
}

.af-progress-wrap {
    flex: 2 1 220px;
    min-width: 160px;
}

.af-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--af-muted);
    margin-bottom: 0.25rem;
}

.af-progress-track {
    height: 8px;
    border-radius: 999px;
    background: rgba(26, 35, 50, 0.08);
    overflow: hidden;
}

.af-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--af-accent), #6366f1);
    transition: width 0.25s ease;
}

.af-error-summary {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(220, 38, 38, 0.35);
    background: rgba(254, 226, 226, 0.45);
    color: #7f1d1d;
    font-size: 0.9rem;
}

.af-error-summary ul {
    margin: 0.5rem 0 0;
    padding-left: 1.15rem;
}

.af-error-summary a {
    color: var(--af-accent-dim);
    font-weight: 600;
}

.af-draft-banner {
    margin: 0 0 1rem;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--af-border);
    background: #fffbeb;
    color: #713f12;
    font-size: 0.88rem;
    display: none;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.af-draft-banner.is-visible {
    display: flex;
}

.af-tipologia-hint {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    color: var(--af-muted);
}

.af-tipologia-hint.is-warning {
    color: #b45309;
    font-weight: 600;
}

.af-pdf-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.af-pdf-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.45rem 0.65rem;
    border-bottom: 1px solid var(--af-border);
    background: #f1f5f9;
}

.af-pdf-toolbar-spacer {
    flex: 1;
}

.af-pdf-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

@media (max-width: 960px) {
    .af-pdf-body {
        flex-direction: column;
    }

    .af-doc-list-vertical {
        max-height: 140px;
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--af-border);
    }
}

.af-doc-list-vertical {
    width: 200px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid var(--af-border);
    background: #f8fafc;
    padding: 0.35rem;
}

.af-doc-list-vertical .af-doc-tab {
    display: block;
    width: 100%;
    text-align: left;
    margin-bottom: 0.25rem;
    white-space: normal;
}

.af-doc-list-vertical .af-doc-tab .af-doc-tab-num {
    font-weight: 700;
    color: var(--af-accent-dim);
}

.af-pdf-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.af-pdf-main .af-preview {
    flex: 1;
    min-height: 680px;
}

.af-pdf-main .af-preview iframe {
    height: 86vh;
    min-height: 600px;
}

.af-pdf-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
}

.af-pdf-viewport.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: #0f172a;
    display: flex;
    flex-direction: column;
}

.af-pdf-viewport.is-fullscreen .af-preview {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
}

.af-pdf-viewport.is-fullscreen .af-preview iframe {
    height: calc(100vh - 0px);
    min-height: 0;
}

.af-split--pratica-edit,
.af-split--admin-edit {
    grid-template-columns: minmax(300px, 560px) 1fr;
    align-items: start;
    min-height: calc(100vh - 140px);
}

@media (max-width: 1100px) {
    .af-split--pratica-edit,
    .af-split--admin-edit {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .af-split--pratica-edit .af-pdf-column,
    .af-split--admin-edit .af-pdf-column {
        position: static !important;
    }
}

.af-split--meta-collapsed {
    grid-template-columns: 1fr;
}

.af-split--meta-collapsed .af-indicizza-meta {
    display: none;
}

.af-split--meta-collapsed .af-toggle-meta-floating {
    display: inline-flex;
}

.af-toggle-meta-floating {
    display: none;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 2;
}

.af-indicizza-meta {
    position: relative;
}

.af-meta-collapse-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

.af-indicizza-sticky {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 400;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.65rem;
    padding: 0.65rem 1.25rem;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--af-border);
    box-shadow: 0 -6px 24px rgba(26, 35, 50, 0.1);
    backdrop-filter: blur(8px);
}

.af-indicizza-sticky-hint {
    margin-right: auto;
    font-size: 0.78rem;
    color: var(--af-muted);
}

.af-indicizza-root {
    /* Spazio sotto il contenuto scrollabile: barra sticky + card footer (titolo/nav/sessione) in fondo pagina */
    padding-bottom: 6.5rem;
}

.af-kbd {
    display: inline-block;
    padding: 0.08rem 0.35rem;
    border-radius: 4px;
    border: 1px solid var(--af-border);
    background: #f1f5f9;
    font-size: 0.72rem;
    font-family: ui-monospace, monospace;
}

/* Laravel paginator (default/simple-default templates) */
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.pagination li {
    margin: 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.65rem;
    border: 1px solid var(--af-border);
    border-radius: 8px;
    background: #fff;
    color: var(--af-text);
    font-size: 0.9rem;
    line-height: 1;
    text-decoration: none;
}

.pagination a:hover {
    background: #eef2f7;
    border-color: #c5d0e0;
}

.pagination li.active span {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.35);
    color: var(--af-accent-dim);
    font-weight: 600;
}

.pagination li.disabled span {
    opacity: 0.55;
    cursor: not-allowed;
}

.af-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.af-login-card {
    width: 100%;
    max-width: 400px;
    box-shadow: var(--af-shadow-md);
}
