* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary:       #1b2d5e;
    --primary-light: #2a4a8f;
    --accent:        #c0182a;
    --bg:            #faf0dc;
    --bubble-user:   #1b2d5e;
    --bubble-ai:     #fffdf5;
    --text:          #2c1f14;
    --text-light:    #7f6e5d;
    --shadow:        0 1px 3px rgba(0,0,0,0.12);
    --radius:        18px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── Layout principale ───────────────────────────────────────── */

.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg);
}

/* ── Header ──────────────────────────────────────────────────── */

.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

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

.avatar {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.header-info h1 {
    color: white;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

.status {
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #2ecc71;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* ── Area messaggi ───────────────────────────────────────────── */

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar       { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 4px; }

/* ── Singolo messaggio ───────────────────────────────────────── */

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeUp 0.25s ease-out;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-message   { align-self: flex-start; }
.user-message { align-self: flex-end; }

.bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.55;
    word-wrap: break-word;
    box-shadow: var(--shadow);
}

.ai-message .bubble {
    background: var(--bubble-ai);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.user-message .bubble {
    background: var(--bubble-user);
    color: white;
    border-bottom-right-radius: 4px;
}

.time {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.user-message .time { text-align: right; }

/* ── Indicatore di digitazione ───────────────────────────────── */

.typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px !important;
    width: 72px;
}

.typing span {
    width: 8px;
    height: 8px;
    background: #bdc3c7;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-7px); }
}

/* ── Form contatto (escalation) ──────────────────────────────── */

.contact-form-area {
    padding: 8px 16px;
    flex-shrink: 0;
}

.contact-card {
    background: white;
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent);
    animation: fadeUp 0.3s ease-out;
}

.contact-label {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 12px;
    font-weight: 500;
}

.contact-input-group {
    display: flex;
    gap: 8px;
}

.contact-input-group input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.contact-input-group input:focus {
    border-color: var(--primary-light);
}

.contact-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 24px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.contact-btn:hover  { background: #d4541e; }
.contact-btn:active { transform: scale(0.96); }

.contact-btn-cancel {
    background: transparent;
    color: #888;
    border: 1.5px solid #ccc;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.contact-btn-cancel:hover { background: #f0f0f0; color: #555; }

@media (max-width: 480px) {
    .contact-input-group {
        flex-wrap: wrap;
    }
    .contact-input-group input {
        flex: 1 1 100%;
    }
    .contact-btn {
        flex: 1;
    }
    .contact-btn-cancel {
        flex: 1;
    }
}

/* ── Area input ──────────────────────────────────────────────── */

.input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: white;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid #e0e0e0;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    background: #f8f8f8;
    transition: border-color 0.2s, background 0.2s;
}

#message-input:focus {
    border-color: var(--primary-light);
    background: white;
}

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

#send-btn:hover  { background: var(--primary); }
#send-btn:active { transform: scale(0.9); }

/* ── Desktop ─────────────────────────────────────────────────── */

@media (min-width: 600px) {
    body { background: #d6dce4; }
    .chat-wrapper {
        box-shadow: 0 8px 40px rgba(0,0,0,0.15);
        height: 100vh;
    }
}


/* ── Messaggi host (Titti) ───────────────────────────────────── */
.host-message {
    align-self: flex-start;
}
.host-message .bubble {
    background: #e8f8f5;
    color: #0d5c46;
    border: 1.5px solid #a8d5c8;
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
}
.sender-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 2px;
    padding-left: 4px;
}
.sender-host {
    color: #117a65;
}

/* ── Avatar Titti ────────────────────────────────────────────── */
.titti-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #117a65;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* ── Avatar Atis ─────────────────────────────────────────────── */
.ai-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.atis-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.ai-body {
    display: flex;
    flex-direction: column;
}
.contact-privacy {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 8px;
    margin-bottom: 0;
    text-align: center;
}