/* ============================================================================
   Health Therapies Clinics — Chatbot widget
   Self-contained, scoped under .htc-chatbot to avoid clashing with site CSS.
   ============================================================================ */

.htc-chatbot,
.htc-chatbot * { box-sizing: border-box; }

.htc-chatbot {
  --htc-primary:    #1F5F8B;        /* deeper blue, distinct from rainbow teal */
  --htc-primary-2:  #2E8FBF;
  --htc-accent:     #F2A640;
  --htc-bg:         #ffffff;
  --htc-bg-alt:     #F2F5F8;
  --htc-bubble-u:   #1F5F8B;
  --htc-bubble-a:   #E6F1F8;
  --htc-text:       #1A2B36;
  --htc-muted:      #6B7A82;
  --htc-border:     #D0D8DC;
  --htc-shadow:     0 10px 40px rgba(0,0,0,0.18);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--htc-text);
  line-height: 1.45;

  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483000;
}

/* ── Launcher ──────────────────────────────────────────────────────────── */
.htc-chatbot__launcher {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--htc-primary), var(--htc-primary-2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: none;
  box-shadow: var(--htc-shadow);
  transition: transform 0.18s ease;
  position: relative;
}
.htc-chatbot__launcher:hover { transform: translateY(-2px); }
.htc-chatbot__launcher svg { width: 28px; height: 28px; }
.htc-chatbot__launcher .htc-chatbot__logo-img { width: 32px; height: 32px; object-fit: contain; }
.htc-chatbot__avatar .htc-chatbot__logo-img { width: 26px; height: 26px; object-fit: contain; }
.htc-chatbot__launcher .htc-chatbot__badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--htc-accent);
  color: #fff;
  font-size: 11px; font-weight: 700;
  border-radius: 10px;
  padding: 2px 6px;
  display: none;
}
.htc-chatbot__launcher.has-unread .htc-chatbot__badge { display: block; }

/* ── Window ────────────────────────────────────────────────────────────── */
.htc-chatbot__window {
  position: absolute;
  bottom: 78px;
  right: 0;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 640px;
  max-height: calc(100vh - 100px);
  background: var(--htc-bg);
  border-radius: 16px;
  box-shadow: var(--htc-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.htc-chatbot.open .htc-chatbot__window {
  display: flex; opacity: 1; transform: translateY(0);
}

.htc-chatbot__header {
  background: linear-gradient(135deg, var(--htc-primary), var(--htc-primary-2));
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
}
.htc-chatbot__avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.htc-chatbot__avatar svg { width: 22px; height: 22px; }
.htc-chatbot__title { font-weight: 600; font-size: 15px; line-height: 1.1; }
.htc-chatbot__subtitle { font-size: 12px; opacity: 0.85; }
.htc-chatbot__close {
  margin-left: auto;
  background: transparent; border: none; color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.htc-chatbot__close:hover { background: rgba(255,255,255,0.15); }

/* Intent chip in header (shown after picker) */
.htc-chatbot__intent-pill {
  margin-left: auto;
  background: rgba(255,255,255,0.2);
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.htc-chatbot__close--with-intent { margin-left: 8px; }

/* ── Body / messages ───────────────────────────────────────────────────── */
.htc-chatbot__body {
  flex: 1; overflow-y: auto;
  padding: 14px;
  background: var(--htc-bg-alt);
}
.htc-chatbot__msg { display: flex; margin-bottom: 10px; }
.htc-chatbot__msg-bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.htc-chatbot__msg.user { justify-content: flex-end; }
.htc-chatbot__msg.user .htc-chatbot__msg-bubble {
  background: var(--htc-bubble-u);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.htc-chatbot__msg.assistant .htc-chatbot__msg-bubble {
  background: var(--htc-bubble-a);
  color: var(--htc-text);
  border-bottom-left-radius: 4px;
}
.htc-chatbot__msg.system .htc-chatbot__msg-bubble {
  background: #FFF3CD;
  color: #664D03;
  font-size: 12px;
  width: 100%; max-width: 100%;
  text-align: center;
  border-radius: 8px;
}
.htc-chatbot__msg-bubble a { color: inherit; text-decoration: underline; }
.htc-chatbot__sources {
  font-size: 11px; color: var(--htc-muted);
  margin: -4px 0 8px 4px;
}
.htc-chatbot__sources a { color: var(--htc-primary); text-decoration: none; }
.htc-chatbot__sources a:hover { text-decoration: underline; }

/* Typing dots */
.htc-chatbot__typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.htc-chatbot__typing span {
  width: 7px; height: 7px;
  background: var(--htc-muted); border-radius: 50%;
  animation: htc-blink 1.2s infinite ease-in-out both;
}
.htc-chatbot__typing span:nth-child(2) { animation-delay: 0.2s; }
.htc-chatbot__typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes htc-blink { 0%,80%,100% { opacity:0.2; } 40% { opacity:1; } }

/* ── Intent picker (initial screen) ────────────────────────────────────── */
.htc-chatbot__picker { padding: 16px; }
.htc-chatbot__picker h3 {
  margin: 0 0 4px;
  font-size: 16px; color: var(--htc-primary);
}
.htc-chatbot__picker p { margin: 0 0 14px; color: var(--htc-muted); font-size: 13px; }
.htc-chatbot__pick-card {
  display: flex; align-items: center; gap: 12px;
  background: #fff;
  border: 1px solid var(--htc-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.htc-chatbot__pick-card:hover {
  border-color: var(--htc-primary-2);
  transform: translateY(-1px);
}
.htc-chatbot__pick-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--htc-bubble-a);
  color: var(--htc-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.htc-chatbot__pick-icon svg { width: 20px; height: 20px; }
.htc-chatbot__pick-title { font-weight: 600; font-size: 14px; }
.htc-chatbot__pick-desc { font-size: 12px; color: var(--htc-muted); margin-top: 2px; }

/* ── Lead capture (patient) ───────────────────────────────────────────── */
.htc-chatbot__lead, .htc-chatbot__app-form {
  background: #fff;
  border: 1px solid var(--htc-border);
  border-radius: 12px;
  padding: 14px;
  margin: 4px 0 10px;
}
.htc-chatbot__lead h4 {
  margin: 0 0 6px; font-size: 13px; color: var(--htc-primary); font-weight: 600;
}
.htc-chatbot__lead p { margin: 0 0 8px; font-size: 12px; color: var(--htc-muted); }

.htc-chatbot__lead input,
.htc-chatbot__app-form input,
.htc-chatbot__app-form select,
.htc-chatbot__app-form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--htc-border);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 6px;
  font-family: inherit;
  color: var(--htc-text);
  background: #fff;
}
.htc-chatbot__app-form textarea { min-height: 60px; resize: vertical; }
.htc-chatbot__lead input:focus,
.htc-chatbot__app-form input:focus,
.htc-chatbot__app-form select:focus,
.htc-chatbot__app-form textarea:focus {
  outline: none;
  border-color: var(--htc-primary-2);
  box-shadow: 0 0 0 3px rgba(46,143,191,0.15);
}
.htc-chatbot__app-form .htc-chatbot__form-row {
  display: flex; gap: 6px;
}
.htc-chatbot__app-form .htc-chatbot__form-row > * { flex: 1; }

.htc-chatbot__lead-actions { display: flex; gap: 6px; margin-top: 4px; }
.htc-chatbot__btn {
  flex: 1;
  padding: 9px 12px;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.htc-chatbot__btn--primary { background: var(--htc-primary); color: #fff; }
.htc-chatbot__btn--primary:hover { background: var(--htc-primary-2); }
.htc-chatbot__btn--ghost { background: transparent; color: var(--htc-muted); }
.htc-chatbot__btn--ghost:hover { color: var(--htc-primary); }

/* ── Application form sections ────────────────────────────────────────── */
.htc-chatbot__app-form h4 {
  margin: 0 0 6px; font-size: 14px; color: var(--htc-primary); font-weight: 700;
}
.htc-chatbot__app-form .htc-chatbot__section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  color: var(--htc-primary); letter-spacing: 0.5px;
  margin: 14px 0 6px; padding-top: 10px;
  border-top: 1px solid var(--htc-border);
}
.htc-chatbot__app-form .htc-chatbot__section-title:first-child {
  margin-top: 0; padding-top: 0; border-top: 0;
}
.htc-chatbot__app-form label.htc-field-label {
  display: block;
  font-size: 12px; color: var(--htc-muted);
  margin-bottom: 3px;
}

.htc-chatbot__chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.htc-chatbot__chip {
  display: inline-flex; align-items: center;
  padding: 4px 9px;
  border: 1.2px solid var(--htc-border);
  border-radius: 999px;
  background: #fff;
  font-size: 12px; cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}
.htc-chatbot__chip:hover { border-color: var(--htc-primary-2); background: var(--htc-bg-alt); }
.htc-chatbot__chip.selected {
  border-color: var(--htc-primary);
  background: var(--htc-bubble-a);
  color: var(--htc-primary);
  font-weight: 600;
}
.htc-chatbot__chip input { display: none; }

.htc-chatbot__check {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--htc-text);
  margin-bottom: 4px;
}
.htc-chatbot__check input { width: auto; margin: 0; }

.htc-chatbot__field-error {
  color: #C0392B; font-size: 11px; margin-top: -4px; margin-bottom: 6px;
}

/* ── Footer / input ───────────────────────────────────────────────────── */
.htc-chatbot__footer {
  border-top: 1px solid var(--htc-border);
  padding: 10px 12px;
  background: #fff;
}
.htc-chatbot__inputwrap {
  display: flex; gap: 6px;
  background: var(--htc-bg-alt);
  border: 1px solid var(--htc-border);
  border-radius: 22px;
  padding: 4px 4px 4px 14px;
  align-items: flex-end;
}
.htc-chatbot__inputwrap textarea {
  flex: 1;
  border: none; background: transparent;
  resize: none;
  font: inherit; color: var(--htc-text);
  padding: 8px 0; max-height: 120px; outline: none;
  font-family: inherit;
}
.htc-chatbot__send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--htc-primary); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.htc-chatbot__send:hover { background: var(--htc-primary-2); }
.htc-chatbot__send:disabled { background: var(--htc-muted); cursor: not-allowed; }
.htc-chatbot__send svg { width: 16px; height: 16px; }
.htc-chatbot__disclaimer {
  text-align: center;
  margin-top: 6px;
  font-size: 10px; color: var(--htc-muted);
}

/* CTA shown after a few practitioner turns */
.htc-chatbot__cta {
  display: flex; gap: 6px;
  background: #fff;
  border: 1px solid var(--htc-border);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 4px 0 10px;
  align-items: center;
}
.htc-chatbot__cta-text { flex: 1; font-size: 12px; }

@media (max-width: 480px) {
  .htc-chatbot { bottom: 12px; right: 12px; left: 12px; }
  .htc-chatbot__window {
    width: auto; right: 0; left: 0;
    height: 80vh;
  }
  .htc-chatbot__launcher { margin-left: auto; }
}
