/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Lora:wght@400;500&family=Source+Sans+3:wght@400;500&display=swap');

:root {
  --ha-gold: #C8963E;
  --ha-green: #2D6A4F;
  --ha-bg: #ffffff; /* Default background */
  --ha-surface: #f8f9fa; /* Default surface */
  --ha-border: #e0e0e0; /* Default border */
  --ha-text: #1a1a1a;
  --ha-muted: #666666;
  --ha-radius: 12px;
}

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

#ha-widget {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  color: var(--ha-text);
  border: 0.5px solid var(--ha-border);
  border-radius: 16px;
  overflow: hidden;
  max-width: 680px;
  margin: 20px auto;
}

#ha-header {
  background: var(--ha-green);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#ha-header-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: white;
}

#ha-header-title { color: #fff; font-weight: 500; font-size: 15px; font-family: 'Lora', serif; }
#ha-header-sub { color: rgba(255,255,255,0.7); font-size: 12px; margin-top: 1px; }

#ha-source-bar, #ha-category-bar {
  background: var(--ha-surface);
  padding: 10px 16px;
  display: flex;
  gap: 6px;
  border-bottom: 0.5px solid var(--ha-border);
  flex-wrap: wrap;
}

.ha-src-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 0.5px solid var(--ha-border);
  background: var(--ha-bg);
  color: var(--ha-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.ha-src-btn.active {
  background: var(--ha-green);
  color: #fff;
  border-color: var(--ha-green);
}

#ha-messages {
  height: 400px;
  overflow-y: auto;
  padding: 16px;
  background: var(--ha-bg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ha-msg { display: flex; gap: 8px; align-items: flex-start; }
.ha-msg.user { flex-direction: row-reverse; }

.ha-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--ha-surface);
  border: 0.5px solid var(--ha-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
}

.ha-msg.user .ha-avatar { background: var(--ha-green); color: #fff; }

.ha-bubble {
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 12px;
  background: var(--ha-surface);
  border: 0.5px solid var(--ha-border);
  font-size: 13.5px;
  line-height: 1.6;
}

.ha-msg.user .ha-bubble {
  background: var(--ha-green);
  color: #fff;
  border-color: transparent;
}

.ha-label {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(200,150,62,0.13);
  color: var(--ha-gold);
  display: inline-block;
  margin-bottom: 5px;
  font-weight: 500;
}

.ha-typing { display: flex; gap: 4px; padding: 6px 0; }
.ha-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ha-muted);
  animation: bounce 1.2s infinite;
}
.ha-dot:nth-child(2) { animation-delay: 0.2s; }
.ha-dot:nth-child(3) { animation-delay: 0.4s; }

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

#ha-input-area {
  padding: 12px 16px;
  background: var(--ha-bg);
  border-top: 0.5px solid var(--ha-border);
  display: flex; gap: 8px;
}

#ha-input {
  flex: 1;
  border: 0.5px solid var(--ha-border);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  resize: none;
}

#ha-send {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--ha-green);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

#ha-send svg { width: 16px; height: 16px; fill: #fff; }

/* Markdown rendered inside an answer bubble. The .ha-md class is only
   applied to bot bubbles whose content went through marked + DOMPurify,
   so user/typing bubbles are unaffected. Defaults are tight - margins
   collapse cleanly with the bubble's existing padding. */
.ha-md > :first-child { margin-top: 0; }
.ha-md > :last-child  { margin-bottom: 0; }
.ha-md p              { margin: 0.4em 0; line-height: 1.5; }
.ha-md ul,
.ha-md ol             { margin: 0.4em 0; padding-inline-start: 1.4em; }
.ha-md li             { margin: 0.15em 0; }
.ha-md li > p         { margin: 0.15em 0; }
.ha-md strong         { font-weight: 600; }
.ha-md em             { font-style: italic; }
.ha-md blockquote {
  margin: 0.5em 0;
  padding: 0.2em 0.75em;
  border-inline-start: 3px solid var(--ha-green);
  color: var(--ha-muted);
  background: var(--ha-surface);
  border-radius: 4px;
}
.ha-md code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.9em;
  padding: 0.05em 0.35em;
  background: var(--ha-surface);
  border-radius: 4px;
}
.ha-md pre {
  margin: 0.5em 0;
  padding: 0.5em 0.75em;
  background: var(--ha-surface);
  border-radius: 6px;
  overflow-x: auto;
}
.ha-md pre code { padding: 0; background: transparent; }
.ha-md h1, .ha-md h2, .ha-md h3,
.ha-md h4, .ha-md h5, .ha-md h6 {
  margin: 0.6em 0 0.3em 0;
  font-weight: 600;
  line-height: 1.3;
}
.ha-md h1 { font-size: 1.15em; }
.ha-md h2 { font-size: 1.10em; }
.ha-md h3 { font-size: 1.05em; }
.ha-md h4,
.ha-md h5,
.ha-md h6 { font-size: 1.00em; }
.ha-md a {
  color: var(--ha-green);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ha-md a:hover { text-decoration: none; }
.ha-md hr {
  border: none;
  border-top: 1px solid var(--ha-border);
  margin: 0.6em 0;
}

/* Citations under each answer */
.ha-citations {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ha-cite {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--ha-surface);
  border: 0.5px solid var(--ha-border);
  color: var(--ha-muted);
  text-decoration: none;
  line-height: 1.4;
}
a.ha-cite:hover { color: var(--ha-green); border-color: var(--ha-green); }
.ha-cite-type {
  font-size: 11px;
  opacity: 0.8;
}
.ha-cite-page {
  font-size: 11px;
  opacity: 0.8;
}

/* Subtle hint shown beneath citations when the session's page cache has
   more reranked chunks ready to serve - the user can type "continue" to
   page through the rest. */
.ha-more-hint {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ha-muted);
  font-style: italic;
}

/* Inline error surfaced when the streaming /chat/stream endpoint fails
   mid-answer or before the first delta. Lives next to the bot bubble. */
.ha-error {
  margin-top: 6px;
  font-size: 12px;
  color: #b3261e;
  background: #fdecea;
  border: 0.5px solid #f5c2bd;
  padding: 6px 10px;
  border-radius: 8px;
}