/* ==========================================================
   AnswerRails Chat Widget
   Variable-driven stylesheet
   ========================================================== */

:root {
  /* Brand colours */
  --ar-accent: #2563eb;
  --ar-accent-hover: #1d4ed8;
  --ar-accent-contrast: #ffffff;

  /* Backgrounds */
  --ar-bg: #ffffff;
  --ar-bg-muted: #fafbfc;
  --ar-bg-user: #e6f0ff;
  --ar-bg-assistant: #f6f7f9;
  --ar-bg-error: #fff5f5;

  /* Borders */
  --ar-border: #e5e7eb;
  --ar-border-light: #eef2f7;
  --ar-border-user: #d7e6ff;
  --ar-border-assistant: #ebedf0;
  --ar-border-error: #fecaca;

  /* Text colours */
  --ar-text: #111827;
  --ar-text-muted: #6b7280;
  --ar-text-strong: #0f172a;
  --ar-text-error: #991b1b;

  /* Shadows */
  --ar-shadow: 0 6px 24px rgba(0, 0, 0, .08);
  --ar-button-shadow: 0 8px 20px rgba(37, 99, 235, .25);

  /* Radii */
  --ar-radius: 14px;
  --ar-radius-pill: 9999px;
  --ar-radius-bubble: 16px;
  --ar-radius-error: 12px;

  /* Sizing */
  --ar-max-width: 720px;
  --ar-max-bubble-width: 680px;
  --ar-max-error-width: 560px;

  /* Spacing */
  --ar-padding: 14px 16px;
  --ar-gap: 14px;
  --ar-line-height: 1.4;

  /* Font */
  --ar-font: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Container */
.answerrails-chat-window {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--ar-max-width);
  border: 1px solid var(--ar-border);
  border-radius: var(--ar-radius);
  background: var(--ar-bg);
  box-shadow: var(--ar-shadow);
  font-family: var(--ar-font);
  color: var(--ar-text);
  overflow: hidden;
}

/* Header */
.answerrails-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ar-padding);
  border-bottom: 1px solid var(--ar-border-light);
}
.answerrails-chat-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ar-text);
}
.answerrails-chat-subtitle {
  font-size: 0.875rem;
  color: var(--ar-text-muted);
}

/* Messages area */
.answerrails-chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--ar-gap);
  padding: 18px 16px 20px;
  max-height: 60vh;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.answerrails-chat-messages::-webkit-scrollbar {
  width: 8px;
}
.answerrails-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.15);
  border-radius: 4px;
}

/* Messages */
.answerrails-message {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.answerrails-message-user {
  align-items: flex-end;
}
.answerrails-message-assistant {
  align-items: flex-start;
}
.answerrails-message-system {
  align-items: center;
}
.answerrails-message-content {
  max-width: var(--ar-max-bubble-width);
  width: auto;
  border: 1px solid transparent;
  border-radius: var(--ar-radius-bubble);
  padding: 16px 18px;
  line-height: var(--ar-line-height);
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.answerrails-message-sender {
  font-weight: 600;
  font-size: 13px;
  color: var(--ar-text-muted);
  margin-bottom: 6px;
}

/* Bubble styles */
.answerrails-message-user .answerrails-message-content {
  background: var(--ar-bg-user);
  border-color: var(--ar-border-user);
  color: var(--ar-text-strong);
  box-shadow: 0 1px 0 rgba(15,23,42,.04) inset;
}
.answerrails-message-assistant .answerrails-message-content {
  background: var(--ar-bg-assistant);
  border-color: var(--ar-border-assistant);
  color: var(--ar-text);
}
.answerrails-error-message {
  background: var(--ar-bg-error);
  border: 1px solid var(--ar-border-error);
  color: var(--ar-text-error);
  border-radius: var(--ar-radius-error);
  padding: 12px 14px;
  width: auto;
  max-width: var(--ar-max-error-width);
  text-align: left;
}

/* Typing indicator */
.answerrails-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--ar-bg-assistant);
  border: 1px solid var(--ar-border-assistant);
  border-radius: var(--ar-radius-bubble);
}

/* Input area */
.answerrails-chat-input-area {
  border-top: 1px solid var(--ar-border-light);
  padding: var(--ar-padding);
  background: var(--ar-bg-muted);
}
.answerrails-chat-input {
  display: flex;
  align-items: center;
  gap: 10px;
}
#answerrails-message-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 12px 16px;
  border: 1px solid var(--ar-border);
  border-radius: var(--ar-radius-pill);
  background: var(--ar-bg);
  resize: vertical;
  font: inherit;
  line-height: 1.4;
}
#answerrails-message-input:focus {
  border-color: #9ec5fe;
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
  outline: none;
}
#answerrails-send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  width: 44px;
  border-radius: var(--ar-radius-pill);
  background: var(--ar-accent);
  color: var(--ar-accent-contrast);
  border: none;
  cursor: pointer;
  transition: background .2s, transform .2s;
}
#answerrails-send-button:hover:not(:disabled) {
  background: var(--ar-accent-hover);
  transform: translateY(-1px);
}
#answerrails-send-button:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* Floating launcher button */
.answerrails-chat-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ar-accent);
  color: var(--ar-accent-contrast);
  border: none;
  cursor: pointer;
  box-shadow: var(--ar-button-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, background .2s;
  z-index: 1000;
}
.answerrails-chat-button:hover {
  background: var(--ar-accent-hover);
  transform: translateY(-2px);
}

/* Mobile */
@media (max-width: 768px) {
  .answerrails-chat-window {
    border-radius: 12px;
    max-width: 100%;
  }
  .answerrails-chat-messages {
    padding: 14px;
  }
}

/* === AnswerRails tweaks: bubble height, sender titles, dock position, footer buttons === */

/* 1) Dock the widget bottom-right, no matter what the theme does */
#answerrails-chat-widget {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  left: auto !important;
  z-index: 99999 !important;
}


.answerrails-message-user .answerrails-message-sender {
  color: var(--ar-text-strong);    /* stronger on user bubble */
}
.answerrails-message-assistant .answerrails-message-sender {
  color: var(--ar-text);           /* solid, not muted */
}

/* 4) Trim vertical footprint of system/error cards too */
.answerrails-error-message {
  padding: 10px 12px;              /* down from 12px 14px */
  line-height: 1.4;
}

/* If those buttons sit under the input, align them to the right neatly */
.answerrails-chat-footer,
.answerrails-chat-actions {
  display: flex;
  justify-content: flex-end;
  padding: 6px 16px 12px;
  gap: 6px;
}


/* 7) On mobile, keep things compact */
@media (max-width: 768px) {
  .answerrails-chat-messages { gap: 10px; }
  .answerrails-message-content { padding: 10px 12px; }
}

/* ===== AnswerRails: compact bubbles + open/close/minimise ===== */

/* Compact spacing */
:root {
  --ar-gap: 10px;
  --ar-padding: 12px 14px;
  --ar-radius-bubble: 12px;
}


/* Widget mounting point (must wrap launcher + window) */
#answerrails-chat-widget {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  left: auto !important;
  z-index: 99999 !important;
}

/* Start closed: only the launcher shows */
#answerrails-chat-widget .answerrails-chat-window {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}

/* When open, reveal the window and hide the launcher */
#answerrails-chat-widget.is-open .answerrails-chat-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity .18s ease, transform .18s ease;
}
#answerrails-chat-widget.is-open .answerrails-chat-button {
  display: none;
}

/* Minimise button in header (fallback selector included) */
.answerrails-btn-minimize,
.answerrails-header-minimize {
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--ar-border);
  background: var(--ar-bg);
  color: var(--ar-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1.4;
  transition: background .15s, transform .15s, border-color .15s;
  margin-left: auto;
}
.answerrails-btn-minimize:hover,
.answerrails-header-minimize:hover {
  background: var(--ar-bg-muted);
  border-color: var(--ar-border-light);
  transform: translateY(-1px);
}

/* Make sure it's aligned at the far right of the header */
.answerrails-chat-header { gap: 8px; }
.answerrails-chat-header > *:last-child {
  margin-left: auto;
}

.answerrails-chat-footer,
.answerrails-chat-actions {
  display: flex;
  justify-content: flex-end;
  padding: 6px 16px 12px;
  gap: 6px;
}


/* ===== TARGETED FIXES FOR CHAT WIDGET ===== */

/* 1. FIXED WIDTH - Chat window maintains consistent size */
.answerrails-chat-window {
  width: 380px;  /* Fixed width instead of flexible */
  max-width: 380px;
  min-width: 380px;
  height: 600px; /* Fixed height */
  max-height: 600px;
}

/* Mobile adjustment */
@media (max-width: 480px) {
  .answerrails-chat-window {
    width: calc(100vw - 40px);
    max-width: calc(100vw - 40px);
    min-width: 280px;
  }
}

/* 2. CONSENT BLOCKING - Overlay that disables input */
.answerrails-consent-notice {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 248, 220, 0.95);
  border-top: 2px solid var(--ar-accent);
  padding: 16px;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.answerrails-consent-notice.active {
  display: block !important;
}

/* When consent required, disable input area */
.answerrails-chat-input-area.consent-required {
  pointer-events: none;
  opacity: 0.5;
}

.answerrails-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
}

#answerrails-consent-checkbox {
  margin: 2px 0 0 0;
  transform: scale(1.1);
}


.answerrails-message-text {
  font-size: 0.95rem;
  line-height: 1.5;
}

/* User messages - right aligned with distinct styling */
.answerrails-message-user {
  align-items: flex-end;
}

.answerrails-message-user .answerrails-message-content {
  background: var(--ar-accent);
  color: white;
  border-color: var(--ar-accent);
}

.answerrails-message-user .answerrails-message-sender {
  color: rgba(255, 255, 255, 0.9);
}

/* Assistant messages - left aligned */
.answerrails-message-assistant {
  align-items: flex-start;
}

.answerrails-message-assistant .answerrails-message-content {
  background: #f8f9fa;
  border-color: #e9ecef;
  color: var(--ar-text);
}

/* 4. BUTTON IMPROVEMENTS */
#answerrails-send-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ar-accent);
  transition: all 0.2s ease;
}

#answerrails-send-button:hover:not(:disabled) {
  background: var(--ar-accent-hover);
  transform: scale(1.05);
}

#answerrails-send-button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* 5. HEADER STYLING */
.answerrails-chat-header {
  background: linear-gradient(135deg, var(--ar-accent) 0%, var(--ar-accent-hover) 100%);
  color: white;
  padding: 16px;
}

.answerrails-chat-title {
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
}

.answerrails-chat-subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.85rem;
}

/* Minimize button in header */
.answerrails-chat-minimize {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
}

.answerrails-chat-minimize:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

/* 6. INPUT AREA IMPROVEMENTS */
.answerrails-chat-input-area {
  background: white;
  border-top: 1px solid var(--ar-border-light);
  padding: 16px;
  position: relative;
}

#answerrails-message-input {
  border: 2px solid var(--ar-border);
  border-radius: 25px;
  padding: 12px 20px;
  font-size: 0.95rem;
  transition: border-color 0.2s ease;
}

#answerrails-message-input:focus {
  border-color: var(--ar-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* 7. MESSAGES AREA */
.answerrails-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fafbfc;
}

/* 8. ERROR MESSAGES */
.answerrails-error-message {
  background: #fee;
  border: 1px solid #fcc;
  color: #c33;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.9rem;
  margin: 8px 0;
}

/* 9. TYPING INDICATOR */
.answerrails-typing-dots {
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 12px 16px;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* 10. WELCOME MESSAGE STYLING */
.answerrails-welcome-message .answerrails-message-content {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border: 1px solid #dee2e6;
  font-style: italic;
}

/* 11. AVATAR STYLING */
.answerrails-chat-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.answerrails-message-avatar img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

/* 12. FOOTER LAYOUT */
.answerrails-chat-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #f8f9fa;
  border-top: 1px solid var(--ar-border-light);
  font-size: 0.75rem;
}

.answerrails-powered-by {
  color: var(--ar-text-muted);
}

.answerrails-powered-by a {
  color: var(--ar-accent);
  text-decoration: none;
}

/* ===== BUBBLE SPACING AND FONT SIZE FIXES ===== */



/* Larger, more prominent labels */
.answerrails-message-sender {
  font-weight: 600;
  font-size: 0.9rem;  /* Increased from 0.8rem */
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;  /* Reduced from 8px */
  opacity: 0.9;        /* Slightly more prominent */
}

/* Message text styling */
.answerrails-message-text {
  font-size: 1rem;     /* Matches content font-size */
  line-height: 1.4;
  margin: 0;           /* Remove any default margins */
}

/* Reduce gap between messages */
.answerrails-chat-messages {
  gap: 8px;           /* Reduced from 14px */
}

/* Compact mobile bubbles */
@media (max-width: 768px) {
  .answerrails-message-content {
    padding: 4px 10px;  /* Even more compact on mobile */
    font-size: 0.95rem;
  }
  
  .answerrails-message-sender {
    font-size: 0.8rem;
    margin-bottom: 3px;
  }
}

/* Remove excess spacing in message content */
.answerrails-message-content {
    padding: 6px 14px;  /* Tighter padding */
    display: flex;
    flex-direction: column;
    gap: 2px;  /* Control exact spacing between sender and text */
}

.answerrails-message-sender {
    margin: 0;  /* Remove all margins */
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.answerrails-message-text {
    margin: 0;  /* Remove all margins */
    font-size: 1rem;
    line-height: 1.4;
}

/* ===== RESIZABLE CHAT WIDGET (TOP-LEFT HANDLE) ===== */

/* Container needs to be positioned for custom resize */
#answerrails-chat-widget {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
}

/* Make the chat window manually resizable from top-left */
.answerrails-chat-window {
  position: relative;
  min-width: 320px;
  min-height: 400px;
  max-width: 600px;
  max-height: 80vh;
  width: 380px;
  height: 600px;
  overflow: hidden;
}

/* Custom resize handle in top-left corner */
.answerrails-chat-window::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  background: 
    linear-gradient(45deg, var(--ar-border) 30%, transparent 30%),
    linear-gradient(-45deg, var(--ar-border) 30%, transparent 30%);
  background-size: 6px 6px;
  background-position: 2px 2px, 2px 2px;
  background-repeat: no-repeat;
  cursor: nw-resize;
  z-index: 10;
  opacity: 0.4;
  transition: opacity 0.2s ease;
}

/* Make resize handle more visible on hover */
.answerrails-chat-window:hover::before {
  opacity: 0.8;
}

/* Ensure messages area adjusts properly when resized */
.answerrails-chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;  /* Ensure messages area doesn't disappear */
}

/* Mobile: Disable resize on small screens */
@media (max-width: 768px) {
  .answerrails-chat-window {
    resize: none;  /* Disable resize on mobile */
    width: calc(100vw - 40px) !important;
    height: 70vh !important;
  }
}

/* Hover effect for resize handle visibility */
.answerrails-chat-window:hover::after {
  opacity: 1;
}

/* Firefox resize handle styling */
.answerrails-chat-window {
  scrollbar-width: thin;
  scrollbar-color: var(--ar-border) transparent;
}


/* Fix welcome message width and alignment */
.answerrails-welcome-message .answerrails-message-content {
  width: auto !important;
  max-width: 80% !important;
  margin-left: 0 !important;
  margin-right: auto !important;
}

/* Temporary diagnostic styling */
.answerrails-welcome-message .answerrails-message-text {
  background: yellow !important;
  border: 2px solid red !important;
  text-align: left !important;
  padding: 0 !important;
  margin: 0 !important;
}

.answerrails-welcome-message .answerrails-message-content {
  font-style: normal !important;
}

.answerrails-welcome-message .answerrails-message-text {
  position: relative !important;
  left: 0 !important;
  right: auto !important;
  float: left !important;
  clear: left !important;
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  text-align: left !important;
  text-indent: 0 !important;
  display: inline-block !important;
}