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

:root {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #999;
    --border: #e8e8e8;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --accent-light: #f4f2ff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.03);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 24px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===== Main ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-secondary);
}

/* Header */
.header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.header-subtitle {
    grid-column: 2;
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-right {
    grid-column: 3;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* User area */
.header-user {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    position: relative;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    user-select: none;
}

.header-user:hover {
    background: var(--bg-primary);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.header-username {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Dropdown */
.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    min-width: 140px;
    display: none;
    z-index: 200;
}

.user-dropdown.open {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s;
    border-radius: 0;
}

.dropdown-item:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.dropdown-item:hover {
    background: var(--bg-primary);
    color: #e74c3c;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 23% 10px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    background: var(--bg-primary);
}

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

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: #d5d5d5;
    border-radius: 10px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* Welcome */
.welcome {
    text-align: center;
    margin: auto;
    padding: 40px 20px;
    max-width: 480px;
}

.welcome-icon {
    font-size: 52px;
    margin-bottom: 24px;
    line-height: 1;
}

.welcome h2 {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.3px;
}

.welcome p {
    color: var(--text-muted);
    margin-bottom: 36px;
    font-size: 15px;
    line-height: 1.6;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.quick-actions button {
    padding: 10px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    box-shadow: var(--shadow-sm);
    font-family: inherit;
}

.quick-actions button:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(108,92,231,0.12);
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: fadeIn 0.2s ease-out;
}

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

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

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    line-height: 1.7;
    font-size: 15px;
    word-break: break-word;
}

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

.message.assistant .message-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-bubble p {
    margin-bottom: 8px;
}

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

.message-bubble ul, .message-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message-bubble li {
    margin-bottom: 4px;
}

.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    margin: 10px 0 6px;
    font-size: 15px;
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
    background: var(--accent-light);
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
}

.result-image {
    display: block;
    max-width: 100%;
    margin-top: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.message-bubble code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", monospace;
    color: #d9464a;
}

.message.user .message-bubble code {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.message-bubble pre {
    background: #1e1e2e;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
}

.message-bubble pre code {
    background: none;
    padding: 0;
    color: #cdd6f4;
    font-size: 13px;
}

.message-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.message-bubble th {
    background: #f9f9f9;
    font-weight: 600;
}

/* Intent badge */
.intent-badge {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: -14px;
    padding-left: 4px;
}

/* Loading dots */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    background: #c4c4c4;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

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

/* Input Area */
.input-area {
    padding: 12px 23% 18px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: 28px;
    padding: 6px 6px 6px 20px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.06);
}

#inputBox {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 0;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 180px;
    font-family: inherit;
    line-height: 1.5;
}

#inputBox::placeholder {
    color: #b0b0b8;
}

.btn-stop {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--text-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-stop:hover {
    background: #333;
    transform: scale(1.06);
}

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.06);
}

.btn-send:disabled {
    background: #e0e0e0;
    color: #bbb;
    cursor: not-allowed;
    transform: none;
}

.input-disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Mobile */
@media (max-width: 768px) {
    .main {
        width: 100%;
    }

    .message {
        max-width: 90%;
    }

    .chat-area {
        padding: 14px 16px 8px;
        gap: 16px;
    }

    .input-area {
        padding: 6px 16px 10px;
    }
}
