:root {
    --inaf-blue: #0056b3;
    --inaf-light-blue: #e7f1ff;
    --border-color: #dee2e6;
    --card-padding: 1.5rem;
    --text-main: #212529;
    --text-muted: #6c757d;
    --action-icon-size: 1.2rem;
}

[data-bs-theme=dark] {
    --inaf-blue: #3d8bfd;
    --inaf-light-blue: #031633;
    --border-color: #495057;
    --text-main: #f8f9fa;
    --text-muted: #adb5bd;
}

[data-bs-theme=dark] .btn-outline-secondary {
    --bs-btn-color: #dee2e6;
    --bs-btn-border-color: #6c757d;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #6c757d;
    --bs-btn-hover-border-color: #6c757d;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #6c757d;
    --bs-btn-active-border-color: #6c757d;
}

body {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
}

.app-card {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    padding: var(--card-padding);
    box-shadow: none; /* Look flat/sobrio come da specifica */
}


.section-title {
    color: var(--inaf-blue);
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Colori icone standardizzati */
.icon-primary { color: var(--inaf-blue); }
.icon-danger { color: #dc3545; }
.icon-success { color: #198754; }
.icon-info { color: #0dcaf0; }
.icon-secondary { color: var(--text-muted); }

.action-icon {
    font-size: var(--action-icon-size);
    transition: transform 0.2s ease-in-out;
}

.action-icon:hover {
    transform: scale(1.2);
}

.form-label {
    font-weight: 600;
}

.mt-1 {
    margin-top: .25rem;
}

.mt-2 {
    margin-top: .5rem;
}

.mb-2 {
    margin-bottom: .5rem;
}

/* Header tweaks */
.navbar-brand {
    font-weight: 700;
    color: var(--inaf-blue);
}

[data-bs-theme=dark] .navbar-brand img {
    filter: brightness(0) invert(1);
}

.navbar {
    min-height: 56px;
}

.smart-scroll {
    transition: transform 0.3s ease-in-out;
}

.scrolled-down {
    transform: translateY(-100%);
}

.scrolled-up {
    transform: translateY(0);
}

.navbar-toggler {
    border: none;
    padding: 0.25rem 0.5rem;
}

.offcanvas-header {
    background-color: var(--bs-body-bg);
    border-bottom: 1px solid var(--border-color);
}

.offcanvas-body .nav-link {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s ease;
}

.offcanvas-body .nav-link:hover {
    background-color: var(--bs-tertiary-bg);
}

.offcanvas-body .nav-link i {
    font-size: 1.25rem;
    margin-right: 0.75rem;
    vertical-align: text-bottom;
}

/* Footer */
footer.app-footer {
    padding: 1rem 0;
    background-color: var(--bs-tertiary-bg);
    border-top: 1px solid var(--bs-border-color);
    color: var(--bs-secondary-color);
    margin-top: auto;
}

.footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.footer-divider {
    display: none;
}

@media (min-width: 768px) {
    .footer-content {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .footer-divider {
        display: inline;
        margin: 0 0.5rem;
        opacity: 0.5;
    }
}

.back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background-color: var(--inaf-blue);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.2s ease;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background-color: var(--bs-primary);
    transform: translateY(-3px);
    color: #fff;
}

/* Responsive form tweaks */
@media (min-width: 768px) {
    .app-card {
        padding: 32px;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

.year-select {
    width: auto;
    display: inline-block;
}

.ore-formazione {
    background-color: green;
    border-radius: 50%;
    padding: 5px;
}

.ore-formazione-yellow {
    background-color: yellow;
    border-radius: 50%;
    padding: 5px;
}

.table-container, .scrollable-table-container {
    max-height: calc(100vh - 380px);
    /* Altezza massima: altezza schermo meno spazio per header/padding/filtri */
    overflow-y: auto;
}

/* Opzionale: mantieni l'header della tabella fisso durante lo scroll */
.table-fixed-header thead th {
    position: sticky;
    top: 0;
    background-color: var(--bs-table-bg);
    z-index: 10;
}

/* Per tabelle con strisce, mantieni il colore di sfondo dell'header */
.table-striped .table-fixed-header thead th {
    background-color: var(--bs-body-bg);
}

/* Stili per la modale di dettaglio */
#employee-details-modal .modal-body iframe {
    width: 100%;
    height: 70vh;
    border: none;
}

.sortable-header {
    cursor: pointer;
}

.sortable-header::after {
    content: '\2195'; /* Up-down arrow */
    color: #ccc;
    margin-left: 5px;
}

.sortable-header.sort-asc::after {
    content: '\25B2'; /* Up arrow */
    color: #333;
}

.sortable-header.sort-desc::after {
    content: '\25BC'; /* Down arrow */
    color: #333;
}

/* === Badge Centralizzati === */
.badge-direttore {
    background-color: var(--bs-primary-alpha-10, rgba(13, 110, 253, 0.1)) !important;
    color: var(--bs-primary-text-emphasis) !important;
    border: 1px solid var(--bs-primary-border-subtle) !important;
}

[data-bs-theme=dark] .badge-direttore {
    background-color: rgba(13, 110, 253, 0.2) !important;
}

.badge-dirigente {
    background-color: var(--bs-info-alpha-10, rgba(13, 202, 240, 0.1)) !important;
    color: var(--bs-info-text-emphasis) !important;
    border: 1px solid var(--bs-info-border-subtle) !important;
}

[data-bs-theme=dark] .badge-dirigente {
    background-color: rgba(13, 202, 240, 0.2) !important;
}

/* Badge di stato attestati */
.badge-stato-assente {
    background-color: var(--bs-danger-alpha-10, rgba(220, 53, 69, 0.1)) !important;
    color: var(--bs-danger-text-emphasis) !important;
    border: 1px solid var(--bs-danger-border-subtle) !important;
}

.badge-stato-incoda {
    background-color: var(--bs-warning-alpha-10, rgba(255, 193, 7, 0.1)) !important;
    color: var(--bs-warning-text-emphasis) !important;
    border: 1px solid var(--bs-warning-border-subtle) !important;
}

.badge-stato-generato {
    background-color: var(--bs-info-alpha-10, rgba(13, 202, 240, 0.1)) !important;
    color: var(--bs-info-text-emphasis) !important;
    border: 1px solid var(--bs-info-border-subtle) !important;
}

.badge-stato-admin {
    background-color: var(--bs-info-alpha-10, rgba(13, 202, 240, 0.1)) !important;
    color: var(--bs-info-text-emphasis) !important;
    border: 1px solid var(--bs-info-border-subtle) !important;
}

.badge-stato-caricato {
    background-color: var(--bs-primary-alpha-10, rgba(13, 110, 253, 0.1)) !important;
    color: var(--bs-primary-text-emphasis) !important;
    border: 1px solid var(--bs-primary-border-subtle) !important;
}

.badge-stato-firmato {
    background-color: var(--bs-success-alpha-10, rgba(25, 135, 84, 0.1)) !important;
    color: var(--bs-success-text-emphasis) !important;
    border: 1px solid var(--bs-success-border-subtle) !important;
}

.badge-valutazione-generic {
    background-color: var(--bs-secondary-bg) !important;
    color: var(--bs-secondary-color) !important;
    border: 1px solid var(--bs-border-color) !important;
}

.app-card .fs-1 {
    font-size: 3rem !important;
    opacity: 0.2;
}

.progress, .progress-bar {
    border-radius: 10px;
}

.badge.bg-info-subtle {
    font-weight: 500;
}

details > summary {
    cursor: pointer;
    list-style: none; /* Rimuovi la freccia di default */
}

details > summary::-webkit-details-marker {
    display: none; /* Rimuovi la freccia di default in Chrome */
}

details > summary::before {
    content: '\F282'; /* Icona bootstrap per freccia a destra */
    font-family: 'bootstrap-icons';
    margin-right: 0.5rem;
    display: inline-block;
    transition: transform 0.2s;
}

details[open] > summary::before {
    transform: rotate(90deg);
}

.user-search-results {
    max-height: 200px;
    overflow-y: auto;
}

/* 2FA Input Style */
.otp-input {
    letter-spacing: 0.5em;
    font-size: 1.5em;
}

/* Scroll Indicator */
.scroll-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background-color: var(--bs-body-bg);
    color: var(--inaf-blue);
    padding: 10px 15px;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(var(--bs-emphasis-color-rgb), 0.15);
    animation: bounce 2s infinite;
    cursor: pointer;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    border: 1px solid var(--bs-border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}


.scroll-indicator.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateX(-50%) translateY(0);}
    40% {transform: translateX(-50%) translateY(-10px);}
    60% {transform: translateX(-50%) translateY(-5px);}
}
/* Row highlight animation */
@keyframes highlightFade {
    0% { box-shadow: inset 0 0 0 9999px rgba(13, 110, 253, 0.4); }
    100% { box-shadow: inset 0 0 0 9999px transparent; }
}
.flash-row > * {
    animation: highlightFade 3s ease-out forwards;
}

/* Table action icons tweaks */
.action-link {
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out;
    padding: 4px;
    border-radius: 4px;
    outline: none;
}

.action-link:hover {
    background-color: rgba(var(--bs-emphasis-color-rgb), 0.05);
    transform: scale(1.2);
}

/* Specific colors for hover if not using standard link-classes */
.action-link.link-primary:hover { color: #0a58ca !important; }
.action-link.link-success:hover { color: #146c43 !important; }
.action-link.link-danger:hover { color: #b02a37 !important; }
.action-link.link-secondary:hover { color: #565e64 !important; }
.action-link.link-info:hover { color: #087990 !important; }

/* Remove any potential focus ring or shadow that could look like a dash */
.action-link:focus {
    box-shadow: none;
}

/* Ensure icons inside links inherit colors correctly */
.action-link i {
    vertical-align: middle;
    line-height: 1;
}

/* Filename truncation for mobile */
.filename-truncate {
    max-width: 150px;
    display: inline-block;
    vertical-align: middle;
}

@media (min-width: 768px) {
    .filename-truncate {
        max-width: 300px;
    }
}
/* Development Ribbon */
.devel-ribbon {
    position: fixed;
    top: 0;
    right: 0;
    width: 150px;
    height: 150px;
    overflow: hidden;
    z-index: 9999;
    pointer-events: none;
}

.devel-ribbon .ribbon-content {
    position: absolute;
    top: 30px;
    right: -40px;
    width: 200px;
    background-color: #dc3545; /* Bootstrap danger red */
    color: white;
    text-align: center;
    line-height: 40px;
    font-weight: bold;
    font-size: 14px;
    text-transform: uppercase;
    transform: rotate(45deg);
    box-shadow: 0 2px 5px rgba(var(--bs-emphasis-color-rgb), 0.2);
    letter-spacing: 1px;
    border: 1px solid rgba(255,255,255,0.3);
}

/* === Responsive Tables === */

/* 1. Card View (< 768px) */
@media (max-width: 767.98px) {
    .table-responsive-card thead {
        display: none;
    }
    
    .table-responsive-card tbody,
    .table-responsive-card tr,
    .table-responsive-card td {
        display: block;
        width: 100%;
    }
    
    .table-responsive-card tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        background-color: var(--bs-body-bg);
    }
    
    .table-responsive-card td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        border: none;
        border-bottom: 1px solid var(--bs-border-color-translucent);
        padding: 0.75rem 1rem;
    }
    
    .table-responsive-card td:last-child {
        border-bottom: none;
        justify-content: flex-end;
    }
    
    .table-responsive-card td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        margin-right: 1rem;
        color: var(--text-muted);
        flex: 1;
    }
}

/* 2. Smart Sticky Header */
.table-sticky-header thead th {
    position: sticky;
    top: 56px; /* navbar height */
    background-color: var(--bs-body-bg);
    z-index: 1010;
    box-shadow: inset 0 -1px 0 var(--bs-border-color);
}

/* If the table is inside a scrollable container (like .table-scroll-wrapper or a max-height container), 
   the sticky header must stick to the top of THAT container (top: 0), not the viewport navbar.
   Vertical stickiness to the viewport is broken by 'overflow: auto/hidden' ancestors anyway. */
.table-scroll-wrapper .table-sticky-header thead th,
.table-container .table-sticky-header thead th,
.scrollable-table-container .table-sticky-header thead th,
[id$="-table-container"] .table-sticky-header thead th {
    top: 0 !important;
}

body.navbar-hidden .table-sticky-header thead th,
body.no-navbar .table-sticky-header thead th {
    top: 0;
}

/* 3. Scroll Shadows */
.table-scroll-wrapper {
    position: relative;
    overflow-x: auto;
    background:
        /* Shadow covers */
        linear-gradient(to right, var(--bs-body-bg) 30%, rgba(255, 255, 255, 0)),
        linear-gradient(to right, rgba(255, 255, 255, 0), var(--bs-body-bg) 70%) 100% 0,
        /* Shadows */
        radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) 100% 0;
    background-repeat: no-repeat;
    background-color: var(--bs-body-bg);
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

[data-bs-theme=dark] .table-scroll-wrapper {
    background:
        /* Shadow covers */
        linear-gradient(to right, var(--bs-body-bg) 30%, rgba(0, 0, 0, 0)),
        linear-gradient(to right, rgba(0, 0, 0, 0), var(--bs-body-bg) 70%) 100% 0,
        /* Shadows */
        radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0)) 100% 0;
    background-repeat: no-repeat;
    background-color: var(--bs-body-bg);
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

/* === Mobile Interactions & Touch === */

/* Touch device improvements: larger targets */
@media (pointer: coarse) {
    .btn, 
    .form-control, 
    .form-select {
        min-height: 44px;
    }
    
    /* Ensure text inputs don't zoom on iOS (min 16px) */
    .form-control, 
    .form-select {
        font-size: 16px;
    }
}

.desktop-filter-toolbar {
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 50px; /* Estremità arrotondate (pill style) */
    padding: 0.2rem 1.25rem; /* Altezza ridotta */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    align-items: center;
    gap: 0;
    width: 100%;
    min-height: 44px; /* Altezza minima standard per click */
}

.desktop-filter-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.15rem 1rem; /* Padding ridotto per ridurre altezza */
    min-width: 0;
    height: 100%;
    border-left: 1px solid var(--bs-border-color);
}

/* Rimuoviamo il bordo al primo elemento di ogni riga è complesso con auto-fit, 
   ma possiamo rimuoverlo al primo elemento assoluto e gestire il resto visivamente */
.desktop-filter-item:first-child {
    border-left: none;
}

.filter-select-desktop {
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    background-color: transparent;
    font-weight: 700;
    padding: 0.25rem 2rem 0.25rem 0.5rem; /* Ridotto da 0.375rem */
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Desktop filter item for Year (always small) */
.desktop-filter-item.item-year {
    grid-column: -2 / -1;
    justify-self: end;
    min-width: 120px;
    flex: 0 0 auto;
}

/* Desktop filter item for Structure (takes more space) */
.desktop-filter-item.item-structure {
    grid-column: span 2;
    min-width: 300px;
}

@media (max-width: 1400px) {
    .desktop-filter-item.item-structure {
        grid-column: span 1;
        min-width: 200px;
    }
}

/* Gestione bordi quando la griglia va a capo */
@media (max-width: 1199.98px) {
    .desktop-filter-item {
        border-left: none;
        border-bottom: 1px solid var(--bs-border-color);
    }
    .desktop-filter-item:last-child {
        border-bottom: none;
    }
}

/* Stato attivo per i filtri */
.filter-select-desktop.is-active {
    color: var(--bs-primary-text-emphasis) !important;
    background-color: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary-border-subtle);
}

[data-bs-theme=dark] .filter-select-desktop.is-active {
    background-color: rgba(13, 110, 253, 0.2);
}

/* Mobile form stacking utility */
@media (max-width: 575.98px) {
    .form-mobile-stack {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .form-mobile-stack > * {
        margin-right: 0 !important;
        margin-bottom: 0.75rem;
    }
    .form-mobile-stack > *:last-child {
        margin-bottom: 0;
    }
    
    /* Force 100% width on stacked elements if they are not already */
    .form-mobile-stack .form-control,
    .form-mobile-stack .form-select,
    .form-mobile-stack .btn {
        width: 100% !important;
    }
}
