/* Shared chat-widget styles. Namespaced .cbw-* so they never collide with the host
   page. Theme by overriding the CSS variables below on the mount node or :root.
   thai-typography: font-synthesis:none everywhere; bubble line-height >= 1.45 so
   Thai stacked vowels/tone marks never clip. */

/* The mount node ([data-bot]) must fill the height the host gives it, otherwise the
   .cbw card inside collapses to content height and the input floats mid-pane. */
[data-bot] { display: block; height: 100%; min-height: 0; }

.cbw {
  --cbw-accent: #a9744f;
  --cbw-accent-ink: #ffffff;
  --cbw-head-bg: var(--cbw-accent);
  --cbw-head-ink: #ffffff;
  --cbw-bot-bg: #f3e7da;
  --cbw-bot-ink: #3a2e26;
  --cbw-surface: #ffffff;
  --cbw-rule: #ece2d6;
  --cbw-muted: #8a7a6d;
  --cbw-radius: 20px;
  --cbw-lead-bg: #ecfdf5;
  --cbw-lead-ink: #065f46;
  --cbw-lead-rule: #a7f3d0;
  /* faint inner-field tint for the rounded input; pages can override */
  --cbw-field-bg: rgba(0, 0, 0, .035);

  /* ---- shape tokens (the "skin" surface) ----
     Color = brand (set per page); SHAPE = interface design (set per skin via the
     cbw-skin-* classes below). A page picks a skin with data-skin so the same widget
     reads as a different UI a client could drop into their own system. Defaults here
     reproduce the original soft/rounded look (café), so unskinned pages don't change. */
  --cbw-bubble-radius: 18px;   /* message corner */
  --cbw-bubble-tail: 5px;      /* the one "spoken" corner; == bubble-radius means no tail */
  --cbw-avatar-radius: 12px;
  --cbw-chip-radius: 999px;
  --cbw-send-radius: 50%;
  --cbw-send-size: 44px;
  --cbw-card-shadow: 0 24px 60px -28px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .5);
  --cbw-bubble-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  --cbw-bot-border: 0 solid transparent;   /* skins can swap bubble shadow for a hairline */
  --cbw-msgs-bg: radial-gradient(120% 60% at 50% 0%, rgba(0, 0, 0, .015), transparent 60%);

  font-family: 'Bai Jamjuree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-synthesis: none;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;        /* defensive: never let the card grow past its pane (keeps input on-screen) */
  background: var(--cbw-surface);
  border: 1px solid var(--cbw-rule);
  border-radius: var(--cbw-radius);
  overflow: hidden;
  box-shadow: var(--cbw-card-shadow);
}
.cbw *,
.cbw *::before,
.cbw *::after { box-sizing: border-box; font-synthesis: none; }

/* ---- header ---- */
.cbw-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--cbw-head-bg);
  color: var(--cbw-head-ink);
}
.cbw-avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--cbw-avatar-radius);
  background: rgba(255, 255, 255, .22);
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}
.cbw-head-text { min-width: 0; }
.cbw-title {
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cbw-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .76rem;
  opacity: .9;
  line-height: 1.4;
}
.cbw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #46e0a0;
  box-shadow: 0 0 0 3px rgba(70, 224, 160, .3);
}

/* ---- messages ---- */
.cbw-msgs {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--cbw-msgs-bg);
}
.cbw-m {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--cbw-bubble-radius);
  line-height: 1.5;
  font-size: .95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--cbw-bubble-shadow);
  animation: cbw-pop .32s cubic-bezier(.2, .9, .2, 1) both;
}
.cbw-bot {
  align-self: flex-start;
  background: var(--cbw-bot-bg);
  color: var(--cbw-bot-ink);
  border: var(--cbw-bot-border);
  border-bottom-left-radius: var(--cbw-bubble-tail);
}
.cbw-user {
  align-self: flex-end;
  background: var(--cbw-accent);
  color: var(--cbw-accent-ink);
  border-bottom-right-radius: var(--cbw-bubble-tail);
}
.cbw-lead {
  align-self: stretch;
  max-width: 100%;
  background: var(--cbw-lead-bg);
  color: var(--cbw-lead-ink);
  border: 1px solid var(--cbw-lead-rule);
  border-radius: 14px;
  font-size: .92rem;
}
@keyframes cbw-pop {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: none; }
}

/* ---- quote card (price-estimate bot: <<QUOTE>> reply) ----
   A paste-ready summary the visitor copies into Fastwork. Uses the page's brand vars
   so it themes per page like the listing card. */
.cbw-quote {
  align-self: stretch;
  max-width: 100%;
  background: var(--cbw-surface);
  border: 1px solid var(--cbw-rule);
  border-left: 3px solid var(--cbw-accent);
  border-radius: var(--cbw-bubble-radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--cbw-bubble-shadow);
  animation: cbw-pop .32s cubic-bezier(.2, .9, .2, 1) both;
}
.cbw-quote-head {
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--cbw-accent);
}
.cbw-quote-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: .9rem;
  line-height: 1.6;
  color: var(--cbw-bot-ink);
  background: var(--cbw-field-bg);
  border: 1px solid var(--cbw-rule);
  border-radius: 10px;
  padding: 11px 13px;
}
.cbw-quote-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cbw-quote-copy {
  flex: 1 1 auto;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  margin: 0;
  background: var(--cbw-accent);
  color: var(--cbw-accent-ink);
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
}
.cbw-quote-copy:hover { filter: brightness(1.06); }
.cbw-quote-copy:active { transform: translateY(1px); }
.cbw-quote-copy.is-done { background: var(--cbw-lead-ink); }
.cbw-quote-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--cbw-rule);
  background: var(--cbw-surface);
  color: var(--cbw-bot-ink);
  font-size: .88rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  transition: border-color .15s ease, color .15s ease;
}
.cbw-quote-link:hover { border-color: var(--cbw-accent); color: var(--cbw-accent); }
@media (prefers-reduced-motion: reduce) {
  .cbw-quote { animation: none !important; }
}

/* ---- structured listing card (estate bot: <<PP>> lines) ----
   Turns a pipe-delimited listing into a scannable card. Uses the page's brand vars
   + the active skin's bubble radius, so it stays on-brand and on-shape. */
.cbw-listing {
  align-self: stretch;
  max-width: 100%;
  background: var(--cbw-surface);
  border: 1px solid var(--cbw-rule);
  border-left: 3px solid var(--cbw-accent);
  border-radius: var(--cbw-bubble-radius);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: var(--cbw-bubble-shadow);
  animation: cbw-pop .32s cubic-bezier(.2, .9, .2, 1) both;
}
.cbw-listing-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.cbw-listing-id {
  flex: 0 0 auto;
  font-size: .73rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--cbw-accent);
  background: var(--cbw-bot-bg);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}
.cbw-listing-price {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--cbw-bot-ink);
}
.cbw-listing-title {
  font-weight: 600;
  font-size: .93rem;
  line-height: 1.5;
  color: var(--cbw-bot-ink);
}
.cbw-listing-loc {
  display: flex;
  gap: 6px;
  font-size: .86rem;
  line-height: 1.5;
  color: var(--cbw-bot-ink);
}
.cbw-listing-loc::before {
  content: "";
  flex: 0 0 auto;
  width: 13px;
  height: 15px;
  margin-top: 2px;
  background: var(--cbw-accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C8.1 2 5 5.1 5 9c0 5.2 7 13 7 13s7-7.8 7-13c0-3.9-3.1-7-7-7zm0 9.5A2.5 2.5 0 1112 6.5a2.5 2.5 0 010 5z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C8.1 2 5 5.1 5 9c0 5.2 7 13 7 13s7-7.8 7-13c0-3.9-3.1-7-7-7zm0 9.5A2.5 2.5 0 1112 6.5a2.5 2.5 0 010 5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.cbw-listing-note {
  font-size: .82rem;
  line-height: 1.55;
  color: var(--cbw-muted);
}

/* typing indicator */
.cbw-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 13px 15px;
  background: var(--cbw-bot-bg);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
}
.cbw-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cbw-muted);
  animation: cbw-blink 1.2s infinite;
}
.cbw-typing i:nth-child(2) { animation-delay: .2s; }
.cbw-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes cbw-blink {
  50% { opacity: .3; transform: translateY(-3px); }
}

/* ---- quick-reply chips ---- */
.cbw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 6px;
}
.cbw-chip {
  border: 1px solid var(--cbw-rule);
  background: var(--cbw-surface);
  color: var(--cbw-bot-ink);
  font: inherit;
  font-size: .85rem;
  padding: 7px 13px;
  border-radius: var(--cbw-chip-radius);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.cbw-chip:hover { background: var(--cbw-bot-bg); border-color: var(--cbw-accent); }
.cbw-chip:active { transform: translateY(1px); }

/* ---- input row ---- */
.cbw-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--cbw-rule);
  background: var(--cbw-surface);
  flex: 0 0 auto;          /* never compress under height pressure — keeps the input on-screen */
}
.cbw-input {
  flex: 1 1 auto;
  min-width: 0;            /* allow the field to shrink in the flex row */
  width: 100%;
  -webkit-appearance: none;
  appearance: none;        /* drop native input box (was rendering taller + bleeding past the edge) */
  margin: 0;
  border: 1px solid var(--cbw-rule);
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--cbw-bot-ink);
  background: var(--cbw-field-bg);
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.cbw-input::placeholder { color: var(--cbw-muted); }
.cbw-send {
  flex: 0 0 auto;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  border: 0;
  width: var(--cbw-send-size);
  height: var(--cbw-send-size);
  border-radius: var(--cbw-send-radius);
  background: var(--cbw-accent);
  color: var(--cbw-accent-ink);
  font: inherit;
  font-size: 0;            /* hide the "ส่ง" glyphs visually; text stays the SR accessible name */
  line-height: 1;
  cursor: pointer;
  /* flex (one row) not grid: the leftover "ส่ง" text node would otherwise become a
     second grid row and shove the icon into the top half (off-center) */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, filter .15s ease;
}
/* paper-plane send icon, tinted to the button ink via mask */
.cbw-send::before {
  content: "";
  width: 18px;
  height: 18px;
  background: currentColor;
  transform: translateX(1px);   /* optical centering: a right-pointing plane reads left-heavy */
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 21l21-9L2 3v7l15 2-15 2v7z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 21l21-9L2 3v7l15 2-15 2v7z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.cbw-send:hover { filter: brightness(1.06); transform: scale(1.06); }
.cbw-send:active { transform: scale(.96); }
.cbw-send:disabled { opacity: .5; cursor: default; transform: none; }

/* ---- image upload (vision bots: data-image="on") ---- */
.cbw-attach {
  flex: 0 0 auto;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  color: var(--cbw-muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s ease, color .15s ease;
}
.cbw-attach:hover { background: var(--cbw-bot-bg); color: var(--cbw-accent); }
.cbw-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 0;
}
.cbw-preview-img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--cbw-rule);
}
.cbw-preview-x {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--cbw-rule);
  background: var(--cbw-surface);
  color: var(--cbw-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.cbw-preview-x:hover { border-color: var(--cbw-accent); color: var(--cbw-accent); }
.cbw-has-img { padding: 6px; }
.cbw-msg-img {
  display: block;
  max-width: 220px;
  width: 100%;
  border-radius: 12px;
}
.cbw-msg-cap { padding: 6px 8px 2px; line-height: 1.5; }

/* ---- footer note ---- */
.cbw-foot {
  padding: 8px 14px 11px;
  font-size: .72rem;
  color: var(--cbw-muted);
  text-align: center;
  background: var(--cbw-surface);
  line-height: 1.4;
}

/* a11y */
.cbw :focus-visible {
  outline: 2px solid var(--cbw-accent);
  outline-offset: 2px;
  border-radius: 8px;
}
/* text field: keep the pill shape; signal focus with an accent border (no harsh outline) */
.cbw-input:focus,
.cbw-input:focus-visible {
  outline: none;
  border-color: var(--cbw-accent);
}

/* mobile: 16px input prevents iOS Safari auto-zoom on focus */
@media (max-width: 768px) {
  .cbw-input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .cbw-m, .cbw-typing i { animation: none !important; }
}

/* ============================================================================
   SKINS — same widget, different interface design.
   A page selects one with data-skin="<name>" on the mount node; widget.js turns
   that into a .cbw-skin-<name> class on the card. Skins reshape the UI (radii,
   tails, header treatment, button shape, density, type) while leaving COLOR to the
   page's own brand variables — so each bot looks native to a different client's
   system, not the same widget recoloured. No skin = the soft/rounded default (café).
   ============================================================================ */

/* --- clean: flat modern support widget (light header, no tails, squircle send). --- */
.cbw.cbw-skin-clean {
  --cbw-radius: 16px;
  --cbw-bubble-radius: 13px;
  --cbw-bubble-tail: 13px;      /* symmetric corners — no spoken tail */
  --cbw-avatar-radius: 11px;
  --cbw-chip-radius: 10px;
  --cbw-send-radius: 13px;      /* rounded square, not a circle */
  --cbw-card-shadow: 0 18px 44px -30px rgba(0, 0, 0, .28);
  --cbw-bubble-shadow: none;
  --cbw-bot-border: 1px solid var(--cbw-rule);
  --cbw-msgs-bg: none;
}
/* light header sits on the page surface with a hairline rule (uses the page's own
   surface/ink/rule vars, so it stays on-brand — just not a colour bar) */
.cbw.cbw-skin-clean .cbw-head {
  background: var(--cbw-surface);
  color: var(--cbw-bot-ink);
  border-bottom: 1px solid var(--cbw-rule);
}
.cbw.cbw-skin-clean .cbw-avatar {
  background: var(--cbw-bot-bg);
  color: var(--cbw-accent);
}
.cbw.cbw-skin-clean .cbw-status { color: var(--cbw-muted); opacity: 1; }

/* --- console: technical/dashboard panel (square avatar, mono labels, grid, sharp). --- */
.cbw.cbw-skin-console {
  --cbw-radius: 12px;
  --cbw-bubble-radius: 7px;
  --cbw-bubble-tail: 7px;
  --cbw-avatar-radius: 8px;
  --cbw-chip-radius: 7px;
  --cbw-send-radius: 9px;
  --cbw-bubble-shadow: none;
  --cbw-bot-border: 1px solid var(--cbw-rule);
  /* faint horizontal grid behind the log — reads like a readout */
  --cbw-msgs-bg: linear-gradient(rgba(0, 0, 0, .028) 1px, transparent 1px) 0 0 / 100% 28px;
}
.cbw.cbw-skin-console .cbw-title {
  font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  letter-spacing: -.01em;
}
.cbw.cbw-skin-console .cbw-status,
.cbw.cbw-skin-console .cbw-chip {
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  letter-spacing: .02em;
}
.cbw.cbw-skin-console .cbw-chip { font-size: .8rem; }

/* --- editorial: luxury magazine (ultra-sharp, uppercase tracked title, hairlines). --- */
.cbw.cbw-skin-editorial {
  --cbw-radius: 2px;
  --cbw-bubble-radius: 2px;
  --cbw-bubble-tail: 2px;
  --cbw-avatar-radius: 2px;
  --cbw-chip-radius: 0px;
  --cbw-send-radius: 2px;
  --cbw-send-size: 46px;
  --cbw-card-shadow: 0 30px 60px -40px rgba(0, 0, 0, .45);
  --cbw-bubble-shadow: none;
  --cbw-bot-border: 1px solid var(--cbw-rule);
  --cbw-msgs-bg: none;
}
.cbw.cbw-skin-editorial .cbw-title {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: .86rem;
  font-weight: 600;
}
.cbw.cbw-skin-editorial .cbw-chip {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .74rem;
}
