/* ── Chatbot Widget ── */

#chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #9b120f;
  color: #fff;
  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: #7a0e0b;
}

#chatbot-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  min-width: 260px;
  max-width: 80vw;
  z-index: 9999;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

#chatbot-drawer.chatbot-open {
  transform: translateX(0);
}

#chatbot-header {
  background: #9b120f;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#chatbot-header-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

#chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#chatbot-new-btn,
#chatbot-close-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  padding: 2px 6px;
  line-height: 1;
  opacity: 0.85;
  transition: opacity 0.15s;
}

#chatbot-new-btn:hover,
#chatbot-close-btn:hover {
  opacity: 1;
}

#chatbot-new-btn {
  font-size: 14px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  padding: 3px 8px;
}

#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbot-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.chatbot-bubble-user {
  align-self: flex-end;
  background: #e9e9e9;
  color: #212529;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.chatbot-bubble-bot {
  align-self: flex-start;
  background: #fdf0f0;
  color: #212529;
  border-bottom-left-radius: 3px;
}

/* ── Markdown elements inside bot bubbles ─────────────────────────────────── */

.chatbot-bubble-bot p       { margin: 0 0 6px; }
.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: 8px 0 4px;
  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: 4px 0 6px;
  padding-left: 20px;
}

.chatbot-bubble-bot li { margin-bottom: 2px; }

.chatbot-bubble-bot code {
  background: #f0e8e8;
  border-radius: 3px;
  padding: 1px 4px;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.9em;
}

.chatbot-bubble-bot pre {
  background: #f0e8e8;
  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 #ddd;
  margin: 8px 0;
}

.chatbot-bubble-bot a {
  color: #9b120f;
  text-decoration: underline;
}

.chatbot-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #9b120f;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: chatbot-blink 0.7s steps(1) infinite;
}

@keyframes chatbot-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

#chatbot-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e5e5e5;
  flex-shrink: 0;
}

#chatbot-input {
  flex: 1;
  resize: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s;
}

#chatbot-input:focus {
  border-color: #9b120f;
}

#chatbot-send-btn {
  background: #9b120f;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

#chatbot-send-btn:hover:not(:disabled) {
  background: #7a0e0b;
}

#chatbot-send-btn:disabled {
  background: #ccc;
  cursor: default;
}

#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: 2px;
  background: rgba(255,255,255,0.35);
  pointer-events: none;
  transition: background 0.15s;
}

#chatbot-resize-handle:hover::after {
  background: rgba(255,255,255,0.7);
}

@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: #fff;
  border-radius: 6px;
  padding: 8px;
}

.chatbot-mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ── Raw-view toggle button ──────────────────────────────────────────────────── */

.chatbot-raw-btn {
  display: block;
  margin-top: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  background: none;
  border: 1px solid rgba(155, 18, 15, 0.30);
  border-radius: 3px;
  color: #9b120f;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s;
  line-height: 1.6;
}

.chatbot-raw-btn:hover             { opacity: 1; }
.chatbot-raw-btn--active           { background: #9b120f; color: #fff; opacity: 0.8; }
.chatbot-raw-btn--active:hover     { opacity: 1; }

/* ── Raw text pre-block ──────────────────────────────────────────────────────── */

.chatbot-raw-pre {
  margin: 0;
  padding: 0;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  color: #444;
}
