/* UI refresh 2026 - base, header, layout, utilities */
:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-strong: #eef4ff;
    --text: #172033;
    --muted: #667085;
    --border: #dbe4f0;
    --primary: #1158d8;
    --primary-dark: #0b3f9e;
    --primary-soft: #e8f0ff;
    --success: #18864b;
    --success-soft: #dcfce7;
    --warning: #b76e00;
    --warning-soft: #fff4d6;
    --danger: #c92a2a;
    --danger-soft: #ffe3e3;
    --info: #087f9b;
    --info-soft: #dff7fb;
    --shadow-sm: 0 4px 12px rgba(23, 32, 51, 0.06);
    --shadow-md: 0 12px 35px rgba(23, 32, 51, 0.12);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --header-height: 72px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(17, 88, 216, 0.12), transparent 28rem),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 44%, #edf2f9 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.55;
}

body.nav-open {
    overflow: hidden;
}

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

a:hover {
    color: var(--primary-dark);
}

button,
input,
select,
textarea {
    font: inherit;
}

img,
svg {
    max-width: 100%;
}

.container,
.table-container,
.form-container,
.card-container,
.dashboard-container {
    width: min(100% - 32px, 1280px);
    margin: 24px auto;
}

.container {
    padding: clamp(18px, 3vw, 32px);
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(219, 228, 240, 0.9);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    flex-grow: 1;
}

h1,
h2,
h3 {
    color: var(--text);
    letter-spacing: -0.025em;
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.45rem, 2.4vw, 2rem);
}

p {
    color: var(--muted);
}

.main-header {
    min-height: var(--header-height);
    background: rgba(255, 255, 255, 0.88);
    color: var(--text);
    padding: 10px clamp(14px, 3vw, 28px);
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 18px;
    align-items: center;
    border-bottom: 1px solid rgba(219, 228, 240, 0.9);
    box-shadow: 0 10px 30px rgba(23, 32, 51, 0.07);
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(14px);
}

.brand-area {
    min-width: 0;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    text-decoration: none;
    min-width: 0;
}

.brand-link:hover {
    color: var(--text);
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #19a7ce);
    color: #fff;
    font-weight: 800;
    font-size: 0.92rem;
    box-shadow: 0 12px 24px rgba(17, 88, 216, 0.24);
}

.brand-text {
    display: grid;
    min-width: 0;
}

.brand-title {
    font-size: clamp(1rem, 1.8vw, 1.18rem);
    font-weight: 800;
    white-space: nowrap;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.main-nav {
    justify-self: center;
    min-width: 0;
}

.main-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    margin: 0;
    flex-wrap: wrap;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    color: #3b475c;
    text-decoration: none;
    font-size: 0.94rem;
    font-weight: 700;
    padding: 9px 12px;
    border-radius: 999px;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.main-nav a:hover,
.main-nav a.active {
    color: var(--primary);
    background: var(--primary-soft);
}

.main-nav a:hover {
    transform: translateY(-1px);
}

.mobile-nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    padding: 10px;
    box-shadow: var(--shadow-sm);
}

.mobile-nav-toggle .icon-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    margin: 5px auto;
    border-radius: 999px;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.mobile-nav-toggle.is-active .icon-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.mobile-nav-toggle.is-active .icon-bar:nth-child(2) {
    opacity: 0;
}
.mobile-nav-toggle.is-active .icon-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.user-menu {
    position: relative;
    justify-self: end;
    user-select: none;
}

.user-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px 10px 6px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.user-menu-toggle:hover,
.user-menu-toggle.active {
    transform: translateY(-1px);
    border-color: rgba(17, 88, 216, 0.35);
    box-shadow: 0 10px 24px rgba(17, 88, 216, 0.12);
}

.user-avatar {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 900;
}

.user-label {
    max-width: 160px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 750;
}

.user-menu-toggle .arrow {
    color: var(--muted);
    font-size: 0.7em;
    transition: transform 0.2s ease;
}

.user-menu-toggle.active .arrow {
    transform: rotate(180deg);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 220px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    z-index: 1100;
}

.user-menu-dropdown a {
    display: block;
    padding: 13px 15px;
    color: var(--text);
    text-decoration: none;
    font-weight: 650;
    border-bottom: 1px solid var(--border);
}

.user-menu-dropdown a:last-child {
    border-bottom: 0;
}

.user-menu-dropdown a:hover {
    background: var(--surface-soft);
}

.user-menu-dropdown .logout-link {
    color: var(--danger);
    background: var(--danger-soft);
}

.mobile-nav-backdrop {
    position: fixed;
    inset: var(--header-height) 0 0;
    z-index: 900;
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(2px);
}

.main-footer {
    margin-top: auto;
    padding: 22px 16px;
    color: #e7ecf4;
    text-align: center;
    background: #101828;
}

.main-footer p {
    color: #e7ecf4;
    margin: 0;
}

.message,
.error-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 15px;
    margin: 0 0 18px;
    border-radius: 14px;
    font-weight: 700;
    border: 1px solid transparent;
}

.message.success,
.error-banner.success {
    color: #065f35;
    background: var(--success-soft);
    border-color: #a7f3c5;
}

.message.error,
.error-banner {
    color: #8a1f1f;
    background: var(--danger-soft);
    border-color: #ffc9c9;
}

.message.warning {
    color: #7a4b00;
    background: var(--warning-soft);
    border-color: #ffe0a3;
}

.message.info {
    color: #075b70;
    background: var(--info-soft);
    border-color: #b8edf6;
}

.hidden {
    display: none !important;
}

.inline-form {
    display: inline-flex;
    margin: 0;
    padding: 0;
}

.inline-form button.btn,
.action-buttons button[type="submit"] {
    width: auto;
    border: 0;
    cursor: pointer;
    font: inherit;
    line-height: normal;
}

.btn,
.add-button,
.export-button,
.back-button,
.print-button,
.submit-button,
.btn-download-report,
.back-link,
button[type="submit"],
#resetFiltersBtn,
.reset-btn {
    touch-action: manipulation;
}

:focus-visible {
    outline: 3px solid rgba(17, 88, 216, 0.35);
    outline-offset: 3px;
}

@media (max-width: 1180px) {
    .main-header {
        grid-template-columns: auto auto auto;
    }

    .mobile-nav-toggle {
        display: inline-block;
        justify-self: end;
        order: 2;
    }

    .user-menu {
        order: 3;
    }

    .main-nav {
        position: fixed;
        top: var(--header-height);
        right: 0;
        bottom: 0;
        width: min(88vw, 380px);
        padding: 18px;
        background: rgba(255, 255, 255, 0.98);
        border-left: 1px solid var(--border);
        box-shadow: -18px 0 40px rgba(15, 23, 42, 0.16);
        transform: translateX(105%);
        transition: transform 0.25s ease;
        z-index: 1000;
        overflow-y: auto;
    }

    .main-nav.is-active {
        transform: translateX(0);
    }

    .main-nav ul {
        display: grid;
        gap: 8px;
        justify-content: stretch;
    }

    .main-nav a {
        width: 100%;
        justify-content: flex-start;
        border-radius: 14px;
        padding: 14px 16px;
        background: var(--surface-soft);
    }
}

@media (max-width: 700px) {
    :root {
        --header-height: 66px;
    }

    .main-header {
        padding: 8px 12px;
        gap: 8px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        font-size: 0.82rem;
    }

    .brand-title {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand-subtitle,
    .user-label {
        display: none;
    }

    .user-menu-toggle {
        padding: 5px;
        min-width: 44px;
        justify-content: center;
    }

    .user-menu-toggle .arrow {
        display: none;
    }

    .user-menu-dropdown {
        right: -4px;
        width: min(260px, 90vw);
    }

    .container,
    .table-container,
    .form-container,
    .card-container,
    .dashboard-container {
        width: min(100% - 18px, 1280px);
        margin: 12px auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}


/* Impersonificazione utenti */
.impersonation-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 22px;
    background: #fff7ed;
    color: #7c2d12;
    border-bottom: 1px solid #fed7aa;
    box-shadow: 0 2px 10px rgba(124, 45, 18, 0.08);
    position: sticky;
    top: 72px;
    z-index: 850;
}
.impersonation-banner strong { display: block; font-size: 0.95rem; }
.impersonation-banner span { display: inline-block; margin-right: 8px; }
.impersonation-meta { color: #9a3412; font-size: 0.9rem; }
.btn-warning,
button.btn-warning {
    background: #f97316;
    color: #fff;
    border: 0;
}
.btn-warning:hover,
button.btn-warning:hover { background: #ea580c; }
.muted-text { color: #667085; }
@media (max-width: 760px) {
    .impersonation-banner {
        align-items: flex-start;
        flex-direction: column;
        top: 64px;
        padding: 12px 16px;
    }
    .impersonation-banner .inline-form { width: 100%; }
    .impersonation-banner button { width: 100%; }
}
