/* =========================================
   1. STILI BASE E VARIABILI
========================================= */
html, body { 
    font-family: 'Roboto', sans-serif; 
    background: linear-gradient(135deg, #1A73E8, #D93025) fixed; 
    margin: 0; 
    padding: 0;
    min-height: 100dvh;
    color: white;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

/* =========================================
   2. GESTIONE VISTE (LOGIN vs WORKSPACE)
========================================= */
#login-view {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    box-sizing: border-box;
    padding: calc(env(safe-area-inset-top, 0px) + 2vh) 15px calc(env(safe-area-inset-bottom, 0px) + 2vh) 15px;
    gap: clamp(10px, 3vh, 35px);
}

body.workspace-active { overflow: hidden; }
body.workspace-active #login-view { display: none !important; }

#workspace-view {
    display: none;
    width: 100vw;
    height: 100dvh;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    background-color: #1A73E8;
    overscroll-behavior-y: contain;
}
body.workspace-active #workspace-view { display: block !important; }
#iframe-container { width: 100%; height: 100%; background: #F8F9FA; }
#iframe-container iframe { width: 100%; height: 100%; border: none; display: none; }
#iframe-container iframe.is-active { display: block; }

/* =========================================
   3. LOGO E INTESTAZIONE
========================================= */
.header {
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    flex-shrink: 1;
}

.main-logo {
    max-width: 220px;
    width: auto;
    height: clamp(60px, 15vh, 160px); 
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
}

.secret-lock { 
    color: rgba(255, 255, 255, 0.2); 
    margin-bottom: 5px; 
    cursor: pointer; 
    display: none !important; 
}
.secret-lock.is-visible { display: inline-block !important; }

.header h1 { margin: 1vh 0 0 0; font-size: clamp(18px, 3vh, 32px); text-shadow: 0 2px 6px rgba(0,0,0,0.4); }
.header p { margin: 5px 0 0 0; font-size: clamp(12px, 1.5vh, 16px); opacity: 0.9; }

/* =========================================
   4. BOX LOGIN
========================================= */
.login-bar { 
    background: rgba(255, 255, 255, 0.15); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: clamp(15px, 2vh, 25px); 
    border-radius: 16px; 
    box-shadow: 0 8px 32px rgba(0,0,0,0.25); 
    display: flex; 
    flex-direction: column; 
    align-items: center;
    width: 100%;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-sizing: border-box;
    flex-shrink: 0;
    margin: 0;
    gap: clamp(10px, 1.5vh, 15px);
}

.login-bar input[type="email"],
.login-bar input[type="text"],
.login-bar input[type="password"] { 
    width: 100%;
    padding: clamp(10px, 1.5vh, 15px); 
    border: 1px solid rgba(255, 255, 255, 0.4); 
    border-radius: 8px; 
    outline: none; 
    font-size: 15px; 
    background: rgba(255, 255, 255, 0.95); 
    color: #333;
    box-sizing: border-box;
}

.remember-wrapper {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    color: white; font-size: 14px; cursor: pointer; width: 100%;
}
.remember-wrapper input[type="checkbox"] { width: 18px; height: 18px; margin: 0; cursor: pointer; }

.action-btn.sync-btn {
    width: 100%;
    background: #0d6efd; color: white; border: none; 
    padding: clamp(12px, 1.5vh, 16px); 
    border-radius: 8px; cursor: pointer; font-weight: bold; 
    font-size: 15px; text-transform: uppercase;
    display: flex; justify-content: center; align-items: center;
}

/* =========================================
   5. GRIGLIA APP
========================================= */
.apps-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 900px;
    gap: clamp(10px, 2vh, 20px);
    flex-shrink: 1;
    margin: 0;
    padding: 0;
}

.app-btn { 
    border-radius: 20px; 
    flex: 0 0 calc(50% - 10px); 
    height: clamp(75px, 13vh, 140px); 
    display: flex; flex-direction: column; cursor: pointer; 
    overflow: hidden; border: 1px solid rgba(255,255,255,0.3); 
    padding: 0; box-shadow: 0 10px 25px rgba(0,0,0,0.2); box-sizing: border-box;
    transition: transform 0.2s;
}
.app-btn:hover { transform: translateY(-5px); border-color: rgba(255,255,255,0.8); }

.bg-squadre { background: linear-gradient(145deg, #fd7e14, #d96408); }
.bg-hr { background: linear-gradient(145deg, #20c997, #179b74); }
.bg-magazzino { background: linear-gradient(145deg, #198754, #12653e); }
.bg-telefonia { background: linear-gradient(145deg, #dc3545, #b02a37); }
.bg-mail { background: linear-gradient(145deg, #6f42c1, #4e2a84); }
.bg-planning { background: linear-gradient(145deg, #0284c7, #0369a1); color: white; }
.bg-avanzamento { background: linear-gradient(145deg, #7c3aed, #5b21b6); color: white; }
.bg-fineturni { background: linear-gradient(145deg, #0d9488, #0f766e); color: white; }
.bg-permesso { background: #eab308; color: white; }
.bg-ricevute { background: #10b981; color: white; }

.app-btn .icon-area { flex: 1; display: flex; justify-content: center; align-items: center; color: white; }
.app-btn .icon-area svg, .app-btn .icon-area i {
    width: clamp(26px, 4.5vh, 50px); height: clamp(26px, 4.5vh, 50px); font-size: clamp(26px, 4.5vh, 50px);
}
.app-btn .label-area { 
    height: clamp(30px, 4vh, 50px); 
    color: white; display: flex; justify-content: center; align-items: center; 
    font-weight: bold; font-size: clamp(10px, 1.6vh, 15px); background: rgba(0,0,0,0.25); 
    text-transform: uppercase; letter-spacing: 1px;
}

.app-btn.app-hidden, .fab-app-btn.app-hidden { display: none !important; }
.app-btn.app-visible, .fab-app-btn.app-visible { display: flex !important; }

/* =========================================
   COMPORTAMENTO DESKTOP (PC/Tablet)
========================================= */
@media (min-width: 768px) {
    .login-bar { max-width: 800px; flex-direction: row; flex-wrap: nowrap; }
    .login-bar input[type="email"], .login-bar input[type="text"], .login-bar input[type="password"] { margin-bottom: 0; width: auto; flex: 1; }
    .remember-wrapper { width: auto; margin-bottom: 0; }
    .action-btn.sync-btn { width: auto; flex-shrink: 0; }
    .app-btn { flex: 0 0 calc(33.333% - 14px); }
}

/* =========================================
   6. MENU FLUTTUANTE (FAB)
========================================= */
.app-switcher-fab { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 20px; z-index: 9999; display: flex; flex-direction: column-reverse; align-items: center; gap: 15px; pointer-events: none; }
.fab-main-btn { width: 60px; height: 60px; border-radius: 50%; background: #0d6efd; color: white; font-size: 24px; border: none; box-shadow: 0 4px 15px rgba(0,0,0,0.3); cursor: pointer; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.fab-menu { display: flex; flex-direction: column; gap: 12px; opacity: 0; pointer-events: none; transform: translateY(20px); transition: all 0.3s; }
.app-switcher-fab.active-menu .fab-menu { opacity: 1; pointer-events: auto; transform: translateY(0); }
.fab-app-btn { width: 48px; height: 48px; border-radius: 50%; border: none; color: white; font-size: 18px; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center; position: relative; }
.bg-dark { background: #343a40; }
.fab-app-btn::before { content: attr(data-label); position: absolute; left: 60px; top: 50%; transform: translateY(-50%); background: #fff; color: #333; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: bold; white-space: nowrap; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border: 1px solid #eee; }

#fab-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9998;
    display: none;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    cursor: pointer;
}
#fab-backdrop.is-active { display: block; }

/* =========================================
   7. MODALI E MESSAGGI ERRORE
========================================= */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.75); align-items: center; justify-content: center; z-index: 9999; backdrop-filter: blur(8px); }
.modal.is-open { display: flex; }
.modal-content { background: white; color: #333; padding: 30px; border-radius: 20px; width: 90%; max-width: 450px; text-align: center; box-shadow: 0 25px 60px rgba(0,0,0,0.6); }
.action-btn { background: #198754; color: white; border: none; padding: 14px 20px; border-radius: 8px; cursor: pointer; font-weight: bold; width: 100%; text-transform: uppercase; margin-bottom: 10px; }
.action-btn.cancel-btn { background: #6c757d; margin-bottom: 0; }
.btn-danger-action { background: #dc3545; }
#errorMsg { color: white; background: rgba(220, 53, 69, 0.95); padding: 14px 20px; border-radius: 8px; font-weight: bold; margin-bottom: 20px; display: none; }
#errorMsg.is-active { display: block; }

.modal-title-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}
.modal-title-wrap svg { margin-right: 10px; }
.modal-title-blue { color: #0d6efd; }
.modal-title-red { color: #dc3545; }

.admin-modal-content {
    width: fit-content;
    min-width: min(92vw, 720px);
    max-width: 95vw;
    height: auto;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.admin-modal-desc { margin-bottom: 15px; font-size: 14px; }
.perm-table-container {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid #eee;
    border-radius: 8px;
}
.perm-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.perm-table thead { background: #f8f9fa; position: sticky; top: 0; z-index: 1; }
.perm-table th { padding: 12px; border-bottom: 2px solid #ddd; white-space: nowrap; }
.perm-table td { padding: 10px; border-bottom: 1px solid #eee; white-space: nowrap; }
.perm-cell-center { text-align: center; }
.perm-user-email { font-weight: bold; color: #333; }
.mt-20 { margin-top: 20px; }
.p-20 { padding: 20px; }
.text-danger { color: #dc3545; }

/* =========================================
   FIX DEFINITIVO: SPREMITURA NO-SCROLL (PIXEL & iOS)
========================================= */
html, body {
    height: 100dvh !important;
    overflow: hidden !important; 
}

#login-view {
    height: 100dvh !important;
    justify-content: space-evenly !important;
    padding: calc(env(safe-area-inset-top, 0px) + 1vh) 15px calc(env(safe-area-inset-bottom, 0px) + 2vh) 15px !important;
    gap: 1vh !important;
}

.header { margin: 0 !important; gap: 0 !important; }
.main-logo { height: clamp(30px, 11vh, 120px) !important; }
.header h1 { font-size: clamp(16px, 2.5vh, 26px) !important; margin-top: 1vh !important; }

.login-bar {
    padding: clamp(10px, 2vh, 20px) !important;
    gap: 1.5vh !important;
    margin: 0 !important;
    position: relative !important;
    transform: translateZ(0) !important; 
    isolation: isolate !important;
}
.login-bar input[type="email"], 
.login-bar input[type="password"] {
    padding: clamp(8px, 1.5vh, 14px) !important;
    position: relative !important;
    z-index: 2 !important;
}
.action-btn.sync-btn {
    padding: clamp(10px, 1.5vh, 15px) !important;
}

.apps-grid {
    gap: clamp(8px, 1.5vh, 15px) !important;
    display: none !important;
}
body.show-apps .apps-grid {
    display: flex !important;
}

.app-btn { height: clamp(50px, 11vh, 130px) !important; }
.app-btn .icon-area svg, .app-btn .icon-area i {
    height: clamp(20px, 4vh, 45px) !important;
    width: clamp(20px, 4vh, 45px) !important;
    font-size: clamp(20px, 4vh, 45px) !important;
}
.app-btn .label-area {
    height: clamp(22px, 3.5vh, 40px) !important;
    font-size: clamp(9px, 1.3vh, 14px) !important;
}

input::-webkit-credentials-auto-fill-button {
    position: absolute !important;
    right: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 3 !important;
}

.login-bar > div:not(.remember-wrapper) {
    position: absolute !important;
    right: 20px !important;
    z-index: 10 !important;
    width: auto !important;
    height: auto !important;
}

.app-switcher-fab {
    right: auto !important;
    left: calc(15px + env(safe-area-inset-left, 0px)) !important;
}

.fab-app-btn::before {
    right: auto !important;
    left: 60px !important;
}

@media (min-width: 768px) {
    .login-bar {
        max-width: 850px !important;
        padding: 25px 30px !important;
        gap: 20px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        justify-content: space-between !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
    }
}

.modal-content input { 
    width: 100% !important; 
    padding: 14px !important; 
    margin-bottom: 20px !important; 
    border: 1px solid #ccc !important; 
    border-radius: 8px !important; 
    box-sizing: border-box !important; 
    font-size: 15px !important; 
    outline: none !important; 
}
.modal-content input:focus { border-color: #1A73E8 !important; }

/* =========================================
   SWITCH (Permessi Matrice)
========================================= */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #0d6efd; }
input:checked + .slider:before { transform: translateX(20px); }
.disabled-toggle { width: 44px; height: 24px; background-color: #e9ecef; border-radius: 24px; position: relative; display: inline-block; cursor: not-allowed; opacity: 0.5; margin: 0 auto; }
.disabled-toggle:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: #adb5bd; border-radius: 50%; }

.action-btn.sync-btn {
    background: transparent !important;
    color: rgba(255, 255, 255, 0.7) !important;
    border: none !important;
    box-shadow: none !important;
    font-size: 13px !important;
    text-transform: none !important;
    font-weight: 400 !important;
    padding: 5px 10px !important;
    margin: 0 !important;
    width: auto !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    cursor: pointer;
}
.action-btn.sync-btn:hover {
    color: #ffffff !important;
    text-decoration: underline !important;
    background: transparent !important;
}
.action-btn.sync-btn svg {
    width: 16px !important;
    height: 16px !important;
    margin-right: 6px !important;
}

/* =========================================
   8. CALENDARIO E MODALI PLANNING
========================================= */
.modal-top {
    z-index: 10001 !important;
}

.calendar-modal-content {
    background: #ffffff;
    width: fit-content;
    min-width: min(92vw, 900px);
    max-width: 95vw;
    height: auto;
    max-height: 92dvh;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header-clean {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid #e9ecef;
}

.modal-title-clean {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    color: #0284c7;
}

.modal-close-clean {
    font-size: 20px;
    color: #6c757d;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close-clean:hover {
    color: #212529;
}

.modal-body-clean {
    padding-top: 15px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.calendar-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.calendar-title-text {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cal-nav-btn {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    color: #334155;
    transition: all 0.2s;
}

.cal-nav-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.calendar-wrapper {
    width: 100%;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    background: #cbd5e1;
    gap: 1px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
}

.calendar-day-header {
    font-weight: 700;
    text-align: center;
    padding: 10px 0;
    background: #f8fafc;
    font-size: 12px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.calendar-day {
    min-height: 85px;
    padding: 6px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    transition: background-color 0.15s;
}

.calendar-day.clickable-day {
    cursor: pointer;
}

.calendar-day.clickable-day:hover {
    background: #f0fdf4;
}

.calendar-day.empty {
    background: #f8fafc;
}

.calendar-day.today {
    background: #eff6ff;
}

.calendar-date-number {
    font-weight: 600;
    margin-bottom: 2px;
    display: block;
    text-align: right;
    color: #64748b;
    font-size: 12px;
}

.calendar-day.today .calendar-date-number {
    color: #0284c7;
    font-weight: 800;
}

.calendar-event {
    background: #0284c7;
    color: #ffffff;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    width: 100%;
    display: block;
    box-sizing: border-box;
    transition: filter 0.2s, transform 0.1s;
}

.calendar-event:hover {
    filter: brightness(1.12);
    transform: scale(1.02);
}

.planning-form-modal {
    max-width: 480px;
    width: 90%;
    text-align: left;
}

.planning-form-body {
    padding-top: 15px;
}

.planning-date-label {
    font-size: 13px;
    color: #475569;
    margin-top: 0;
    margin-bottom: 15px;
    font-weight: 600;
}

.form-group-planning {
    margin-bottom: 15px;
}

.form-group-last {
    margin-bottom: 22px;
}

.form-label-planning {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    display: block;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input-planning {
    width: 100% !important;
    padding: 12px 14px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    box-sizing: border-box !important;
    font-size: 14px !important;
    outline: none !important;
    margin-bottom: 0 !important;
    background: #ffffff !important;
    color: #0f172a !important;
}

.form-input-planning:focus {
    border-color: #0284c7 !important;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15) !important;
}

.planning-detail-modal {
    max-width: 440px;
    width: 90%;
    text-align: left;
}

.planning-detail-body {
    padding: 20px 0;
    font-size: 14px;
    line-height: 1.8;
    color: #1e293b;
}

.detail-row-item {
    margin-bottom: 10px;
}

.detail-label-bold {
    font-weight: 700;
    color: #334155;
}

.detail-highlight-time {
    color: #0284c7;
    font-weight: 700;
}

.detail-meta-author {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 15px;
    border-top: 1px solid #e2e8f0;
    padding-top: 8px;
}

.planning-detail-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.planning-delete-btn {
    margin-bottom: 0 !important;
}

.planning-delete-btn.is-hidden {
    display: none !important;
}

.planning-delete-btn.is-visible {
    display: block !important;
}

.planning-confirm-modal {
    max-width: 420px;
    width: 90%;
    text-align: center;
}

.planning-confirm-title {
    margin: 0 0 0 10px;
    font-size: 18px;
    font-weight: 700;
}

.planning-confirm-desc {
    font-size: 14px;
    color: #475569;
    margin-bottom: 24px;
    line-height: 1.6;
}

@media (max-width: 600px) {
    .calendar-day {
        min-height: 65px;
        padding: 4px;
    }
    .calendar-event {
        font-size: 10px;
        padding: 2px 4px;
    }
    .calendar-date-number {
        font-size: 11px;
    }
    .calendar-day-header {
        font-size: 11px;
        padding: 6px 0;
    }
}

/* Stili Modale Avanzamento Lavorazioni */
.avanzamento-modal-content {
    width: fit-content;
    min-width: min(92vw, 960px);
    max-width: 95vw;
    height: auto;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.avanzamento-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.modal-title-icon-avanzamento {
    color: #8b5cf6;
    margin-right: 8px;
}

.avanzamento-controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b;
    padding: 12px 18px;
    border-radius: 12px;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
    border: 1px solid #334155;
}

.avanzamento-month-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-ctrl-nav {
    background: #334155;
    color: #f8fafc;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-ctrl-nav:hover {
    background: #475569;
}

.avanzamento-select-group {
    display: flex;
    gap: 8px;
}

.avanzamento-select-group select {
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid #475569;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}

.avanzamento-select-group select:focus {
    border-color: #8b5cf6;
}

.btn-ctrl-today {
    background: #7c3aed;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-ctrl-today:hover {
    background: #6d28d9;
}

.avanzamento-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    color: #94a3b8;
    gap: 12px;
}

.avanzamento-charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    transition: opacity 0.2s ease-in-out;
}

.avanzamento-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
}

.avanzamento-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #334155;
}

.badge-brand {
    font-size: 13px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.badge-fc {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.badge-ced {
    background: rgba(14, 165, 233, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-total {
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
}

.avanzamento-card-content {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.chart-wrapper {
    position: relative;
    width: 200px;
    height: 200px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-empty-msg {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    color: #64748b;
    font-size: 12px;
    border: 2px dashed #334155;
    border-radius: 50%;
    padding: 10px;
}

.stats-side-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    background: rgba(15, 23, 42, 0.5);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #334155;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    background: #0f172a;
}

.stat-label-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ind-ok { background: #1E8E3E; }
.ind-ko { background: #D93025; }
.ind-migr { background: #17A2B8; }
.ind-cambio { background: #6610F2; }

.stat-name {
    font-size: 12px;
    font-weight: 500;
    color: #cbd5e1;
}

.stat-val-wrap {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.stat-num {
    font-size: 14px;
    font-weight: 700;
    color: #f8fafc;
}

.stat-pct {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
}

.stat-item-tot {
    border-top: 1px dashed #475569;
    margin-top: 4px;
    padding-top: 8px;
    background: transparent;
}

.stat-num-tot {
    color: #38bdf8;
}

@media (max-width: 820px) {
    .avanzamento-charts-grid {
        grid-template-columns: 1fr;
    }
    .avanzamento-card-content {
        flex-direction: column;
    }
    .chart-wrapper {
        width: 180px;
        height: 180px;
    }
    .stats-side-panel {
        width: 100%;
    }
}

/* Stili Scheda Obiettivi Mensili Avanzamento */
.avanzamento-goals-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 18px;
    margin-bottom: 20px;
}

.goals-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 10px;
}

.goals-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #f8fafc;
}

.goals-icon {
    color: #f59e0b;
}

.goals-tot-badge {
    background: rgba(30, 142, 62, 0.15);
    border: 1px solid rgba(30, 142, 62, 0.35);
    color: #4ade80;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.goals-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.goal-item-card {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s;
}

.goal-item-card.is-reached {
    border-color: rgba(30, 142, 62, 0.5);
    background: rgba(30, 142, 62, 0.08);
}

.goal-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: #cbd5e1;
}

.goal-target {
    color: #94a3b8;
    font-size: 11px;
}

.goal-progress-wrap {
    width: 100%;
    height: 8px;
    background: #334155;
    border-radius: 4px;
    overflow: hidden;
}

.goal-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #ec4899);
    border-radius: 4px;
    transition: width 0.4s ease-out;
}

.goal-item-card.is-reached .goal-progress-bar {
    background: linear-gradient(90deg, #1E8E3E, #22c55e);
}

.goal-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.goal-pct {
    color: #cbd5e1;
    font-size: 11px;
    font-weight: 600;
}

.status-missing {
    color: #f59e0b;
    font-size: 12px;
    font-weight: 600;
}

.status-reached {
    color: #4ade80;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 900px) {
    .goals-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 520px) {
    .goals-grid {
        grid-template-columns: 1fr;
    }
}

/* Modale e componenti del modulo Fine Turni */
.fineturni-modal-content {
    width: fit-content;
    min-width: min(92vw, 960px);
    max-width: 95vw;
    height: auto;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0f172a;
    color: #f8fafc;
    border-radius: 12px;
    border: 1px solid #334155;
    padding: 24px;
    box-sizing: border-box;
}

.modal-title-icon-fineturni {
    color: #14b8a6;
    margin-right: 10px;
}

.fineturni-controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #1e293b;
    border-radius: 8px;
    margin-bottom: 16px;
}

.fineturni-date-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fineturni-date-input {
    background: #0f172a;
    border: 1px solid #334155;
    color: #f8fafc;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
}

.fineturni-date-input:focus {
    outline: none;
    border-color: #14b8a6;
}

.fineturni-actions-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.fineturni-search-input {
    background: #0f172a;
    border: 1px solid #334155;
    color: #f8fafc;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    min-width: 180px;
    font-family: inherit;
}

.fineturni-search-input:focus {
    outline: none;
    border-color: #14b8a6;
}

.fineturni-stats-badge {
    background: #0f766e;
    color: #ccfbf1;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.fineturni-body {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

.fineturni-table-container {
    overflow-x: auto;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #1e293b;
}

.fineturni-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.fineturni-table th {
    background: #0f172a;
    color: #94a3b8;
    font-weight: 600;
    padding: 12px 14px;
    border-bottom: 1px solid #334155;
    position: sticky;
    top: 0;
    z-index: 2;
}

.fineturni-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #334155;
    vertical-align: middle;
}

.fineturni-table tr:hover {
    background: #253349;
}

.fineturni-emp-name {
    font-weight: 600;
    color: #f8fafc;
    display: flex;
    flex-direction: column;
}

.fineturni-emp-sub {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

.badge-status-completed {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(20, 184, 166, 0.15);
    color: #2dd4bf;
    border: 1px solid rgba(45, 212, 191, 0.4);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 12px;
}

.badge-status-pending {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(148, 163, 184, 0.1);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.2);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
    font-size: 12px;
}

.btn-pdf-view {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #dc2626;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-pdf-view:hover {
    background: #b91c1c;
}

.btn-pdf-disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: #475569;
    color: #94a3b8;
    pointer-events: none;
}

.btn-zip-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #0284c7;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-zip-download:hover {
    background: #0369a1;
}

.btn-zip-empty {
    opacity: 0.45;
    background: #334155;
    cursor: not-allowed;
}

.fineturni-hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .fineturni-modal-content {
        padding: 16px;
        width: 98%;
        max-height: 94vh;
    }

    .fineturni-controls-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .fineturni-date-selector {
        justify-content: space-between;
    }

    .fineturni-actions-group {
        flex-direction: column;
        align-items: stretch;
    }

    .fineturni-search-input {
        width: 100%;
        box-sizing: border-box;
    }

    .fineturni-table th, .fineturni-table td {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* Stili Tabella Riepilogo Percentuali in Avanzamento */
.avanzamento-riepilogo-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 18px;
    margin-top: 20px;
}

.riepilogo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.riepilogo-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #f8fafc;
}

.riepilogo-title i {
    color: #38bdf8;
}

.avanzamento-table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid #334155;
    background: #0f172a;
}

.avanzamento-riepilogo-table {
    width: 100%;
    border-collapse: collapse;
    color: #e2e8f0;
    font-size: 13px;
    min-width: 560px;
    white-space: nowrap;
}

.avanzamento-riepilogo-table th {
    padding: 12px 14px;
    border-bottom: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
    font-weight: 600;
}

.avanzamento-riepilogo-table th:last-child {
    border-right: none;
}

.avanzamento-riepilogo-table tr:last-child th {
    border-bottom: none;
}

.riep-col-label {
    text-align: left;
    min-width: 190px;
    background: #162032;
    color: #cbd5e1;
}

.riep-col-team {
    text-align: center;
    min-width: 130px;
}

.riep-dashed-top {
    border-top: 1px dashed #334155 !important;
}

.riep-align-top {
    vertical-align: top;
}

.riep-sub-muted {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
}

.riep-pct-muted {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
}

.riep-mini-muted {
    font-size: 10px;
    color: #94a3b8;
    font-weight: 500;
}

.riep-num-big {
    font-size: 22px;
    font-weight: 700;
    color: #f8fafc;
}

.riep-num-team {
    font-size: 19px;
    font-weight: 700;
    color: #f8fafc;
}

.riep-num-ok {
    font-size: 19px;
    font-weight: 700;
    color: #4ade80;
}

.riep-num-ok-sm {
    font-size: 15px;
    font-weight: 700;
    color: #4ade80;
}

.riep-num-fc {
    font-size: 16px;
    font-weight: 700;
    color: #60a5fa;
}

.riep-num-fc-sm {
    font-size: 14px;
    font-weight: 700;
    color: #60a5fa;
}

.riep-num-ced {
    font-size: 16px;
    font-weight: 700;
    color: #22d3ee;
}

.riep-num-ced-sm {
    font-size: 14px;
    font-weight: 700;
    color: #22d3ee;
}

.riep-num-ko {
    font-size: 19px;
    font-weight: 700;
    color: #f87171;
}

.riep-num-ko-sm {
    font-size: 14px;
    font-weight: 700;
    color: #f87171;
}

.riep-num-ko-xs {
    font-size: 12px;
    font-weight: 700;
    color: #f87171;
}

.riep-team-name {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 700;
    color: #f8fafc;
    display: block;
    margin-bottom: 5px;
}

.riep-ko-main {
    margin-bottom: 8px;
}

.riep-ko-split {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid #334155;
    padding-top: 8px;
}

.riep-ko-split-center {
    justify-content: space-around;
    gap: 6px;
}

.d-block {
    display: block;
}

@media (max-width: 768px) {
    .admin-modal-content,
    .calendar-modal-content,
    .avanzamento-modal-content,
    .fineturni-modal-content {
        width: 96vw;
        min-width: 0;
        max-width: 96vw;
        max-height: 94dvh;
        padding: 16px;
    }
}

/* =========================================
   SWITCH TEMA CHIARO / SCURO MODALI
   ========================================= */
.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-theme-toggle {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(148, 163, 184, 0.14);
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background-color 0.2s, transform 0.15s;
}

.modal-theme-toggle:hover {
    background: rgba(148, 163, 184, 0.28);
    transform: scale(1.05);
}

/* Tema Scuro per Planning */
body[data-modal-theme="dark"] .calendar-modal-content,
body[data-modal-theme="dark"] .planning-form-modal,
body[data-modal-theme="dark"] .planning-detail-modal,
body[data-modal-theme="dark"] .planning-confirm-modal {
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid #334155;
}

body[data-modal-theme="dark"] .calendar-modal-content .modal-header-clean,
body[data-modal-theme="dark"] .planning-form-modal .modal-header-clean,
body[data-modal-theme="dark"] .planning-detail-modal .modal-header-clean,
body[data-modal-theme="dark"] .planning-confirm-modal .modal-header-clean {
    border-bottom-color: #334155;
}

body[data-modal-theme="dark"] .calendar-modal-content .modal-title-clean,
body[data-modal-theme="dark"] .planning-form-modal .modal-title-clean,
body[data-modal-theme="dark"] .planning-detail-modal .modal-title-clean,
body[data-modal-theme="dark"] .calendar-title-text,
body[data-modal-theme="dark"] .planning-detail-body {
    color: #f8fafc;
}

body[data-modal-theme="dark"] .cal-nav-btn {
    background: #1e293b;
    color: #f8fafc;
    border-color: #334155;
}

body[data-modal-theme="dark"] .calendar-grid {
    background: #334155;
    border-color: #334155;
}

body[data-modal-theme="dark"] .calendar-day-header {
    background: #1e293b;
    color: #94a3b8;
}

body[data-modal-theme="dark"] .calendar-day {
    background: #0f172a;
}

body[data-modal-theme="dark"] .calendar-day.empty {
    background: #162033;
}

body[data-modal-theme="dark"] .calendar-day.today {
    background: rgba(2, 132, 199, 0.18);
}

body[data-modal-theme="dark"] .calendar-day.clickable-day:hover {
    background: rgba(16, 185, 129, 0.14);
}

body[data-modal-theme="dark"] .calendar-date-number,
body[data-modal-theme="dark"] .planning-date-label,
body[data-modal-theme="dark"] .form-label-planning,
body[data-modal-theme="dark"] .detail-label-bold,
body[data-modal-theme="dark"] .planning-confirm-desc {
    color: #cbd5e1;
}

body[data-modal-theme="dark"] .form-input-planning {
    background: #1e293b !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

body[data-modal-theme="dark"] .detail-meta-author {
    border-top-color: #334155;
}

/* Tema Chiaro per Avanzamento e Fine Turni */
body[data-modal-theme="light"] .avanzamento-modal-content,
body[data-modal-theme="light"] .fineturni-modal-content {
    background: #ffffff;
    color: #0f172a;
    border-color: #cbd5e1;
}

body[data-modal-theme="light"] .avanzamento-modal-content .modal-header-clean,
body[data-modal-theme="light"] .fineturni-modal-content .modal-header-clean {
    border-bottom-color: #e2e8f0;
}

body[data-modal-theme="light"] .avanzamento-modal-content .modal-title-clean,
body[data-modal-theme="light"] .fineturni-modal-content .modal-title-clean,
body[data-modal-theme="light"] .riep-num-big,
body[data-modal-theme="light"] .riep-num-team,
body[data-modal-theme="light"] .riep-team-name,
body[data-modal-theme="light"] .avanzamento-card-header,
body[data-modal-theme="light"] .goals-title,
body[data-modal-theme="light"] .riepilogo-title,
body[data-modal-theme="light"] .stat-num,
body[data-modal-theme="light"] .fineturni-emp-name {
    color: #0f172a;
}

body[data-modal-theme="light"] .avanzamento-controls-bar,
body[data-modal-theme="light"] .fineturni-controls-bar,
body[data-modal-theme="light"] .avanzamento-card,
body[data-modal-theme="light"] .avanzamento-goals-card,
body[data-modal-theme="light"] .avanzamento-riepilogo-card {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #0f172a;
}

body[data-modal-theme="light"] .avanzamento-card-header {
    border-bottom-color: #e2e8f0;
}

body[data-modal-theme="light"] .stats-side-panel {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

body[data-modal-theme="light"] .stat-item,
body[data-modal-theme="light"] .goal-item-card,
body[data-modal-theme="light"] .avanzamento-table-wrap,
body[data-modal-theme="light"] .fineturni-table-container {
    background: #ffffff;
    border-color: #cbd5e1;
}

body[data-modal-theme="light"] .stat-item-tot {
    background: transparent;
    border-top-color: #cbd5e1;
}

body[data-modal-theme="light"] .stat-name,
body[data-modal-theme="light"] .goal-item-top,
body[data-modal-theme="light"] .goal-pct {
    color: #1e293b;
}

body[data-modal-theme="light"] .stat-pct,
body[data-modal-theme="light"] .goal-target,
body[data-modal-theme="light"] .badge-total,
body[data-modal-theme="light"] .fineturni-emp-sub,
body[data-modal-theme="light"] .riep-sub-muted,
body[data-modal-theme="light"] .riep-pct-muted,
body[data-modal-theme="light"] .riep-mini-muted {
    color: #64748b;
}

body[data-modal-theme="light"] .stat-num-tot {
    color: #0284c7;
}

body[data-modal-theme="light"] .goal-progress-wrap {
    background: #e2e8f0;
}

body[data-modal-theme="light"] .goal-item-card.is-reached {
    background: rgba(22, 163, 74, 0.08);
    border-color: rgba(22, 163, 74, 0.4);
}

body[data-modal-theme="light"] .goals-tot-badge {
    background: rgba(22, 163, 74, 0.12);
    border-color: rgba(22, 163, 74, 0.35);
    color: #15803d;
}

body[data-modal-theme="light"] .status-reached,
body[data-modal-theme="light"] .riep-num-ok,
body[data-modal-theme="light"] .riep-num-ok-sm {
    color: #15803d;
}

body[data-modal-theme="light"] .status-missing {
    color: #d97706;
}

body[data-modal-theme="light"] .riep-num-fc,
body[data-modal-theme="light"] .riep-num-fc-sm {
    color: #2563eb;
}

body[data-modal-theme="light"] .riep-num-ced,
body[data-modal-theme="light"] .riep-num-ced-sm {
    color: #0891b2;
}

body[data-modal-theme="light"] .riep-num-ko,
body[data-modal-theme="light"] .riep-num-ko-sm,
body[data-modal-theme="light"] .riep-num-ko-xs {
    color: #dc2626;
}

body[data-modal-theme="light"] .chart-empty-msg {
    border-color: #cbd5e1;
}

body[data-modal-theme="light"] .btn-ctrl-nav,
body[data-modal-theme="light"] .avanzamento-select-group select,
body[data-modal-theme="light"] .fineturni-date-input,
body[data-modal-theme="light"] .fineturni-search-input {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #cbd5e1;
}

body[data-modal-theme="light"] .avanzamento-riepilogo-table {
    color: #0f172a;
}

body[data-modal-theme="light"] .avanzamento-riepilogo-table th,
body[data-modal-theme="light"] .avanzamento-riepilogo-table td,
body[data-modal-theme="light"] .fineturni-table th,
body[data-modal-theme="light"] .fineturni-table td {
    border-color: #e2e8f0;
    color: #0f172a;
}

body[data-modal-theme="light"] .riep-col-label {
    background: #f1f5f9;
    color: #1e293b;
}

body[data-modal-theme="light"] .fineturni-table th {
    background: #f1f5f9;
    color: #334155;
}

body[data-modal-theme="light"] .fineturni-table tr:hover {
    background: #f8fafc;
}

body[data-modal-theme="light"] .badge-status-completed {
    background: rgba(13, 148, 136, 0.12);
    color: #0f766e;
    border-color: rgba(13, 148, 136, 0.35);
}

body[data-modal-theme="light"] .badge-status-pending {
    background: #f1f5f9;
    color: #475569;
    border-color: #cbd5e1;
}

body[data-modal-theme="light"] .btn-pdf-disabled,
body[data-modal-theme="light"] .btn-zip-empty {
    background: #e2e8f0;
    color: #64748b;
}

body[data-modal-theme="light"] .riep-dashed-top,
body[data-modal-theme="light"] .riep-ko-split {
    border-color: #cbd5e1;
}
