/* --- WEBLOW ERP FINAL STYLES (FULL) --- */

/* 1. CONFIGURAZIONE VARIABILI */
.app-container {
    /* DARK MODE (Default) */
    --bg-main: #0b0e14;
    --bg-side: #11141b;
    --bg-panel: #131720;
    --border: #333;
    --text-main: #ffffff;
    --text-dim: #8899aa;
    --input-bg: #050608;
    --input-border: #444;
    --accent: #00f3ff;
    
    /* LAYOUT & DIMENSIONI */
    width: 95%;
    max-width: 1600px;
    height: 85vh; 
    min-height: 750px;
    margin: 40px auto; 
    margin-bottom: 100px;
    
    display: flex; flex-direction: column;
    background: var(--bg-main); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    color: var(--text-main);
    transition: all 0.3s;
    font-family: 'Inter', sans-serif;
    position: relative;
    z-index: 10;
}

/* LIGHT MODE */
.app-container.light-theme {
    --bg-main: #f0f2f5;
    --bg-side: #ffffff;
    --bg-panel: #ffffff;
    --border: #d1d5db;
    --text-main: #111827;
    --text-dim: #4b5563;
    --input-bg: #ffffff;
    --input-border: #ccc;
    --accent: #2563eb;
}

/* 2. HEADER & TOOLBAR */
.app-toolbar {
    height: 60px; background: #161b25; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center; padding: 0 20px;
    flex-shrink: 0;
}
.app-container.light-theme .app-toolbar { background: #ffffff; }

.app-brand { font-weight: bold; font-family: 'Rajdhani'; letter-spacing: 1px; display: flex; align-items: center; gap: 10px; color: var(--text-main); }
.app-ico svg { width: 20px; height: 20px; color: var(--accent); }
.badge-v { background: var(--accent); color: #000; font-size: 0.7rem; padding: 2px 5px; border-radius: 4px; font-weight: bold; }
.btn-exit { color: #ff5555; text-decoration: none; font-size: 0.8rem; font-weight: bold; border: 1px solid #ff5555; padding: 5px 15px; border-radius: 4px; }
.btn-exit:hover { background: #ff5555; color: white; }

/* 3. WORKSPACE */
.erp-workspace { flex: 1; display: flex; overflow: hidden; height: 100%; }

.erp-sidebar { 
    width: 260px; background: var(--bg-side); border-right: 1px solid var(--border); 
    padding: 20px; display: flex; flex-direction: column; overflow-y: auto;
}
.user-profile { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.avatar { width: 40px; height: 40px; background: rgba(0,243,255,0.1); color: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; border: 1px solid var(--accent); }
.u-name { font-weight: bold; font-size: 0.9rem; color: var(--text-main); }
.u-role { color: var(--text-dim); font-size: 0.75rem; }

.erp-nav a { display: block; color: var(--text-dim); text-decoration: none; padding: 12px 15px; margin-bottom: 5px; border-radius: 6px; transition: 0.2s; font-size: 0.95rem; }
.erp-nav a:hover, .erp-nav a.active { background: rgba(255,255,255,0.05); color: var(--text-main); border-left: 3px solid var(--accent); }
.count { float: right; background: #ff4444; color: white; font-size: 0.7rem; padding: 2px 6px; border-radius: 10px; }

.erp-content { flex: 1; padding: 30px; overflow-y: auto; background: var(--bg-main); }
.erp-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.erp-header h2 { margin: 0; font-family: 'Rajdhani'; font-weight: 700; text-transform: uppercase; color: var(--text-main); }
.date-display { color: var(--accent); font-family: 'JetBrains Mono'; font-size: 0.8rem; }

/* 4. COMPONENTI UI */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--bg-panel); border: 1px solid var(--border); padding: 20px; border-radius: 8px; }
.s-label { color: var(--text-dim); font-size: 0.75rem; font-weight: bold; letter-spacing: 1px; }
.s-val { color: var(--text-main); font-size: 2rem; font-weight: bold; margin: 10px 0; font-family: 'Rajdhani'; }
.s-val.pending { color: #ffcc00; }
.s-trend { font-size: 0.8rem; font-weight: bold; }
.s-trend.up { color: #00ff88; } .s-trend.down { color: #ff5555; } .s-trend.flat { color: var(--text-dim); }

.dashboard-split { display: grid; grid-template-columns: 2fr 1.5fr; gap: 20px; }
.panel-box { background: var(--bg-panel); border: 1px solid var(--border); padding: 20px; border-radius: 8px; }
.panel-box h3 { color: var(--text-main); margin-top: 0; font-size: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 15px; margin-bottom: 20px; }

.view-subtitle { color: var(--text-main) !important; margin: 0; font-family: 'Rajdhani'; text-transform: uppercase; font-size: 1.1rem; }
.css-chart { display: flex; align-items: flex-end; gap: 15px; height: 200px; padding-top: 20px; border-bottom: 1px solid var(--border); }
.bar { flex: 1; background: linear-gradient(to top, rgba(0,243,255,0.1), var(--accent)); opacity: 0.6; border-radius: 4px 4px 0 0; transition: height 0.5s ease; }

.erp-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.erp-table th { text-align: left; color: var(--text-dim); padding: 10px; border-bottom: 1px solid var(--border); }
.erp-table td { color: var(--text-main); padding: 12px 10px; border-bottom: 1px solid var(--border); }
.tag { padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; }
.tag.success { background: rgba(0,255,136,0.1); color: #00ff88; }
.tag.warning { background: rgba(255,204,0,0.1); color: #ffcc00; }

.inventory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.prod-card { background: var(--bg-panel); border: 1px solid var(--border); padding: 20px; border-radius: 8px; text-align: center; }
.prod-img { width: 60px; height: 60px; margin: 0 auto 15px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-main); border: 1px solid var(--border); }
.prod-img svg { width: 30px; height: 30px; stroke: var(--text-main); }
.prod-card h4 { color: var(--text-main); margin: 0 0 10px 0; }
.prod-card p { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 15px; }

.crm-list { display: flex; flex-direction: column; gap: 10px; }
.crm-item { background: var(--bg-panel); padding: 15px; border-radius: 8px; display: flex; align-items: center; gap: 15px; border: 1px solid var(--border); }
.crm-info h4 { color: var(--text-main); margin: 0; }
.crm-info p { color: var(--text-dim); margin: 0; font-size: 0.8rem; }
.crm-status { margin-left: auto; font-size: 0.75rem; padding: 4px 8px; border-radius: 4px; }
.crm-status.active { color: #00ff88; background: rgba(0, 255, 136, 0.1); }
.crm-status.pending { color: #ffcc00; background: rgba(255, 204, 0, 0.1); }

/* 5. FORM & INPUTS */
.toolbar-inner { display: flex; gap: 10px; margin-bottom: 20px; }
.erp-input, .erp-search { width: 100%; padding: 10px; background-color: var(--input-bg); border: 1px solid var(--input-border); color: var(--text-main); border-radius: 6px; outline: none; }
.erp-input:focus { border-color: var(--accent); }

select.erp-input { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2300f3ff%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-position: right .7em top 50%; background-size: .65em auto; }
.app-container.light-theme select.erp-input { background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23000000%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E"); }
.erp-input option { background-color: #1a1f2b; color: white; }
.app-container.light-theme .erp-input option { background-color: #ffffff; color: black; }

.erp-btn { padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.erp-btn.primary { background: var(--accent); color: #000; }
.erp-btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }

/* Toggle */
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--border); }
.setting-row label { color: var(--text-main); font-weight: 500; }
.toggle { width: 44px; height: 24px; background: #4b5563; border-radius: 24px; position: relative; cursor: pointer; transition: 0.3s; }
.toggle::after { content:''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: 0.3s; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.toggle.active { background: var(--accent); }
.toggle.active::after { left: 22px; background: white; }

/* 6. MODALI */
.erp-view { display: none; animation: fadeInView 0.3s ease; }
.erp-view.active { display: block; }
@keyframes fadeInView { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.erp-overlay { position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.7); backdrop-filter: blur(5px); display: none; align-items: center; justify-content: center; z-index: 100; }
.erp-overlay.active { display: flex; animation: popIn 0.3s; }
.erp-modal-box { width: 400px; background: var(--bg-panel); border: 1px solid var(--accent); border-radius: 8px; padding: 20px; box-shadow: 0 0 40px rgba(0,0,0,0.8); }
.modal-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 15px; margin-bottom: 20px; }
.modal-head h3 { margin: 0; color: var(--text-main) !important; font-family: 'Rajdhani'; font-size: 1.2rem; text-transform: uppercase; }
.close-modal { cursor: pointer; color: var(--text-dim); font-size: 1.2rem; }
.inp-group { margin-bottom: 15px; }
.inp-group label { display: block; color: var(--text-main) !important; margin-bottom: 8px; font-size: 0.85rem; font-weight: 600; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ========================================= */
/* === 7. CHAT WIDGET (PARTE MANCANTE) === */
/* ========================================= */

.erp-chat-widget {
    position: fixed; bottom: 100px; right: 30px;
    width: 340px; height: 450px;
    background: var(--bg-panel);
    border: 1px solid var(--accent);
    border-radius: 12px;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0; pointer-events: none; transform: translateY(20px);
    transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.erp-chat-widget.active { opacity: 1; pointer-events: all; transform: translateY(0); }

.chat-header {
    padding: 15px;
    background: linear-gradient(90deg, var(--accent), #2563eb);
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    border-radius: 11px 11px 0 0;
    color: #000; font-weight: bold;
}
.ch-info { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; background: #fff; border-radius: 50%; animation: blink 1s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.close-chat-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #000; }

.chat-body {
    flex: 1; padding: 15px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
}
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }

.msg-bubble {
    max-width: 80%; padding: 10px 14px; border-radius: 12px;
    font-size: 0.9rem; line-height: 1.4;
}
.msg-row.bot .msg-bubble { background: #222; color: #fff; border: 1px solid #333; }
.msg-row.user .msg-bubble { background: var(--accent); color: #000; }

.chat-input-area {
    padding: 15px; border-top: 1px solid var(--border);
    display: flex; align-items: center !important; gap: 10px;
    background: #111; border-radius: 0 0 12px 12px;
}
.chat-input-area input {
    flex: 1; background: #18181b !important; border: 1px solid var(--border) !important;
    color: #ffffff !important; border-radius: 20px; outline: none;
    height: 42px !important; min-height: 42px !important;
    padding: 0 15px !important; box-sizing: border-box !important; margin: 0 !important;
}
.chat-input-area input:focus { border-color: var(--accent) !important; }
.chat-input-area button {
    background: var(--accent); color: white; border: none; border-radius: 50%; cursor: pointer;
    width: 42px !important; height: 42px !important; padding: 0 !important; margin: 0 !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    flex-shrink: 0; transition: 0.2s; font-size: 1.2rem;
}
.chat-input-area button:hover { transform: scale(1.1); }

.chat-trigger-btn {
    position: fixed; bottom: 30px; right: 30px;
    width: 60px; height: 60px;
    background: var(--accent); color: #000;
    border-radius: 50%; border: none;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    cursor: pointer; z-index: 990;
    display: flex; align-items: center; justify-content: center;
    transition: 0.3s;
}
.chat-trigger-btn:hover { transform: scale(1.1); }
.chat-trigger-btn svg { width: 28px; height: 28px; }
/* ============================================================ */
/* === MOBILE ERP: PRO APP LAYOUT (2 COLONNE + SMART NAV) === */
/* ============================================================ */

@media (max-width: 900px) {

    /* 1. CONTENITORE & LAYOUT GENERALE */
    .app-container {
        width: 100% !important;
        height: 100vh !important; /* Occupa tutto lo schermo */
        margin: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        position: fixed !important; /* Blocca il contenitore */
        top: 0; left: 0;
        z-index: 9999; /* Sopra a tutto, sotto al dock */
        background: var(--bg-main) !important;
    }

    .erp-workspace {
        display: flex;
        flex-direction: column;
        height: 100%;
        padding-top: 80px; /* Spazio per l'header del sito */
    }

    /* 2. HEADER APP (Titolo + Exit) */
    /* CERCA QUESTA REGOLA DENTRO LA MEDIA QUERY MOBILE E SOSTITUISCILA */
/* 2. HEADER APP (Titolo + Exit) */
.app-toolbar {
    padding: 0 15px;
    height: 50px;
    min-height: 50px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main) !important; /* <--- CAMBIATO: Ora usa lo sfondo principale */
}

/* CERCA ANCHE QUESTA REGOLA POCO SOTTO E SOSTITUISCILA */
/* 3. MENU DI NAVIGAZIONE (SMART SCROLL) */
.erp-sidebar {
    width: 100% !important;
    height: 55px !important;
    min-height: 55px;
    padding: 0 10px;
    
    display: flex; 
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    
    background: var(--bg-main) !important; /* <--- CAMBIATO: Niente più nero trasparente */
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
    /* Nascondi scrollbar Chrome/Safari */
    .erp-sidebar::-webkit-scrollbar { display: none; }

    .user-profile { display: none !important; }

    .erp-nav { display: flex; gap: 8px; width: auto; }

    .erp-nav a {
        padding: 6px 12px !important; /* Più piccoli */
        font-size: 0.75rem !important;
        border-radius: 6px !important; /* Meno rotondi, più tech */
        background: rgba(255,255,255,0.05);
        border: 1px solid rgba(255,255,255,0.1);
        margin: 0 !important;
        display: inline-flex;
        align-items: center;
        white-space: nowrap;
    }
    
    .erp-nav a.active {
        background: var(--accent) !important;
        color: #000 !important;
        font-weight: 800;
        box-shadow: 0 0 10px var(--accent);
    }

    /* 4. CONTENUTO SCORREVOLE */
    .erp-content {
        flex: 1; /* Prende tutto lo spazio rimanente */
        padding: 15px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 120px !important; /* Spazio per il Dock */
    }

    /* 5. HEADER PAGINA INTERNA */
    .erp-header {
        flex-direction: column; align-items: flex-start; gap: 5px; margin-bottom: 20px;
    }
    .erp-header h2 { font-size: 1.3rem; }
    .date-display { font-size: 0.7rem; opacity: 0.7; }

    /* 6. GRIGLIA STATISTICHE (LA SVOLTA: 2 COLONNE) */
    .stats-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important; /* DUE COLONNE! */
        gap: 10px !important;
    }

    .stat-card {
        padding: 15px !important;
    }
    
    .s-label { font-size: 0.65rem; }
    
    /* Numeri più piccoli per farli stare */
    .s-val { 
        font-size: 1.2rem !important; 
        margin: 5px 0; 
        word-break: break-all; /* Evita che €42.000 esca fuori */
    }

    /* 7. GRAFICI E TABELLE */
    .dashboard-split {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }
    
    .panel-box { padding: 15px; }
    
    /* Tabelle CRM in lista compatta */
    .crm-item {
        padding: 10px;
        flex-direction: row; /* Rimettiamole in riga se ci stanno */
        align-items: center;
        justify-content: space-between;
    }
    .crm-info h4 { font-size: 0.9rem; }
    .crm-info p { font-size: 0.7rem; }
    .crm-status { font-size: 0.6rem; padding: 2px 6px; }

    /* Fix Tabelle larghe */
    .erp-table { display: block; overflow-x: auto; white-space: nowrap; }
}