/* ==========================================================================
   ExtruBot Widget — Floating Chat Button
   Mirrors the Give Feedback widget pattern. Positioned above the feedback
   button in the bottom-right corner.
   ========================================================================== */

.extrubot-widget {
  position: fixed;
  right: 1.5rem;
  bottom: 5.5rem; /* stacks above the feedback button (~3.5rem height + gap) */
  z-index: 1040;
  font-family: "Inter", system-ui, sans-serif;
}

.extrubot-widget * {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Toast notification (appears above the launcher)
   -------------------------------------------------------------------------- */
.extrubot-widget__toast {
  position: fixed;
  right: 1.5rem;
  bottom: 10rem;
  width: min(24rem, calc(100vw - 2rem));
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  font-size: 0.92rem;
  line-height: 1.45;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.24);
}

/* --------------------------------------------------------------------------
   Launcher button
   -------------------------------------------------------------------------- */
.extrubot-widget__launcher {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1.2rem;
  border: none;
  border-radius: 999px;
  background:
    linear-gradient(135deg, rgba(55, 48, 163, 0.96), rgba(99, 102, 241, 0.96)),
    #4f46e5;
  color: #ffffff;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 18px 40px rgba(79, 70, 229, 0.28);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
  white-space: nowrap;
}

.extrubot-widget__launcher:hover,
.extrubot-widget__launcher:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 22px 48px rgba(79, 70, 229, 0.36);
}

.extrubot-widget__launcher:focus-visible {
  outline: 3px solid rgba(129, 140, 248, 0.5);
  outline-offset: 3px;
}

.extrubot-widget__launcher-icon {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1rem;
}

/* Hide launcher when panel is open */
.extrubot-widget.is-open .extrubot-widget__launcher {
  display: none;
}

/* --------------------------------------------------------------------------
   Backdrop
   -------------------------------------------------------------------------- */
.extrubot-widget__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 28, 0.28);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

/* --------------------------------------------------------------------------
   Chat panel
   -------------------------------------------------------------------------- */
.extrubot-widget__panel {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: min(400px, calc(100vw - 3rem));
  height: min(560px, calc(100vh - 3rem));
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 1.4rem;
  background:
    radial-gradient(circle at top right, rgba(129, 140, 248, 0.12), transparent 36%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(248, 250, 252, 0.99));
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  overflow: hidden;
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 200ms ease, opacity 200ms ease;
}

.extrubot-widget.is-open .extrubot-widget__panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Panel header */
.extrubot-widget__panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  flex-shrink: 0;
}

.extrubot-widget__eyebrow {
  margin: 0 0 0.2rem;
  color: #4f46e5;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.extrubot-widget__panel-header h2 {
  margin: 0;
  color: #0f172a;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.extrubot-widget__panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.extrubot-widget__full-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(79, 70, 229, 0.1);
  color: #4338ca;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 140ms ease;
  white-space: nowrap;
}

.extrubot-widget__full-link:hover {
  background: rgba(79, 70, 229, 0.18);
}

.extrubot-widget__new-chat-btn,
.extrubot-widget__close {
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  color: #475569;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 140ms ease, color 140ms ease;
}

.extrubot-widget__new-chat-btn:hover,
.extrubot-widget__close:hover {
  background: rgba(148, 163, 184, 0.28);
  color: #0f172a;
}

.extrubot-widget__new-chat-btn:focus-visible,
.extrubot-widget__close:focus-visible {
  outline: 3px solid rgba(129, 140, 248, 0.5);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Messages area
   -------------------------------------------------------------------------- */
.extrubot-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.extrubot-widget__messages::-webkit-scrollbar {
  width: 4px;
}

.extrubot-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 2px;
}

/* Empty state */
.extrubot-widget__empty {
  margin: auto;
  padding: 1.5rem;
  color: #64748b;
  font-size: 0.9rem;
  line-height: 1.55;
  text-align: center;
}

/* Message bubbles */
.extrubot-widget__msg {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-width: 92%;
}

.extrubot-widget__msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.extrubot-widget__msg--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.extrubot-widget__msg-title {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.extrubot-widget__msg-bubble {
  padding: 0.65rem 0.9rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

.extrubot-widget__msg--user .extrubot-widget__msg-bubble {
  background: linear-gradient(135deg, rgba(55, 48, 163, 0.9), rgba(99, 102, 241, 0.9));
  color: #ffffff;
  border-bottom-right-radius: 0.3rem;
}

.extrubot-widget__msg--assistant .extrubot-widget__msg-bubble {
  background: rgba(241, 245, 249, 0.9);
  color: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-bottom-left-radius: 0.3rem;
}

/* Rich text within assistant bubbles */
.extrubot-widget__richtext p {
  margin: 0 0 0.5em;
}

.extrubot-widget__richtext p:last-child {
  margin-bottom: 0;
}

.extrubot-widget__richtext ol,
.extrubot-widget__richtext ul {
  margin: 0.4em 0;
  padding-left: 1.3em;
}

.extrubot-widget__richtext li {
  margin-bottom: 0.25em;
}

.extrubot-widget__richtext h4 {
  margin: 0.5em 0 0.3em;
  font-size: 0.88rem;
  font-weight: 700;
  color: #1e293b;
}

.extrubot-widget__richtext code {
  padding: 0.1em 0.35em;
  border-radius: 0.3em;
  background: rgba(79, 70, 229, 0.1);
  font-size: 0.84em;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
}

.extrubot-widget__richtext a {
  color: #4338ca;
  text-underline-offset: 2px;
}

/* Citations within message */
.extrubot-widget__msg-citation {
  color: #4338ca;
  font-size: 0.82em;
  text-decoration: none;
  border-bottom: 1px dotted rgba(67, 56, 202, 0.5);
}

.extrubot-widget__msg-citation:hover {
  border-bottom-style: solid;
}

/* Sources section */
.extrubot-widget__msg-sources {
  margin-top: 0.4rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.7rem;
  background: rgba(241, 245, 249, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.5;
}

.extrubot-widget__msg-sources-title {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #64748b;
}

.extrubot-widget__msg-sources-list {
  margin: 0;
  padding-left: 1.1em;
}

.extrubot-widget__msg-sources-list li {
  margin-bottom: 0.2rem;
}

.extrubot-widget__msg-sources a {
  color: #4338ca;
  text-decoration: none;
}

.extrubot-widget__msg-sources a:hover {
  text-decoration: underline;
}

.extrubot-widget__msg-sources--none {
  font-size: 0.78rem;
  color: #94a3b8;
  font-style: italic;
}

/* Feedback row */
.extrubot-widget__msg-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.2rem;
}

.extrubot-widget__msg-feedback-label {
  color: #94a3b8;
  font-size: 0.75rem;
}

.extrubot-widget__msg-feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 140ms ease, transform 100ms ease;
  line-height: 1;
}

.extrubot-widget__msg-feedback-btn:hover {
  background: rgba(148, 163, 184, 0.18);
}

.extrubot-widget__msg-feedback-btn.is-selected {
  background: rgba(79, 70, 229, 0.15);
}

.extrubot-widget__msg-feedback-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Loading indicator */
.extrubot-widget__loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  align-self: flex-start;
  padding: 0.5rem 0.75rem;
  border-radius: 0.7rem;
  background: rgba(241, 245, 249, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #64748b;
  font-size: 0.84rem;
}

.extrubot-widget__loading-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(79, 70, 229, 0.2);
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: extrubot-widget-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes extrubot-widget-spin {
  to { transform: rotate(360deg); }
}

/* Status messages */
.extrubot-widget__status {
  align-self: center;
  padding: 0.4rem 0.75rem;
  border-radius: 0.6rem;
  font-size: 0.8rem;
  text-align: center;
}

.extrubot-widget__status--info {
  background: rgba(241, 245, 249, 0.8);
  color: #475569;
}

.extrubot-widget__status--warning {
  background: rgba(254, 243, 199, 0.85);
  color: #92400e;
}

.extrubot-widget__status--error {
  background: rgba(254, 226, 226, 0.85);
  color: #991b1b;
}

/* --------------------------------------------------------------------------
   Input area (footer of panel)
   -------------------------------------------------------------------------- */
.extrubot-widget__input-area {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.extrubot-widget__input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.extrubot-widget__textarea {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 140ms ease, box-shadow 140ms ease;
  field-sizing: content;
  min-height: 2.6rem;
}

.extrubot-widget__textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14);
  outline: none;
}

.extrubot-widget__textarea:disabled {
  opacity: 0.55;
}

.extrubot-widget__send-btn {
  flex-shrink: 0;
  width: 2.6rem;
  height: 2.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #ffffff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 140ms ease, transform 100ms ease;
}

.extrubot-widget__send-btn:hover {
  opacity: 0.88;
  transform: scale(1.05);
}

.extrubot-widget__send-btn:disabled {
  opacity: 0.45;
  transform: none;
  cursor: default;
}

.extrubot-widget__send-btn:focus-visible {
  outline: 3px solid rgba(129, 140, 248, 0.5);
  outline-offset: 2px;
}

/* Privacy toggle */
.extrubot-widget__privacy {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #64748b;
  font-size: 0.76rem;
  cursor: pointer;
  user-select: none;
}

.extrubot-widget__privacy input[type="checkbox"] {
  width: 0.85rem;
  height: 0.85rem;
  accent-color: #4f46e5;
  cursor: pointer;
}

/* Third-party processing notice */
.extrubot-widget__third-party-notice {
  margin: 0.25rem 0 0;
  color: #94a3b8;
  font-size: 0.72rem;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   Responsive — on narrow viewports the panel fills most of the screen
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .extrubot-widget__panel {
    right: 0.75rem;
    bottom: 0.75rem;
    width: calc(100vw - 1.5rem);
    height: calc(100vh - 1.5rem);
    border-radius: 1.2rem;
  }

  .extrubot-widget {
    right: 0.75rem;
    bottom: 5rem;
  }
}
