/* Premium Mobile App Theme */
:root {
    --app-bg: #f0f2f5;
    --header-bg: rgba(255, 255, 255, 0.95);
    --primary-color: #667eea;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chat-bg-user: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chat-bg-ai: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #718096;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
    --input-bg: #f7fafc;
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Kanit', sans-serif;
    background: #eef2f6;
    /* Soft gray-blue background */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    color: var(--text-primary);
}

/* Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    max-width: 600px;
    /* Limit width on desktop just in case */
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
}

/* Header */
.app-header {
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: calc(10px + var(--safe-area-top, 0px)) 20px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
    z-index: 100;
}

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

.mascot-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    object-fit: cover;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.header-title {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

.header-status {
    font-size: 0.75rem;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.home-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #f7fafc;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.home-btn:active {
    background: #edf2f7;
    transform: scale(0.95);
}

/* Chat Area */
.chat-area {
    flex: 1;
    background: #f0f2f5;
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

.message.ai-message {
    justify-content: flex-start;
}

.message.user-message {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-top: auto;
    /* Bottom align avatar */
    margin-bottom: 2px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.ai-message .msg-avatar {
    background: white;
    margin-right: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.user-message .msg-avatar {
    display: none;
    /* Hide user avatar on mobile to save space usually */
}

.msg-bubble {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

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

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

.msg-bubble p {
    margin: 0 0 8px 0;
}

.msg-bubble p:last-child {
    margin: 0;
}

/* Input Area */
.input-area {
    background: white;
    padding: 15px 15px calc(15px + var(--safe-area-bottom, 0px));
    border-radius: 25px 25px 0 0;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 100;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.text-input {
    flex: 1;
    background: var(--input-bg);
    border: none;
    padding: 14px 20px;
    border-radius: 25px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.text-input:focus {
    background: #edf2f7;
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--primary-gradient);
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s;
}

.send-btn:active {
    transform: scale(0.9);
}

/* Voice Button - Floating or centered */
.voice-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.voice-btn-main {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b6b, #ee5253);
    color: white;
    border: 6px solid white;
    box-shadow: 0 8px 20px rgba(238, 82, 83, 0.3);
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-top: -45px;
    /* Pull up to overlap input area border */
    position: relative;
    z-index: 10;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.voice-btn-main:active {
    transform: scale(0.9);
}

.voice-btn-main.listening {
    animation: ripple 1.5s linear infinite;
}

.voice-hint {
    position: absolute;
    bottom: -20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ripple {
    0% {
        box-shadow: 0 0 0 0 rgba(238, 82, 83, 0.5), 0 0 0 0 rgba(238, 82, 83, 0.5);
    }

    100% {
        box-shadow: 0 0 0 20px rgba(238, 82, 83, 0), 0 0 0 40px rgba(238, 82, 83, 0);
    }
}

/* Loading */
.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}