* {
    box-sizing: border-box;
}

:root {
    --bg: #f2f4f7;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --primary: #78003f;
    --primary-text: #ffffff;
    --assistant-bubble: #eef1f6;
    --shadow: rgba(15, 23, 42, 0.08);
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
}

.chat-app {
    width: 100%;
    max-width: 720px;
    height: min(85vh, 860px);
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-title h1 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}

.chat-header-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
}

.clear-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.clear-btn:hover {
    background: #f3f4f6;
    color: var(--text);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    max-width: 100%;
}

.message.user {
    justify-content: flex-end;
}

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

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.45;
    font-size: 14.5px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

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

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

.message.error .bubble {
    background: #fee2e2;
    color: #991b1b;
}

.loading-indicator {
    display: flex;
    gap: 4px;
    padding: 0 20px 10px;
}

.loading-indicator.hidden {
    display: none;
}

.loading-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.2s infinite ease-in-out;
}

.loading-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.loading-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.message-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14.5px;
    font-family: inherit;
    min-height: 60px;
    max-height: 140px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease;
}

.message-input:focus {
    border-color: var(--primary);
}

.send-btn {
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.send-btn:hover {
    opacity: 0.9;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .chat-app {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
        border: none;
    }

    .bubble {
        max-width: 88%;
    }
}
