Files
helix-engage-server/widget-src/src/styles.ts
saridsa2 aa41a2abb7 feat: widget chat with generative UI, branch selection, captcha gate, lead dedup
- Streaming AI chat via Vercel AI SDK v6 UI message stream — tool-based
  generative UI (pick_branch, list_departments, show_clinic_timings,
  show_doctors, show_doctor_slots, suggest_booking). Typing indicator,
  markdown suppressed, text parts hidden when widgets are rendered.
- Centralized Preact store (store.tsx) for visitor, leadId, captchaToken,
  bookingPrefill, doctors roster, branches, selectedBranch — replaces prop
  drilling across chat/book/contact tabs.
- Cloudflare Turnstile captcha gate rendered via light-DOM portal so it
  renders correctly inside the shadow DOM (Turnstile CSS doesn't cross
  shadow boundaries).
- Lead dedup helper (findOrCreateLeadByPhone, 24h phone window) shared
  across chat-start / book / contact so one visitor == one lead. Booking
  upgrades existing lead status NEW → APPOINTMENT_SET via updateLeadStatus.
- Pre-chat name+phone form captures the visitor; chat transcript logged
  to leadActivity records after each stream.
- Booking wizard gains a branch step 0 (skipped for single-branch
  hospitals); departments + doctors filtered by selectedBranch. Chat slot
  picks prefill the booking details step and lock the branch.
- Window-level captcha gate, modal maximize mode, header badge showing
  selected branch, widget font inherits from host page (fix :host { all:
  initial } override).
- 23 FA Pro 7.1 duotone icons bundled — medical departments, nav, actions,
  hospital/location-dot for branch context.
- main.ts: resolve public/ from process.cwd() so widget.js serves in both
  dev and prod. tsconfig: exclude widget-src/public/data from server tsc.
- captcha.guard: switch from reCAPTCHA v3 to Cloudflare Turnstile verify.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 16:04:46 +05:30

463 lines
17 KiB
TypeScript

import type { WidgetConfig } from './types';
export const getStyles = (config: WidgetConfig) => `
/* all: initial isolates the widget from host-page style bleed, but we then
explicitly re-enable font-family inheritance so the widget picks up the
host page's font stack instead of falling back to system default. */
:host {
all: initial;
font-family: inherit;
font-size: 14px;
line-height: 1.4;
color: #1f2937;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
.widget-bubble {
width: 56px; height: 56px; border-radius: 50%;
background: #fff; color: ${config.colors.primary};
display: flex; align-items: center; justify-content: center;
cursor: pointer; border: 1px solid #e5e7eb;
box-shadow: 0 6px 20px rgba(17, 24, 39, 0.15), 0 2px 4px rgba(17, 24, 39, 0.08);
transition: transform 0.2s, box-shadow 0.2s; outline: none;
}
.widget-bubble:hover {
transform: scale(1.08);
box-shadow: 0 10px 28px rgba(17, 24, 39, 0.2), 0 4px 8px rgba(17, 24, 39, 0.1);
}
.widget-bubble img { width: 32px; height: 32px; border-radius: 6px; }
.widget-bubble svg { width: 26px; height: 26px; }
.widget-panel {
width: 380px; height: 520px; border-radius: 16px;
background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
display: flex; flex-direction: column; overflow: hidden;
border: 1px solid #e5e7eb; position: absolute; bottom: 68px; right: 0;
animation: slideUp 0.25s ease-out;
transition: width 0.25s ease, height 0.25s ease, border-radius 0.25s ease;
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes widgetFadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
/* Maximized modal mode */
.widget-backdrop {
position: fixed; inset: 0;
background: rgba(17, 24, 39, 0.55);
backdrop-filter: blur(2px);
animation: widgetFadeIn 0.2s ease-out;
z-index: 1;
}
.widget-panel-maximized {
position: fixed;
top: 50%; left: 50%; right: auto; bottom: auto;
transform: translate(-50%, -50%);
width: min(960px, 92vw);
height: min(720px, 88vh);
max-width: 92vw; max-height: 88vh;
border-radius: 20px;
box-shadow: 0 24px 64px rgba(0,0,0,0.25);
z-index: 2;
animation: widgetFadeIn 0.2s ease-out;
}
.widget-header {
display: flex; align-items: center; gap: 10px;
padding: 14px 16px; background: ${config.colors.primary}; color: #fff;
}
.widget-header img { width: 32px; height: 32px; border-radius: 8px; }
.widget-header-text { flex: 1; min-width: 0; }
.widget-header-name { font-size: 14px; font-weight: 600; }
.widget-header-sub { font-size: 11px; opacity: 0.85; }
.widget-header-branch {
display: inline-flex; align-items: center; gap: 3px;
font-weight: 500;
}
.widget-header-btn {
background: none; border: none; color: #fff; cursor: pointer;
padding: 6px; opacity: 0.8; display: flex; align-items: center;
justify-content: center; border-radius: 6px; margin-left: 2px;
transition: background 0.15s, opacity 0.15s;
}
.widget-header-btn:hover { opacity: 1; background: rgba(255,255,255,0.15); }
.widget-tabs {
display: flex; border-bottom: 1px solid #e5e7eb; background: #fafafa;
}
.widget-tab {
flex: 1; padding: 10px 0; text-align: center; font-size: 12px;
font-weight: 500; cursor: pointer; border: none; background: none;
color: #6b7280; border-bottom: 2px solid transparent;
transition: all 0.15s; display: inline-flex; align-items: center;
justify-content: center; gap: 6px;
}
.widget-tab.active {
color: ${config.colors.primary}; border-bottom-color: ${config.colors.primary};
font-weight: 600;
}
.widget-body { flex: 1; overflow-y: auto; padding: 16px; }
.widget-panel-maximized .widget-body { padding: 24px 32px; }
.widget-panel-maximized .widget-tabs { padding: 0 16px; }
.widget-panel-maximized .widget-tab { padding: 14px 0; font-size: 13px; }
.widget-input {
width: 100%; padding: 10px 12px; border: 1px solid #d1d5db;
border-radius: 8px; font-size: 13px; outline: none;
transition: border-color 0.15s;
}
.widget-input:focus { border-color: ${config.colors.primary}; }
.widget-textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.widget-select {
width: 100%; padding: 10px 12px; border: 1px solid #d1d5db;
border-radius: 8px; font-size: 13px; background: #fff; outline: none;
}
.widget-label { font-size: 12px; font-weight: 500; color: #374151; margin-bottom: 4px; display: block; }
.widget-field { margin-bottom: 12px; }
.widget-section-title {
font-size: 13px; font-weight: 600; color: #1f2937;
margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.widget-section-sub {
font-size: 12px; color: #6b7280; margin-bottom: 16px;
}
.widget-error {
color: #dc2626; font-size: 12px; margin-bottom: 8px;
padding: 8px 10px; background: #fef2f2; border-radius: 6px;
border: 1px solid #fecaca;
}
.widget-btn {
width: 100%; padding: 10px 16px; border: none; border-radius: 8px;
font-size: 13px; font-weight: 600; cursor: pointer;
transition: opacity 0.15s; color: #fff; background: ${config.colors.primary};
}
.widget-btn:hover { opacity: 0.9; }
.widget-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.widget-btn-secondary { background: #f3f4f6; color: #374151; }
.widget-btn-with-icon {
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.widget-btn-row {
display: flex; gap: 8px; margin-top: 12px;
}
.widget-btn-row > .widget-btn { flex: 1; }
/* Row buttons — department list, doctor list, etc. */
.widget-row-btn {
width: 100%; display: flex; align-items: center; gap: 12px;
padding: 12px 14px; margin-bottom: 6px; border: 1px solid #e5e7eb;
border-radius: 10px; background: #fff; cursor: pointer;
text-align: left; color: #1f2937; transition: all 0.15s;
font-family: inherit;
}
.widget-row-btn:hover {
border-color: ${config.colors.primary};
background: ${config.colors.primaryLight};
}
.widget-row-btn.widget-row-btn-stack { align-items: flex-start; }
.widget-row-icon {
display: inline-flex; align-items: center; justify-content: center;
width: 32px; height: 32px; border-radius: 8px;
background: ${config.colors.primaryLight}; color: ${config.colors.primary};
flex-shrink: 0;
}
.widget-row-main { flex: 1; min-width: 0; }
.widget-row-label { font-size: 13px; font-weight: 600; color: #1f2937; }
.widget-row-sub { font-size: 11px; color: #6b7280; margin-top: 2px; }
.widget-row-chevron {
display: inline-flex; color: #9ca3af; flex-shrink: 0;
}
.widget-row-btn:hover .widget-row-chevron { color: ${config.colors.primary}; }
.widget-slots {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0;
}
.widget-slot {
padding: 8px; text-align: center; font-size: 12px; border-radius: 6px;
border: 1px solid #e5e7eb; cursor: pointer; background: #fff;
transition: all 0.15s;
}
.widget-slot:hover { border-color: ${config.colors.primary}; }
.widget-slot.selected { background: ${config.colors.primary}; color: #fff; border-color: ${config.colors.primary}; }
.widget-slot.unavailable { opacity: 0.4; cursor: not-allowed; text-decoration: line-through; }
.widget-success {
text-align: center; padding: 32px 16px;
display: flex; flex-direction: column; align-items: center;
}
.widget-success-icon {
display: flex; align-items: center; justify-content: center;
width: 80px; height: 80px; border-radius: 50%;
background: #ecfdf5; margin-bottom: 16px;
}
.widget-success-title { font-size: 16px; font-weight: 600; color: #059669; margin-bottom: 8px; }
.widget-success-text { font-size: 13px; color: #6b7280; line-height: 1.6; }
/* Chat empty state */
.chat-empty {
text-align: center; padding: 32px 8px 16px;
}
.chat-intro {
padding: 24px 4px 8px;
display: flex; flex-direction: column;
}
.chat-intro .chat-empty-icon { align-self: center; }
.chat-intro .chat-empty-title { text-align: center; font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 6px; }
.chat-intro .chat-empty-text { text-align: center; font-size: 12px; color: #6b7280; margin-bottom: 20px; line-height: 1.5; }
.chat-empty-icon {
display: flex; align-items: center; justify-content: center;
margin-bottom: 12px;
}
.chat-empty-title {
font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 6px;
}
.chat-empty-text {
font-size: 12px; color: #6b7280; margin-bottom: 18px; line-height: 1.5;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 0; }
.chat-msg { margin-bottom: 10px; display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }
.chat-msg-stack {
display: flex; flex-direction: column; gap: 6px;
max-width: 85%;
}
.chat-msg.user .chat-msg-stack { align-items: flex-end; }
.chat-msg.assistant .chat-msg-stack { align-items: flex-start; }
.chat-bubble {
padding: 10px 14px; border-radius: 12px;
font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.chat-msg.user .chat-bubble { background: ${config.colors.primary}; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant .chat-bubble { background: #f3f4f6; color: #1f2937; border-bottom-left-radius: 4px; }
/* Typing indicator (animated dots) */
.chat-typing-dots {
display: inline-flex; gap: 4px; align-items: center;
padding: 2px 0;
}
.chat-typing-dots > span {
width: 6px; height: 6px; border-radius: 50%;
background: #9ca3af; display: inline-block;
animation: chatDot 1.4s ease-in-out infinite both;
}
.chat-typing-dots > span:nth-child(2) { animation-delay: 0.16s; }
.chat-typing-dots > span:nth-child(3) { animation-delay: 0.32s; }
@keyframes chatDot {
0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
40% { transform: translateY(-4px); opacity: 1; }
}
/* Generic chat widget (tool UI) container */
.chat-widget {
background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
padding: 12px; font-size: 12px; color: #1f2937;
width: 100%; max-width: 300px;
}
.chat-widget-title {
font-size: 12px; font-weight: 600; color: #374151;
display: flex; align-items: center; gap: 6px;
margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em;
}
.chat-widget-loading {
display: inline-flex; align-items: center; gap: 8px;
padding: 8px 12px; background: #f3f4f6; border-radius: 10px;
font-size: 12px; color: #6b7280;
}
.chat-widget-loading-label { font-style: italic; }
.chat-widget-empty { font-size: 12px; color: #6b7280; font-style: italic; }
.chat-widget-error { font-size: 12px; color: #dc2626; padding: 8px 12px; background: #fef2f2; border-radius: 8px; border: 1px solid #fecaca; }
/* Branch picker cards */
.chat-widget-branches .chat-widget-branch-card {
width: 100%; display: block; text-align: left;
padding: 10px 12px; margin-bottom: 6px;
background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.chat-widget-branches .chat-widget-branch-card:last-child { margin-bottom: 0; }
.chat-widget-branches .chat-widget-branch-card:hover {
border-color: ${config.colors.primary};
background: ${config.colors.primaryLight};
}
.chat-widget-branch-name { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; }
.chat-widget-branch-meta { font-size: 11px; color: #6b7280; }
/* Department chip grid */
.chat-widget-dept-grid {
display: flex; flex-wrap: wrap; gap: 6px;
}
.chat-widget-dept-chip {
display: inline-flex; align-items: center; gap: 6px;
padding: 6px 10px; border-radius: 999px;
border: 1px solid ${config.colors.primary};
background: ${config.colors.primaryLight};
color: ${config.colors.primary};
font-size: 11px; font-weight: 500; cursor: pointer;
font-family: inherit; transition: all 0.15s;
}
.chat-widget-dept-chip:hover {
background: ${config.colors.primary}; color: #fff;
}
/* Doctor cards */
.chat-widget-doctor-card {
padding: 10px; background: #f9fafb; border-radius: 8px;
border: 1px solid #f3f4f6; margin-bottom: 6px;
}
.chat-widget-doctor-card:last-child { margin-bottom: 0; }
.chat-widget-doctor-name { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; }
.chat-widget-doctor-meta { font-size: 11px; color: #6b7280; line-height: 1.4; }
.chat-widget-doctor-action {
margin-top: 8px; width: 100%;
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
padding: 6px 10px; font-size: 11px; font-weight: 600;
color: ${config.colors.primary};
background: #fff;
border: 1px solid ${config.colors.primary};
border-radius: 6px; cursor: pointer;
font-family: inherit; transition: all 0.15s;
}
.chat-widget-doctor-action:hover {
background: ${config.colors.primary}; color: #fff;
}
/* Clinic timings widget */
.chat-widget-timings .chat-widget-timing-dept {
margin-bottom: 10px; padding-bottom: 8px;
border-bottom: 1px solid #f3f4f6;
}
.chat-widget-timings .chat-widget-timing-dept:last-child {
margin-bottom: 0; padding-bottom: 0; border-bottom: 0;
}
.chat-widget-timing-dept-name {
display: flex; align-items: center; gap: 6px;
font-size: 12px; font-weight: 600; color: ${config.colors.primary};
margin-bottom: 4px;
}
.chat-widget-timing-row {
padding: 4px 0 4px 22px;
}
.chat-widget-timing-doctor {
font-size: 12px; font-weight: 500; color: #1f2937;
}
.chat-widget-timing-hours {
font-size: 11px; color: #4b5563; line-height: 1.4;
}
.chat-widget-timing-clinic {
font-size: 11px; color: #9ca3af; font-style: italic;
}
/* Slots grid widget */
.chat-widget-slots-doctor { font-size: 13px; font-weight: 600; color: #1f2937; }
.chat-widget-slots-meta { font-size: 11px; color: #6b7280; margin-bottom: 8px; }
.chat-widget-slots-grid {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.chat-widget-slot-btn {
padding: 8px 6px; font-size: 12px; font-weight: 500;
color: ${config.colors.primary};
background: ${config.colors.primaryLight};
border: 1px solid ${config.colors.primary};
border-radius: 6px; cursor: pointer;
font-family: inherit; transition: all 0.15s;
}
.chat-widget-slot-btn:hover {
background: ${config.colors.primary}; color: #fff;
}
.chat-widget-slot-btn.unavailable {
color: #9ca3af; background: #f3f4f6;
border-color: #e5e7eb; cursor: not-allowed;
text-decoration: line-through;
}
/* Booking suggestion card */
.chat-widget-booking {
display: flex; gap: 12px; align-items: flex-start;
background: ${config.colors.primaryLight};
border-color: ${config.colors.primary};
}
.chat-widget-booking-icon {
flex-shrink: 0; width: 40px; height: 40px;
border-radius: 10px; background: #fff;
display: flex; align-items: center; justify-content: center;
color: ${config.colors.primary};
}
.chat-widget-booking-body { flex: 1; min-width: 0; }
.chat-widget-booking-title { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 2px; }
.chat-widget-booking-reason { font-size: 12px; color: #4b5563; line-height: 1.5; margin-bottom: 6px; }
.chat-widget-booking-dept { font-size: 11px; color: ${config.colors.primary}; font-weight: 500; margin-bottom: 8px; }
.chat-widget-booking .widget-btn { padding: 8px 14px; font-size: 12px; }
.chat-input-row { display: flex; gap: 8px; padding-top: 8px; border-top: 1px solid #e5e7eb; }
.chat-input { flex: 1; }
.chat-send {
width: 36px; height: 36px; border-radius: 8px;
background: ${config.colors.primary}; color: #fff;
border: none; cursor: pointer; display: flex;
align-items: center; justify-content: center;
flex-shrink: 0;
}
.chat-send:hover { opacity: 0.9; }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.quick-action {
padding: 6px 12px; border-radius: 16px; font-size: 11px;
border: 1px solid ${config.colors.primary}; color: ${config.colors.primary};
background: ${config.colors.primaryLight}; cursor: pointer;
transition: all 0.15s; font-family: inherit;
}
.quick-action:hover { background: ${config.colors.primary}; color: #fff; }
.widget-steps { display: flex; gap: 4px; margin-bottom: 16px; }
.widget-step {
flex: 1; height: 3px; border-radius: 2px; background: #e5e7eb;
}
.widget-step.active { background: ${config.colors.primary}; }
.widget-step.done { background: #059669; }
/* Captcha gate — full-panel verification screen */
.widget-captcha-gate {
flex: 1; display: flex; flex-direction: column; align-items: center;
justify-content: center; padding: 32px 24px; text-align: center;
background: #fafafa;
}
.widget-captcha-gate-icon {
display: flex; align-items: center; justify-content: center;
width: 96px; height: 96px; border-radius: 50%;
background: ${config.colors.primaryLight}; margin-bottom: 20px;
}
.widget-captcha-gate-title {
font-size: 17px; font-weight: 600; color: #1f2937; margin-bottom: 8px;
}
.widget-captcha-gate-text {
font-size: 13px; color: #6b7280; margin-bottom: 24px; line-height: 1.5;
max-width: 280px;
}
.widget-captcha {
display: flex; flex-direction: column; align-items: center;
gap: 8px; width: 100%;
}
/* Placeholder reserves space for the Turnstile widget which is portaled to
document.body (light DOM) and visually positioned over this element. */
.widget-captcha-mount {
width: 300px; height: 65px;
display: block;
}
.widget-captcha-status {
font-size: 11px; color: #6b7280; text-align: center;
}
.widget-captcha-error { color: #dc2626; }
`;