/* ==========================================================================
   FOGLIO DI STILE UNIFICATO - DESIGN SYSTEM DYNAMICS 365 BUSINESS CENTRAL
   ========================================================================== */

:root {
    --primary: #126464;               /* Verde Petrolio scuro nativo Business Central per azioni principali */
    --primary-hover: #167e7e;         /* Verde Petrolio intermedio per stati attivi e hover */
    --teal-dark: #126464;             /* Verde Petrolio scuro per i blocchi attività */
    --teal-light: #167e7e;            /* Verde Petrolio intermedio per stati attivi */
    --bg: #ffffff;                    /* Grigio neutro chiarissimo di sfondo della pagina   --bg: #f3f2f1;   */
    --panel: #ffffff;                 /* Sfondo bianco puro per i blocchi card e i form */
    --text: #201f1e;                  /* Antracite scuro ad alta leggibilità per i testi */
    --muted: #605e5c;                 /* Grigio Slate per etichette, descrizioni e label */
    --danger: #a80000;                /* Rosso scuro istituzionale per blocchi e cancellazioni */
    --success: #107c41;               /* Verde per le conferme e salvataggi riusciti */
    --line: #edebe9;                  /* Grigio geometrico sottile per i bordi */
    --radius: 4px;                    /* Angoli netti a raggio ridotto tipici di Business Central */
}

* { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; 
}

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif !important;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* TITOLO HEADER REVISIONATO E UNIFORMATO A 1.5rem SU OGNI SCHERMATA */
h1 {
    color: var(--teal-dark) !important;      
    font-size: 1.5rem !important;
    font-family: "Segoe UI", sans-serif !important;
    font-weight: 600;
    margin: 0;
}

/* LOGIN OVERLAY */
.overlay {
    position: fixed; 
    inset: 0;
    background: var(--bg);
    display: flex; 
    align-items: center; 
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--panel);
    padding: 30px; 
    border-radius: var(--radius);
    width: 90%; 
    max-width: 400px;
    box-shadow: 0 1.6px 3.6px 0 rgba(0,0,0,0.11), 0 0.3px 0.9px 0 rgba(0,0,0,0.13);
    border: 1px solid var(--line);
    text-align: center;
}

.login-card input {
    width: 100%; 
    padding: 12px; 
    margin: 10px 0;
    border: 1px solid var(--line); 
    border-radius: var(--radius); 
    font-size: 1rem;
    font-family: "Segoe UI", sans-serif;
}

.btn-login {
    width: 100%; 
    background: var(--primary); 
    color: white;
    border: 1px solid var(--primary); 
    padding: 14px; 
    border-radius: var(--radius);
    font-weight: 600; 
    font-size: 1rem; 
    margin-top: 10px;
    cursor: pointer;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.15s ease;
}

.btn-login:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* APP LAYOUT IN STILE BUSINESS CENTRAL CON FINITURA CHIARA */
.app { 
    display: grid; 
    grid-template-columns: 260px 1fr; 
    min-height: 100vh; 
}

aside {
    background: #ffffff; 
    color: var(--text);
    padding: 20px 0; 
    display: flex; 
    flex-direction: column;
    border-right: 1px solid var(--line);
}

.brand { 
    font-weight: 700; 
    font-size: 1.3rem; 
    margin-bottom: 20px; 
    padding: 0 20px;
    color: var(--teal-dark); 
    font-family: "Segoe UI", sans-serif;
}

.user-welcome { 
    margin-bottom: 20px; 
    padding: 0 20px 15px 20px; 
    border-bottom: 1px solid var(--line); 
}

.user-welcome #user-name {
    font-weight: 600;
    color: var(--text);
}

.small-slug { 
    display: block; 
    font-size: 0.8rem; 
    color: var(--muted); 
}

.menu-section-title {
    padding: 15px 20px 5px 20px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#menu a {
    padding: 10px 20px;
    display: block;
    color: var(--text);
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

#menu a:hover {
    background: #f3f2f1;
    color: var(--primary-hover);
}

.logout-link { 
    color: var(--danger) !important; 
    margin-top: auto; 
}

.logout-link:hover {
    background: #fde7e9 !important;
}

/* AREA MAIN CONTENT */
main { 
    flex: 1;
    padding: 20px; 
    background: var(--bg);
    overflow-y: auto;
    display: flex; 
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
}

header {
    background: var(--panel); 
    padding: 15px 20px;
    display: flex; 
    align-items: center; 
    gap: 15px;
    border-bottom: 1px solid var(--line);
    position: sticky; 
    top: 0; 
    z-index: 100;
    margin-bottom: 20px;
}

#content { 
    padding: 0; 
    flex: 1; 
    width: 100%;
}

/* GESTIONE VISIBILITÀ VIDEATE DI NAVIGAZIONE */
.screen { 
    display: none !important; 
    width: 100%;
    margin-top: 0;
    padding-top: 0;
}

.screen.active { 
    display: block !important; 
    animation: fadeIn 0.15s ease; 
}

@keyframes fadeIn { 
    from { opacity: 0; } 
    to { opacity: 1; } 
}

/* CARDS RESPONSIVE CON OMBREGGIATURA SOTTILE MICROSOFT */
.card {
    background: var(--panel); 
    padding: clamp(15px, 3vw, 25px); 
    border-radius: var(--radius); 
    box-shadow: 0 1.6px 3.6px 0 rgba(0,0,0,0.11), 0 0.3px 0.9px 0 rgba(0,0,0,0.13);
    border: 1px solid var(--line);
    margin-bottom: 20px;
    width: 100%;
    max-width: 100%;
    overflow: hidden; 
}

/* ACTIVITY TILES INTEGRATI (Rettangoli di Stato e Collegamenti Veloci) */
.activity-tile {
    background-color: var(--teal-dark);
    color: #ffffff;
    padding: 16px;
    border-radius: 2px;
    min-height: 95px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: background-color 0.15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.activity-tile:hover {
    background-color: var(--teal-light);
}

.activity-tile .tile-number {
    font-size: 28px;
    font-weight: 300;
    line-height: 1.1;
    font-family: "Segoe UI", sans-serif;
}

.activity-tile .tile-label {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.95;
    letter-spacing: 0.3px;
}

/* GRIGLIE INPUT COERENTI CON PROTEZIONE DA FUORIUSCITA */
.form-grid {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 
    gap: 15px; 
    margin-bottom: 15px;
    width: 100%;
}

.form-group {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
}

.form-group label { 
    display: block; 
    font-weight: 600; 
    margin-bottom: 5px; 
    color: var(--muted); 
    font-size: 0.85rem;
    white-space: normal; 
}

input, select, textarea {
    width: 100%; 
    padding: 10px 12px; 
    border: 1px solid #cbd5e0;
    border-radius: var(--radius); 
    font-size: 14px;
    color: var(--text);
    background-color: #ffffff;
    max-width: 100%;
    box-sizing: border-box;
    font-family: "Segoe UI", sans-serif;
    transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    outline: none;
}

textarea {
    resize: vertical;
}

.input-group { 
    display: flex; 
    gap: 8px;
    width: 100%;
}

.input-group input {
    flex: 1;
    min-width: 0; 
}

.input-group button {
    background: #605e5c; 
    color: white; 
    border: none;
    padding: 0 15px; 
    border-radius: var(--radius); 
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}

.input-group button:hover {
    background: #484644;
}

/* STRUTTURA TABELLE REGISTRO E ARCHIVI DATI */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
}

th {
    background-color: #f3f2f1 !important;
    color: var(--muted) !important;
    font-size: 12px;
    font-weight: 700;
/*     text-transform: uppercase; */
    padding: 10px 12px;
    border-bottom: 2px solid var(--line);
    font-family: "Segoe UI", sans-serif;
}

td {
    padding: 12px;
    font-size: 14px;
    color: var(--text);
    border-bottom: 1px solid var(--line);
}

tr:hover td {
    background-color: #faf9f8;
}

/* STRUTTURA BOTTONI PERFETTAMENTE PARITARI E GEOMETRICI */
.flex-button-container {
    display: flex;
    gap: 12px;
    margin-top: 15px;
    width: 100%;
    flex-wrap: wrap; 
}

.flex-button-container button,
.footer-action-bar .buttons-group button {
    flex: 1;
    min-width: 140px; 
    margin: 0 !important;
    box-sizing: border-box;
}

.footer-action-bar {
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 15px; 
    margin-top: 25px; 
    padding-top: 15px; 
    border-top: 1px solid var(--line);
    flex-wrap: wrap; 
    width: 100%;
}

.footer-action-bar .switch-group {
    display: flex; 
    align-items: center; 
    gap: 15px;
}

.footer-action-bar .buttons-group {
    display: flex; 
    gap: 12px;
    flex-wrap: wrap;
    flex: 1;
    justify-content: flex-end;
}

/* BOTTONI CON PARITÀ DIMENSIONALE ED ALTEZZA STANDARDIZZATA */
.btn-save {
    background: var(--primary); 
    color: white;
    border: 1px solid var(--primary); 
    padding: 10px 20px; 
    border-radius: var(--radius);
    font-size: 14px; 
    font-weight: 600; 
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.15s ease;
}

.btn-save:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-cancel {
    background: #ffffff; 
    color: var(--text); 
    border: 1px solid #cbd5e0;
    padding: 10px 20px; 
    border-radius: var(--radius); 
    font-size: 14px; 
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.15s ease;
}

.btn-cancel:hover {
    background: #f3f2f1;
    border-color: #a19f9d;
}

/* INTERFACCIA RIGHE TABELLA IN PERFETTO STILE NATIVO BUSINESS CENTRAL */
.btn-modifica-modern {
    background: transparent;
    color: var(--text);
    border: none;
    padding: 6px 12px;
    border-radius: 2px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.1s ease, color 0.1s ease;
}

.btn-modifica-modern:hover {
    background-color: #edebe9;
    color: var(--primary);
}

.btn-elimina-modern {
    background: transparent;
    color: var(--text);
    border: none;
    padding: 6px 12px;
    border-radius: 2px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.1s ease, color 0.1s ease;
}

.btn-elimina-modern:hover {
    background-color: #fde7e9;
    color: var(--danger);
}

.btn-icon-minimal {
    font-size: 11px;
    line-height: 1;
    font-weight: normal;
    color: var(--muted);
}

.btn-modifica-modern:hover .btn-icon-minimal {
    color: var(--primary);
}

.btn-elimina-modern:hover .btn-icon-minimal {
    color: var(--danger);
}

/* MODALE SCANNER TELECAMERA */
.modal {
    display: none; 
    position: fixed; 
    z-index: 9999; 
    left: 0; top: 0; width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.4); 
    align-items: center;    
    justify-content: center; 
}

.modal-content {
    background-color: #ffffff;
    padding: 25px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    width: 95%;
    max-width: 500px;
    height: auto;           
    max-height: 85vh;       
    overflow-y: auto;       
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    position: relative;
    display: flex;          
    flex-direction: column;
}

#reader { 
    width: 100%;
    flex: 1; 
}

/* MEDIA QUERIES TABLET ED AMPI SCHERMI */
@media (max-width: 1024px) {
    .app { 
        display: block !important; 
    }

    #sidebar {
        position: fixed !important;
        top: 0; bottom: 0; left: -260px !important;
        width: 260px; height: 100vh;
        background: #ffffff;
        z-index: 99999 !important;
        transition: left 0.25s ease-in-out;
        display: flex !important;
        padding-top: 20px;
    }

    #sidebar.active {
        left: 0 !important;
        box-shadow: 0 0 40px rgba(0,0,0,0.15) !important;
    }

    main {
        margin-left: 0 !important;
        width: 100%;
        padding: 15px;
    }
}

/* DISPOSIZIONE VERTICALE COMPLETA PER SMARTPHONE */
@media (max-width: 580px) {
    .flex-button-container, .footer-action-bar, .footer-action-bar .buttons-group {
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: center !important;
        width: 100% !important;
        gap: 10px !important;
    }
    
    .flex-button-container button, .footer-action-bar .buttons-group button {
        width: 100% !important;
        flex: none !important;
    }

    .footer-action-bar .switch-group {
        width: 100%;
        justify-content: space-between;
        margin-bottom: 5px;
    }
}

.menu-trigger {
    background: var(--teal-dark); 
    color: white; 
    border: none;
    padding: 10px 15px; 
    border-radius: var(--radius); 
    font-weight: 600;
    cursor: pointer;
    font-family: "Segoe UI", sans-serif;
    transition: background-color 0.15s ease;
}

.menu-trigger:hover {
    background: var(--teal-light);
}

.log-container {
    padding: 10px 20px; 
    background: #201f1e; 
    color: #00ff00;
    font-family: monospace; 
    font-size: 0.8rem; 
    max-height: 100px; 
    overflow-y: auto;
    border-radius: var(--radius);
}

/* SWITCH BLU STRUTTURATO */
.switch-custom-blue {
    position: relative;
    display: inline-block;
    width: 85px;
    height: 38px;
    flex-shrink: 0;
}

.switch-custom-blue input {
    opacity: 0; width: 0; height: 0;
}

.slider-custom-blue {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ffffff;
    border: 3px solid var(--primary); 
    border-radius: 38px;
    transition: .3s;
}

.slider-custom-blue:before {
    position: absolute; content: "";
    height: 26px; width: 26px; right: 4px; bottom: 3px;
    background-color: var(--primary);
    border-radius: 50%;
    transition: .3s;
}

.slider-custom-blue:after {
    content: "ON";
    position: absolute;
    color: var(--primary);
    font-family: "Segoe UI", Arial, sans-serif;
    font-weight: bold;
    font-size: 16px;
    left: 12px; top: 4px;
    transition: .3s;
}

.switch-custom-blue input:not(:checked) + .slider-custom-blue {
    border-color: #cbd5e0;
}

.switch-custom-blue input:not(:checked) + .slider-custom-blue:after {
    content: "OFF";
    color: #a19f9d;
    left: auto; right: 12px;
}

.switch-custom-blue input:not(:checked) + .slider-custom-blue:before {
    transform: translateX(-43px);
    background-color: #a19f9d;
}
@keyframes modalFadeIn {
                            from { opacity: 0; transform: translateY(-20px); }
                            to { opacity: 1; transform: translateY(0); }
                            
                        }
@keyframes modalCenArtFadeIn {
                    from { opacity: 0; transform: translateY(-20px); }
                    to { opacity: 1; transform: translateY(0); }
                }
@keyframes modalDepFadeIn {
                            from { opacity: 0; transform: translateY(-20px); }
                            to { opacity: 1; transform: translateY(0); }
                        }