/* ────────────────────────────────────────────────────────────────
   WP Flow Chatbot — modern, mobile-first chat UI (RTL)

   All sizes inside the widget are `em`-based with a fixed 16px base
   font-size on `.wp-flow-chatbot`, so host-theme root-font scaling
   can't break the layout. Colors come from CSS custom properties —
   per-flow `brand` overrides are applied as inline custom props.
──────────────────────────────────────────────────────────────── */

/* ─────────────────────── RTL OVERRIDE ─────────────────────── */
.wp-flow-chatbot,
.wp-flow-chatbot * {
  direction: rtl !important;
}

/* ────────────────────────────────────────────────────────────────
   Design tokens
──────────────────────────────────────────────────────────────── */
:root {
  --bg-window:         #ffffff;
  --bg-chat:           #f7f7f8;
  --txt-primary:       #1f2024;
  --txt-secondary:     #6b6f76;

  --accent:            #F9D930;
  --chatbot-header-bg: #3F3E46;

  --user-bubble-bg:    var(--accent);
  --user-bubble-text:  #1f2024;

  --option-bg:         #ffffff;
  --option-text:       var(--txt-primary);

  --start-btn-bg:      var(--accent);
  --start-btn-text:    #1f2024;

  --surface-border:    #e6e6eb;
  --bot-bubble:        #ffffff;
  --radius-bubble:     18px;
  --radius-pill:       999px;
  --shadow-bubble:     0 1px 2px rgba(16, 17, 20, 0.06);
  --shadow-panel:      0 4px 24px rgba(16, 17, 20, 0.06);
}

/* ────────────────────────────────────────────────────────────────
   Layout shell
──────────────────────────────────────────────────────────────── */
.wp-flow-chatbot {
  /* isolate typography from host themes */
  font-size: 16px;
  line-height: 1.55;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Arial Hebrew',
               'Noto Sans Hebrew', 'Helvetica Neue', Arial, sans-serif;
  color: var(--txt-primary);
  background: var(--bg-chat);
  max-width: 680px;
  margin: 2rem auto;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-panel);
  -webkit-font-smoothing: antialiased;
}

/* ────────────────────────────────────────────────────────────────
   Header — compact, with live status dot
──────────────────────────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  gap: 0.7em;
  justify-content: flex-end; /* RTL: content hugs the right edge */
  background: var(--chatbot-header-bg);
  color: #fff;
  padding: 0.85em 1.15em;
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.chatbot-header img {
  display: block;
  height: auto;
  max-height: 40px;
  width: auto;
  filter: brightness(100);
}

.chatbot-header-text {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-style: normal;
}
/* live/online indicator */
.chatbot-header-text::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

/* ────────────────────────────────────────────────────────────────
   Start screen
──────────────────────────────────────────────────────────────── */
.chatbot-start {
  text-align: center;
  padding: 2.75em 1.75em 2.25em;
  background: var(--bg-window);
}
.chatbot-start h2 {
  margin: 0 0 0.6em;
  font-size: 1.4em;
  font-weight: 700;
  color: var(--txt-primary);
}
.chatbot-start p {
  margin: 0 0 1.75em;
  font-size: 1em;
  color: var(--txt-secondary);
}
.chatbot-start-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 2em;
  font-size: 1.05em;
  font-weight: 600;
  font-family: inherit;
  color: var(--start-btn-text);
  background: var(--start-btn-bg);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.chatbot-start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
  filter: brightness(1.04);
}
.chatbot-start-btn:active { transform: scale(0.97); }

/* ────────────────────────────────────────────────────────────────
   Chat window & messages
──────────────────────────────────────────────────────────────── */
.chatbot-window {
  display: none;
  flex-direction: column;
  background: var(--bg-chat);
  height: 560px;
  height: min(640px, 75dvh); /* dvh keeps mobile browser chrome from cutting the chat */
}
.messages {
  flex: 1;
  padding: 1.25em 1.15em;
  overflow-y: auto;
  background: var(--bg-chat);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.14);
  border-radius: 3px;
}

.chatbot-message {
  display: block;
  max-width: 78%;
  margin: 0 0 0.7em;
  padding: 0.7em 1.05em;
  font-size: 0.97em;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: fadeInUp 0.25s ease both;
}
/* RTL chat: assistant messages hug the right (start), visitor's the left */
.chatbot-message.bot {
  background: var(--bot-bubble);
  color: var(--txt-primary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
  box-shadow: var(--shadow-bubble);
  text-align: right;
  margin-left: auto; /* aligns to the right edge in block flow */
}
.chatbot-message.user {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-radius: var(--radius-bubble) var(--radius-bubble) 4px var(--radius-bubble);
  box-shadow: 0 1px 3px rgba(16, 17, 20, 0.12);
  text-align: right;
  margin-right: auto; /* aligns to the left edge in block flow */
  font-weight: 500;
}

/* Typing indicator — three bouncing dots */
.chatbot-message.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bot-bubble);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-bubble);
  padding: 0.85em 1.05em;
}
.chatbot-message.typing .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--txt-secondary);
  opacity: 0.9;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.chatbot-message.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chatbot-message.typing .dot:nth-child(3) { animation-delay: 0.3s; }

/* ────────────────────────────────────────────────────────────────
   Conversation summary (rendered inside a bot bubble by lead-capture)
──────────────────────────────────────────────────────────────── */
.chatbot-summary {
  margin: 0.15em 0;
}
.chatbot-summary-title {
  font-weight: 700;
  margin-bottom: 0.6em;
  font-size: 0.95em;
}
.chatbot-summary ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45em;
}
.chatbot-summary li {
  display: flex;
  flex-direction: column;
  padding: 0.55em 0.8em;
  background: var(--bg-chat);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  font-size: 0.9em;
}
.chatbot-summary-q {
  color: var(--txt-secondary);
  font-size: 0.92em;
}
.chatbot-summary-a {
  font-weight: 700;
}

/* ────────────────────────────────────────────────────────────────
   Info box
──────────────────────────────────────────────────────────────── */
.chatbot-info {
  background: #f0f4f8;
  border: 1px solid #d7e2ec;
  padding: 0.75em 1em;
  border-radius: 12px;
  margin: 0 0 0.7em;
  color: var(--txt-secondary);
  font-size: 0.9em;
  max-width: 78%;
  margin-left: auto;
}

/* ────────────────────────────────────────────────────────────────
   Quick-reply chips
──────────────────────────────────────────────────────────────── */
.chatbot-options-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: flex-start; /* RTL: chips hug the right */
  margin: 0 0 1.1em;
  max-width: 78%;
  margin-left: auto; /* align under the bot bubble (right side in RTL) */
  animation: fadeInUp 0.25s ease both;
}

/* Unified pill style for every option chip */
.chatbot-options-group button,
.chatbot-category-chip,
.chatbot-question-chip,
.chatbot-related-chip,
.chatbot-back-chip,
.chatbot-home-chip,
.chatbot-multi-chip,
.chatbot-submit-chip {
  appearance: none;
  font-family: inherit;
  font-size: 0.93em;
  font-weight: 500;
  line-height: 1.4;
  min-height: 44px; /* comfortable touch target */
  padding: 0.6em 1.15em;
  background: var(--option-bg, #ffffff);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-pill);
  color: var(--option-text, var(--txt-primary));
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
              transform 0.1s ease, background 0.15s ease, opacity 0.2s ease;
}
.chatbot-options-group button:hover:not(:disabled),
.chatbot-category-chip:hover:not(:disabled),
.chatbot-question-chip:hover:not(:disabled),
.chatbot-related-chip:hover:not(:disabled),
.chatbot-back-chip:hover:not(:disabled),
.chatbot-home-chip:hover:not(:disabled),
.chatbot-multi-chip:hover:not(:disabled),
.chatbot-submit-chip:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(16, 17, 20, 0.08);
  transform: translateY(-1px);
}
.chatbot-options-group button:active:not(:disabled),
.chatbot-category-chip:active:not(:disabled),
.chatbot-question-chip:active:not(:disabled),
.chatbot-related-chip:active:not(:disabled),
.chatbot-back-chip:active:not(:disabled),
.chatbot-home-chip:active:not(:disabled),
.chatbot-multi-chip:active:not(:disabled),
.chatbot-submit-chip:active:not(:disabled) {
  transform: scale(0.97);
}

/* FAQ question list: full-width rows */
.chatbot-question-chip {
  width: 100%;
  text-align: right;
  justify-content: space-between;
  border-radius: 14px;
}

/* Ghost chips for navigation (back / home) */
.chatbot-back-chip,
.chatbot-home-chip {
  background: transparent;
  border-color: transparent;
  color: var(--txt-secondary);
  min-height: 40px;
  padding: 0.45em 0.9em;
  font-size: 0.88em;
}
.chatbot-back-chip:hover:not(:disabled),
.chatbot-home-chip:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.045);
  border-color: transparent;
  color: var(--txt-primary);
  box-shadow: none;
}

/* Multi-select */
.chatbot-multi-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--txt-primary);
  font-weight: 600;
}
.chatbot-submit-chip {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}
.chatbot-submit-chip:not(:disabled):hover {
  filter: brightness(1.05);
  border-color: var(--accent);
}
.chatbot-submit-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Disabled options (previous turns) */
.chatbot-options-group button:disabled,
.chatbot-options-group button.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Subtle text option — secondary actions like skipping lead capture */
.chatbot-subtle-option {
  appearance: none;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.4em 0.75em;
  font-family: inherit;
  font-size: 0.85em;
  min-height: 36px;
  color: var(--txt-secondary);
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: color 0.15s ease;
}
.chatbot-subtle-option:hover {
  color: var(--txt-primary);
  background: transparent;
}

/* Contextual FAQ hints label */
.chatbot-hints-label {
  width: 100%;
  text-align: right;
  font-size: 0.82em;
  color: var(--txt-secondary);
  margin-top: 0.4em;
  padding: 0.2em 0.4em;
}

/* Deprecated bottom options bar (kept hidden for safety) */
.options { display: none; }

/* ────────────────────────────────────────────────────────────────
   Cards
──────────────────────────────────────────────────────────────── */
.chatbot-card {
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0.4em 0 1em;
  margin-left: auto; /* aligned with bot bubbles (right in RTL) */
  background: #fff;
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-bubble);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  animation: fadeInUp 0.25s ease both;
}
.chatbot-card:hover {
  box-shadow: 0 6px 18px rgba(16, 17, 20, 0.1);
  transform: translateY(-2px);
}
.chatbot-card-img { margin: 0; padding: 0; }
.chatbot-card-img img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  height: auto;
}
.chatbot-card > :not(.chatbot-card-img) {
  padding: 0.9em 1em 0;
}
.chatbot-card-title {
  font-size: 1em;
  font-weight: 700;
  margin: 0;
  color: var(--txt-primary);
  text-align: right;
}
.chatbot-card-button {
  display: block;
  margin: 0.8em -1em 0; /* bleed to card edges */
  padding: 0.85em 1em;
  background: var(--accent);
  color: var(--txt-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.93em;
  text-align: center;
  transition: filter 0.15s ease;
}
.chatbot-card-button:hover { filter: brightness(1.05); }

/* ────────────────────────────────────────────────────────────────
   Lead-capture inline input
──────────────────────────────────────────────────────────────── */
.chatbot-input-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em;
  max-width: 78%;
  margin: 0 0 1.1em;
  margin-left: auto; /* align with bot bubbles (right in RTL) */
  animation: fadeInUp 0.25s ease both;
}
.chatbot-input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 1.2em;
  font-family: inherit;
  font-size: 0.97em;
  color: var(--txt-primary);
  background: #fff;
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-pill);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chatbot-input::placeholder { color: #a3a7ae; }
.chatbot-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.chatbot-input-send {
  appearance: none;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--txt-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.chatbot-input-send:hover { filter: brightness(1.06); }
.chatbot-input-send:active { transform: scale(0.92); }
.chatbot-input-send svg { transform: scaleX(-1); } /* point left for RTL */

/* skip chip inside the input group */
.chatbot-input-group .chatbot-input-skip {
  flex-basis: 100%;
  justify-content: center;
}

/* Honeypot field — invisible to humans, tempting to bots.
   NOTE: keep it inside the widget bounds — offscreen positioning (left:-9999px)
   expands the RTL scrollable area and yanks the chat sideways. */
.chatbot-hp {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  clip-path: inset(50%);
  pointer-events: none;
}

/* ────────────────────────────────────────────────────────────────
   Animations
──────────────────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ────────────────────────────────────────────────────────────────
   Mobile
──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .wp-flow-chatbot {
    max-width: 100%;
    margin: 1rem 0;
    border-radius: 16px;
  }
  .chatbot-window {
    height: 70dvh;
    min-height: 420px;
  }
  .messages { padding: 1em 0.85em; }
  .chatbot-message,
  .chatbot-options-group,
  .chatbot-input-group,
  .chatbot-info {
    max-width: 90%;
  }
  .chatbot-start { padding: 2em 1.25em 1.75em; }
  .chatbot-start h2 { font-size: 1.25em; }
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .wp-flow-chatbot *,
  .wp-flow-chatbot *::before {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
