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

:root {
    --primary: #1e3a5f;
    --primary-light: #2a4f7a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --user-bubble: #3b82f6;
    --bot-bubble: #f0f0f0;
    --bot-text: #1a1a1a;
    --bg-start: #e8edf2;
    --bg-end: #d5dce4;
    --surface: #ffffff;
    --border: #dce1e8;
    --meta: #7a8a9e;
    --font: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: linear-gradient(160deg, var(--bg-start), var(--bg-end));
}

/* Chat App Container */
.chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.12);
}

/* Header */
.title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary);
    color: #fff;
    padding: 16px 20px;
    flex-shrink: 0;
}

.title-text {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.title-bar-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.title-bar-btn:hover {
    opacity: 1;
}

.title-bar-spacer {
    width: 26px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: linear-gradient(180deg, #f5f7fa 0%, #eef1f5 100%);
}

/* Welcome Screen */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 56px 20px 24px;
    gap: 10px;
}

.welcome-profile {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
}

.welcome-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 4px;
}

.welcome-desc {
    font-size: 0.85rem;
    color: var(--meta);
}

.quick-questions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
    width: 100%;
    max-width: 360px;
}

.quick-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 11px 18px;
    font-size: 0.85rem;
    color: var(--accent);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    font-family: var(--font);
}

.quick-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Date Separator */
.date-sep {
    text-align: center;
    padding: 14px 0 8px;
    font-size: 0.73rem;
    color: var(--meta);
}

.date-sep span {
    background: rgba(0, 0, 0, 0.06);
    padding: 4px 14px;
    border-radius: 12px;
}

/* Message Row */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msgSlide 0.25s ease;
}

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

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

.msg-row.bot {
    flex-direction: row;
}

/* Bot Profile */
.msg-profile {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    align-self: flex-start;
}

.msg-body {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}

.msg-row.user .msg-body {
    align-items: flex-end;
}

.msg-sender {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 4px;
    margin-left: 4px;
}

/* Bubble Content + Time */
.msg-content {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.msg-row.user .msg-content {
    flex-direction: row-reverse;
}

.bubble {
    padding: 10px 14px;
    line-height: 1.6;
    font-size: 0.9rem;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-row.user .bubble {
    background: var(--user-bubble);
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}

.msg-row.bot .bubble {
    background: var(--bot-bubble);
    color: var(--bot-text);
    border-radius: 16px 16px 16px 4px;
}

.msg-time {
    font-size: 0.67rem;
    color: var(--meta);
    white-space: nowrap;
    flex-shrink: 0;
    padding-bottom: 2px;
}

/* Sources */
.sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #ddd;
    font-size: 0.75rem;
    color: #888;
}

.sources span {
    display: inline-block;
    background: #e8ebef;
    border-radius: 4px;
    padding: 2px 8px;
    margin: 2px 4px 2px 0;
}

/* Typing / Loading Animation */
.loading-text {
    font-size: 0.82rem;
    color: #888;
    margin-bottom: 4px;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 6px 2px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #aaa;
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

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

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

@keyframes blink {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Input Bar */
.input-bar {
    background: var(--surface);
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

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

#userInput {
    flex: 1;
    padding: 11px 16px;
    border: 1px solid var(--border);
    border-radius: 22px;
    font-size: 0.9rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9fafb;
}

#userInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: #fff;
}

#sendBtn {
    padding: 10px 22px;
    border: none;
    border-radius: 22px;
    background: var(--accent);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

#sendBtn:hover:not(:disabled) {
    background: var(--accent-hover);
}

#sendBtn:disabled {
    background: #c4cdd8;
    color: #fff;
    cursor: default;
}

/* Markdown in Bubbles */
.bubble p {
    margin: 0 0 6px;
}

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

.bubble strong.md-h1 {
    display: block;
    font-size: 1.1rem;
    margin: 10px 0 4px;
}

.bubble strong.md-h2 {
    display: block;
    font-size: 1.02rem;
    margin: 8px 0 4px;
}

.bubble strong.md-h3 {
    display: block;
    font-size: 0.95rem;
    margin: 6px 0 3px;
}

.bubble strong.md-h4 {
    display: block;
    font-size: 0.9rem;
    margin: 4px 0 2px;
}

.bubble .md-li {
    padding-left: 8px;
    margin: 2px 0;
}

.bubble .md-num {
    color: var(--accent);
    font-weight: 600;
}

.bubble .md-bullet::before {
    content: "\2022";
    color: var(--accent);
    font-weight: 700;
}

.bubble hr.md-hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 8px 0;
}

.bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 0.82rem;
    line-height: 1.5;
}

.bubble code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85em;
}

.bubble > code {
    background: #e8ebef;
    padding: 1px 5px;
    border-radius: 4px;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar {
    width: 5px;
}

.chat-area::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 640px) {
    .chat-app {
        max-width: 100%;
        box-shadow: none;
    }

    .msg-body {
        max-width: 80%;
    }

    .quick-questions {
        max-width: 100%;
    }

    .title-bar {
        padding: 14px 14px;
    }

    #sendBtn {
        padding: 10px 16px;
    }
}
