* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ================================
   LOGIN STYLES
   ================================ */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 32px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-box h2 {
    color: #2d3748;
    margin-bottom: 16px;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-size: 15px;
}

/* Stile per icone nei pulsanti */
.button-icon {
    filter: brightness(0) saturate(100%) invert(27%) sepia(11%) saturate(634%) hue-rotate(186deg) brightness(94%) contrast(88%);
    transition: filter 0.2s ease;
}

.login-button:hover .button-icon {
    filter: brightness(0) saturate(100%) invert(100%);
}


.forgot {
    text-align: right;
    font-size: 13px;
    margin-bottom: 12px;
}

.forgot a {
    color: #667eea;
    text-decoration: none;
}

.login-button {
    background: #e5e7eb;
    border: none;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    transition: all 0.2s ease;
    width: 100%;
    margin-bottom: 10px;
}

.login-button:hover {
    background: #475569;
    color: white;
    transform: translateY(-1px);
}

.reset-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

/* ================================
   MAIN LAYOUT
   ================================ */
.app-container {
    display: flex;
    height: 100vh;
    background: #f8fafc;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: 280px;
    background: white;
    border-right: 1px solid #e2e8f0;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    transition: width 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    width: 64px;
}

.app-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 88px;
}

.sidebar.collapsed .app-header {
    justify-content: center;
    padding: 24px 0;
}

.app-logo {
    width: 40px;
    height: 40px;
    background: #dc2626;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.app-logo:hover {
    background: #b91c1c;
    transform: scale(1.05);
}

.app-logo svg {
    width: 28px;
    height: 28px;
    pointer-events: none;
}

.app-name {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .app-name {
    opacity: 0;
    width: 0;
}

/* NAVIGATION */
.nav-menu {
    flex: 1;
    overflow-y: auto;      /* ← aggiunge scrollbar se il menu è troppo lungo */
    overflow-x: hidden;    /* ← evita scroll orizzontale indesiderato */
    min-height: 0;         /* ← necessario per far funzionare overflow in flex */
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    color: #64748b;
    transition: all 0.2s ease;
    cursor: pointer;
    gap: 12px;
    position: relative;
    height: 52px;
}

.sidebar.collapsed .nav-item {
    padding: 14px 0;
    justify-content: center;
}

.nav-item:hover {
    background: #f1f5f9;
    color: #334155;
}

.nav-item.active {
    background: #475569;
    color: white;
}

.nav-item.active .nav-icon {
    filter: brightness(0) invert(1);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-text {
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Tooltip for collapsed sidebar */
.nav-item .tooltip {
    /* position: absolute;
    left: 70px;
    top: 50%; */
    position: fixed;          /* ← era absolute */
    left: 72px;               /* distanza fissa dal bordo sinistro della sidebar collassata */
    transform: translateY(-50%);
    background: #1e293b;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 20000;
}

/* .sidebar.collapsed .nav-item:hover .tooltip {
    opacity: 1;
    visibility: visible;
} */

.tooltip::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1e293b;
}

/* CONTENT AREA */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-width: 0;
}

/* TOP MENU */
.top-menu {
    background: #f8fafc;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 80px;
}

.top-menu-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.section-title-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-menu {
    position: relative;
}

.menu-icon {
    width: 24px;
    height: 24px;
    cursor: pointer;
    color: #475569;
    transition: color 0.2s ease;
}

.menu-icon:hover {
    color: #1e293b;
}

.section-title {
    font-size: 24px;
    font-weight: 700;
    color: #1e293b;
}

.top-menu-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#dynamicActions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ================================
   BUTTONS - Unificati
   ================================ */
.action-button {
    background: transparent;
    border: 1px solid #e2e8f0;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    color: #374151;
    transition: all 0.2s ease;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.action-button:hover {
    background: #475569;
    color: white;
    border-color: #475569;
    transform: translateY(-1px);
}

.action-button span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.action-button svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* Tooltip per action buttons */
.action-tooltip {
    position: fixed;
    background: #1e293b;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 21000;
    pointer-events: none;
}

.action-tooltip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #1e293b;
}

/* Button nel top menu (più piccoli) */
.top-menu .action-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
}

/* ACCOUNT MENU */
.account-menu {
    position: relative;
}

.account-btn {
    width: 40px;
    height: 40px;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.account-btn:hover {
    background: #b91c1c;
    transform: scale(1.05);
}

/* ================================
   DROPDOWN MENUS
   ================================ */
.menu-dropdown {
    position: absolute;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1000;
    display: none;
    margin-top: 8px;
}

.menu-dropdown.show {
    display: block;
}

.section-dropdown {
    top: 100%;
    left: 0;
}

.dropdown-menu {
    top: 100%;
    right: 0;
}

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    font-size: 14px;
    color: #374151;
}

.dropdown-item:hover {
    background: #f8fafc;
    color: #000;
}

/* WORK AREA */
.work-area {
    flex: 1;
    padding: 24px;
    background: #f8fafc;
    overflow-y: auto;
}

/* ================================
   MODALS - Sistema Unificato
   ================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    max-height: 85vh;
}

/* Modali strutturate */
.modal-content.modal-flex {
    display: flex;
    flex-direction: column;
    overflow: visible; /* Per tooltip */
}

.modal-content.modal-lg {
    max-width: 800px;
}

.modal-header {
    flex-shrink: 0;
    margin-bottom: 20px;
}

.modal-body {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 20px;
    min-height: 0;
}

.modal-footer {
    flex-shrink: 0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 0;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

/* Fix tooltip nelle modali */
.modal-flex .action-button {
	border-radius: 50%;
    position: relative;
    z-index: 20050;
}

.modal-flex .action-button .action-tooltip {
    z-index: 21000;
}

/* Scrollbar personalizzate */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

/* ================================
   FORM FIELDS
   ================================ */
.modal-field {
    margin-bottom: 20px;
}

.modal-field-label {
    display: block;
    margin-bottom: 12px;
    font-weight: 700;
    color: #1e293b;
    font-size: 16px;
    text-align: left;
}

.modal-field-input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-size: 15px;
    transition: border-color 0.2s ease;
}

.modal-field-input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.modal-field-with-button {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.modal-field-with-button .modal-field-input {
    flex: 1;
}

/* ================================
   SECTION HEADERS
   ================================ */
.modal-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.modal-section-title {
    font-weight: 600;
    color: #374151;
    font-size: 18px;
    margin: 0;
}

/* ================================
   TABELLE
   ================================ */
.modal-table-container {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
}

.modal-table-small {
    height: 180px;
    min-height: 180px;
    max-height: 180px;
}

.filter-section {
    flex-shrink: 0;
    padding: 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.table-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#aziendaTable {
    flex: 1;
    height: 100%;
}

/* ================================
   BUTTONS - Sistema Unificato
   ================================ */
.btn {
    padding: 12px 16px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-width: 100px;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-danger {
    background: #e5e7eb;
    color: #374151;
}

.btn-danger:hover {
    background: #dc2626;
    color: white;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background: #475569;
    color: white;
    transform: translateY(-1px);
}

/* ================================
   TABULATOR OVERRIDES
   ================================ */
.tabulator {
    background: white;
    border: none;
    font-size: 14px;
}

.tabulator .tabulator-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.tabulator .tabulator-col {
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    font-weight: 600;
    color: #1e293b;
    font-size: 15px;
}

.tabulator .tabulator-col:last-child {
    border-right: none;
}

.tabulator .tabulator-col-title {
    padding: 16px;
    font-size: 17px;
}

.tabulator .tabulator-row {
    background: white;
    border-bottom: 1px solid #f1f5f9;
}

.tabulator .tabulator-row:hover {
    background: #f8fafc;
}

.tabulator .tabulator-cell {
    padding: 12px;
    border-right: 1px solid #f1f5f9;
    color: #475569;
    font-size: 15px;
    font-weight: 500;
    vertical-align: middle;
}

.tabulator .tabulator-cell:last-child {
    border-right: none;
}

/* Status badges */
.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    display: inline-block;
    cursor: pointer;
    transition: all 0.2s ease;
}

.status-badge.active {
    background: #dcfce7;
    color: #475569;
}

.status-badge.active:hover {
    background: #166534;
    color: #ffffff;
}

.status-badge.inactive {
    background: #fee2e2;
    color: #475569;
}

.status-badge.inactive:hover {
    background: #dc2626;
    color: #ffffff;
}

/* Action buttons nelle tabelle */
.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.action-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: transparent;
    color: #475569;
}

.action-btn:hover {
    background: #475569;
    color: #ffffff;
}

.action-btn img {
    width: 16px;
    height: 16px;
    filter: brightness(0) saturate(100%) invert(41%) sepia(17%) saturate(634%) hue-rotate(186deg) brightness(94%) contrast(88%);
    transition: all 0.2s ease;
}

.action-btn:hover img {
    filter: brightness(0) saturate(100%) invert(100%);
}

/* ================================
   NOTIFICATION TOAST
   ================================ */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: transparent;
    color: white;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 3000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    font-size: 14px;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: #10b981;
}

.notification.warning {
    background: #f59e0b;
}

.notification {
    background: transparent;
    box-shadow: none; /* ← rimuovi l'ombra di default */
}

.notification.show {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* ← ombra solo quando visibile */
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 768px) {
    .modal-content.modal-lg {
        max-width: 95%;
    }
    
    .modal-flex .modal-footer {
        flex-direction: column;
    }
    
    .modal-flex .modal-footer .btn {
        width: 100%;
    }
}

/* ================================
   MODAL BUTTONS - Sistema Unificato
   ================================ */

/* Base button per modali - grigio neutro */
.modal-btn {
    background: #e5e7eb;
    color: #374151;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 80px;
}

/* Variante con hover rosso */
.modal-btn.red_hover:hover {
    background: #dc2626;
    color: white;
    transform: translateY(-1px);
}

/* Variante con hover verde */
.modal-btn.green_hover:hover {
    background: #10b981;
    color: white;
    transform: translateY(-1px);
}

/* Hover standard grigio scuro */
.modal-btn:hover:not(.red_hover):not(.green_hover) {
    background: #6b7280;
    color: white;
    transform: translateY(-1px);
}


/* Checkbox unificato per modali */
.modal-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
}

.modal-checkbox input {
    width: 16px;
    height: 16px;
    margin: 0;
}

.modal-checkbox label {
    margin: 0;
    font-size: 15px;
    font-weight: normal;
    color: #374151;
    cursor: pointer;
}

.modal-select {
    width: 100%;
    padding: 12px 16px;
    padding-right: 40px;
    margin-bottom: 16px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-size: 15px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: white;
    background-image: url("icons/freccia_giu.svg");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 16px;
    cursor: pointer;
}

.modal-select:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.modal-conditional-fields {
    margin-left: 24px;
}

/* Testi di dettaglio per celle tabella */
.cell-detail-text {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.cell-detail-success {
    color: #166534;
}

.cell-detail-danger {
    color: #dc2626;
}

/* Tabulator nelle modali - righe più compatte */
.modal-table-container .tabulator-col {
    min-height: 24px;
    padding: 2px 8px;
}

.modal-table-container .tabulator-col-title {
    padding: 2px 8px;
    min-height: 20px;
}

.modal-table-container .tabulator-row {
    min-height: 20px;
}

.modal-table-container .tabulator-cell {
    padding: 1px 8px;
    min-height: 18px;
}

.modal-table-container .tabulator-cell > * {
    min-height: 16px;
}

/* Container base per le sezioni */
.section-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 128px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

/* ================================
   IMPORT CSV MODAL
   ================================ */

.import-csv-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

.import-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 28px 16px;
    border: 2px dashed #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    text-align: center;
}

.import-dropzone:hover,
.import-dropzone.dragover {
    border-color: #10b981;
    background: #f0fdf4;
}

.import-dropzone-icon {
    opacity: 0.35;
}

.import-dropzone-label {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.import-dropzone-hint {
    font-size: 11px;
    color: #94a3b8;
}

.import-result {
    display: none;
    max-height: 150px;
    overflow-y: auto;
}

.import-summary {
    display: flex;
    gap: 16px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.import-ok {
    color: #166534;
}

.import-error-row {
    font-size: 12px;
    color: #dc2626;
    background: #fef2f2;
    border-radius: 6px;
    padding: 4px 10px;
    margin-bottom: 4px;
    border-left: 3px solid #dc2626;
}

/* ================================
   FULLSCREEN MODE
   ================================ */

/* Nasconde sidebar e top-menu quando #mainApp ha classe .fullscreen */
#mainApp.fullscreen .sidebar,
#mainApp.fullscreen .top-menu {
    display: none;
}

/* La work-area occupa tutto lo spazio disponibile */
#mainApp.fullscreen .work-area {
    height: 100vh;
}

/* Bottone flottante per uscire dal fullscreen */
#exitFullscreenBtn {
    display: none; /* nascosto di default, mostrato solo in fullscreen */
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    background: rgba(30, 41, 59, 0.35);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: background 0.2s ease, transform 0.2s ease;
}

#exitFullscreenBtn img {
    filter: brightness(0) invert(1);
    display: block;
}

#exitFullscreenBtn:hover {
    background: rgba(30, 41, 59, 0.70);
    transform: translateY(-1px);
}

/* Mostra il bottone solo quando siamo in fullscreen */
#mainApp.fullscreen ~ #exitFullscreenBtn,
body.fullscreen-active #exitFullscreenBtn {
    display: flex;
}