/* ==========================================================================
   ByteHarvest Website Chatbot — styles
   Self-contained: redeclares the brand palette locally so this file works
   whether or not style.css is also loaded on the page. All selectors are
   scoped under .bh-chat-root so nothing here can leak into host page CSS.
   ========================================================================== */

.bh-chat-root {
  --bh-navy:      #2B4478;
  --bh-navy-dk:   #1e3260;
  --bh-navy-lt:   #3d5a9e;
  --bh-olive:     #7A9A2E;
  --bh-olive-dk:  #5e7a1f;
  --bh-olive-lt:  #9bbf3a;
  --bh-olive-bg:  #f0f5e6;
  --bh-navy-bg:   #eef1f8;
  --bh-white:     #ffffff;
  --bh-gray-50:   #f8f8f7;
  --bh-gray-100:  #f0efea;
  --bh-gray-200:  #e2e1da;
  --bh-gray-400:  #9a9990;
  --bh-gray-600:  #5c5b55;
  --bh-gray-800:  #2c2b27;
  --bh-radius-sm: 6px;
  --bh-radius-md: 12px;
  --bh-radius-lg: 20px;
  --bh-shadow-md: 0 4px 20px rgba(43,68,120,0.14);
  --bh-shadow-lg: 0 12px 48px rgba(43,68,120,0.22);
  --bh-font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bh-font-head: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  position: fixed;
  inset: auto 20px 20px auto;
  z-index: 2147483000;
  font-family: var(--bh-font-body);
  -webkit-font-smoothing: antialiased;
}

.bh-chat-root * { box-sizing: border-box; }

/* --- RTL: mirror the whole widget to the opposite corner, matching the
   site's existing convention of scoping RTL under body.lang-ar ------------ */
html[dir="rtl"] body.lang-ar .bh-chat-root,
.bh-chat-root.bh-rtl {
  inset: auto auto 20px 20px;
}

/* Mobile: keep the launcher anchored to its corner. Do NOT stretch the root
   full-width — it isn't a flex container, so the launcher would slide to the
   left edge. The panel goes full-screen via its own position:fixed instead. */
@media (max-width: 480px) {
  .bh-chat-root {
    inset: auto 14px calc(14px + env(safe-area-inset-bottom, 0px)) auto;
  }
  html[dir="rtl"] body.lang-ar .bh-chat-root,
  .bh-chat-root.bh-rtl {
    inset: auto auto calc(14px + env(safe-area-inset-bottom, 0px)) 14px;
  }
}

/* ---------------------------------------------------------------- Launcher */
.bh-chat-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--bh-olive-lt), var(--bh-olive));
  box-shadow: var(--bh-shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.bh-chat-launcher:hover { transform: translateY(-2px) scale(1.04); }
.bh-chat-launcher:active { transform: translateY(0) scale(0.98); }
.bh-chat-launcher:focus-visible {
  outline: 3px solid var(--bh-navy-lt);
  outline-offset: 3px;
}
.bh-chat-launcher svg { width: 26px; height: 26px; }
.bh-chat-launcher .bh-icon-close { display: none; }
.bh-chat-root.bh-open .bh-chat-launcher .bh-icon-chat { display: none; }
.bh-chat-root.bh-open .bh-chat-launcher .bh-icon-close { display: block; }

/* First-visit attention pulse — runs once, then removed by JS */
.bh-chat-launcher.bh-pulse::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid var(--bh-olive-lt);
  animation: bh-pulse 2.2s ease-out 3;
}
@keyframes bh-pulse {
  0%   { transform: scale(0.85); opacity: 0.9; }
  100% { transform: scale(1.35); opacity: 0; }
}

.bh-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bh-navy);
  color: var(--bh-white);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bh-white);
}
.bh-chat-root.bh-open .bh-chat-badge,
.bh-chat-badge[hidden] { display: none; }

/* --------------------------------------------------------------- Tooltip */
.bh-chat-tooltip {
  position: absolute;
  bottom: 72px;
  right: 0;
  max-width: 220px;
  background: var(--bh-white);
  color: var(--bh-gray-800);
  padding: 10px 14px;
  border-radius: var(--bh-radius-md);
  box-shadow: var(--bh-shadow-md);
  font-size: 13.5px;
  line-height: 1.4;
  font-weight: 500;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.bh-chat-tooltip.bh-show { opacity: 1; transform: translateY(0); }
.bh-chat-root.bh-open .bh-chat-tooltip,
.bh-chat-root.bh-dismissed .bh-chat-tooltip { display: none; }
.bh-rtl .bh-chat-tooltip { right: auto; left: 0; }

/* ------------------------------------------------------------------ Panel */
.bh-chat-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 600px;
  max-height: calc(100vh - 110px);
  background: var(--bh-white);
  border-radius: var(--bh-radius-lg);
  box-shadow: var(--bh-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.bh-rtl .bh-chat-panel { right: auto; left: 0; }
.bh-chat-root.bh-open .bh-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (max-width: 480px) {
  .bh-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    /* 100dvh tracks the *visible* viewport, so the footer isn't hidden behind
       iOS Safari's collapsing toolbar. vh is the fallback for older browsers. */
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    transform: translateY(100%);       /* slide up from the bottom on mobile */
  }
  .bh-chat-root.bh-open .bh-chat-panel { transform: translateY(0); }
  .bh-rtl .bh-chat-panel { left: 0; right: 0; }

  /* Header clears the notch; footer clears the home indicator. */
  .bh-chat-header { padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
  .bh-chat-footer { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }

  /* iOS Safari zooms the page when a focused input is under 16px. */
  .bh-chat-input { font-size: 16px; }

  /* The panel is full-screen and has its own close button in the header —
     the floating launcher would just overlap the conversation. */
  .bh-chat-root.bh-open .bh-chat-launcher { display: none; }

  /* Slightly roomier tap targets on touch. */
  .bh-chip { padding: 9px 15px; font-size: 13.5px; }
  .bh-chat-send { width: 38px; height: 38px; }
  .bh-msg-bubble { max-width: 84%; font-size: 14.5px; }
}

/* ------------------------------------------------------------------ Header */
.bh-chat-header {
  background: linear-gradient(135deg, var(--bh-navy), var(--bh-navy-dk));
  color: var(--bh-white);
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.bh-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bh-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.bh-chat-avatar img { width: 26px; height: 26px; object-fit: contain; }
.bh-chat-header-text { flex: 1; min-width: 0; }
.bh-chat-header-name {
  font-family: var(--bh-font-head);
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bh-chat-online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74,222,128,0.25);
  flex-shrink: 0;
}
.bh-chat-header-sub {
  font-size: 12px;
  opacity: 0.82;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bh-chat-header-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.bh-chat-lang-toggle {
  display: flex;
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.bh-chat-lang-btn {
  border: none;
  background: transparent;
  color: var(--bh-white);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.7;
  font-family: var(--bh-font-body);
}
.bh-chat-lang-btn.bh-active { background: var(--bh-white); color: var(--bh-navy); opacity: 1; }
.bh-chat-lang-btn:focus-visible { outline: 2px solid var(--bh-white); outline-offset: 1px; }

.bh-chat-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: var(--bh-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bh-chat-close:hover { background: rgba(255,255,255,0.22); }
.bh-chat-close:focus-visible { outline: 2px solid var(--bh-white); outline-offset: 1px; }
.bh-chat-close svg { width: 15px; height: 15px; }

/* ----------------------------------------------------------------- Body */
.bh-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bh-gray-50);
  scroll-behavior: smooth;
}
.bh-chat-body::-webkit-scrollbar { width: 6px; }
.bh-chat-body::-webkit-scrollbar-thumb { background: var(--bh-gray-200); border-radius: 999px; }

.bh-msg-row { display: flex; gap: 8px; max-width: 100%; }
.bh-msg-row.bh-bot { justify-content: flex-start; }
.bh-msg-row.bh-user { justify-content: flex-end; }

.bh-msg-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bh-navy);
  color: var(--bh-white);
  font-size: 11px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-family: var(--bh-font-head);
}

.bh-msg-bubble {
  max-width: 78%;
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: var(--bh-radius-md);
  white-space: pre-line;
}
.bh-msg-row.bh-bot .bh-msg-bubble {
  background: var(--bh-white);
  color: var(--bh-gray-800);
  border: 1px solid var(--bh-gray-200);
  border-start-start-radius: 4px;
}
.bh-msg-row.bh-user .bh-msg-bubble {
  background: var(--bh-navy);
  color: var(--bh-white);
  border-start-end-radius: 4px;
}
.bh-msg-bubble a { color: inherit; text-decoration: underline; font-weight: 600; }
.bh-msg-row.bh-bot .bh-msg-bubble a { color: var(--bh-navy-lt); }

/* Typing indicator */
.bh-typing .bh-msg-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 13px 15px;
}
.bh-typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--bh-gray-400);
  animation: bh-typing 1.1s infinite ease-in-out;
}
.bh-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.bh-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bh-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick-reply chips */
.bh-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-inline-start: 34px;
  margin-top: 2px;
}
.bh-chip {
  border: 1.5px solid var(--bh-olive);
  background: var(--bh-white);
  color: var(--bh-olive-dk);
  font-family: var(--bh-font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.bh-chip:hover { background: var(--bh-olive); color: var(--bh-white); }
.bh-chip:focus-visible { outline: 2px solid var(--bh-navy-lt); outline-offset: 2px; }
.bh-chip[disabled] { opacity: 0.45; cursor: default; pointer-events: none; }

/* Inline WhatsApp CTA card, shown inside the message flow */
.bh-wa-card {
  margin-inline-start: 34px;
  background: var(--bh-olive-bg);
  border: 1px solid rgba(122,154,46,0.25);
  border-radius: var(--bh-radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.bh-wa-card-text { flex: 1; font-size: 12.5px; color: var(--bh-gray-800); line-height: 1.4; }
.bh-wa-card-text strong { display: block; font-size: 13.5px; margin-bottom: 1px; }
.bh-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #25D366;
  color: var(--bh-white);
  font-weight: 700;
  font-size: 12.5px;
  padding: 8px 12px;
  border-radius: 999px;
  text-decoration: none;
  flex-shrink: 0;
  white-space: nowrap;
}
.bh-wa-btn:hover { filter: brightness(1.05); }
.bh-wa-btn svg { width: 14px; height: 14px; }

/* ----------------------------------------------------------------- Footer */
.bh-chat-footer {
  border-top: 1px solid var(--bh-gray-200);
  padding: 10px 12px;
  background: var(--bh-white);
  flex-shrink: 0;
}
.bh-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bh-gray-100);
  border-radius: 999px;
  padding: 4px 4px 4px 14px;
}
.bh-rtl .bh-chat-input-row { padding: 4px 14px 4px 4px; }
.bh-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: var(--bh-font-body);
  color: var(--bh-gray-800);
  padding: 8px 0;
  outline: none;
  min-width: 0;
}
.bh-chat-input::placeholder { color: var(--bh-gray-400); }
.bh-chat-send {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bh-olive);
  color: var(--bh-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.bh-chat-send:hover { background: var(--bh-olive-dk); }
.bh-chat-send:disabled { background: var(--bh-gray-200); cursor: default; }
.bh-chat-send svg { width: 15px; height: 15px; }
.bh-rtl .bh-chat-send svg { transform: scaleX(-1); }

.bh-chat-footnote {
  text-align: center;
  font-size: 10.5px;
  color: var(--bh-gray-400);
  margin-top: 7px;
}
.bh-chat-footnote a { color: var(--bh-gray-600); font-weight: 600; }

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bh-chat-launcher, .bh-chat-panel, .bh-chat-tooltip, .bh-typing-dot,
  .bh-chat-launcher.bh-pulse::before {
    transition: none !important;
    animation: none !important;
  }
}
