/* Premium Dashboard Layout overrides */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --topbar-height: 80px;
    --nga-blue: #0f172a; 
    --nga-orange: #f97316;
    --bg-main: #f1f5f9;
    --shadow-soft: 0 4px 20px -2px rgba(0,0,0,0.04), 0 2px 8px -1px rgba(0,0,0,0.02);
    --shadow-heavy: 0 20px 40px -8px rgba(0,0,0,0.08), 0 8px 16px -4px rgba(0,0,0,0.04);
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.4);
}

body.d-flex {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(249, 115, 22, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(15, 23, 42, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    overflow-x: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width) !important;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(165deg, var(--nga-blue) 0%, #020617 100%) !important;
    box-shadow: 4px 0 30px rgba(0,0,0,0.2);
    overflow-x: hidden;
    position: relative;
}
.sidebar::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at 0% 0%, rgba(249, 115, 22, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width) !important;
}

body.sidebar-collapsed .sidebar .sidebar-text,
body.sidebar-collapsed .sidebar .user-card-details,
body.sidebar-collapsed .sidebar hr {
    display: none !important;
    opacity: 0;
}

body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding-left: 0 !important;
    padding-right: 0 !important;
}
body.sidebar-collapsed .sidebar .nav-link i {
    margin-right: 0 !important;
    font-size: 1.2rem;
}
.sidebar .nav-link {
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar .navbar-logo {
    margin-right: 0 !important;
    width: 35px !important;
    margin: 0 auto !important;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 100vh;
    padding: 0 !important; /* Topbar will handle top padding */
    display: flex;
    flex-direction: column;
}
body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 999;
}

.topbar-btn {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--nga-blue);
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}
.topbar-btn:hover {
    background: #f8fafc;
    color: var(--nga-orange);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Enhancing Cards globally */
.card-custom, .card-item, .stat-bar, .target-card, .login-card, .preventivo-sheet {
    border-radius: 20px !important;
    border: 1px solid var(--glass-border) !important;
    box-shadow: var(--shadow-soft) !important;
    background: var(--glass-bg) !important;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}
.card-item:hover, .card-custom:hover, .target-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-heavy) !important;
    border-color: var(--nga-orange) !important;
}

@media print {
    .preventivo-sheet, .card-custom, .card-item, .stat-bar {
        box-shadow: none !important;
        border-radius: 0 !important;
        border: none !important;
    }
}

/* Content Container */
.content-wrapper {
    padding: 2rem;
    flex-grow: 1;
}

/* Responsive Off-canvas */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        margin-left: 0 !important;
    }
    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
    }
    body.sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }
}

@media (max-width: 768px) {
    .content-wrapper {
        padding: 1rem;
    }
}

@media (max-width: 576px) {
    .content-wrapper {
        padding: 0.65rem;
    }

    /* Topbar: comprime il badge utente */
    .topbar {
        height: auto;
        min-height: 60px;
        padding-top: 8px;
        padding-bottom: 8px;
    }
    .topbar .px-4 {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Nasconde l'orologio realtime nell'assistente su mobile */
    #orologio-realtime {
        display: none !important;
    }

    /* Stat-bar: riduce ulteriormente */
    .stat-bar {
        padding: 12px 10px !important;
        gap: 8px !important;
    }
    .stat-value {
        font-size: 1.6rem !important;
    }

    /* Header pagina con titolo + bottone: wrap su mobile */
    .page-header-flex {
        flex-wrap: wrap !important;
        gap: 12px !important;
    }
    .page-header-flex .btn-premium {
        width: 100% !important;
        justify-content: center;
    }

    /* Registro header filtri: wrap */
    .registro-header-inner {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .registro-header-inner .d-flex.gap-1 {
        flex-shrink: 0;
    }
}

/* =========================================
   PREMIUM BUTTONS STANDARDIZATION
   ========================================= */
.btn-premium {
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    font-size: 0.85rem;
    text-decoration: none;
    line-height: 1.5;
}
.btn-premium:hover {
    transform: translateY(-3px);
}
.btn-premium-orange {
    background: linear-gradient(135deg, var(--nga-orange), #ff8533) !important;
    color: white !important;
    box-shadow: 0 6px 20px rgba(249,115,22,0.3) !important;
}
.btn-premium-orange:hover {
    box-shadow: 0 10px 25px rgba(249,115,22,0.45) !important;
}
.btn-premium-dark {
    background: linear-gradient(135deg, var(--nga-blue), #1e293b) !important;
    color: white !important;
    box-shadow: 0 6px 20px rgba(15,23,42,0.25) !important;
}
.btn-premium-dark:hover {
    box-shadow: 0 10px 25px rgba(15,23,42,0.4) !important;
}
.btn-premium-white {
    background: white !important;
    color: var(--nga-blue) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05) !important;
}
.btn-premium-white:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.08) !important;
    color: var(--nga-orange) !important;
}

/* Preview Specific Button */
.btn-preview {
    background: rgba(14, 165, 233, 0.1) !important;
    color: #0284c7 !important;
    border: 1px solid rgba(14, 165, 233, 0.2) !important;
}
.btn-preview:hover {
    background: #0284c7 !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3) !important;
}

/* Sync Button Animation */
#syncBtn:hover i {
    transform: rotate(180deg);
}
#syncBtn i {
    transition: transform 0.4s ease;
}

/* Smooth Image Preview */
#imageFrame {
    transition: opacity 0.3s ease;
    opacity: 0;
}
#imageFrame[src] {
    opacity: 1;
}

/* Safari Print Fixes */
@media print {
    .sidebar, .topbar, #sidebar-overlay, .sidebar-overlay, .no-print, .btn-premium { display: none !important; }
    .main-content { margin-left: 0 !important; width: 100% !important; }
    .content-wrapper { padding: 0 !important; margin: 0 !important; }
    .card-custom { box-shadow: none !important; border: 1px solid #eee !important; }
}

/* =========================================
   ANIMAZIONI CARD FADE-IN + SLIDE-UP
   ========================================= */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(22px); }
    to   { opacity: 1; transform: translateY(0); }
}
.card-custom, .card-item, .target-card, .stat-bar {
    animation: fadeSlideUp 0.45s cubic-bezier(0.16,1,0.3,1) both;
}
.row.g-4 > [class*="col-"]:nth-child(1) .card-custom { animation-delay: 0.04s; }
.row.g-4 > [class*="col-"]:nth-child(2) .card-custom { animation-delay: 0.10s; }
.row.g-4 > [class*="col-"]:nth-child(3) .card-custom { animation-delay: 0.16s; }
.row.g-4 > [class*="col-"]:nth-child(4) .card-custom { animation-delay: 0.22s; }

/* Dashboard Entrances */
.stat-bar { animation-delay: 0.05s; }
.card-custom { animation-delay: 0.1s; }
.table-responsive { animation: fadeSlideUp 0.6s ease-out both; animation-delay: 0.2s; }

/* =========================================
   TABELLA ZEBRATA REPORT
   ========================================= */
.table-registro tbody tr:nth-child(even) {
    background: #f8fafc;
}
.table-registro tbody tr {
    transition: background 0.15s ease;
}
.table-registro tbody tr:hover {
    background: #fff4ec !important;
}

/* =========================================
   AVATAR CONSULENTE
   ========================================= */
.consultant-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 800;
    color: white;
    margin-right: 8px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.av-orange { background: linear-gradient(135deg, #f97316, #ea580c); }
.av-blue   { background: linear-gradient(135deg, #0ea5e9, #0284c7); }
.av-purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.av-teal   { background: linear-gradient(135deg, #14b8a6, #0d9488); }
.av-rose   { background: linear-gradient(135deg, #f43f5e, #e11d48); }
.av-lime   { background: linear-gradient(135deg, #84cc16, #65a30d); }

/* Autocomplete Suggestions */
.autocomplete-suggestions {
    position: absolute; top: 100%; left: 0; right: 0; background: white;
    border: 1px solid var(--border); border-radius: 0 0 12px 12px;
    z-index: 9999; display: none; margin-top: -10px; padding-top: 10px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); 
    max-height: 220px; overflow-y: auto; overflow-x: hidden;
}
.suggestion-item {
    padding: 10px 15px; cursor: pointer; font-size: 0.9rem;
    color: var(--dark); border-bottom: 1px solid #f1f5f9;
}
.suggestion-item:hover { background: #f8fafc; color: var(--nga-blue); font-weight: 600; }
.suggestion-item:last-child { border-bottom: none; }


/* =========================================
   MOBILE RESPONSIVENESS (ADVANCED)
   ========================================= */
@media (max-width: 991px) {
    .sidebar-overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px);
        z-index: 999; opacity: 0; visibility: hidden; transition: all 0.3s;
    }
    body.sidebar-mobile-open .sidebar-overlay { opacity: 1; visibility: visible; }
    
    .target-container { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    .target-card { padding: 15px 10px !important; }
    .circle-wrapper { width: 70px; height: 70px; }
    .target-actual { 
        top: 50%; left: 50%; transform: translate(-50%, -50%); 
        width: 100%; text-align: center;
        margin-top: 0;
    }
}


@media (max-width: 576px) {
    /* High-Density Mobile Table (User Reference Style) - FINAL STABILITY */
    .table-registro thead { display: table-header-group !important; }
    .table-registro thead th { 
        font-size: 0.62rem !important; 
        padding: 12px 4px !important; 
        text-transform: uppercase; 
        color: #94a3b8;
        background: #f8fafc;
        border-bottom: 2px solid #e2e8f0 !important;
        text-align: center;
    }
    
    /* Report Page: Show 2, 4, 5 | Hide 1, 3 */
    #report-page .table-registro th:nth-child(1), #report-page .table-registro td:nth-child(1),
    #report-page .table-registro th:nth-child(3), #report-page .table-registro td:nth-child(3) {
        display: none !important;
    }
    #report-page .table-registro td:nth-child(2), #report-page .table-registro th:nth-child(2) { display: table-cell !important; width: 50%; text-align: left !important; padding-left: 10px !important; font-weight: 700; color: #1e293b; }
    #report-page .table-registro td:nth-child(4), #report-page .table-registro th:nth-child(4) { display: table-cell !important; width: 35%; text-align: center !important; }
    #report-page .table-registro td:nth-child(5), #report-page .table-registro th:nth-child(5) { display: table-cell !important; width: 15%; text-align: right !important; padding-right: 10px !important; }

    /* Clienti Page: Show 1, 2 | Hide 3, 4 */
    #clienti-page .table-registro th:nth-child(3), #clienti-page .table-registro td:nth-child(3),
    #clienti-page .table-registro th:nth-child(4), #clienti-page .table-registro td:nth-child(4) {
        display: none !important;
    }
    #clienti-page .table-registro td:nth-child(1), #clienti-page .table-registro th:nth-child(1) { display: table-cell !important; width: 70%; text-align: left !important; padding-left: 15px !important; font-weight: 700; color: var(--nga-blue); }
    #clienti-page .table-registro td:nth-child(2), #clienti-page .table-registro th:nth-child(2) { display: table-cell !important; width: 30%; text-align: center !important; }

    .table-registro { table-layout: fixed !important; width: 100% !important; border-collapse: collapse !important; border: none !important; }
    .table-registro tbody tr { border-bottom: 1px solid #f1f5f9 !important; background: #fff !important; }
    
    .table-registro td { 
        padding: 14px 2px !important; 
        vertical-align: middle !important;
        font-size: 0.78rem;
        line-height: 1.2;
    }
    
    .table-registro td:before { display: none !important; }

    .badge-custom, .badge { font-size: 0.6rem !important; padding: 4px 7px !important; white-space: nowrap; }
    
    /* Layout tweaks */
    .stat-bar { padding: 15px 10px !important; }
    .stat-label { font-size: 0.6rem; }
    .stat-value { font-size: 1.4rem !important; }
    .card-custom [style*="min-height: 220px"] { min-height: 200px !important; }
    
    /* Icons spacing */
    #report-page .table-registro td:last-child a, 
    #report-page .table-registro td:last-child button { margin: 0 3px !important; display: inline-block; }

    /* Performance Staff Ranking - High Density */
    .table-ranking thead th { font-size: 0.55rem !important; padding: 8px 2px !important; }
    .table-ranking td { padding: 8px 2px !important; font-size: 0.65rem !important; }
    .consultant-avatar { width: 22px !important; height: 22px !important; font-size: 8px !important; margin-right: 5px !important; }
    .total-pill { padding: 2px 6px !important; font-size: 0.65rem !important; }
}

/* Online Status Dot Animation */
.status-dot-online {
    animation: status-pulse 2s infinite;
}
@keyframes status-pulse {
    0% { box-shadow: 0 0 0 0 rgba(34,197,94, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(34,197,94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94, 0); }
}

