/* ---------- 0. Design tokens ---------- */
:root {
  --color-primary: #2563eb;
  --color-bg: #f6f6f6;
  --color-surface: #ffffff;
  --color-surface-alt: #e5e5e5;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --radius: 12px;
  --font-sans: 'Inter', system-ui, sans-serif;
}

.is-hidden { display: none !important; }

/* ---------- 1. Reset / layout ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
}

body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--color-bg);
  font-family: var(--font-sans);
  color: var(--color-text);
  line-height: 1.45;
}

a { color: var(--color-primary); }

/* ---------- 2. Wrapper ---------- */
.chatbot {
  max-width: 640px;
  width: 100%;
  text-align: center;
}

/* ---------- 3. Typography ---------- */
.chatbot__title {
  font-size: 2.95rem;
  font-weight: 600;
  line-height: 1;
  margin-bottom: 1.25rem;
}

.chatbot__subtitle {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: 2.5rem;
}

/* ---------- 4. Input group ---------- */
.input-group {
  display: flex;
  background: var(--color-surface);
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative; /* for absolutely-positioned button */
}

.input-group textarea {
  flex: 1 1 auto;
  border: none;
  resize: none;
  padding: 1.25rem 6rem 1.25rem 1rem;
  font: inherit;
  line-height: 1.4;
}

.input-group textarea:focus { outline: none; }

.input-group button {
  border: none;
  background: var(--color-primary);
  color: #fff;
  padding: 0.5rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  height: auto;
  border-radius: calc(var(--radius) / 2);
}

.input-group button:hover:not(:disabled) { background: #1e49c5; }
.input-group button:disabled { background: #9ca3af; cursor: not-allowed; }

/* ---------- 5. Answer bubble ---------- */
#answer-area {
  margin-top: 2rem;
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  text-align: left;
}

#answer-text {
  white-space: pre-wrap;
  margin-bottom: 1rem;
}

/* ---------- 6. Loading spinner ---------- */
#loading-indicator {
  display: flex;               /* visible state; hidden via .is-hidden */
  align-items: center;
  gap: 0.75rem;
  font-style: italic;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

#loading-indicator .loading-text { display: none; }

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-left-color: var(--color-primary);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 7. Sources ---------- */
.source-item {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--color-text-muted);
  border-radius: calc(var(--radius) / 2);
  background-color: var(--color-surface);
}

.source-item .source-metadata {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.source-item .source-content {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 0.9rem;
  color: var(--color-text);
}

.kb-source .source-metadata { font-weight: 500; }

.web-source .source-metadata a { text-decoration: none; }
.web-source .source-metadata a:hover { text-decoration: underline; }

/* Remove default disclosure triangle on summary (optional) */
details summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

details[open] summary { margin-bottom: 0.75rem; }
