/* ============================================================
   NUJÈ CRM - GLOBAL STYLESHEET (DESKTOP & MOBILE TOUCH)
   ============================================================ */

:root {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --bg-dark: #0f172a;
    --sidebar-bg: #1e293b;
    --sidebar-border: #334155;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --bg-body: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

button, select, input, .radio-btn, .btn-filter-pill, .btn-table-action, .nav-item, .app-switcher-item {
    touch-action: manipulation;
    font-family: inherit;
}

/* ============================================================
   SIDEBAR A SCOMPARSA (MINI-BARRA 72px -> ESPANSIONE 250px)
   ============================================================ */
#sidebar {
    width: 72px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10000;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s;
    overflow: visible; /* Fondamentale per far uscire la tendina */
    white-space: nowrap;
    position: relative;
}

#sidebar:hover {
    width: 250px;
    box-shadow: 6px 0 25px rgba(0,0,0,0.35);
}

.sidebar-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--sidebar-border);
    cursor: pointer;
    position: relative;
    user-select: none;
    min-height: 68px;
    /* OVERFLOW HIDDEN ELIMINATO DA QUI PER SBLOCCARE LA TENDINA */
}

.sidebar-header img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #ffffff;
    padding: 2px;
    object-fit: contain;
    flex-shrink: 0;
}

.nav-label {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
}

#sidebar:hover .nav-label {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
}

.nav-menu {
    list-style: none;
    margin: 0;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.15s;
    overflow: hidden;
}

.nav-item:hover { background: #334155; color: #ffffff; }
.nav-item.active { background: var(--primary); color: #ffffff; }

.nav-icon {
    font-size: 20px;
    width: 26px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 12px 8px;
}

.app-switcher-dropdown {
    position: absolute;
    top: 72px;
    left: 8px;
    width: 234px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    box-shadow: 0 15px 30px rgba(0,0,0,0.6);
    display: none;
    flex-direction: column;
    padding: 8px;
    z-index: 20000;
}

.app-switcher-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 6px;
    color: #cbd5e1;
    text-decoration: none;
    transition: 0.15s;
}

.app-switcher-item:hover { background: #1e293b; color: #ffffff; }
.app-switcher-item img { width: 32px; height: 32px; border-radius: 6px; object-fit: contain; background: #ffffff; padding: 2px; }

/* ============================================================
   MAIN WRAPPER & TOPBAR
   ============================================================ */
#app-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }
#topbar { background: #ffffff; border-bottom: 1px solid var(--border-color); padding: 14px 25px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 500; }
.topbar-left { display: flex; align-items: center; gap: 15px; }
.topbar-title { font-size: 20px; font-weight: 800; color: #0f172a; letter-spacing: -0.5px; }
.btn-mobile-menu { display: none; background: transparent; border: none; font-size: 22px; cursor: pointer; color: #0f172a; padding: 4px; }
.topbar-controls { display: flex; align-items: center; gap: 14px; }
.user-badge { background: #f1f5f9; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #334155; border: 1px solid #cbd5e1; display: flex; align-items: center; gap: 6px; }
.btn-logout { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 700; cursor: pointer; transition: 0.15s; }
.btn-logout:hover { background: #fca5a5; }

/* ============================================================
   CONTAINERS E CARDS
   ============================================================ */
.main-content { padding: 25px; }
.content-container { max-width: 1400px; margin: 0 auto; }

.search-card { background: #ffffff; border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; display: flex; gap: 12px; align-items: center; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.02); }
.search-input { flex: 1; padding: 10px 14px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; outline: none; transition: border-color 0.15s; }
.search-input:focus { border-color: var(--primary); }
.btn-action-primary { background: var(--primary); color: #ffffff; border: none; padding: 10px 18px; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; transition: 0.15s; white-space: nowrap; }
.btn-action-primary:hover { background: var(--primary-hover); }

.filter-pills { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.btn-filter-pill { padding: 6px 14px; border-radius: 20px; border: 1px solid #cbd5e1; background: #ffffff; color: #475569; font-size: 13px; font-weight: 600; cursor: pointer; transition: 0.15s; }
.btn-filter-pill:hover { background: #f1f5f9; }
.btn-filter-pill.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }

.table-card { background: #ffffff; border: 1px solid var(--border-color); border-radius: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.table-header-info { padding: 14px 18px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.app-table { width: 100%; border-collapse: collapse; text-align: left; min-width: 700px; }
.app-table th { background: #f8fafc; padding: 12px 16px; font-size: 12px; font-weight: 700; color: #475569; text-transform: uppercase; border-bottom: 1px solid var(--border-color); }
.app-table td { padding: 14px 16px; border-bottom: 1px solid var(--border-color); font-size: 13.5px; color: #1e293b; vertical-align: middle; }
.app-table tr:hover { background: #f8fafc; }

.btn-table-action { background: #f1f5f9; border: 1px solid #cbd5e1; color: #0f172a; padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; transition: 0.15s; }
.btn-table-action:hover { background: #e2e8f0; }

.badge-stato { padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; display: inline-block; }
.stato-attesa { background: #fef3c7; color: #92400e; }
.stato-approvato { background: #dcfce7; color: #166534; }
.stato-rifiutato { background: #fee2e2; color: #991b1b; }

.badge-perm { padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.perm-si { background: #dcfce7; color: #166534; }
.perm-no { background: #f1f5f9; color: #94a3b8; }

.date-filter-card { background: #ffffff; padding: 18px; border-radius: 12px; border: 1px solid var(--border-color); display: flex; gap: 15px; align-items: flex-end; margin-bottom: 20px; flex-wrap: wrap; }
.date-input-group { display: flex; flex-direction: column; gap: 5px; }
.date-input-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.date-input-group input { padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }

.finance-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 25px; }
.summary-box { background: #0f172a; padding: 20px; border-radius: 12px; color: #ffffff; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
.summary-title { font-size: 12px; color: #94a3b8; font-weight: 700; text-transform: uppercase; }
.summary-value { font-size: 26px; font-weight: 800; }
.val-green { color: #22c55e; } .val-blue { color: #38bdf8; } .val-orange { color: #f97316; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-top: 20px; }
.stats-card { background: #ffffff; border-radius: 12px; padding: 20px; border: 1px solid var(--border-color); box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.stats-card-full { grid-column: span 2; }
.stats-title { font-size: 15px; font-weight: 700; color: #0f172a; margin-bottom: 15px; border-bottom: 2px solid #f1f5f9; padding-bottom: 8px; }
.chart-container { position: relative; height: 260px; width: 100%; }

/* ============================================================
   MODALI & FORM CONTROLS
   ============================================================ */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 20000; padding: 15px; }
.modal { background: #ffffff; border-radius: 14px; padding: 25px; width: 100%; max-width: 520px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); position: relative; }
.modal-large { max-width: 860px; max-height: 90vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.row-dual { display: flex; gap: 15px; }
.row-dual > div { flex: 1; }
label { display: block; font-size: 12px; font-weight: 700; color: #475569; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 13.5px; outline: none; background: #ffffff; transition: border-color 0.15s; }
input:focus, select:focus { border-color: var(--primary); }

.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-btn { flex: 1; min-width: 90px; text-align: center; padding: 9px; border: 1px solid #cbd5e1; border-radius: 6px; cursor: pointer; color: #475569; font-weight: 600; font-size: 13px; transition: 0.15s; background: #f8fafc; user-select: none; }
.radio-btn.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }

.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }
.btn { padding: 10px 18px; border-radius: 7px; font-weight: 700; font-size: 13px; cursor: pointer; border: none; transition: 0.15s; }
.btn-cancel { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.btn-cancel:hover { background: #e2e8f0; }
.btn-save { background: var(--primary); color: #ffffff; }
.btn-save:hover { background: var(--primary-hover); }
.btn-delete-single { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.btn-delete-single:hover { background: #fca5a5; }

.perm-box-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 6px; }
.perm-checkbox-card { background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; transition: 0.15s; }
.perm-checkbox-card:hover { background: #f1f5f9; }
.perm-checkbox-card input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* ============================================================
   RESPONSIVE DESIGN: SMARTPHONE & TABLET (< 768px)
   ============================================================ */
@media (max-width: 768px) {
    body { flex-direction: column; overflow-x: hidden; }
    .btn-mobile-menu { display: block; }
    
    #sidebar {
        position: fixed; top: 0; bottom: 0; left: -260px; width: 250px;
        box-shadow: none; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #sidebar:hover { width: 250px; }
    #sidebar.mobile-open { left: 0; box-shadow: 10px 0 30px rgba(0,0,0,0.5); }
    #sidebar.mobile-open .nav-label { opacity: 1; visibility: visible; transform: translateX(0); pointer-events: auto; }
    
    #app-wrapper { width: 100%; }
    #topbar { padding: 10px 15px; }
    .topbar-title { font-size: 16px; }
    .main-content { padding: 12px; }
    .row-dual { flex-direction: column !important; gap: 10px !important; }
    .finance-summary { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .stats-card-full { grid-column: span 1; }
    .modal-large, .modal { width: 95% !important; max-width: 95% !important; padding: 16px !important; max-height: 92vh !important; }
    .filter-pills { overflow-x: auto; white-space: nowrap; padding-bottom: 6px; }
    .search-card { flex-direction: column; align-items: stretch; }
    .search-card button, .search-card input { width: 100%; }
    .perm-box-grid { grid-template-columns: 1fr; }
}