﻿/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --cb-primary:              #491AB1;
  --cb-primary-dark:         #3a148e;
  --cb-primary-light:        #ede9fe;
  --cb-surface:              #ffffff;
  --cb-surface-muted:        #f3f4f6;
  --cb-surface-input:        #f9fafb;
  --cb-border:               #e5e7eb;
  --cb-text-primary:         #374151;
  --cb-text-secondary:       #9ca3af;
  --cb-text-disabled:        #d1d5db;
  --cb-text-on-primary:      #ffffff;
  --cb-text-on-primary-muted:#c4b5fd;
  --cb-feedback-positive:    #16a34a;
  --cb-feedback-pos-bg:      #f0fdf4;
  --cb-feedback-negative:    #dc2626;
  --cb-feedback-neg-bg:      #fef2f2;
  --cb-text-success:         #6b7280;
}

/* ── Toggle button ──────────────────────────────────────────────────────────── */

#chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark));
  color: var(--cb-text-on-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: background 0.2s;
}

#chatbot-toggle:hover {
  background: linear-gradient(135deg, var(--cb-primary-dark), var(--cb-primary-dark));
}

/* ── Chat panel ─────────────────────────────────────────────────────────────── */

#chatbot-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 480px;
  min-width: 280px;
  max-width: 640px;
  z-index: 9999;
  background: var(--cb-surface);
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  font-family: system-ui, sans-serif;
  font-size: 13px;
}

#chatbot-drawer.chatbot-open {
  transform: translateX(0);
}

/* ── Header ─────────────────────────────────────────────────────────────────── */

#chatbot-header {
  background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark));
  color: var(--cb-text-on-primary);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#chatbot-header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#chatbot-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cb-text-on-primary);
  line-height: 1.3;
}

#chatbot-header-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--cb-text-on-primary-muted);
  line-height: 1.3;
}

#chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

#chatbot-new-btn,
#chatbot-close-btn {
  background: none;
  border: none;
  color: var(--cb-text-on-primary-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  padding: 0;
}

#chatbot-new-btn:hover,
#chatbot-close-btn:hover {
  color: var(--cb-text-on-primary);
  background: rgba(255,255,255,0.1);
}

/* ── Message list ───────────────────────────────────────────────────────────── */

#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Message rows ───────────────────────────────────────────────────────────── */

.chatbot-msg-row {
  display: flex;
  flex-direction: column;
}

.chatbot-msg-row--bot {
  align-items: flex-start;
}

.chatbot-msg-row--user {
  align-items: flex-end;
}

.chatbot-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.chatbot-avatar {
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background: var(--cb-primary-dark);
  color: var(--cb-text-on-primary);
  font-size: 8px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chatbot-sender-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--cb-text-secondary);
}

/* ── Bubbles ────────────────────────────────────────────────────────────────── */

.chatbot-bubble {
  max-width: 88%;
  padding: 7px 11px;
  font-size: inherit;
  line-height: 1.4;
  word-break: break-word;
}

.chatbot-bubble-bot {
  background: var(--cb-surface-muted);
  color: var(--cb-text-primary);
  border-radius: 12px 12px 12px 2px;
}

.chatbot-bubble-user {
  background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark));
  color: var(--cb-text-on-primary);
  border-radius: 12px 12px 2px 12px;
  white-space: pre-wrap;
}

.chatbot-bubble-error {
  background: var(--cb-feedback-neg-bg);
  color: var(--cb-feedback-negative);
  border-radius: 12px;
  font-size: 13px;
}

/* ── Markdown elements inside bot bubbles ───────────────────────────────────── */

/* Reset font-size and line-height on all elements inside the bubble so
   host-page element-level rules (e.g. body, ul { font-size: 10.5pt }) cannot
   bleed in and make the response text larger than the input. */
.chatbot-bubble-bot *,
.chatbot-bubble-user * {
  font-size: inherit;
  line-height: inherit;
}

.chatbot-bubble-bot p            { margin: 0 0 4px; }
.chatbot-bubble-bot p:last-child { margin-bottom: 0; }

.chatbot-bubble-bot h1,
.chatbot-bubble-bot h2,
.chatbot-bubble-bot h3,
.chatbot-bubble-bot h4,
.chatbot-bubble-bot h5,
.chatbot-bubble-bot h6 {
  margin: 6px 0 2px;
  font-weight: 600;
  line-height: 1.3;
}

.chatbot-bubble-bot h1 { font-size: 1.15em; }
.chatbot-bubble-bot h2 { font-size: 1.1em; }
.chatbot-bubble-bot h3 { font-size: 1.05em; }
.chatbot-bubble-bot h4,
.chatbot-bubble-bot h5,
.chatbot-bubble-bot h6 { font-size: 1em; }

.chatbot-bubble-bot ul,
.chatbot-bubble-bot ol {
  margin: 2px 0 4px;
  padding-left: 18px;
}

.chatbot-bubble-bot li { margin-bottom: 1px; }

.chatbot-bubble-bot code {
  background: var(--cb-border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.9em;
}

.chatbot-bubble-bot pre {
  background: var(--cb-border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
}

.chatbot-bubble-bot pre code {
  background: none;
  padding: 0;
  font-size: 0.88em;
}

.chatbot-bubble-bot hr {
  border: none;
  border-top: 1px solid var(--cb-border);
  margin: 8px 0;
}

.chatbot-bubble-bot a {
  color: var(--cb-primary);
  text-decoration: underline;
}

/* ── Typing indicator ───────────────────────────────────────────────────────── */

.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.chatbot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 9999px;
  background: var(--cb-primary);
  animation: chatbot-bounce 1.2s ease-in-out infinite;
}

.chatbot-typing-dot:nth-child(1) { animation-delay: 0ms; }
.chatbot-typing-dot:nth-child(2) { animation-delay: 150ms; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 300ms; }

@keyframes chatbot-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* ── Input footer ───────────────────────────────────────────────────────────── */

#chatbot-input-footer {
  flex-shrink: 0;
  background: var(--cb-surface);
  padding: 12px;
  border-top: 1px solid var(--cb-border);
}

#chatbot-disclaimer {
  margin: 6px 0 0;
  font-size: 10px;
  color: var(--cb-text-disabled);
  line-height: 1.4;
  text-align: center;
}

/* Hidden until the user approaches the input's character cap (bug 90141). */
#chatbot-char-counter {
  display: none;
  margin: 4px 2px 0;
  font-size: 10px;
  text-align: right;
  color: var(--cb-text-disabled);
}

#chatbot-char-counter.chatbot-char-counter-visible {
  display: block;
}

#chatbot-char-counter.chatbot-char-counter-limit {
  color: var(--cb-feedback-negative);
}

#chatbot-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cb-surface-input);
  border: 1px solid var(--cb-border);
  border-radius: 12px;
  padding: 6px 8px;
}

#chatbot-input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  padding: 4px;
  font: inherit;
  /* Must stay >= 16px: iOS Safari auto-zooms the page on focus for any
     form control with a smaller computed font-size (bug 90138). */
  font-size: 16px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  color: var(--cb-text-primary);
}

#chatbot-input::placeholder {
  color: var(--cb-text-disabled);
}

#chatbot-send-btn {
  flex-shrink: 0;
  /* >= 44x44px per WCAG 2.5.5 (bug 90140): the icon stays visually small,
     centered inside the enlarged hit area. */
  width: 44px;
  height: 44px;
  background: var(--cb-primary);
  color: var(--cb-text-on-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  padding: 0;
}

#chatbot-send-btn:hover:not(:disabled) {
  background: var(--cb-primary-dark);
}

#chatbot-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Resize handle ──────────────────────────────────────────────────────────── */

#chatbot-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  z-index: 10000;
}

#chatbot-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 1px;
  transform: translateY(-50%);
  width: 3px;
  height: 40px;
  border-radius: 9999px;
  background: rgba(0,0,0,0.12);
  pointer-events: none;
  transition: background 0.15s;
}

#chatbot-resize-handle:hover::after {
  background: var(--cb-primary-light);
}

@media (max-width: 767px) {
  #chatbot-drawer {
    width: 100vw !important;
  }

  #chatbot-resize-handle {
    display: none;
  }
}

/* ── Mermaid diagrams ───────────────────────────────────────────────────────── */

.chatbot-mermaid {
  overflow-x: auto;
  text-align: center;
  margin: 8px 0;
  background: var(--cb-surface);
  border-radius: 6px;
  padding: 8px;
}

.chatbot-mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ── Feedback bar ───────────────────────────────────────────────────────────── */

.chatbot-feedback-bar {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
  gap: 4px;
}

.chatbot-fb-label {
  font-size: 12px;
  color: var(--cb-text-secondary);
  margin-right: 2px;
}

.chatbot-fb-thumb {
  background: none;
  border: none;
  outline: none;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  padding: 3px 7px;
  color: var(--cb-text-secondary);
  opacity: 0.8;
  transition: opacity 0.15s, color 0.15s;
  margin-right: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-fb-thumb:hover {
  opacity: 1;
}

.chatbot-fb-thumb:focus,
.chatbot-fb-thumb:focus-visible {
  outline: none;
}

.chatbot-fb-copy {
  background: none;
  border: none;
  outline: none;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  padding: 3px 7px;
  color: var(--cb-text-secondary);
  opacity: 0.8;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-fb-copy:hover {
  opacity: 1;
}

.chatbot-fb-copy:focus,
.chatbot-fb-copy:focus-visible {
  outline: none;
}

.chatbot-fb-copy--done {
  color: var(--cb-feedback-positive);
  opacity: 1;
}

.chatbot-fb-thumb.chatbot-fb-active-positive {
  color: var(--cb-feedback-positive);
  opacity: 1;
}

.chatbot-fb-thumb.chatbot-fb-active-negative {
  color: var(--cb-feedback-negative);
  opacity: 1;
}

/* ── Feedback form ──────────────────────────────────────────────────────────── */

.chatbot-fb-panel {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  flex-basis: 100%;
}

.chatbot-fb-panel--visible {
  display: flex;
}

.chatbot-fb-category {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--cb-border);
  border-radius: 4px;
  padding: 5px 8px;
  outline: none;
  transition: border-color 0.15s;
  background: var(--cb-surface);
  color: var(--cb-text-primary);
}

.chatbot-fb-category:focus {
  border-color: var(--cb-primary);
}

.chatbot-fb-comment {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--cb-border);
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
  min-height: 60px;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
  color: var(--cb-text-primary);
  background: var(--cb-surface);
}

.chatbot-fb-comment:focus {
  border-color: var(--cb-primary);
}

.chatbot-fb-notice {
  font-size: 11px;
  color: var(--cb-text-secondary);
  background: var(--cb-primary-light);
  border-radius: 4px;
  padding: 5px 8px;
  line-height: 1.4;
}

.chatbot-fb-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.chatbot-fb-cancel {
  background: none;
  border: none;
  font-size: 13px;
  font-family: inherit;
  color: var(--cb-text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.15s;
}

.chatbot-fb-cancel:hover {
  color: var(--cb-text-primary);
}

.chatbot-fb-submit {
  background: var(--cb-primary);
  color: var(--cb-text-on-primary);
  border: none;
  border-radius: 4px;
  padding: 5px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.chatbot-fb-submit:hover:not(:disabled) {
  background: var(--cb-primary-dark);
}

.chatbot-fb-submit:disabled {
  opacity: 0.4;
  cursor: default;
}

.chatbot-fb-thanks {
  font-size: 12px;
  color: var(--cb-text-success);
}
