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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f1f5f9;
    color: #1e293b;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ============ TOP BAR ============ */
.topbar {
    background: #1e293b;
    color: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-brand h1 { font-size: 18px; font-weight: 600; }
.topbar-logo {
    width: 32px; height: 32px; border-radius: 8px;
    background: #2563eb; display: flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: 16px;
}

.topbar-session-info { display: flex; gap: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.session-badge {
    background: rgba(255,255,255,0.1); padding: 4px 10px;
    border-radius: 6px; font-size: 13px;
}
.session-badge code {
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
}

/* ============ EXPORT BUTTONS ============ */
.btn-export {
    background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
    color: white; padding: 3px 10px; border-radius: 4px; font-size: 12px;
    cursor: pointer; font-weight: 500;
}
.btn-export:hover { background: rgba(255,255,255,0.3); }

/* ============ LANGUAGE SELECT ============ */
.lang-select {
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
    color: white; padding: 6px 10px; border-radius: 6px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    outline: none;
}
.lang-select option { color: #1e293b; background: white; }

/* ============ BUTTONS ============ */
.btn {
    padding: 8px 16px; border: none; border-radius: 8px;
    font-size: 13px; font-weight: 500; cursor: pointer;
    transition: background 0.15s;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-icon {
    background: none; border: 1px solid rgba(255,255,255,0.2);
    color: inherit; width: 28px; height: 28px; border-radius: 6px;
    cursor: pointer; font-size: 14px; display: flex;
    align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,0.1); }

/* ============ MAIN LAYOUT ============ */
.main-layout {
    display: grid;
    grid-template-columns: 280px 1fr 360px;
    flex: 1;
    overflow: hidden;
}

/* ============ PANELS ============ */
.panel {
    display: flex; flex-direction: column;
    overflow: hidden; border-right: 1px solid #e2e8f0;
}
.panel:last-child { border-right: none; }
.panel-header {
    padding: 12px 16px; border-bottom: 1px solid #e2e8f0;
    display: flex; align-items: center; justify-content: space-between;
    background: white; flex-shrink: 0;
}
.panel-header h2 {
    font-size: 14px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: #64748b;
}

/* ============ SESSIONS SIDEBAR ============ */
.panel-sessions { background: white; }
.session-list { flex: 1; overflow-y: auto; }
.session-item {
    padding: 12px 16px; border-bottom: 1px solid #f1f5f9;
    cursor: pointer; transition: background 0.1s;
}
.session-item:hover { background: #f8fafc; }
.session-item--active { background: #eff6ff; border-left: 3px solid #2563eb; }
.session-item-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 4px;
}
.session-item-id { font-family: monospace; font-size: 12px; color: #64748b; }
.session-item-count { font-size: 11px; color: #94a3b8; }
.session-item-preview {
    font-size: 13px; color: #475569; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.session-item-date { font-size: 11px; color: #94a3b8; margin-top: 2px; }

.empty-state { text-align: center; color: #94a3b8; padding: 40px 16px; font-size: 13px; }

/* ============ CHAT PANEL ============ */
.panel-chat { background: #f8fafc; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex;
    flex-direction: column; gap: 12px;
}
.chat-empty-state {
    text-align: center; color: #94a3b8; padding: 40px;
    font-size: 14px; margin: auto;
}

.chat-msg { max-width: 75%; }
.msg-user { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }
.chat-msg-header {
    font-size: 11px; color: #94a3b8; margin-bottom: 2px;
    display: flex; gap: 8px;
}
.chat-msg-content {
    padding: 10px 14px; border-radius: 12px; font-size: 14px;
    line-height: 1.5; white-space: pre-wrap;
}
.msg-user .chat-msg-content {
    background: #2563eb; color: white; border-bottom-right-radius: 4px;
}
.msg-assistant .chat-msg-content {
    background: white; color: #1e293b; border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

/* Clickable assistant messages */
.msg-assistant.msg-clickable { cursor: pointer; }
.msg-assistant.msg-clickable:hover .chat-msg-content {
    border-color: #2563eb; box-shadow: 0 0 0 1px #2563eb;
}
.msg-assistant.msg-selected .chat-msg-content {
    border-color: #2563eb; background: #eff6ff;
}

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 8px 14px; }
.typing-dots span {
    width: 8px; height: 8px; background: #94a3b8; border-radius: 50%;
    animation: typingDot 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Input area */
.chat-input-area {
    display: flex; padding: 12px 16px; gap: 8px;
    border-top: 1px solid #e2e8f0; background: white;
}
.chat-input-area input {
    flex: 1; padding: 10px 14px; border: 1px solid #e2e8f0;
    border-radius: 8px; font-size: 14px; outline: none;
}
.chat-input-area input:focus { border-color: #2563eb; }
.chat-input-area input:disabled { background: #f1f5f9; }
.chat-status {
    padding: 4px 16px; font-size: 11px; text-align: center;
    background: white; border-top: 1px solid #f1f5f9;
}
.chat-status--connected { color: #16a34a; }
.chat-status--disconnected { color: #dc2626; }
.chat-status--error { color: #dc2626; }
.chat-status--reconnecting { color: #d97706; }
.chat-status--readonly { color: #2563eb; }
.chat-status--accumulating { color: #d97706; }

/* ============ TRACES PANEL ============ */
.panel-traces { background: white; }
.trace-content { flex: 1; overflow-y: auto; padding: 12px; }
.trace-empty-state { text-align: center; color: #94a3b8; padding: 40px 12px; font-size: 13px; }

.trace-tabs {
    display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px;
}
.trace-tab {
    display: flex; align-items: center; gap: 6px; padding: 6px 10px;
    border: 1px solid #e2e8f0; border-radius: 6px; background: white;
    cursor: pointer; font-size: 11px; transition: all 0.1s;
}
.trace-tab:hover { border-color: #2563eb; }
.trace-tab--active { background: #eff6ff; border-color: #2563eb; color: #2563eb; }
.trace-tab-num { font-weight: 600; }
.trace-tab-query { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace-tab-time { color: #94a3b8; }

.trace-section { margin-bottom: 16px; }
.trace-section h3 {
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    color: #64748b; letter-spacing: 0.5px; margin-bottom: 8px;
    padding-bottom: 4px; border-bottom: 1px solid #f1f5f9;
}
.trace-query {
    font-size: 13px; padding: 8px; background: #f8fafc;
    border-radius: 6px; margin-bottom: 6px;
}
.trace-meta { display: flex; gap: 12px; font-size: 11px; color: #94a3b8; }
.trace-timing { font-size: 11px; color: #94a3b8; margin-bottom: 8px; }
.trace-timing-breakdown {
    display: flex; flex-wrap: wrap; gap: 6px 12px;
    font-size: 11px; color: #64748b; margin-top: 6px;
    padding: 6px 8px; background: #f8fafc; border-radius: 4px;
}

.trace-chunk {
    border: 1px solid #f1f5f9; border-radius: 6px; padding: 8px;
    margin-bottom: 6px; font-size: 12px;
}
.trace-chunk-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.trace-chunk-num { font-weight: 600; color: #64748b; }
.trace-chunk-score { font-family: monospace; font-size: 11px; }
.score-similarity { color: #2563eb; }
.score-relevance { color: #16a34a; }
.trace-chunk-content { color: #475569; line-height: 1.4; word-break: break-word; }
.trace-chunk-meta { font-size: 10px; color: #94a3b8; margin-top: 4px; }
.trace-response {
    font-size: 13px; padding: 8px; background: #f0fdf4;
    border-radius: 6px; line-height: 1.5; white-space: pre-wrap;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
