/* --- HOTEL APP STYLES (LUXURY V4 - FINAL FIX) --- */

.app-container {
    /* DARK MODE (Default) */
    --bg-main: #050505;
    --bg-side: #0a0a0a;
    --bg-panel: #111;
    --border: #333;
    --text-main: #e0e0e0;
    --text-dim: #888;
    
    --accent: #d4af37; /* ORO */
    --input-bg: #000;
    
    /* LAYOUT BASE */
    width: 95%; max-width: 1600px; 
    min-height: 80vh; height: auto;
    margin: 40px auto; margin-bottom: 150px; /* Spazio per footer */
    
    display: flex; flex-direction: column;
    background: var(--bg-main); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
    box-shadow: 0 0 60px rgba(0,0,0,0.7);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    position: relative; z-index: 10;
}

/* LIGHT MODE */
.app-container.light-theme {
    --bg-main: #f8f9fa;
    --bg-side: #ffffff;
    --bg-panel: #ffffff;
    --border: #e2e8f0;
    --text-main: #1a202c;
    --text-dim: #718096;
    --accent: #2563eb; /* BLU REALE */
    --input-bg: #fff;
}

/* --- HEADER & SIDEBAR --- */
.app-toolbar { height: 60px; background: var(--bg-side); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; }
.app-brand { color: var(--text-main); font-weight: bold; font-family: 'Rajdhani'; letter-spacing: 1px; display: flex; align-items: center; gap: 10px; }
.badge-v { padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; }
.btn-exit { color: #ff5555; border: 1px solid #ff5555; padding: 5px 15px; border-radius: 4px; text-decoration: none; font-size: 0.8rem; }

.erp-workspace { flex: 1; display: flex; }
.erp-sidebar { width: 260px; background: var(--bg-side); border-right: 1px solid var(--border); padding: 20px; }

/* FIX PROFILO (Quello che era rotto) */
.user-profile { 
    display: flex !important;       
    flex-direction: row;            
    align-items: center;            
    gap: 15px;                      
    margin-bottom: 40px; 
    padding-bottom: 20px; 
    border-bottom: 1px solid var(--border); 
}
.avatar { 
    width: 45px; height: 45px; min-width: 45px; 
    border-radius: 50%; 
    display: flex; align-items: center; justify-content: center; 
    font-weight: 800; font-size: 1.1rem;
    border: 2px solid var(--accent); 
    background: rgba(212, 175, 55, 0.1); 
    color: var(--accent);
}
.u-details { display: flex; flex-direction: column; justify-content: center; }
.u-name { font-weight: bold; font-size: 0.95rem; color: var(--text-main); line-height: 1.2; }
.u-role { color: var(--text-dim); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; }

/* NAVIGAZIONE */
.erp-nav a { display: block; color: var(--text-dim); padding: 12px 15px; margin-bottom: 5px; text-decoration: none; border-radius: 6px; transition: 0.2s; }
.erp-nav a:hover, .erp-nav a.active { background: rgba(255,255,255,0.05); color: var(--accent); border-left: 3px solid var(--accent); }
.app-container.light-theme .erp-nav a:hover { background: #f1f5f9; }

/* --- CONTENUTO E VISTE --- */
.erp-content { flex: 1; padding: 30px; background: var(--bg-main); }
.erp-header { display: flex; justify-content: space-between; margin-bottom: 30px; align-items: center; }
.erp-header h2 { margin: 0; color: var(--text-main); font-family: 'Rajdhani'; text-transform: uppercase; letter-spacing: 1px; }

/* === FIX FONDAMENTALE PER LE SCHEDE === */
/* Nasconde tutte le viste di default */
.erp-view { display: none; animation: fadeIn 0.3s ease; }
/* Mostra solo quella attiva */
.erp-view.active { display: block; }

/* --- WIDGETS CIRCOLARI (3/5) --- */
.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); border-radius: 8px; padding: 25px; display: flex; align-items: center; justify-content: space-between; }
.s-label { color: var(--text-dim); font-size: 0.75rem; font-weight: bold; text-transform: uppercase; }

.circle-chart { 
    width: 65px; height: 65px; border-radius: 50%; 
    background: conic-gradient(var(--c) calc(var(--p) * 1%), rgba(255,255,255,0.1) 0); 
    display: flex; align-items: center; justify-content: center; position: relative; 
}
.circle-chart::before { 
    content:''; position: absolute; width: 53px; height: 53px; 
    background: var(--bg-panel); border-radius: 50%; 
}
.circle-chart span { 
    position: relative; z-index: 2; 
    font-size: 0.9rem; font-weight: 800; 
    color: var(--text-main); font-family: 'Rajdhani', sans-serif; 
}

/* --- TABELLE & PANNELLI --- */
.panel-box { background: var(--bg-panel); border: 1px solid var(--border); padding: 20px; border-radius: 8px; }
.erp-table { width: 100%; border-collapse: collapse; margin-top: 15px; }
.erp-table th { text-align: left; color: var(--text-dim); padding: 10px; border-bottom: 1px solid var(--border); }
.erp-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); color: var(--text-main); }
.tag { padding: 4px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; }
.tag.success { background: rgba(0,255,136,0.1); color: #00ff88; }
.tag.warning { background: rgba(255,165,0,0.1); color: orange; }
.tag.danger { background: rgba(255,85,85,0.1); color: #ff5555; }

/* --- PLANNING & HOUSEKEEPING --- */
.hotel-plan-grid { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--bg-panel); margin-top: 15px; }
.plan-row { display: grid; grid-template-columns: 60px repeat(7, 1fr); border-bottom: 1px solid var(--border); height: 50px; }
.plan-row.header { background: var(--bg-side); font-weight: bold; color: var(--text-dim); height: 40px; align-items: center; text-align: center; }
.room-col { border-right: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-weight: bold; color: var(--text-main); background: var(--bg-side); }
.plan-cell { border-right: 1px solid #333; margin: 5px; border-radius: 4px; font-size: 0.75rem; color: white; display: flex; align-items: center; padding-left: 5px; overflow: hidden; white-space: nowrap; }
.res-blue { background: #3b82f6; grid-column: span 3; }
.res-green { background: #10b981; grid-column: span 2; }
.res-gold { background: #d4af37; color: black; font-weight: bold; grid-column: span 4; }
.res-gray { background: #4b5563; grid-column: span 2; border: 1px dashed #aaa; opacity: 0.7; }

.inventory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.hk-card { background: var(--bg-panel); padding: 20px; border: 1px solid var(--border); border-radius: 8px; text-align: center; }
.hk-card h4 { font-size: 1.5rem; margin: 0; color: var(--text-main); }
.hk-card.clean { border-top: 4px solid #00ff88; }
.hk-card.dirty { border-top: 4px solid #ff5555; }
.hk-card.maint { border-top: 4px solid orange; }

/* --- COMPONENTI UI (Btn, Toggle, Modal) --- */
.erp-btn { padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
.erp-btn.primary { background: var(--accent); color: #000; }
.btn-xs { background: var(--border); color: var(--text-main); border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 0.7rem; }
.btn-xs:hover { background: var(--accent); color: #000; }

.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; }
.toggle.active { background: var(--accent); }
.toggle.active::after { left: 22px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--border); }

.erp-overlay { position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(5px); }
.erp-overlay.active { display: flex; animation: fadeIn 0.3s; }
.erp-modal-box { width: 400px; background: var(--bg-panel); border: 1px solid var(--accent); padding: 20px; border-radius: 8px; }
.erp-input { width: 100%; padding: 10px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text-main); margin-top: 5px; }
.modal-head { display: flex; justify-content: space-between; color: var(--text-main); margin-bottom: 15px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 900px) { .erp-sidebar { display: none; } .stats-row { grid-template-columns: 1fr; } .app-container { margin: 0; border:none; height:auto; } }
@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }
/* --- FIX VISIBILITÀ TESTI (LIGHT/DARK) --- */
.erp-header h2,
.panel-box h3,
.view-subtitle,
.modal-head h3,
.inp-group label {
    color: var(--text-main) !important;
    transition: color 0.3s ease;
}

/* Fix specifico per il calendario che costruiremo */
.cal-day { color: var(--text-main); }
.cal-day.disabled { color: var(--text-dim); opacity: 0.3; }
.cal-head { color: var(--text-dim); }
/* --- CALENDAR WIDGET STYLES --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    margin-top: 20px;
}

.cal-head {
    text-align: center;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    padding-bottom: 10px;
    color: var(--text-dim);
}

.cal-day {
    aspect-ratio: 1; /* Quadrati perfetti */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--bg-side);
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px solid transparent;
    transition: 0.2s;
}

.cal-day:hover:not(.disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

/* Oggi */
.cal-day.today {
    background: rgba(255,255,255,0.1);
    font-weight: bold;
    border: 1px solid var(--text-dim);
}

/* Selezione Range (Dal - Al) */
.cal-day.range-start,
.cal-day.range-end {
    background: var(--accent);
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
}

.cal-day.range-mid {
    background: rgba(212, 175, 55, 0.15); /* Oro trasparente */
    color: var(--text-main);
}
/* --- MODALE PRENOTAZIONE "LUXURY" --- */

/* Allarghiamo la modale per farci stare tutto */
.erp-modal-box.luxury-modal {
    width: 800px; /* Molto più larga */
    max-width: 95%;
    padding: 30px;
}

/* Layout a Griglia (2 Colonne) */
.res-grid-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

/* Separatore verticale tra le colonne */
.res-column {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.res-column.right-col {
    border-left: 1px solid var(--border);
    padding-left: 30px;
}

/* Titoli delle sezioni (Ospite / Soggiorno) */
.form-section-title {
    color: var(--accent);
    text-transform: uppercase;
    font-size: 0.9rem;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
    letter-spacing: 1px;
}

/* Righe con due input (Nome | Cognome) */
.inp-row {
    display: flex;
    gap: 15px;
}
.inp-group.half {
    width: 50%;
}

/* TextArea (Note) */
textarea.erp-input {
    resize: none;
    font-family: 'Inter', sans-serif;
}

/* Box Prezzo Totale */
.price-box {
    margin-top: auto; /* Spinge in fondo */
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid var(--accent);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-main);
}
.price-val {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    font-family: 'Rajdhani';
}

/* Adattamento Mobile (torna a 1 colonna) */
@media (max-width: 768px) {
    .res-grid-layout { grid-template-columns: 1fr; gap: 0; }
    .res-column.right-col { border-left: none; padding-left: 0; margin-top: 20px; border-top: 1px solid var(--border); padding-top: 20px; }
}
/* ========================================= */
/* === FIX DEFINITIVO TENDINE (DROPDOWN) === */
/* ========================================= */

.app-container {
    color-scheme: dark; 
}

.app-container.light-theme {
    color-scheme: light;
}

/* Stile specifico per le opzioni (sovrascrive tutto) */
select.erp-input option {
    background-color: #050505 !important;
    color: #e0e0e0 !important;
}

.app-container.light-theme select.erp-input option {
    background-color: #ffffff !important;
    color: #1a202c !important;
}
/* --- CHAT WIDGET STYLES --- */
.chat-trigger-btn { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: #fff; border: none; cursor: pointer; box-shadow: 0 10px 30px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: center; transition: 0.3s; z-index: 900; }
.chat-trigger-btn:hover { transform: scale(1.1); box-shadow: 0 0 20px var(--accent); }
.chat-trigger-btn svg { width: 24px; height: 24px; stroke: #000; }

.erp-chat-widget { position: fixed; bottom: 100px; right: 30px; width: 350px; height: 450px; background: var(--bg-panel); border: 1px solid var(--border); 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: var(--bg-side); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0; }
.ch-info { display: flex; align-items: center; gap: 8px; color: var(--text-main); }
.status-dot { width: 8px; height: 8px; background: #00ff88; border-radius: 50%; box-shadow: 0 0 5px #00ff88; }
.close-chat-btn { background: none; border: none; color: var(--text-dim); font-size: 1.2rem; cursor: pointer; }

.chat-body { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.chat-body::-webkit-scrollbar { width: 5px; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.msg-row { display: flex; width: 100%; }
.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; animation: popMsg 0.3s ease; }
.msg-row.bot .msg-bubble { background: var(--bg-side); border: 1px solid var(--border); color: var(--text-main); border-bottom-left-radius: 2px; }
.msg-row.user .msg-bubble { background: var(--accent); color: #000; border-bottom-right-radius: 2px; font-weight: 500; }

.chat-input-area { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 10px; background: var(--bg-side); border-radius: 0 0 12px 12px; }
.chat-input-area input { flex: 1; background: var(--bg-main); border: 1px solid var(--border); color: var(--text-main); padding: 8px 12px; border-radius: 20px; outline: none; font-size: 0.9rem; }
.chat-input-area button { background: var(--accent); color: #000; border: none; width: 35px; height: 35px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: bold; }

@keyframes popMsg { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
/* ============================================================ */
/* === MOBILE HOTEL APP: V11 (ACTIVE STATE RESTORED) === */
/* ============================================================ */

@media (max-width: 900px) {

    /* 1. SBLOCCO SCROLL */
    html, body {
        overflow-y: auto !important;
        height: auto !important;
    }

    /* 2. CONTENITORE PRINCIPALE */
    .app-container {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        margin: 0 !important;
        border: none !important;
        background: var(--bg-main) !important;
        display: block !important;
        
        padding-top: 220px !important; 
        padding-bottom: 200px !important;
        z-index: 10;
        overflow: visible !important;
    }

    /* 3. TOOLBAR APP */
    .app-toolbar {
        position: fixed !important;
        top: 80px !important; 
        left: 0 !important;
        width: 100% !important;
        height: 60px !important;
        
        background: var(--bg-main) !important;
        border-bottom: 1px solid var(--border) !important;
        
        display: flex !important; align-items: center; justify-content: space-between;
        padding: 0 15px;
        z-index: 9999 !important; 
        box-shadow: 0 5px 10px rgba(0,0,0,0.1);
    }
    
    .app-brand { color: var(--text-main) !important; }

    /* 4. MENU APP (SOTTO LA TOOLBAR) */
    .hotel-sidebar, .erp-sidebar {
        position: fixed !important;
        top: 140px !important; 
        left: 0 !important;
        width: 100vw !important;
        height: 60px !important;
        min-height: 60px !important;
        display: flex !important; flex-direction: row !important; align-items: center !important;
        padding: 0 10px !important;
        
        background: var(--bg-main) !important; 
        border-bottom: 1px solid var(--border) !important;
        
        overflow-x: auto !important; white-space: nowrap !important;
        z-index: 9998 !important;
    }
    .hotel-sidebar::-webkit-scrollbar { display: none; }
    .user-profile { display: none !important; }

    /* PULSANTI MENU */
    .hotel-nav, .erp-nav { display: flex !important; gap: 10px !important; width: auto !important; margin: 0 !important; }
    
    /* STILE BASE PULSANTE (INATTIVO) */
    .hotel-nav a, .erp-nav a {
        padding: 8px 16px !important;
        font-size: 0.8rem !important;
        border-radius: 20px !important;
        
        /* Colori Inattivi */
        background: var(--bg-panel) !important;
        border: 1px solid var(--border) !important;
        color: var(--text-main) !important;
        opacity: 0.7 !important; /* Li rendiamo leggermente spenti */
        
        white-space: nowrap !important;
        display: inline-flex !important;
        align-items: center; justify-content: center;
        transition: all 0.3s ease !important;
    }
    
    /* STILE PULSANTE ATTIVO (FIXED) */
    /* Usiamo una specificità più alta per vincere */
    .hotel-sidebar .hotel-nav a.active, 
    .erp-sidebar .erp-nav a.active {
        background: var(--accent) !important; /* Colore ORO/BLU */
        color: #000 !important; /* Testo Nero */
        border-color: var(--accent) !important;
        font-weight: 800 !important;
        opacity: 1 !important; /* Piena visibilità */
        box-shadow: 0 0 15px var(--accent) !important; /* Glow */
        transform: scale(1.05); /* Leggermente più grande */
    }

    /* 5. CONTENUTO STANDARD */
    .hotel-workspace, .erp-workspace { display: block !important; padding: 0 !important; margin: 0 !important; height: auto !important; overflow: visible !important; }
    .hotel-content, .erp-content { padding: 15px !important; height: auto !important; overflow: visible !important; margin-top: 0 !important; }
    
    .stats-row { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
    .stat-card { 
        padding: 10px !important; min-height: 100px; text-align: center; flex-direction: column !important; justify-content: center !important; 
        background: var(--bg-panel) !important;
        border: 1px solid var(--border) !important;
    }
    .room-grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 10px !important; }

    /* ================================================= */
    /* 6. TABELLA -> CARD VIEW */
    /* ================================================= */
    .hotel-table thead, .erp-table thead, .hotel-table th, .erp-table th { display: none !important; }
    .hotel-table, .erp-table, .hotel-table tbody, .erp-table tbody, .hotel-table tr, .erp-table tr, .hotel-table td, .erp-table td { display: block !important; width: 100% !important; }

    /* CARD OSPITE */
    .hotel-table tr, .erp-table tr {
        background: var(--bg-panel) !important;
        border: 1px solid var(--border) !important;
        border-radius: 12px;
        margin-bottom: 20px;
        padding: 20px;
        position: relative;
        box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    }

    .hotel-table td, .erp-table td {
        display: flex !important; justify-content: space-between; align-items: center;
        padding: 8px 0 !important; border: none !important;
        border-bottom: 1px solid var(--border) !important;
        text-align: right;
        min-height: 30px;
        color: var(--text-main) !important;
    }
    
    .hotel-table td:last-child, .erp-table td:last-child { border-bottom: none !important; margin-top: 10px; }

    /* 1. Camera (Titolo Grande) */
    .hotel-table td:nth-child(1), .erp-table td:nth-child(1) {
        font-size: 1.4rem; font-weight: 800; color: var(--accent) !important;
        justify-content: flex-start;
        padding-bottom: 15px !important; margin-bottom: 10px;
        border-bottom: 1px solid var(--border) !important;
    }
    
    /* QUI C'ERA L'ERRORE: Ora legge l'attributo invece di scrivere "Camera" fisso */
    .hotel-table td:nth-child(1)::before, .erp-table td:nth-child(1)::before {
        content: attr(data-label); /* <--- MODIFICA FONDAMENTALE */
        font-size: 0.8rem; 
        color: var(--text-dim); 
        margin-right: 10px; 
        font-weight: normal;
        text-transform: uppercase;
    }

    /* --- ETICHETTE INTELLIGENTI (AUTOMATICHE) --- */
    
    /* Regola Universale per tutte le etichette: Legge l'attributo HTML */
    .hotel-table td::before, .erp-table td::before { 
        content: attr(data-label); /* <--- QUESTA È LA MAGIA */
        font-weight: bold; 
        color: var(--text-dim); 
        font-size: 0.8rem; 
        text-transform: uppercase;
    }

    /* 1. Camera (Titolo Grande) - Stile Specifico */
    .hotel-table td:nth-child(1), .erp-table td:nth-child(1) {
        font-size: 1.4rem; font-weight: 800; color: var(--accent) !important;
        justify-content: flex-start;
        padding-bottom: 15px !important; margin-bottom: 10px;
        border-bottom: 1px solid var(--border) !important;
    }
    
    /* Fix per la prima etichetta (Camera) per distanziarla dal numero */
    .hotel-table td:nth-child(1)::before, .erp-table td:nth-child(1)::before {
        margin-right: 10px; 
        font-weight: normal;
    }

    /* 5. Azioni (Nessuna etichetta necessaria o posizionamento a destra) */
    .hotel-table td:nth-child(5), .erp-table td:nth-child(5) {
        justify-content: flex-end; 
    }
    .hotel-table td:nth-child(5)::before, .erp-table td:nth-child(5)::before {
        display: none; /* Nascondiamo l'etichetta "Azioni" per pulizia estetica */
    }
}