/* ────────────────────────────────────────────────
   RESET & BASE
───────────────────────────────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100dvh;
    min-height: -webkit-fill-available;
    width: 100vw;
    overflow: hidden;
    touch-action: manipulation;
    background: #0d0e17;
    color: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ────────────────────────────────────────────────
   MAIN LAYOUT
───────────────────────────────────────────────── */
.chat-header {
    flex-shrink: 0;
    padding: 14px 16px;
    background: linear-gradient(135deg, #1a1f38 0%, #0f1225 100%);
    border-bottom: 1px solid #1e2235;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

#messages-container {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px 16px 100px;           /* Extra bottom space for fixed input */
    background: #0b0d14;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    background: #11141f;
    border-top: 1px solid #1e2235;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
}

/* Messages */
.message {
    max-width: 82%;
    margin: 6px 0;
    padding: 12px 18px;
    border-radius: 22px;
    font-size: 15.5px;
    line-height: 1.45;
    word-wrap: break-word;
}

.message.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, #7a6cff 0%, #5a4aff 100%);
    color: white;
    border-bottom-right-radius: 8px;
}

.message.received {
    align-self: flex-start;
    background: #1f2538;
    color: #f0f2f5;
    border-bottom-left-radius: 8px;
}

/* Typing Indicator */
.typing-indicator {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: #1f2538;
    border-radius: 22px;
    border-bottom-left-radius: 8px;
    max-width: 82%;
    margin: 6px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #6b7280;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Input */
#user-input {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 30px;
    background: #1a1f2e;
    color: white;
    font-size: 16px !important;   /* Prevents iOS zoom */
}

#send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #7a6cff;
    color: white;
    border: none;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Avatar & Modal */
.avatar-container {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.avatar {
    width: 48px !important;
    height: 48px !important;
    border-radius: 50% !important;
    background-size: cover !important;
    border: 2px solid #7a6cff;
}

.avatar-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(12px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.avatar-modal.show { display: flex; }

.avatar-modal-content {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 0 60px rgba(195,0,255,0.7);
    object-fit: contain;
}

.avatar-modal-close {
    position: absolute;
    top: 30px;
    right: 40px;
    color: white;
    font-size: 60px;
    cursor: pointer;
}

/* Voice Note (if you use it) */
.voice-note {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(45, 30, 75, 0.95);
    border-radius: 9999px;
    max-width: 78%;
    align-self: flex-start;
}

/* Scrollbar */
#messages-container::-webkit-scrollbar {
    width: 6px;
}
#messages-container::-webkit-scrollbar-thumb {
    background: #2a3147;
    border-radius: 3px;
}

/* Responsive tweaks */
@media (max-width: 480px) {
    .message, .typing-indicator {
        max-width: 85%;
    }
    .chat-header, .input-area {
        padding-left: 12px;
        padding-right: 12px;
    }
}
