/* Chat widget — ink palette + configurable accent (default brand teal). */
:root {
  --kb-ink-100: #f1f5f9; --kb-ink-200: #e2e8f0; --kb-ink-300: #cbd5e1;
  --kb-ink-400: #94a3b8; --kb-ink-500: #64748b; --kb-ink-700: #334155; --kb-ink-900: #0f172a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--kb-ink-700);
  background: #fff;
  -webkit-font-smoothing: antialiased;
}
.chat { display: flex; flex-direction: column; height: 100vh; }

/* Header: white with avatar mark, name and online dot */
.chat-head {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 16px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--kb-ink-200);
  flex: 0 0 auto;
}
.chat-avatar {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 36px;
  background: var(--kb-accent, #1abdca); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; overflow: hidden;
  box-shadow: 0 1px 2px 0 rgba(16,24,40,.05), 0 1px 3px 0 rgba(16,24,40,.10);
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-head-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.chat-title {
  font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; color: var(--kb-ink-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-sub {
  font-size: 11.5px; color: var(--kb-ink-400); font-weight: 500;
  display: flex; align-items: center; gap: 5px;
}
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: #10b981; flex: 0 0 6px; }

/* Messages */
.chat-messages {
  flex: 1 1 auto; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: #f8fafc;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  overflow-wrap: break-word;
  font-size: 14px;
}
.msg.user .bubble {
  background: var(--kb-accent, #1abdca); color: #fff;
  border-bottom-right-radius: 4px; white-space: pre-wrap;
  box-shadow: 0 1px 2px 0 rgba(16,24,40,.08);
}
.msg.bot .bubble {
  background: #fff; border: 1px solid var(--kb-ink-200);
  border-bottom-left-radius: 4px; color: var(--kb-ink-700);
  box-shadow: 0 1px 2px 0 rgba(16,24,40,.05), 0 1px 3px 0 rgba(16,24,40,.08);
}
.bubble.error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.bubble pre {
  background: var(--kb-ink-100); border-radius: 10px; padding: 10px;
  overflow-x: auto; font-size: 12.5px; margin: 0 0 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble code {
  background: var(--kb-ink-100); border-radius: 5px; padding: 1px 5px; font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble a { color: var(--kb-accent, #1abdca); font-weight: 500; }
.msg.user .bubble a { color: #fff; text-decoration: underline; }


.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--kb-ink-300);
  animation: kb-blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes kb-blink { 0%, 70%, 100% { opacity: .3 } 35% { opacity: 1 } }

/* Composer zone (below the grey message list): white, with a clear top divider */
.chat-composer {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid var(--kb-ink-200);
}
.powered-by {
  text-align: center;
  font-size: 11.5px; font-weight: 500;
  color: var(--kb-ink-400);
  padding: 8px 12px 2px;
}
.chat-notice {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 6px 12px;
  background: var(--kb-ink-100);
  border: 1px solid var(--kb-ink-200);
  border-radius: 12px;
  padding: 10px 12px 10px 14px;
  font-size: 13px; color: var(--kb-ink-700);
}
.chat-notice a { color: var(--kb-accent, #1abdca); font-weight: 600; }
.chat-notice-text { flex: 1; }
.chat-notice button {
  flex: 0 0 auto;
  border: none; background: none; cursor: pointer;
  color: var(--kb-ink-500); font-size: 13px; padding: 1px 4px; border-radius: 6px;
}
.chat-notice button:hover { background: var(--kb-ink-200); color: var(--kb-ink-900); }
.chat-footer {
  text-align: center;
  font-size: 12px; color: var(--kb-ink-500);
  padding: 2px 14px 10px;
}
.chat-footer a { color: var(--kb-ink-900); font-weight: 600; }

/* Input bar */
.chat-input {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  background: #fff;
}
.chat-input textarea {
  flex: 1; resize: none;
  border: 1px solid var(--kb-ink-300); border-radius: 12px;
  padding: 10px 13px; font: inherit; color: var(--kb-ink-900);
  font-size: 16px; /* under 16px, iOS Safari zooms the whole host page on focus */
  outline: none; max-height: 120px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input textarea:focus {
  border-color: var(--kb-accent, #1abdca);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kb-accent, #1abdca) 18%, transparent);
}
.chat-input button {
  flex: 0 0 42px; height: 42px;
  border: none; border-radius: 11px;
  background: var(--kb-accent, #1abdca); color: #fff;
  font-size: 15px; cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(16,24,40,.1);
  transition: filter .15s;
}
.chat-input button:hover { filter: brightness(.92); }
.chat-input button:disabled { opacity: .45; cursor: default; filter: none; }

/* Feedback: thumbs up / down under an answer */
.msg.bot { flex-direction: column; align-items: flex-start; }
.feedback { display: flex; gap: 2px; margin: 4px 0 0 4px; }
.fb-btn {
  display: inline-grid; place-items: center; width: 28px; height: 26px; padding: 0;
  border: none; border-radius: 8px; background: none; cursor: pointer;
  color: var(--kb-ink-400); transition: background .12s, color .12s, transform .12s;
}
.fb-btn:hover { background: var(--kb-ink-100); color: var(--kb-ink-700); }
.fb-btn:active { transform: scale(.9); }
.fb-down svg { transform: rotate(180deg); }
.fb-btn[aria-pressed="true"] { color: var(--kb-accent, #1abdca); }
.fb-btn[aria-pressed="true"] svg path:last-child { fill: currentColor; fill-opacity: .18; }
