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

:root {
    --bg: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text: #e5e5e5;
    --text-dim: #888;
    --accent: #6c5ce7;
    --accent-hover: #7c6df7;
    --border: #2a2a2a;
    --green: #00b894;
    --red: #e74c3c;
    --radius: 12px;
    --sidebar-width: 280px;
}

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

.screen { height: 100vh; }

/* Login */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f0f0f 0%, #1a1a2e 100%);
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    width: 380px;
}

.login-logo { font-size: 48px; margin-bottom: 16px; }
.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-subtitle { color: var(--text-dim); margin-bottom: 24px; }

.login-card input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
}

.login-card input:focus { border-color: var(--accent); }

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-card button:hover { background: var(--accent-hover); }
.error { color: var(--red); margin-top: 12px; font-size: 14px; }

/* App Layout */
#app { display: flex; }

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo { font-size: 28px; }
.logo-text { font-weight: 700; font-size: 18px; }

.sidebar-section {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
}

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 600;
}

.kb-item, .session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.kb-item:hover, .session-item:hover { background: var(--bg-tertiary); }
.kb-item.active, .session-item.active { background: var(--accent); color: white; }

.session-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    position: relative;
}

.session-item .session-date {
    font-size: 11px;
    color: var(--text-dim);
}

.session-item .session-preview {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.session-search {
    margin-bottom: 12px;
}

.session-search input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.session-search input:focus {
    border-color: var(--accent);
}

.session-actions {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: none;
    gap: 4px;
}

.session-item:hover .session-actions {
    display: flex;
}

.session-action-btn {
    background: rgba(0, 0, 0, 0.8);
    border: none;
    color: var(--text);
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.session-action-btn:hover {
    background: rgba(0, 0, 0, 1);
}

.session-action-btn.pin-btn.pinned {
    color: var(--accent);
}

.session-item.pinned::before {
    content: "📌 ";
    position: absolute;
    left: -2px;
    top: 10px;
    font-size: 12px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-new-session {
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-new-session:hover { background: var(--accent-hover); }

.btn-logout {
    padding: 8px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

/* Main */
#main { flex: 1; display: flex; flex-direction: column; height: 100vh; position: relative; }

.main-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
}

.main-welcome h2 { margin-bottom: 8px; }
.main-welcome p { color: var(--text-dim); margin-bottom: 32px; }

#kb-cards {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.kb-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 220px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
    text-align: center;
}

.kb-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.kb-card .card-icon { font-size: 40px; margin-bottom: 12px; }
.kb-card .card-name { font-weight: 600; margin-bottom: 4px; }
.kb-card .card-desc { font-size: 12px; color: var(--text-dim); }

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

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.chat-header-actions { display: flex; gap: 4px; }

.chat-header-actions button {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}

.chat-header-actions button:hover { background: var(--bg-tertiary); }

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

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

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

.message.assistant .msg-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.message.assistant .msg-content a { color: var(--accent); }
.message.assistant .msg-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.msg-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.msg-sources {
    font-size: 11px;
    color: var(--text-dim);
    cursor: pointer;
}

.msg-sources:hover { color: var(--accent); }

.msg-feedback { display: flex; gap: 4px; }
.msg-feedback button {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.msg-feedback button:hover { opacity: 1; }
.msg-feedback button.active { opacity: 1; }

.message.loading .dots::after {
    content: '⠋';
    animation: loading 0.8s infinite;
}

@keyframes loading {
    0% { content: '⠋'; }
    14% { content: '⠙'; }
    28% { content: '⠹'; }
    42% { content: '⠸'; }
    57% { content: '⠼'; }
    71% { content: '⠴'; }
    85% { content: '⠦'; }
    100% { content: '⠧'; }
}

/* Sources Panel */
.sources-panel {
    position: absolute;
    right: 0;
    top: 60px;
    bottom: 80px;
    width: 350px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px;
    z-index: 10;
}

.sources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sources-header button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
}

.source-item {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    font-size: 13px;
}

.source-item .source-topic {
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
    margin-bottom: 4px;
}

.source-item .source-text {
    color: var(--text-dim);
    line-height: 1.4;
    margin-bottom: 6px;
}

.source-item a {
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
}

.source-item .source-score {
    font-size: 11px;
    color: var(--text-dim);
    float: right;
}

/* Chat Input */
.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

#chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
}

#chat-input:focus { border-color: var(--accent); }

#send-btn {
    padding: 12px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* Mobile */
@media (max-width: 768px) {
    #sidebar { display: none; }
    .message { max-width: 95%; }
    .sources-panel { width: 100%; }
}
