/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --bg:          #f4f6f9;
  --surface:     #ffffff;
  --surface-2:   #f0f2f5;
  --surface-3:   #e5e8ee;
  --border:      #e0e3ea;
  --border-2:    #c9cdd8;
  --text:        #111827;
  --text-muted:  #6b7280;
  --text-subtle: #9ca3af;

  --active:      #2563eb;

  --font-ui:     'Syne', sans-serif;
  --font-mono:   'DM Mono', monospace;
  --font-body:   -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── App shell ─────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: 228px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-wordmark {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--active);
  margin-bottom: 3px;
  transition: color 0.3s;
}

.sidebar-title {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

/* ── Chatbot list ──────────────────────────────────────────────────── */
.chatbot-list {
  padding: 12px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 0 8px 8px;
  display: block;
}

.chatbot-btn {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
  transition: background 0.12s, border-color 0.12s;
  text-align: left;
}

.chatbot-btn:hover { background: var(--surface-2); }

.chatbot-btn.active {
  background: var(--surface-2);
  border-color: var(--border);
  border-left-color: var(--btn-color);
}

.chatbot-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: box-shadow 0.25s;
}

.chatbot-btn.active .chatbot-dot {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--btn-color) 18%, transparent);
}

.chatbot-btn-label { flex: 1; min-width: 0; }

.chatbot-btn-name {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: block;
}

.chatbot-btn-desc {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-subtle);
  display: block;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Context panel ─────────────────────────────────────────────────── */
.sidebar-context {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-context::-webkit-scrollbar { width: 3px; }
.sidebar-context::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.context-field { margin-bottom: 10px; padding: 0 4px; }

.context-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}

.context-select {
  width: 100%;
  padding: 7px 26px 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  appearance: none;
  transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239ca3af' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.context-select:focus { outline: none; border-color: var(--active); }

.no-context {
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
  font-style: italic;
}

/* ── Chat main ─────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
}

/* ── Chat header ───────────────────────────────────────────────────── */
.chat-header {
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
}

.chat-header-identity {
  display: flex;
  align-items: center;
  gap: 9px;
}

.chat-header-pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  transition: background 0.3s;
}

.chat-header-name {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 4px;
}

.btn-new-session {
  padding: 6px 13px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}

.btn-new-session:hover { color: #dc2626; border-color: #dc2626; }

/* ── Messages ──────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

.message {
  display: flex;
  flex-direction: column;
  max-width: 840px;
  animation: msg-in 0.18s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user      { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; }

.bubble {
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--active);
  color: #fff;
  border-bottom-right-radius: 3px;
  transition: background 0.3s;
}

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--active);
  border-bottom-left-radius: 3px;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: border-left-color 0.3s;
}

/* ── Markdown ─────────────────────────────────────────────────────── */
.bubble.md { white-space: normal; }
.bubble.md > *:first-child { margin-top: 0; }
.bubble.md > *:last-child  { margin-bottom: 0; }

.bubble.md h1, .bubble.md h2, .bubble.md h3 {
  font-family: var(--font-ui);
  font-weight: 700;
  margin: 16px 0 6px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.bubble.md h1 { font-size: 15px; }
.bubble.md h2 { font-size: 14px; }
.bubble.md h3 { font-size: 13px; }
.bubble.md p  { margin: 8px 0; }
.bubble.md ul, .bubble.md ol { margin: 8px 0; padding-left: 20px; }
.bubble.md li { margin: 3px 0; }
.bubble.md strong { font-weight: 600; }
.bubble.md em     { font-style: italic; color: var(--text-muted); }
.bubble.md hr     { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.bubble.md blockquote {
  border-left: 2px solid var(--active);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 8px 0;
  transition: border-color 0.3s;
}
.bubble.md code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
}
.bubble.md pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.bubble.md pre code { background: none; border: none; padding: 0; }
.bubble.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
}
.bubble.md th, .bubble.md td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
}
.bubble.md th {
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.bubble.md tr:nth-child(even) td { background: var(--surface-2); }

/* ── Message metadata ─────────────────────────────────────────────── */
.msg-stats {
  display: flex;
  gap: 5px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-subtle);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 20px;
}

.stat-pill.cache {
  color: var(--active);
  border-color: color-mix(in srgb, var(--active) 35%, transparent);
  background: color-mix(in srgb, var(--active) 6%, transparent);
  transition: color 0.3s, border-color 0.3s;
}

.sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.source-btn {
  background: color-mix(in srgb, var(--active) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--active) 30%, transparent);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--active);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.source-btn:hover {
  background: color-mix(in srgb, var(--active) 16%, transparent);
}

.source-plain {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-subtle);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ── Knowledge sidebar panel ─────────────────────────────────────── */
.sidebar-kb {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.kb-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 6px 2px 10px;
}

.kb-loading {
  font-size: 11px;
  color: var(--text-subtle);
  padding: 8px 2px;
}

.kb-sources {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kb-source-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.kb-source-btn:hover {
  background: color-mix(in srgb, var(--active) 8%, transparent);
  border-color: color-mix(in srgb, var(--active) 30%, transparent);
}

.kb-source-name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--active);
  transition: color 0.15s;
}

.kb-source-origin {
  font-size: 10px;
  color: var(--text-subtle);
  line-height: 1.3;
}

/* ── Knowledge modal ──────────────────────────────────────────────── */
.km-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.km-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
}

.km-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.km-filename {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.km-close {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}
.km-close:hover { background: var(--surface-2); }

.km-body {
  overflow-y: auto;
  padding: 20px 24px;
  flex: 1;
}

.km-loading, .km-error {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}
.km-error { color: #ef4444; }

/* ── Suggestions ──────────────────────────────────────────────────── */
.suggestions {
  border-top: 1px solid var(--border);
  padding: 10px 24px;
  flex-shrink: 0;
  background: var(--surface);
}

.suggestions-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.chip:hover {
  border-color: var(--active);
  color: var(--active);
  background: color-mix(in srgb, var(--active) 6%, transparent);
}

/* ── Input area ───────────────────────────────────────────────────── */
.input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.input-area textarea {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--text);
  resize: none;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.input-area textarea::placeholder { color: var(--text-subtle); }
.input-area textarea:focus { outline: none; border-color: var(--active); }

.btn-send {
  padding: 0 20px;
  height: 42px;
  background: var(--active);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.12s, transform 0.1s, background 0.3s;
}

.btn-send:hover  { filter: brightness(1.1); }
.btn-send:active { transform: scale(0.97); }

.btn-send:disabled {
  background: var(--surface-3);
  color: var(--text-subtle);
  cursor: not-allowed;
  filter: none;
}

/* ── Loading indicator ────────────────────────────────────────────── */
.typing {
  display: flex;
  gap: 5px;
  padding: 13px 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--active);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  width: fit-content;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: border-left-color 0.3s;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--text-subtle);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 40px;
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
}

.empty-glyph {
  font-family: var(--font-mono);
  font-size: 28px;
  opacity: 0.25;
  transition: color 0.3s;
  line-height: 1;
}

.empty-name {
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  transition: color 0.3s;
}

.empty-about {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 2px;
}

.empty-when {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: left;
  width: 100%;
  margin-top: 4px;
}

.empty-when-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.empty-when-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.empty-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
  letter-spacing: 0.03em;
  margin-top: 8px;
}
