/*
 * Obris Launch — In-Site Chatbot Widget
 * Vendor-neutral, mobile-first, theme-token-driven.
 * Spec: obris/chatbot/conversation-spec.md (v2.0)
 *
 * Color tokens come from main.css :root (--bd-*); never hardcode brand hex here.
 * Font is inherited from the page (Poppins, set by main.css).
 */

/* ============================================================
   Launcher button — fixed bottom-right, clears back-to-top
   ============================================================ */

.obris-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px; /* canonical chat-widget corner; back-to-top is pushed up — see .progress-wrap override below */
  z-index: 10000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(6, 96, 189, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.obris-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(6, 96, 189, 0.4);
}

.obris-chat-launcher:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px var(--bd-theme-primary, #0660bd);
}

.obris-chat-launcher svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .obris-chat-launcher,
  .obris-chat-launcher:hover {
    transition: none;
    transform: none;
  }
}

@media (max-width: 480px) {
  .obris-chat-launcher {
    width: 48px;
    height: 48px;
    bottom: 16px;
    right: 16px; /* canonical corner; back-to-top is pushed up — see .progress-wrap override below */
  }
  .obris-chat-launcher svg {
    width: 22px;
    height: 22px;
  }
}

/* ============================================================
   Back-to-top relocation — the chat launcher claims the canonical
   bottom-right corner; the site's vendor back-to-top (.progress-wrap
   from backtotop.css, normally at right:50px / bottom:50px desktop)
   gets pushed UP into the same column ABOVE the launcher. This is
   a scoped override; we do not modify the vendor backtotop.css.
   ============================================================ */

.progress-wrap {
  right: 29px !important;   /* center-aligns the 46px circle under the 56px launcher (24 + 28 - 23 = 29) */
  bottom: 100px !important; /* clears the 56px launcher (24 + 56 + 20 gap) */
}

@media (max-width: 768px) {
  .progress-wrap {
    right: 17px !important;  /* center-aligns the 46px circle under the 48px mobile launcher */
    bottom: 80px !important; /* clears the 48px launcher (16 + 48 + 16 gap) */
  }
}

/* ============================================================
   Backdrop scrim (mobile only — desktop has no scrim)
   ============================================================ */

.obris-chat-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.obris-chat-scrim.is-open {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 481px) {
  .obris-chat-scrim {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .obris-chat-scrim {
    transition: none;
  }
}

/* ============================================================
   Chat panel — slides up from bottom-right
   ============================================================ */

.obris-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  max-height: 80vh;
  z-index: 9999;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--bd-ff-body, 'Poppins', sans-serif);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.obris-chat-panel.is-open {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .obris-chat-panel {
    transition: none;
    transform: none;
  }
}

@media (max-width: 480px) {
  .obris-chat-panel {
    width: calc(100vw - 32px);
    right: 16px;
    left: 16px;
    bottom: 76px;
    max-height: calc(100vh - 96px);
  }
}

/* ----- Panel header ----- */

.obris-chat-header {
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.obris-chat-header__title {
  font-family: var(--bd-ff-heading, 'Poppins', sans-serif);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
  margin: 0;
  color: #ffffff;
}

.obris-chat-header__subtitle {
  font-size: 14px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.85);
  margin: 2px 0 0;
  line-height: 1.4;
}

.obris-chat-close {
  background: transparent;
  border: none;
  color: #ffffff;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}

.obris-chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.obris-chat-close:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.obris-chat-close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ----- Progress indicator (for lead-capture steps) ----- */

.obris-chat-progress {
  font-size: 14px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.08);
  padding: 8px 18px;
  text-align: center;
  flex-shrink: 0;
}

.obris-chat-progress[hidden] {
  display: none !important;
}

/* ============================================================
   Message log — scrollable list of bubbles
   ============================================================ */

.obris-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #ffffff;
  scrollbar-width: thin;
}

.obris-chat-log::-webkit-scrollbar {
  width: 6px;
}
.obris-chat-log::-webkit-scrollbar-thumb {
  background: var(--bd-grey-2, #e2ebf4);
  border-radius: 3px;
}

.obris-chat-bubble {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.obris-chat-bubble--bot {
  align-self: flex-start;
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
  border-bottom-left-radius: 4px;
}

.obris-chat-bubble--user {
  align-self: flex-end;
  background: var(--bd-grey-1, #f5f8fb);
  color: #000000;
  border-bottom-right-radius: 4px;
}

.obris-chat-bubble a {
  color: inherit;
  text-decoration: underline;
}

/* Typing indicator (3 bouncing dots) */
.obris-chat-typing {
  align-self: flex-start;
  background: var(--bd-grey-1, #f5f8fb);
  padding: 12px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
}
.obris-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bd-text-body, #888888);
  animation: obris-chat-typing-bounce 1.2s infinite ease-in-out;
}
.obris-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.obris-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes obris-chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-5px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .obris-chat-typing span { animation: none; }
}

/* ============================================================
   Input area — buttons, text fields, checkboxes, send actions
   ============================================================ */

.obris-chat-input {
  flex-shrink: 0;
  padding: 14px 16px 16px;
  background: #ffffff;
  border-top: 1px solid var(--bd-grey-2, #e2ebf4);
}

/* Quick-reply button group */
.obris-chat-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.obris-chat-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  background: #ffffff;
  color: var(--bd-theme-primary, #0660bd);
  border: 1.5px solid var(--bd-theme-primary, #0660bd);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 44px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.obris-chat-btn:hover {
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
}

.obris-chat-btn:focus-visible {
  outline: 2px solid var(--bd-theme-primary, #0660bd);
  outline-offset: 2px;
}

.obris-chat-btn[disabled],
.obris-chat-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.obris-chat-btn--primary {
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
}

.obris-chat-btn--primary:hover {
  background: #054d97;
  color: #ffffff;
}

/* External link button (Calendly) */
.obris-chat-btn--link {
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.obris-chat-btn--link:hover {
  background: #054d97;
  color: #ffffff;
}
.obris-chat-btn--link svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

@media (prefers-reduced-motion: reduce) {
  .obris-chat-btn,
  .obris-chat-btn:hover {
    transition: none;
  }
}

/* Text/email input field */
.obris-chat-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.obris-chat-field {
  flex: 1 1 auto;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  padding: 12px 14px;
  border: 1.5px solid var(--bd-border-2, #b7c3cf);
  border-radius: 10px;
  background: #ffffff;
  color: #000000;
  min-height: 44px;
  width: 100%;
}

.obris-chat-field:focus {
  outline: none;
  border-color: var(--bd-theme-primary, #0660bd);
  box-shadow: 0 0 0 3px rgba(6, 96, 189, 0.15);
}

textarea.obris-chat-field {
  resize: vertical;
  min-height: 72px;
  font-family: inherit;
}

.obris-chat-send {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  background: var(--bd-theme-primary, #0660bd);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  min-height: 44px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.obris-chat-send:hover {
  background: #054d97;
}

.obris-chat-send:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: -3px;
  box-shadow: 0 0 0 4px var(--bd-theme-primary, #0660bd);
}

.obris-chat-send[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Inline field error */
.obris-chat-error {
  color: #b22b2b;
  font-size: 14px;
  margin-top: 8px;
  line-height: 1.4;
}

/* Consent / helper microcopy */
.obris-chat-consent {
  font-size: 14px;
  color: var(--bd-text-body, #888888);
  line-height: 1.5;
  margin: 12px 0 4px;
}

/* Multi-select checklist (services picker) */
.obris-chat-fieldset {
  border: none;
  padding: 0;
  margin: 0 0 12px;
}

.obris-chat-fieldset legend {
  font-size: 14px;
  color: var(--bd-text-body, #888888);
  margin-bottom: 8px;
  padding: 0;
}

.obris-chat-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.obris-chat-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--bd-border-2, #b7c3cf);
  cursor: pointer;
  min-height: 44px;
  background: #ffffff;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.obris-chat-check:hover {
  border-color: var(--bd-theme-primary, #0660bd);
}

.obris-chat-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--bd-theme-primary, #0660bd);
  cursor: pointer;
  margin: 0;
}

.obris-chat-check input[type="checkbox"]:focus-visible + span {
  text-decoration: underline;
}

.obris-chat-check:has(input:checked) {
  background: rgba(6, 96, 189, 0.08);
  border-color: var(--bd-theme-primary, #0660bd);
}

.obris-chat-check__label {
  font-size: 15px;
  color: #000000;
  line-height: 1.4;
  -webkit-user-select: none;
  user-select: none;
}

/* Loading state */
.obris-chat-loading {
  text-align: center;
  padding: 24px 14px;
  color: var(--bd-text-body, #888888);
  font-size: 15px;
}

.obris-chat-loading::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 10px;
  vertical-align: -3px;
  border: 2px solid var(--bd-grey-2, #e2ebf4);
  border-top-color: var(--bd-theme-primary, #0660bd);
  border-radius: 50%;
  animation: obris-chat-spin 0.8s linear infinite;
}

@keyframes obris-chat-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .obris-chat-loading::before { animation: none; }
}

/* Screen-reader-only status (live region) */
.obris-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile-specific tweaks */
@media (max-width: 480px) {
  .obris-chat-bubble {
    font-size: 15px;
    max-width: 90%;
  }
  .obris-chat-btn {
    font-size: 14px;
    min-height: 48px;
  }
  .obris-chat-check {
    min-height: 48px;
  }
}
