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

:root {
    --primary: #1a56db;
    --primary-light: #e1effe;
    --primary-dark: #1e429f;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --user-bg: #1a56db;
    --user-text: #ffffff;
    --assistant-bg: #f1f5f9;
    --assistant-text: #1e293b;
    --danger: #dc2626;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
}

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

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.btn-new {
    background: var(--primary);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.btn-new:hover { background: var(--primary-dark); }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-light); color: var(--primary-dark); }

.conv-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-item .conv-delete {
    opacity: 0;
    border: none;
    background: none;
    color: var(--danger);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 16px;
    border-radius: 4px;
}

.conv-item:hover .conv-delete { opacity: 0.6; }
.conv-item .conv-delete:hover { opacity: 1; background: #fee2e2; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.back-link {
    color: var(--text-light);
    text-decoration: none;
    font-size: 13px;
}

.back-link:hover { color: var(--primary); }

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.chat-header .subtitle {
    color: var(--text-light);
    font-size: 13px;
}

.btn-menu {
    display: none;
    background: none;
    border: 1px solid var(--border);
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.welcome {
    text-align: center;
    padding: 60px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon { font-size: 48px; margin-bottom: 16px; }

.welcome h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text);
}

.welcome p {
    color: var(--text-light);
    margin-bottom: 24px;
    line-height: 1.5;
}

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

.chip {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    transition: all 0.15s;
}

.chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
}

.message {
    max-width: 800px;
    margin: 0 auto 16px;
    display: flex;
    gap: 12px;
}

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

.message .bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
}

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

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

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

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

.message .bubble th {
    background: #e2e8f0;
    font-weight: 600;
    white-space: nowrap;
}

.message .bubble td { white-space: nowrap; }

.message .bubble code {
    background: #e2e8f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

.message .bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
}

.message .bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

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

.message .bubble p { margin: 4px 0; }
.message .bubble p:first-child { margin-top: 0; }
.message .bubble p:last-child { margin-bottom: 0; }

.message .bubble strong { font-weight: 600; }

.query-info {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 11px;
    color: var(--text-light);
}

.loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    max-width: 800px;
    margin: 0 auto;
}

.loading .dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: bounce 1.4s infinite both;
    margin: 0 2px;
}

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

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

/* Input */
.input-area {
    padding: 12px 20px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.15s;
}

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

#input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    background: transparent;
    color: var(--text);
    max-height: 120px;
    line-height: 1.5;
}

.btn-send {
    background: var(--primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.btn-send:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.btn-send:not(:disabled):hover { background: var(--primary-dark); }

.input-footer {
    text-align: center;
    font-size: 11px;
    color: var(--text-light);
    margin-top: 6px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .btn-menu { display: block; }
}
