/* --- STILE GENERALE --- */
body, html {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #eef2f5;
    overflow: hidden;
}

.main-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1000px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
    background: white;
}

/* --- MENU DI NAVIGAZIONE SUPERIORE --- */
.top-nav {
    display: flex;
    background: #fff;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}

.nav-btn {
    flex: 1;
    padding: 15px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
}

.nav-btn:hover { background-color: #f8f9fa; color: #002fff; }
.nav-btn.active { color: #002fff; border-bottom: 3px solid #002fff; background-color: #f0f7ff; }
.nav-btn i { margin-right: 8px; }

/* --- GESTIONE VISTE (CHAT vs DATA) --- */
.view-section {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}
.view-section.active-view { display: flex; }

/* --- SEZIONE CHAT --- */
.chat-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-header {
    background: linear-gradient(135deg, #002fff 0%,#01b516 100%);
    padding: 15px 20px;
    color: white;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}
.chat-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.chat-header .status { font-size: 12px; opacity: 0.8; }

/* Avatar specifico per l'header (Overrides default) */
.chat-header .avatar {
    background: white;
    color: #0051ff;
}

.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 10px; }

/* MESSAGGI */
.message { display: flex; align-items: flex-end; max-width: 85%; opacity: 0; animation: fadeIn 0.3s forwards; }
@keyframes fadeIn { to { opacity: 1; transform: translateY(0); } }
.message.bot { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.bubble { padding: 12px 16px; border-radius: 18px; font-size: 14px; line-height: 1.5; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.message.bot .bubble { background: #fff; color: #333; border-bottom-left-radius: 4px; }
.message.user .bubble { background: #002fff; color: white; border-bottom-right-radius: 4px; }

.avatar { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 10px; font-size: 14px; }
.bot .avatar { background-color: #fff; color: #002fff; }
.user .avatar { display: none; }

.chat-footer { padding: 15px; background: #fff; border-top: 1px solid #eee; display: flex; gap: 10px; flex-shrink: 0; }
.chat-footer input { flex: 1; padding: 12px 15px; border: 1px solid #ddd; border-radius: 25px; outline: none; }
.chat-footer input:focus { border-color: #01b516; }
.chat-footer button { width: 45px; height: 45px; background: #01b516; color: white; border: none; border-radius: 50%; cursor: pointer; }
.typing-indicator { font-size: 12px; color: #888; margin-left: 55px; margin-bottom: 5px; display: none; }

.btn-data { display: inline-block; margin-top: 10px; padding: 6px 12px; background: #f0f0f0; border: 1px solid #ccc; border-radius: 12px; cursor: pointer; color: #333; font-size: 12px; }
.btn-data:hover { background: #e0e0e0; }

/* --- SEZIONE CONSULTA DATI --- */
.full-data-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.full-data-header h3 { margin: 0; font-size: 16px; color: #333; }
.btn-refresh { background: #fff; border: 1px solid #ddd; padding: 8px 15px; border-radius: 5px; cursor: pointer; color: #002fff; }
.btn-refresh:hover { background: #002fff; color: white; }

/* Wrapper della tabella */
.full-table-wrapper {
    flex: 1;
    overflow: auto;
    padding: 0;
    background: white;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
}

/* Classi di utilità per stati di caricamento/errore (Nuove) */
.loading-state { text-align: center; padding: 40px; color: #888; }
.error-msg { color: red; padding: 20px; }
.empty-msg { padding: 20px; color: #666; }

/* --- TABELLA --- */
table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0;
    font-size: 13px; 
    color: #333;
    table-layout: auto;
}

td { 
    padding: 12px 15px; 
    border-bottom: 1px solid #eee; 
    background: #fff;
    white-space: nowrap;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

th { 
    background-color: #f8f9fa; 
    color: #002fff; 
    font-weight: 700; 
    text-transform: uppercase; 
    font-size: 11px; 
    padding: 15px;
    position: sticky; 
    top: 0; 
    z-index: 100; 
    border-bottom: 2px solid #ddd;
    border-top: 1px solid #ddd;
    cursor: pointer; 
    user-select: none;
    white-space: nowrap;
}

th:hover { background-color: #e9ecef; }
th i { margin-left: 5px; color: #bbb; }
th.sorted-asc i { color: #002fff; }
th.sorted-desc i { color: #ff0000; }
tr:hover td { background-color: #f1f8ff !important; }

/* MINI PANEL (dentro la chat) */
.data-panel {
    height: 40%;
    background: #fff;
    display: none;
    flex-direction: column;
    border-top: 2px solid #002fff;
    animation: slideUp 0.3s ease-out;
}
.data-header { display: flex; justify-content: space-between; padding: 10px 20px; background: #f9f9f9; border-bottom: 1px solid #eee; }
/* Stili specifici per il titolo del mini-panel (che prima erano inline) */
.data-header h3 { margin: 0; color: #002fff; font-size: 16px; }
.data-header h3 i { margin-right: 8px; color: #01b516; }

.table-container { flex: 1; overflow: auto; padding: 0 20px; }
.close-btn { background: none; border: none; font-size: 20px; cursor: pointer; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }


/* =========================================
   PAGINA DI LOGIN
   ========================================= */

.login-body {
    background: linear-gradient(135deg, #eef2f5 0%, #dbeeff 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100%;
    margin: 0;
    overflow: auto; /* Permette lo scroll se lo schermo è troppo piccolo in altezza */
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: white;
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 47, 255, 0.1);
    text-align: center;
    animation: slideUp 0.5s ease-out;
}

.login-header { margin-bottom: 30px; }
.login-header h2 { margin: 15px 0 5px; color: #333; font-size: 22px; font-weight: 600; }
.login-header p { color: #888; margin: 0; font-size: 14px; }

.icon-circle {
    width: 60px;
    height: 60px;
    background: #e6f0ff;
    color: #002fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    font-size: 24px;
}

.input-group {
    position: relative;
    margin-bottom: 20px;
    text-align: left;
}
.input-group i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
    pointer-events: none; /* L'icona non deve bloccare il click */
}
.input-group input {
    width: 100%;
    padding: 12px 15px 12px 45px; /* Spazio a sinistra per l'icona */
    border: 2px solid #eee;
    border-radius: 10px;
    box-sizing: border-box; /* Essenziale per non sforare la larghezza */
    outline: none;
    transition: 0.3s;
    font-size: 15px;
    color: #333;
}
.input-group input:focus {
    border-color: #002fff;
    background: #fbfdff;
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #002fff 0%, #01b516 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 10px;
}
.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 47, 255, 0.3);
}

.error-banner {
    background: #ffe6e6;
    color: #d63031;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #ffcccc;
}