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

:root {
  --primary: #1a5276;
  --primary-hover: #2e86c1;
  --primary-light: #3498db;
  --sidebar-bg: #1a1a2e;
  --sidebar-hover: #2a2a4a;
  --danger: #e74c3c;
  --text: #333;
  --text-muted: #666;
  --text-light: #888;
  --text-placeholder: #999;
  --border: #e0e0e0;
  --border-light: #ddd;
  --bg: #f5f5f5;
  --bg-white: #fff;
  --bubble-user: var(--primary-hover);
  --bubble-assistant-border: var(--border);
  --disabled: #ccc;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; height: 100vh; display: flex; background: var(--bg); }
#root { width: 100%; height: 100vh; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; width: 100%; height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%); }
.login-box { background: var(--bg-white); padding: 40px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,0.15); text-align: center; width: 360px; }
.login-box h1 { font-size: 24px; color: var(--primary); margin-bottom: 8px; }
.login-box p { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.login-box input { width: 100%; padding: 12px; border: 1px solid var(--border-light); border-radius: 6px; margin-bottom: 12px; font-size: 14px; }
.login-box button { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; }
.login-box button:hover { background: var(--primary-hover); }
.login-box .error { color: var(--danger); font-size: 12px; margin-top: 8px; }
.login-box .toggle { color: var(--primary-hover); cursor: pointer; font-size: 13px; margin-top: 12px; }

/* App layout */
#app { display: flex; width: 100%; height: 100vh; }
.sidebar { width: 280px; background: var(--sidebar-bg); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 16px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h2 { font-size: 16px; font-weight: 600; }
.new-chat-btn { background: var(--primary-hover); border: none; color: #fff; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.new-chat-btn:hover { background: var(--primary-light); }
.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; color: #ccc; margin-bottom: 2px; display: flex; justify-content: space-between; align-items: center; position: relative; }
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--primary-hover); color: #fff; }
.session-item .menu-btn { opacity: 0; background: none; border: none; color: #fff; cursor: pointer; font-size: 18px; padding: 0; line-height: 1; border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.session-item:hover .menu-btn { opacity: 1; }
.session-item .menu-btn:hover { background: rgba(255,255,255,0.15); }
.session-menu { position: absolute; right: 8px; top: 100%; background: var(--bg-white); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); z-index: 10; min-width: 140px; }
.session-menu button { display: block; width: 100%; padding: 8px 14px; border: none; background: none; text-align: left; font-size: 13px; cursor: pointer; color: var(--text); }
.session-menu button:hover { background: var(--bg); }
.session-menu button.danger { color: var(--danger); }
.session-menu button.danger:hover { background: #fde8e8; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid #333; font-size: 12px; color: var(--text-light); display: flex; justify-content: space-between; }
.logout-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 12px; }

/* Chat area */
.chat-area { flex: 1; display: flex; flex-direction: column; }
.chat-header { padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-white); font-weight: 600; font-size: 15px; }
.chat-header .session-id { font-weight: 400; font-size: 11px; color: var(--text-light); margin-left: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 20px; }
.message { max-width: 85%; margin-bottom: 16px; }
.message.user { margin-left: auto; }
.message.assistant { margin-right: auto; }
.message .bubble { padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.6; }
.message.user .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 4px; }
.message.assistant .bubble { background: var(--bg-white); border: 1px solid var(--bubble-assistant-border); border-bottom-left-radius: 4px; }
.message .sources { font-size: 11px; color: var(--text-light); margin-top: 6px; padding: 0 4px; }
.message .sources summary { cursor: pointer; }
.msg-footer { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 6px; gap: 8px; }
.msg-footer .sources { flex: 1; }
.rate-btn { font-size: 11px; color: var(--text-light); cursor: pointer; background: none; border: none; padding: 2px 8px; white-space: nowrap; flex-shrink: 0; }
.rate-btn:hover { background: var(--bg); }
.rate-panel { font-size: 12px; margin-top: 6px; padding: 8px; background: var(--bg); border-radius: 6px; border: 1px solid var(--border-light); }
.rate-stars { display: flex; gap: 4px; margin-bottom: 6px; }
.rate-stars span { cursor: pointer; font-size: 18px; color: var(--border-light); }
.rate-stars span.active { color: #f39c12; }
.rate-panel textarea { width: 100%; padding: 6px; border: none; border-radius: 4px; font-size: 12px; font-family: inherit; resize: vertical; min-height: 40px; background: var(--bg-white); outline: none; }
.rate-panel button { margin-top: 4px; padding: 4px 12px; font-size: 11px; background: var(--primary); color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.rate-panel button:hover { background: var(--primary-hover); }
.rate-saved { font-size: 11px; color: var(--text-light); cursor: pointer; }
.rate-saved:hover { color: var(--text); }
.message .sources .source-item { padding: 2px 0; }
.message .sources .source-also-relevant { opacity: 0.7; }
.message .thinking { font-size: 11px; color: var(--text-light); margin-top: 6px; margin-bottom: 8px; padding: 0 4px; }
.message .thinking summary { cursor: pointer; }
.message .thinking .step { padding: 2px 0; }

/* Input */
.input-area { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--bg-white); }
.input-row { display: flex; gap: 8px; }
.input-row input, .input-row textarea { flex: 1; padding: 12px; border: 1px solid var(--border-light); border-radius: 8px; font-size: 14px; font-family: inherit; resize: none; overflow-y: auto; min-height: 42px; max-height: 200px; }
.input-row button { padding: 12px 24px; background: var(--primary); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; }
.input-row button:hover { background: var(--primary-hover); }
.input-row button:disabled { background: var(--disabled); cursor: not-allowed; }

/* Empty state */
.empty-state { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-placeholder); font-size: 15px; }

/* Loading */
.typing { display: inline-block; }
.typing span { display: inline-block; width: 8px; height: 8px; background: var(--text-placeholder); border-radius: 50%; margin: 0 2px; animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-8px); } }

/* Markdown rendering */
.bubble h1,.bubble h2,.bubble h3,.bubble h4 { margin: 12px 0 6px; font-weight: 600; font-family: inherit; }
.bubble h1 { font-size: 16px; }
.bubble h2 { font-size: 15px; }
.bubble h3 { font-size: 14px; }
.bubble h4 { font-size: 14px; }
.bubble ul,.bubble ol { padding-left: 20px; margin: 4px 0; }
.bubble li { margin: 1px 0; }
.bubble p { margin: 4px 0; }
.bubble blockquote { border-left: 3px solid var(--border); padding-left: 12px; margin: 6px 0; color: var(--text-muted); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble sup.cite { font-size: 0.7em; color: var(--accent); cursor: default; margin: 0 1px; }
.bubble code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 13px; font-family: inherit; }
.bubble pre { background: #f0f0f0; padding: 8px 12px; border-radius: 6px; margin: 6px 0; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 12px; }
.bubble th,.bubble td { border: 1px solid var(--border-light); padding: 4px 8px; }
.bubble th { background: var(--bg); }
