/* ---- Reset & variables ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #1a1a2e;
  --bg-surface:   #16213e;
  --bg-elevated:  #0f3460;
  --border:       #2a2a4a;
  --text:         #e0e0f0;
  --text-muted:   #888aaa;
  --accent:       #4f8ef7;
  --accent-hover: #6aa3ff;
  --user-bubble:  #0f3460;
  --ai-bubble:    #1e1e3a;
  --tool-bubble:  #1a2e1a;
  --error:        #e74c3c;
  --success:      #2ecc71;
  --radius:       12px;
  --sidebar-w:    220px;
  --shadow:       0 4px 20px rgba(0,0,0,.4);
}

body.light {
  --bg:           #f0f2f5;
  --bg-surface:   #ffffff;
  --bg-elevated:  #e8edf5;
  --border:       #d0d5e0;
  --text:         #1a1a2e;
  --text-muted:   #666680;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --user-bubble:  #dbeafe;
  --ai-bubble:    #ffffff;
  --tool-bubble:  #dcfce7;
  --shadow:       0 4px 20px rgba(0,0,0,.1);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.logo-icon { font-size: 1.3rem; }
.logo-text { font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: .02em; }

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--bg-elevated); color: var(--text); }
.nav-item.active { background: var(--bg-elevated); color: var(--accent); font-weight: 600; }

.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; }

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

.theme-btn {
  background: none;
  border: none;
  width: 100%;
  text-align: left;
}

/* ---- Main content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.content-section {
  display: none;
  flex-direction: column;
  height: 100%;
}
.content-section.active { display: flex; }

/* ---- Chat header ---- */
.chat-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-header h1 { font-size: 1rem; font-weight: 600; flex: 1; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-elevated); color: var(--text); }

/* ---- Messages ---- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.message { display: flex; flex-direction: column; gap: 4px; max-width: 720px; width: 100%; margin: 0 auto; padding: 0 24px; }
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.message-role {
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: .93rem;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}
.message.user .message-bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; }
.message.assistant .message-bubble { background: var(--ai-bubble); border-bottom-left-radius: 4px; }

/* Typing cursor on streaming messages */
.message-bubble.streaming::after {
  content: "▋";
  animation: blink .8s step-end infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

/* Tool call / result blocks */
.tool-event {
  background: var(--tool-bubble);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .78rem;
  font-family: monospace;
  max-width: 720px;
  width: calc(100% - 48px);
  margin: 0 auto;
  color: var(--text-muted);
}
.tool-event .tool-name { color: var(--success); font-weight: bold; }
.tool-event .tool-label { color: var(--accent); text-transform: uppercase; font-size: .68rem; letter-spacing: .08em; }
.tool-event pre {
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.error-msg {
  max-width: 720px;
  width: calc(100% - 48px);
  margin: 0 auto;
  background: rgba(231,76,60,.15);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .85rem;
}

/* ---- Input area (Claude Desktop style) ---- */
.input-wrapper {
  padding: 16px 24px 8px;
  background: var(--bg);
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  align-self: center;
  width: 100%;
  padding: 16px 24px 8px;
}

.input-area {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  transition: border-color .2s;
  box-shadow: var(--shadow);
}
.input-area:focus-within { border-color: var(--accent); }

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 2px 4px;
  font-size: .95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.5;
}

#send-btn {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { background: var(--border); cursor: not-allowed; }
#send-btn svg { width: 16px; height: 16px; }

.status-bar {
  text-align: center;
  font-size: .75rem;
  color: var(--text-muted);
  padding: 6px 4px 2px;
  min-height: 24px;
}

/* ---- Other sections ---- */
.page-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}
.page-header h1 { font-size: 1rem; font-weight: 600; }

.placeholder-content {
  padding: 40px 32px;
  color: var(--text-muted);
  font-size: .95rem;
  line-height: 1.7;
}

.faq-list { display: flex; flex-direction: column; gap: 20px; max-width: 640px; }
.faq-list dt { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.faq-list dd { color: var(--text-muted); padding-left: 4px; }
.faq-list code {
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .88em;
  color: var(--accent);
}

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

/* Responsive */
@media (max-width: 640px) {
  .sidebar { width: 56px; min-width: 56px; padding: 12px 8px; }
  .logo-text, .nav-label { display: none; }
  .sidebar-logo { justify-content: center; padding: 8px 0 16px; }
  .nav-item { justify-content: center; padding: 10px; }
  .message { max-width: 100%; }
}
