/* =========================================================================
   MEF Audit App — Design System
   Palette istituzionale, tipografia Titillium Web, componenti riusabili.
   ========================================================================= */

/* ---------- Design tokens ---------- */
:root {
    /* Primary (Accenture blue) */
    --primary-50:  #e6f0fa;
    --primary-100: #cce0f5;
    --primary-200: #99c2eb;
    --primary-500: #1a75d1;
    --primary-600: #0066cc;
    --primary-700: #004d99;
    --primary-800: #003366;

    /* Neutrali */
    --gray-50:  #f7f8fa;
    --gray-100: #eef0f3;
    --gray-200: #e1e5eb;
    --gray-300: #cbd2db;
    --gray-400: #9ba3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #0f172a;

    /* Semantici */
    --success-50:  #e8f5e9;
    --success-600: #2e7d32;
    --warning-50:  #fff4e5;
    --warning-600: #ed6c02;
    --danger-50:   #fdecea;
    --danger-600:  #c62828;
    --info-50:     #e1f5fe;
    --info-600:    #0277bd;

    /* Superfici */
    --surface:    #ffffff;
    --background: #f5f7fa;

    /* Spaziature */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    /* Raggi */
    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;

    /* Ombre */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.10);

    /* Tipografia */
    --font-sans: "Titillium Web", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --line-tight:  1.25;
    --line-normal: 1.5;
    --line-relaxed: 1.65;

    /* Layout */
    --navbar-height: 72px;
    --transition: 150ms ease;
}

/* ---------- Reset / base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: var(--line-relaxed);
    color: var(--gray-800);
    background-color: var(--background);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 600;
    line-height: var(--line-tight);
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

a { color: var(--primary-600); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-700); text-decoration: underline; }

main { flex: 1; }

/* Focus visibile coerente */
:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Riduzione movimento */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Bootstrap overrides ---------- */
.btn {
    font-weight: 600;
    border-radius: var(--radius);
    padding: 0.5rem 1.125rem;
    transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }

.btn-primary {
    background-color: var(--primary-600);
    border-color: var(--primary-600);
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-700);
    border-color: var(--primary-700);
}
.btn-primary:active,
.btn-primary:focus-visible {
    background-color: var(--primary-800) !important;
    border-color: var(--primary-800) !important;
}

.btn-outline-primary {
    color: var(--primary-600);
    border-color: var(--primary-600);
    background-color: transparent;
}
.btn-outline-primary:hover {
    background-color: var(--primary-50);
    color: var(--primary-700);
    border-color: var(--primary-700);
}

.btn-danger {
    background-color: var(--danger-600);
    border-color: var(--danger-600);
}
.btn-outline-danger {
    color: var(--danger-600);
    border-color: var(--gray-300);
    background-color: transparent;
}
.btn-outline-danger:hover {
    background-color: var(--danger-50);
    border-color: var(--danger-600);
    color: var(--danger-600);
}

.form-control,
.form-select {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.9375rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus,
.form-select:focus {
    border-color: var(--primary-600);
    box-shadow: 0 0 0 3px var(--primary-50);
}
.form-label {
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
    font-size: 0.9375rem;
}

/* ---------- Navbar ---------- */
.app-navbar {
    background-color: var(--surface);
    border-bottom: 1px solid var(--gray-200);
    box-shadow: none;
    padding: 0;
    min-height: var(--navbar-height);
}
.app-navbar .container {
    min-height: var(--navbar-height);
}
.app-navbar .navbar-brand {
    padding: 0;
    margin-right: var(--space-6);
    display: inline-flex;
    align-items: center;
    gap: 0;
    text-decoration: none !important;
}
.app-navbar .navbar-brand img {
    height: 28px;
    width: auto;
    max-width: 136px;
    object-fit: contain;
    object-position: left center;
    display: block;
    flex-shrink: 0;
}
.app-navbar .brand-sep {
    display: inline-block;
    width: 1px;
    height: 22px;
    background-color: var(--gray-300);
    margin: 0 0.9375rem;
    flex-shrink: 0;
    align-self: center;
}
.app-navbar .brand-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-800);
    letter-spacing: -0.015em;
    white-space: nowrap;
    line-height: 1;
}
.app-navbar .nav-link {
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.9375rem;
    padding: 0.5rem 0.875rem !important;
    border-radius: var(--radius-sm);
    position: relative;
    transition: color var(--transition);
    text-decoration: none !important;   /* annulla underline globale e Bootstrap */
}
.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    color: var(--primary-700);
    text-decoration: none !important;
}
.app-navbar .nav-link.active {
    color: var(--primary-700);
}
.app-navbar .nav-link.active::after {
    content: "";
    position: absolute;
    left: 0.875rem;
    right: 0.875rem;
    bottom: -1px;
    height: 2px;
    background-color: var(--primary-600);
    border-radius: 2px;
}
.app-navbar .dropdown-toggle::after { margin-left: 0.25rem; }
.app-navbar .dropdown-menu {
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius);
    padding: 0.375rem;
}
.app-navbar .dropdown-item {
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.9375rem;
}
.app-navbar .dropdown-item:hover {
    background-color: var(--primary-50);
    color: var(--primary-700);
}
.app-navbar .user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gray-700);
}
.app-navbar .user-chip .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary-50);
    color: var(--primary-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8125rem;
    text-transform: uppercase;
}

/* ---------- Footer ---------- */
.app-footer {
    background-color: var(--surface);
    border-top: 1px solid var(--gray-200);
    color: var(--gray-600);
    font-size: 0.875rem;
    padding: var(--space-5) 0;
    margin-top: var(--space-7);
}
.app-footer__row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    justify-content: space-between;
    align-items: center;
}
.app-footer__links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    list-style: none;
    margin: 0;
    padding: 0;
}
.app-footer__links a {
    color: var(--gray-600);
}
.app-footer__links a:hover {
    color: var(--primary-700);
}

/* ---------- Page header ---------- */
.app-page-header {
    margin-bottom: var(--space-6);
}
.app-page-header__breadcrumb {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-bottom: var(--space-2);
}
.app-page-header__breadcrumb a { color: var(--gray-600); }
.app-page-header__breadcrumb .separator {
    margin: 0 0.375rem;
    color: var(--gray-400);
}
.app-page-header h1 {
    margin: 0;
    font-size: 1.75rem;
}
.app-page-header__subtitle {
    margin-top: var(--space-2);
    color: var(--gray-600);
    font-size: 1rem;
}
.app-page-header__meta {
    margin-top: var(--space-3);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

/* Chip */
.app-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background-color: var(--gray-100);
    color: var(--gray-700);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
}
.app-chip i { color: var(--gray-500); }
.app-chip--primary {
    background-color: var(--primary-50);
    color: var(--primary-700);
}
.app-chip--primary i { color: var(--primary-600); }

/* ---------- Card ---------- */
.app-card {
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
    overflow: hidden;
}
.app-card__body { padding: var(--space-5); }
.app-card__footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--gray-100);
    background-color: var(--gray-50);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
}
.app-card__title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 0 0 var(--space-2) 0;
    color: var(--gray-900);
}
.app-card__subtitle {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin: 0;
}
.app-card__meta {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-3);
}
.app-card__meta-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}
.app-card__meta-row i {
    color: var(--gray-400);
    width: 14px;
}
.app-card__meta-row strong {
    color: var(--gray-800);
    font-weight: 600;
}

/* Action card (index page) */
.app-card--action {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
    position: relative;
}
.app-card--action:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
    color: inherit;
}
.app-card--action .app-card__body {
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    flex: 1;
}
.app-card--action .icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background-color: var(--primary-50);
    color: var(--primary-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: var(--space-2);
}
.app-card--action h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    color: var(--gray-900);
}
.app-card--action p {
    color: var(--gray-600);
    font-size: 0.9375rem;
    margin: 0;
    flex: 1;
}
.app-card--action .arrow {
    color: var(--primary-600);
    font-size: 0.875rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: var(--space-3);
}
.app-card--action:hover .arrow i {
    transform: translateX(2px);
    transition: transform var(--transition);
}

/* Project card */
.app-card--project { display: flex; flex-direction: column; height: 100%; }
.app-card--project .app-card__body { flex: 1; }

/* ---------- Empty state ---------- */
.app-empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    background-color: var(--surface);
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-lg);
}
.app-empty-state__icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--primary-50);
    color: var(--primary-600);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: var(--space-4);
}
.app-empty-state h2 {
    font-size: 1.25rem;
    margin: 0 0 var(--space-2) 0;
}
.app-empty-state p {
    color: var(--gray-600);
    margin: 0 auto var(--space-5);
    max-width: 480px;
}

/* ---------- Flash messages ---------- */
.app-flash-container {
    margin-top: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.app-flash {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border: 1px solid;
    font-size: 0.9375rem;
}
.app-flash__icon { flex-shrink: 0; padding-top: 2px; }
.app-flash__body { flex: 1; }
.app-flash__close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.6;
    padding: 0;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
}
.app-flash__close:hover { opacity: 1; }

.app-flash--success { background-color: var(--success-50); color: var(--success-600); border-color: rgba(46, 125, 50, 0.2); }
.app-flash--warning { background-color: var(--warning-50); color: var(--warning-600); border-color: rgba(237, 108, 2, 0.2); }
.app-flash--danger,
.app-flash--error   { background-color: var(--danger-50);  color: var(--danger-600);  border-color: rgba(198, 40, 40, 0.2); }
.app-flash--info,
.app-flash--message { background-color: var(--info-50);    color: var(--info-600);    border-color: rgba(2, 119, 189, 0.2); }

/* ---------- Forms ---------- */
.app-form-section {
    padding: var(--space-5);
    border-bottom: 1px solid var(--gray-100);
}
.app-form-section:last-child { border-bottom: none; }
.app-form-section__title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 var(--space-1) 0;
}
.app-form-section__hint {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin: 0 0 var(--space-4) 0;
}
.app-form-helper {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 0.375rem;
}
.app-form-actions {
    padding: var(--space-4) var(--space-5);
    background-color: var(--gray-50);
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* File input dropzone */
.app-file-input {
    border: 1.5px dashed var(--gray-300);
    border-radius: var(--radius);
    background-color: var(--gray-50);
    padding: var(--space-5);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background-color var(--transition);
    position: relative;
}
.app-file-input:hover,
.app-file-input.is-dragover {
    border-color: var(--primary-600);
    background-color: var(--primary-50);
}
.app-file-input input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.app-file-input__icon {
    font-size: 1.5rem;
    color: var(--primary-600);
    margin-bottom: var(--space-2);
}
.app-file-input__label {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.25rem;
}
.app-file-input__hint {
    font-size: 0.8125rem;
    color: var(--gray-500);
}
.app-file-list {
    list-style: none;
    padding: 0;
    margin: var(--space-3) 0 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.app-file-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--gray-700);
}
.app-file-list li i { color: var(--danger-600); }
.app-file-list__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-file-list__size { color: var(--gray-500); font-size: 0.8125rem; }

/* Loading overlay */
.app-loading {
    display: none;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background-color: var(--primary-50);
    border-radius: var(--radius);
    color: var(--primary-700);
    font-weight: 600;
    margin-top: var(--space-4);
}
.app-loading.is-visible { display: flex; }
.app-loading .spinner-border {
    width: 1.25rem;
    height: 1.25rem;
    border-width: 2px;
}

/* ---------- Login ---------- */
.app-auth {
    min-height: calc(100vh - var(--navbar-height) - 100px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5) 0;
}
.app-auth__card {
    width: 100%;
    max-width: 420px;
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-6);
}
.app-auth__header { text-align: center; margin-bottom: var(--space-5); }
.app-auth__logo { height: 44px; margin-bottom: var(--space-4); }
.app-auth__title { font-size: 1.5rem; margin: 0 0 var(--space-1) 0; }
.app-auth__subtitle { color: var(--gray-600); font-size: 0.9375rem; margin: 0; }

/* ---------- Search bar ---------- */
.app-search {
    position: relative;
    max-width: 360px;
}
.app-search input {
    padding-left: 2.25rem;
}
.app-search i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}

/* ---------- Tables ---------- */
.app-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}
.app-table th {
    background-color: var(--gray-50);
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}
.app-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
    font-size: 0.9375rem;
    color: var(--gray-800);
}
.app-table tbody tr:last-child td { border-bottom: none; }
.app-table tbody tr:hover td { background-color: var(--gray-50); }

.app-table--scroll {
    max-height: 480px;
    overflow: auto;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background-color: var(--surface);
}
.app-table--scroll table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.app-table--scroll th {
    position: sticky;
    top: 0;
    background-color: var(--gray-50);
    z-index: 2;
    box-shadow: inset 0 -1px 0 var(--gray-200);
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.75rem 1rem;
    text-align: left;
}
.app-table--scroll td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: top;
    font-size: 0.9rem;
}
.app-table--scroll tbody tr:nth-child(even) td { background-color: var(--gray-50); }

/* Editable cells */
.editable-cell {
    position: relative;
    cursor: pointer;
    padding-right: 1.75rem !important;
}
.editable-cell:hover::after {
    content: "\f303"; /* fa-pencil-alt */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    position: absolute;
    right: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-600);
    font-size: 0.8125rem;
}
.editable-cell.editing { padding: 0 !important; }
.editable-cell.editing input {
    width: 100%;
    border: none;
    padding: 0.75rem 1rem;
    background-color: var(--surface);
    box-shadow: inset 0 0 0 2px var(--primary-600);
    outline: none;
    font-size: 0.9rem;
    font-family: inherit;
}
.editable-cell.modified { background-color: var(--warning-50) !important; }
.editable-entity {
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.375rem;
    margin: -0.25rem -0.375rem;
    transition: background-color var(--transition);
    display: inline-block;
    min-width: 60px;
}
.editable-entity:hover { background-color: var(--primary-50); }
.editable-entity.editing { padding: 0; }
.editable-entity.editing input {
    border: 1px solid var(--primary-600);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
    font: inherit;
    width: 100%;
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-50);
}
.editable-entity.modified { background-color: var(--warning-50); }

/* ---------- Tabs ---------- */
.app-tabs-outer {
    position: relative;
    margin-bottom: var(--space-5);
}

/* Scroll orizzontale silenzioso su mobile */
.app-tabs-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.app-tabs-scroll::-webkit-scrollbar { display: none; }

/* Ombra a destra — segnala contenuto nascosto su mobile */
.app-tabs-outer::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 1px;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--background));
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms;
}
.app-tabs-outer.has-overflow::after { opacity: 1; }

.nav-tabs.app-tabs {
    border-bottom: 1px solid var(--gray-200);
    gap: 0;
    flex-wrap: nowrap;
    white-space: nowrap;
    min-width: max-content;    /* impedisce wrap su mobile */
}
.nav-tabs.app-tabs .nav-link {
    border: none;
    color: var(--gray-500);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.8125rem 1.125rem;
    border-radius: 0;
    position: relative;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
    text-decoration: none !important;
    transition: color 150ms ease;
    white-space: nowrap;
}

/* Indicatore inferiore animato */
.nav-tabs.app-tabs .nav-link::after {
    content: "";
    position: absolute;
    left: 50%;
    right: 50%;
    bottom: -1px;
    height: 2px;
    background-color: var(--primary-600);
    border-radius: 2px 2px 0 0;
    transition: left 200ms ease, right 200ms ease;
}
.nav-tabs.app-tabs .nav-link:hover {
    color: var(--gray-800);
}
.nav-tabs.app-tabs .nav-link:hover::after {
    left: 1.125rem;
    right: 1.125rem;
    background-color: var(--gray-300);
}
.nav-tabs.app-tabs .nav-link.active {
    color: var(--primary-700);
}
.nav-tabs.app-tabs .nav-link.active::after {
    left: 1.125rem;
    right: 1.125rem;
    background-color: var(--primary-600);
}

.nav-tabs.app-tabs .nav-link i,
.nav-tabs.app-tabs .nav-link svg {
    color: var(--gray-400);
    font-size: 0.875rem;
    transition: color 150ms ease;
    flex-shrink: 0;
}
.nav-tabs.app-tabs .nav-link:hover i,
.nav-tabs.app-tabs .nav-link:hover svg { color: var(--gray-600); }
.nav-tabs.app-tabs .nav-link.active i,
.nav-tabs.app-tabs .nav-link.active svg { color: var(--primary-600); }

/* Badge numerici */
.nav-tabs.app-tabs .nav-link .tab-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background-color: var(--gray-100);
    color: var(--gray-500);
    font-size: 0.6875rem;
    font-weight: 700;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 150ms ease, color 150ms ease;
}
.nav-tabs.app-tabs .nav-link.active .tab-badge {
    background-color: var(--primary-100);
    color: var(--primary-700);
}

/* Transizione contenuto tab */
.tab-content > .tab-pane {
    animation: none;
}
.tab-content > .tab-pane.show {
    animation: tab-enter 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes tab-enter {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Section heading ---------- */
.app-section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.app-section-heading h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}
.app-section-heading__hint {
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* ---------- AI Chat ---------- */

/* ── Wrapper sezione assistente (fuori dai tab) ── */
.ai-chat-section {
    margin-top: var(--space-6);
    border-top: 1px solid var(--gray-200);
    padding-top: var(--space-5);
}
.ai-chat-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}
.ai-chat-section__title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}
.ai-chat-section__title svg { color: var(--primary-600); }

/* Chat box: altezza generosa fissa — sempre visibile nella pagina */
.ai-chat {
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: clamp(480px, 55vh, 680px);
    position: relative;
    transition: box-shadow 200ms ease;
}
.ai-chat:focus-within {
    box-shadow: 0 4px 24px rgba(0, 102, 204, 0.10);
}

/* Toolbar — appare con has-messages */
.ai-chat__toolbar {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 10;
    display: flex;
    gap: 8px;
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    transition: opacity 220ms ease, transform 220ms ease;
    pointer-events: none;
}
.ai-chat.has-messages .ai-chat__toolbar {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.ai-chat__icon-btn {
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    color: var(--gray-600);
    border-radius: 999px;
    padding: 0.3125rem 0.8125rem;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(15,23,42,.06);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: background-color 150ms, color 150ms, border-color 150ms, box-shadow 150ms;
}
.ai-chat__icon-btn:hover {
    background-color: var(--primary-50);
    color: var(--primary-700);
    border-color: var(--primary-200);
    box-shadow: 0 2px 8px rgba(0,102,204,.10);
}

/* Scroll area */
.ai-chat__scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
    scroll-padding-bottom: 12px;
    background: var(--surface);

    /* Gradiente decorativo sottile in cima */
    background-image: radial-gradient(ellipse 80% 120px at 50% 0, rgba(230, 240, 250, .55) 0%, transparent 100%);
    background-repeat: no-repeat;

    /* Scrollbar sottile */
    scrollbar-width: thin;
    scrollbar-color: var(--gray-200) transparent;
}
.ai-chat__scroll::-webkit-scrollbar {
    width: 4px;
}
.ai-chat__scroll::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat__scroll::-webkit-scrollbar-thumb {
    background-color: var(--gray-200);
    border-radius: 4px;
}
.ai-chat__scroll::-webkit-scrollbar-thumb:hover {
    background-color: var(--gray-300);
}

/* ----- Empty state ----- */
.ai-chat__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: clamp(1.5rem, 4vh, 3rem) 1.25rem 1.5rem;
    min-height: 100%;
    animation: ai-empty-in 350ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes ai-empty-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-chat__empty-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--primary-100) 0%, var(--primary-50) 100%);
    color: var(--primary-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.125rem;
    box-shadow: 0 4px 20px rgba(0, 102, 204, .14), 0 0 0 1px rgba(0,102,204,.06);
    animation: ai-icon-pulse 3s ease-in-out infinite;
}
@keyframes ai-icon-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0,102,204,.14), 0 0 0 1px rgba(0,102,204,.06); }
    50%       { box-shadow: 0 6px 28px rgba(0,102,204,.22), 0 0 0 1px rgba(0,102,204,.10); }
}

.ai-chat__empty-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0 0 0.5rem;
    letter-spacing: -0.015em;
}
.ai-chat__empty-text {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
    max-width: 360px;
    line-height: 1.6;
}

/* Chips / suggerimenti */
.ai-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    max-width: 520px;
    width: 100%;
}
.ai-chat__chip {
    background-color: var(--surface);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    padding: 0.4375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    line-height: 1;
    transition: background-color 150ms, color 150ms, border-color 150ms,
                box-shadow 150ms, transform 120ms;
    /* Stagger entrance */
    opacity: 0;
    animation: chip-in 300ms ease both;
}
/* Stagger per ogni chip (6 max) */
.ai-chat__chip:nth-child(1) { animation-delay:  60ms; }
.ai-chat__chip:nth-child(2) { animation-delay: 110ms; }
.ai-chat__chip:nth-child(3) { animation-delay: 160ms; }
.ai-chat__chip:nth-child(4) { animation-delay: 210ms; }
.ai-chat__chip:nth-child(5) { animation-delay: 260ms; }
.ai-chat__chip:nth-child(6) { animation-delay: 310ms; }

@keyframes chip-in {
    from { opacity: 0; transform: translateY(6px) scale(.97); }
    to   { opacity: 1; transform: translateY(0)  scale(1); }
}

.ai-chat__chip i, .ai-chat__chip svg {
    font-size: 0.75rem;
    color: var(--primary-600);
    flex-shrink: 0;
}
.ai-chat__chip:hover {
    background-color: var(--primary-50);
    border-color: var(--primary-200);
    color: var(--primary-700);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,102,204,.10);
}
.ai-chat__chip:hover i, .ai-chat__chip:hover svg { color: var(--primary-700); }
.ai-chat__chip:active { transform: translateY(0); box-shadow: none; }

/* ----- Area messaggi ----- */
.ai-chat__messages {
    max-width: 700px;
    width: 100%;
    margin: 0 auto;
    padding: 1.25rem 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Singolo messaggio */
.ai-msg {
    display: flex;
    animation: ai-msg-in 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
    will-change: opacity, transform;
}
.ai-msg--user      { justify-content: flex-end; }
.ai-msg--assistant { align-items: flex-start; gap: 0.75rem; }

@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Bubble utente */
.ai-msg__user-bubble {
    max-width: min(78%, 560px);
    min-width: 3rem;
    padding: 0.625rem 1rem;
    border-radius: 16px 16px 4px 16px;
    background-color: var(--gray-100);
    color: var(--gray-900);
    font-size: 0.9375rem;
    line-height: 1.55;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15,23,42,.04);
}

/* Avatar assistente */
.ai-msg__avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 8px;
    background: linear-gradient(140deg, var(--primary-500) 0%, var(--primary-800) 100%);
    color: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 5px rgba(0, 102, 204, .28);
    margin-top: 2px;
    flex-shrink: 0;
}
.ai-msg__avatar svg {
    width: 14px;
    height: 14px;
    stroke: #fff;
    stroke-width: 2;
    flex-shrink: 0;
}

/* Contenuto risposta assistente */
.ai-msg__content {
    flex: 1;
    min-width: 0;
    max-width: min(88%, 580px);
    color: var(--gray-800);
    font-size: 0.9375rem;
    line-height: 1.65;
    overflow-wrap: break-word;
    word-break: break-word;
}
.ai-msg__content > *:first-child { margin-top: 0; }
.ai-msg__content > *:last-child  { margin-bottom: 0; }
.ai-msg__content p  { margin: 0 0 0.5rem; }
.ai-msg__content ul,
.ai-msg__content ol { padding-left: 1.25rem; margin: 0.375rem 0; }
.ai-msg__content li { margin-bottom: 0.25rem; }
.ai-msg__content strong { font-weight: 700; color: var(--gray-900); }
.ai-msg__content code {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.875em;
    background-color: var(--gray-100);
    padding: 0.125em 0.35em;
    border-radius: 4px;
    color: var(--primary-700);
}

/* Typing indicator */
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.6rem 0.875rem;
    background-color: var(--gray-100);
    border-radius: 14px;
}
.ai-typing span {
    width: 5px;
    height: 5px;
    background-color: var(--gray-400);
    border-radius: 50%;
    animation: ai-bounce 1.3s ease infinite;
    will-change: transform, opacity;
}
.ai-typing span:nth-child(2) { animation-delay: 0.16s; }
.ai-typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes ai-bounce {
    0%, 55%, 100% { opacity: 0.35; transform: translateY(0); }
    27%            { opacity: 1;    transform: translateY(-4px); }
}

/* Errore */
.ai-msg__error {
    padding: 0.625rem 0.875rem;
    background-color: var(--danger-50);
    border: 1px solid rgba(198,40,40,.18);
    color: var(--danger-600);
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ----- Composer ----- */
.ai-composer-wrap {
    flex-shrink: 0;
    padding: 0.5rem 1rem 1rem;

    /* Velatura che sfuma l'ultimo messaggio sotto il composer */
    background: linear-gradient(to bottom, transparent 0%, var(--surface) 55%);
}
.ai-composer {
    max-width: 700px;
    margin: 0 auto;
    background-color: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    box-shadow: 0 1px 4px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.04);
    transition: border-color 160ms ease, box-shadow 160ms ease;
    cursor: text;
    overflow: hidden;
}
.ai-composer:hover {
    border-color: var(--gray-300);
}
.ai-composer.is-focused {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(0,102,204,.10), 0 2px 8px rgba(15,23,42,.06);
}

.ai-composer__textarea {
    display: block;
    width: 100%;
    min-height: 26px;
    max-height: 160px;
    padding: 0.8125rem 1rem 0;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--gray-900);
    overflow-y: hidden;
    caret-color: var(--primary-600);
}
.ai-composer__textarea::placeholder { color: var(--gray-400); }
.ai-composer__textarea:disabled { opacity: 0.55; cursor: not-allowed; }

.ai-composer__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3125rem 0.5rem 0.5rem;
    gap: 8px;
}
.ai-composer__hint {
    color: var(--gray-400);
    font-size: 0.6875rem;
    padding-left: 0.5rem;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
    overflow: hidden;
}
.ai-composer__hint kbd {
    display: inline-block;
    background-color: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-bottom-width: 2px;
    border-radius: 3px;
    padding: 1px 4px;
    font-family: inherit;
    font-size: 0.625rem;
    color: var(--gray-600);
    line-height: 1.4;
}

/* Bottone send / stop */
.ai-composer__send {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    border: none;
    background-color: var(--gray-200);
    color: var(--gray-400);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: not-allowed;
    flex-shrink: 0;
    transition: background-color 150ms ease, color 150ms ease,
                transform 100ms ease, box-shadow 150ms ease;
}
.ai-composer__send svg { width: 14px; height: 14px; display: block; flex-shrink: 0; }

.ai-composer__send[data-state="ready"] {
    background-color: var(--primary-600);
    color: var(--surface);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,102,204,.25);
}
.ai-composer__send[data-state="ready"]:hover {
    background-color: var(--primary-700);
    box-shadow: 0 3px 12px rgba(0,102,204,.32);
    transform: scale(1.04);
}
.ai-composer__send[data-state="ready"]:active {
    transform: scale(0.94);
    box-shadow: none;
}
.ai-composer__send[data-state="streaming"] {
    background-color: var(--gray-800);
    color: var(--surface);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15,23,42,.18);
    animation: streaming-pulse 1.8s ease-in-out infinite;
}
@keyframes streaming-pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(15,23,42,.18); }
    50%       { box-shadow: 0 3px 14px rgba(15,23,42,.28); }
}
.ai-composer__send[data-state="streaming"]:hover {
    background-color: var(--gray-700);
}

/* ---------- Utility ---------- */
.text-muted-soft { color: var(--gray-500); }
.divider-y {
    border-left: 1px solid var(--gray-200);
    height: 1.25rem;
    margin: 0 var(--space-3);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .app-page-header h1 { font-size: 1.5rem; }
    .app-footer__row { justify-content: center; text-align: center; }

    /* Tabs */
    .nav-tabs.app-tabs .nav-link { padding: 0.6875rem 0.875rem; font-size: 0.8125rem; }

    /* Chat */
    .ai-chat { height: clamp(380px, 50vh, 520px); }
    .ai-chat__messages { padding: 1rem 0.875rem 0.75rem; gap: 1rem; }
    .ai-chat__empty { padding: 1.25rem 1rem 1rem; }
    .ai-chat__suggestions { gap: 0.375rem; }
    .ai-chat__chip { font-size: 0.75rem; padding: 0.375rem 0.75rem; }
    .ai-composer-wrap { padding: 0.375rem 0.75rem 0.875rem; }
    .ai-composer { border-radius: 14px; }
    .ai-composer__textarea { padding: 0.75rem 0.875rem 0; font-size: 0.9rem; }
    .ai-composer__hint { display: none; }    /* nasconde hint shortcut su mobile */
    .ai-composer__actions { padding: 0.25rem 0.375rem 0.375rem; }

    /* User bubble più compatta */
    .ai-msg__user-bubble { max-width: 86%; }
    .ai-msg__content { max-width: 90%; }

    .app-search { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chat__empty, .ai-chat__chip,
    .ai-msg, .ai-chat__toolbar,
    .ai-chat__empty-icon {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    .tab-content > .tab-pane.show { animation: none; }
}
