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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --user-bg: #eff6ff;
  --assistant-bg: #ffffff;
  --tag-bg: #f3f4f6;
  --tag-text: #374151;
  --tag-kf-bg: #fef3c7;
  --tag-kf-text: #92400e;
  --tag-ref-bg: #e0f2fe;
  --tag-ref-text: #0c4a6e;
  --error: #dc2626;
  --sidebar-width: 280px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
}

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

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

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

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

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

.sidebar-section h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-footer a { color: var(--primary); text-decoration: none; }

/* Document list */
.country-group summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 0;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.country-group summary::-webkit-details-marker { display: none; }
.country-group summary::before { content: "▶"; font-size: 0.6rem; transition: transform 0.15s; }
.country-group[open] summary::before { transform: rotate(90deg); }

.doc-count { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; }

.doc-list { list-style: none; padding: 4px 0 8px 12px; }

.doc-item {
  font-size: 0.78rem;
  padding: 3px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-link { color: var(--primary); text-decoration: none; }
.doc-link:hover { text-decoration: underline; }
.doc-link.no-link { color: var(--text); }

.no-docs { font-size: 0.8rem; color: var(--text-muted); }

/* ── Chat area ────────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px;
}

.chat-header {
  padding: 20px 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header h2 { font-size: 1rem; font-weight: 600; }
.chat-header p { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

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

.message { display: flex; }

.user-message { justify-content: flex-end; }
.user-message .message-body {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius) var(--radius) 2px var(--radius);
  padding: 10px 14px;
  max-width: 72%;
  font-size: 0.9rem;
}

.assistant-message .message-body {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-radius: 2px var(--radius) var(--radius) var(--radius);
  padding: 14px 16px;
  max-width: 100%;
  font-size: 0.88rem;
  line-height: 1.6;
}

.assistant-message.welcome .message-body {
  background: var(--user-bg);
  border-color: #bfdbfe;
}

.answer-text { white-space: pre-wrap; }

.error-text { color: var(--error); font-size: 0.85rem; }

/* Citations */
.citations {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.citations h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.citation {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.citation-number {
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.citation-meta { display: flex; flex-direction: column; gap: 3px; }
.citation-meta strong a { color: var(--primary); text-decoration: none; }
.citation-meta strong a:hover { text-decoration: underline; }

.citation-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.citation-excerpt {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-style: italic;
  line-height: 1.4;
}

/* Tags */
.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 500;
}
.tag-kf { background: var(--tag-kf-bg); color: var(--tag-kf-text); }
.tag-ref { background: var(--tag-ref-bg); color: var(--tag-ref-text); }

/* ── Input form ───────────────────────────────────────────────────────────── */
form {
  padding: 12px 0 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s;
}
textarea:focus { border-color: var(--primary); }

button[type="submit"] {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
button[type="submit"]:hover { background: var(--primary-hover); }
button[type="submit"]:disabled { background: #93c5fd; cursor: not-allowed; }

.hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.loading { font-size: 0.8rem; color: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .chat-area { padding: 0 12px; }
}
