:root {
    --uil-blue: #0a4a8f;
    --uil-blue-deep: #06325f;
    --uil-blue-light: #1565b3;
    /* gradiente blu della copertina */
    --uil-gradient: linear-gradient(135deg, #06325f 0%, #0a4a8f 50%, #1565b3 100%);

    --sidebar-bg: #06325f;
    --sidebar-hover: #0a4a8f;
    --sidebar-text: #eaf1f9;
    --sidebar-text-dim: #9bb6d4;

    --bg: #ffffff;
    --text: #0d1b2e;
    --text-dim: #5a6b82;
    --border: #e2e9f1;
    --border-strong: #c5d4e6;
    --assistant-bg: #f3f7fc;

    --font: 'Saira Semi Condensed', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
    font-family: var(--font);
    font-weight: 300;
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ============ HEADER ============ */
.header {
    background: var(--uil-gradient);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo-badge {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    font-weight: 800;
    font-size: 13px;
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-logo h1 {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

.header-logo p {
    color: rgba(255,255,255,0.45);
    font-size: 11px;
}

.header-actions { display: flex; align-items: center; }

.btn-reset {
    padding: 6px 14px;
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.8);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-reset:hover { background: rgba(255,255,255,0.13); }

/* ============ CHAT WRAPPER ============ */
.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 20px;
    min-height: 0;
}

/* ============ MESSAGES ============ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 4px 0 8px;
    min-height: 0;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* Welcome */
.message-welcome {
    text-align: center;
    padding: 50px 20px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.message-welcome .welcome-icon {
    width: 52px;
    height: 52px;
    background: var(--uil-blue);
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    box-shadow: 0 6px 18px rgba(0,48,135,0.2);
}
.message-welcome .welcome-icon svg { width: 26px; height: 26px; }

.message-welcome h2 {
    font-size: 40px;
    font-weight: 700;
    color: var(--uil-blue);
    margin-bottom: 14px;
    letter-spacing: -0.02em;
}

.message-welcome p {
    font-size: 18px;
    color: var(--text-dim);
    max-width: 460px;
    margin: 0 auto;
    line-height: 1.5;
}
.message-welcome em { color: var(--uil-blue); font-style: normal; font-weight: 600; }

.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 28px;
    width: 100%;
    max-width: 520px;
}
.suggestions button {
    text-align: left;
    padding: 14px 16px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
}
/* alternati: blu (gradiente) e bianchi col bordo blu */
.suggestions button:nth-child(4n+1),
.suggestions button:nth-child(4n) {
    background: var(--uil-gradient);
    border: none;
    color: #fff;
}
.suggestions button:nth-child(4n+2),
.suggestions button:nth-child(4n+3) {
    background: var(--bg);
    border: 1.5px solid var(--uil-blue);
    color: var(--uil-blue);
}
.suggestions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(10,74,143,0.22);
}
@media (max-width: 600px) {
    .suggestions { grid-template-columns: 1fr; }
}

/* Message rows — WhatsApp style (bolle destra/sinistra) */
.message-row {
    display: flex;
    gap: 10px;
    padding: 5px 0;
    align-items: flex-end;
}
.message-row.user { flex-direction: row-reverse; }

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}
.avatar-bot { background: var(--uil-blue); color: #fff; }
.avatar-user { background: var(--uil-blue-light); color: #fff; }

.message-bubble {
    max-width: 75%;
    font-size: 15px;
    line-height: 1.55;
    word-break: break-word;
    padding: 9px 13px;
    border-radius: 16px;
    position: relative;
}

/* bot a sinistra */
.message-row.bot .message-bubble {
    background: var(--assistant-bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
/* user a destra, colore UIL */
.message-row.user .message-bubble {
    background: var(--uil-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }

/* Tasto speaker sotto la bolla del bot */
.speaker-btn {
    margin-top: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-dim);
    padding: 2px 4px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
}
.speaker-btn:hover { color: var(--uil-blue); background: var(--assistant-bg); }
.speaker-btn.playing { color: var(--uil-blue); }
.speaker-btn svg { width: 15px; height: 15px; }
.bot-wrap { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 7px; height: 7px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: bounce 1.3s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ============ INPUT ============ */
.chat-input-area {
    margin-top: 14px;
    background: var(--bg);
    border: 1.5px solid var(--border-strong);
    border-radius: 14px;
    display: flex;
    align-items: flex-end;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: border-color 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
}
.chat-input-area:focus-within {
    border-color: #b4b4b4;
    box-shadow: 0 2px 14px rgba(0,0,0,0.09);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    background: transparent;
    color: var(--text);
    resize: none;
    min-height: 48px;
    max-height: 160px;
    line-height: 1.5;
}
.chat-input::placeholder { color: var(--text-dim); }

.mic-btn {
    margin: 6px 2px 6px 6px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-dim);
    transition: color 0.15s, background 0.15s;
}
.mic-btn:hover { background: var(--assistant-bg); color: var(--text); }
.mic-btn svg { width: 18px; height: 18px; }

/* Durante la registrazione: onda minimal reattiva all'energia (--vad: 0→1) */
.mic-btn.recording {
    --vad: 0;
    color: #dc2626;
    position: relative;
}
.mic-btn.recording svg {
    /* l'icona pulsa leggermente con la voce */
    transform: scale(calc(1 + var(--vad) * 0.25));
    transition: transform 0.06s linear;
}
.mic-btn.recording::before {
    /* alone che si espande con l'energia */
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #dc2626;
    opacity: calc(0.12 + var(--vad) * 0.28);
    transform: scale(calc(0.8 + var(--vad) * 0.9));
    transition: transform 0.06s linear, opacity 0.06s linear;
    z-index: -1;
}

.send-btn {
    margin: 6px;
    width: 36px;
    height: 36px;
    background: var(--text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.send-btn:hover:not(:disabled) { opacity: 0.8; }
.send-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; }

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    color: white;
    background: #1a1a1a;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.25s ease;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-error { background: #dc2626; }
.toast-success { background: #059669; }
.toast-warning { background: #d97706; }

@media (max-width: 600px) {
    .chat-wrapper { padding: 12px 12px 12px; }
    .header { padding: 0 16px; }
}
