/* Site Assistant Chatbot — frontend widget styles (v1.1)
 * Built to survive aggressive theme/page-builder button & input styles:
 * every control is reset first, then styled with higher specificity.
 */

/* ---------- design tokens ---------- */
.sac-root {
  --sac-color: #4f46e5;
  --sac-on: #ffffff;
  --sac-bg: #ffffff;
  --sac-surface: #eef2f7;
  --sac-dots: rgba(15, 23, 42, .045);
  --sac-text: #1f2937;
  --sac-muted: #64748b;
  --sac-border: #e2e8f0;
  --sac-field-border: #cbd5e1;
  --sac-field-bg: #f8fafc;
  --sac-bot-bg: #ffffff;
  --sac-agent-bg: #ecfdf5;
  --sac-agent-border: #a7f3d0;
  --sac-agent-text: #047857;
  --sac-shadow: 0 18px 55px rgba(15, 23, 42, .28);
}
.sac-root.sac-theme-dark {
  --sac-bg: #111827;
  --sac-surface: #0b1220;
  --sac-dots: rgba(255, 255, 255, .04);
  --sac-text: #e5e7eb;
  --sac-muted: #94a3b8;
  --sac-border: #243044;
  --sac-field-border: #334155;
  --sac-field-bg: #0f172a;
  --sac-bot-bg: #1e293b;
  --sac-agent-bg: #052e22;
  --sac-agent-border: #14532d;
  --sac-agent-text: #6ee7b7;
  --sac-shadow: 0 18px 55px rgba(0, 0, 0, .6);
}
@media (prefers-color-scheme: dark) {
  .sac-root.sac-theme-auto {
    --sac-bg: #111827;
    --sac-surface: #0b1220;
    --sac-dots: rgba(255, 255, 255, .04);
    --sac-text: #e5e7eb;
    --sac-muted: #94a3b8;
    --sac-border: #243044;
    --sac-field-border: #334155;
    --sac-field-bg: #0f172a;
    --sac-bot-bg: #1e293b;
    --sac-agent-bg: #052e22;
    --sac-agent-border: #14532d;
    --sac-agent-text: #6ee7b7;
    --sac-shadow: 0 18px 55px rgba(0, 0, 0, .6);
  }
}

/* ---------- reset (beats theme styles on buttons/inputs/forms) ---------- */
.sac-root, .sac-root *, .sac-root *::before, .sac-root *::after { box-sizing: border-box; }
.sac-root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.5; color: var(--sac-text);
  text-align: left; letter-spacing: normal; text-transform: none;
  z-index: 99999;
}
.sac-root [hidden] { display: none !important; }
.sac-root p { margin: 0 0 9px; padding: 0; font-size: inherit; line-height: inherit; color: inherit; }
.sac-root p:last-child { margin-bottom: 0; }
.sac-root img { max-width: 100%; height: auto; border: 0; box-shadow: none; }
.sac-root button,
.sac-root input,
.sac-root textarea {
  font: inherit; font-size: 14px; letter-spacing: normal; text-transform: none; text-shadow: none;
  margin: 0; float: none; box-shadow: none; -webkit-appearance: none; appearance: none;
}
.sac-root button {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 0 !important; min-height: 0 !important; width: auto; height: auto;
  padding: 0; border: 0; border-radius: 0; background: none; color: inherit;
  line-height: 1.2; text-decoration: none; cursor: pointer; white-space: normal;
}
.sac-root button:focus-visible,
.sac-root a:focus-visible { outline: 2px solid var(--sac-color); outline-offset: 2px; }

/* ---------- placement: the launcher and the panel never stack ---------- */
.sac-root.sac-pos-bottom-right,
.sac-root.sac-pos-bottom-left { position: fixed; bottom: 20px; display: flex; flex-direction: column; }
.sac-root.sac-pos-bottom-right { right: 20px; align-items: flex-end; }
.sac-root.sac-pos-bottom-left { left: 20px; align-items: flex-start; }
.sac-root.sac-pos-bottom-right .sac-panel { position: absolute; right: 0; bottom: 0; }
.sac-root.sac-pos-bottom-left .sac-panel { position: absolute; left: 0; bottom: 0; }
/* When the chat is open the launcher disappears completely. */
.sac-root.sac-open .sac-toggle,
.sac-root.sac-open .sac-teaser { display: none !important; }

/* ---------- launcher ---------- */
.sac-root .sac-toggle {
  position: relative; width: 62px !important; height: 62px !important; padding: 0 !important;
  border: 0 !important; border-radius: 50% !important;
  background: var(--sac-color) !important; color: var(--sac-on) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.28), 0 0 0 6px color-mix(in srgb, var(--sac-color) 14%, transparent) !important;
  transition: transform .16s ease;
}
.sac-root .sac-toggle:hover { transform: scale(1.07); }
.sac-root .sac-toggle svg { width: 30px; height: 30px; fill: var(--sac-on); pointer-events: none; }
.sac-root .sac-badge {
  position: absolute; top: -3px; right: -3px; min-width: 21px; height: 21px; padding: 0 5px;
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
  border-radius: 11px; border: 2px solid #fff; display: flex; align-items: center; justify-content: center;
}

/* ---------- teaser bubble ---------- */
.sac-root .sac-teaser {
  position: relative; max-width: 250px; margin: 0 0 12px; padding: 11px 34px 11px 14px;
  background: var(--sac-bg); color: var(--sac-text); border: 1px solid var(--sac-border);
  border-radius: 14px; box-shadow: 0 8px 28px rgba(15,23,42,.2); cursor: pointer;
  animation: sac-rise .3s ease;
}
.sac-root .sac-teaser-x {
  position: absolute; top: 6px; right: 6px; width: 22px !important; height: 22px !important;
  border-radius: 50% !important; color: var(--sac-muted) !important; font-size: 16px; line-height: 1;
}
.sac-root .sac-teaser-x:hover { background: var(--sac-field-bg) !important; }

/* ---------- panel ---------- */
.sac-root .sac-panel {
  width: 384px; max-width: calc(100vw - 32px);
  height: 580px; max-height: calc(100vh - 110px); max-height: calc(100dvh - 110px);
  background: var(--sac-bg); color: var(--sac-text); border-radius: 20px;
  box-shadow: var(--sac-shadow); border: 1px solid var(--sac-border);
  display: flex; flex-direction: column; overflow: hidden;
  animation: sac-rise .24s ease;
}
@keyframes sac-rise {
  from { opacity: 0; transform: translateY(16px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* ---------- header ---------- */
.sac-root .sac-header {
  display: flex; align-items: center; gap: 11px; flex-shrink: 0;
  padding: 14px 12px 14px 16px; color: var(--sac-on);
  background: linear-gradient(135deg, rgba(255,255,255,.14), rgba(0,0,0,.14)), var(--sac-color);
}
.sac-root .sac-avatar {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.22); border: 1.5px solid rgba(255,255,255,.4);
  font-weight: 700; font-size: 17px; color: var(--sac-on);
}
.sac-root .sac-headtext { min-width: 0; flex: 1; }
.sac-root .sac-title { font-weight: 700; font-size: 15.5px; color: var(--sac-on); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sac-root .sac-status { display: flex; align-items: center; gap: 6px; margin-top: 1px; font-size: 12px; color: var(--sac-on); opacity: .9; }
.sac-root .sac-dot { width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; background: #fbbf24; }
.sac-root .sac-status.is-online .sac-dot,
.sac-root .sac-status.is-live .sac-dot { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.sac-root .sac-close {
  width: 36px !important; height: 36px !important; flex-shrink: 0; padding: 0 !important;
  border: 0 !important; border-radius: 50% !important; background: transparent !important;
  color: var(--sac-on) !important; font-size: 24px; line-height: 1; opacity: .9;
}
.sac-root .sac-close:hover { background: rgba(255,255,255,.18) !important; opacity: 1; }

/* ---------- messages ---------- */
.sac-root .sac-messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px;
  background-color: var(--sac-surface);
  background-image: radial-gradient(var(--sac-dots) 1px, transparent 1px);
  background-size: 18px 18px;
  display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin;
}
.sac-root .sac-msg {
  max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: 14px;
  word-wrap: break-word; overflow-wrap: anywhere; animation: sac-rise .18s ease;
}
.sac-root .sac-bot {
  align-self: flex-start; background: var(--sac-bot-bg); color: var(--sac-text);
  border: 1px solid var(--sac-border); border-bottom-left-radius: 5px; box-shadow: 0 2px 6px rgba(15,23,42,.06);
}
.sac-root .sac-user {
  align-self: flex-end; background: var(--sac-color); color: var(--sac-on);
  border-bottom-right-radius: 5px; box-shadow: 0 2px 6px rgba(15,23,42,.14);
}
.sac-root .sac-agent {
  align-self: flex-start; background: var(--sac-agent-bg); color: var(--sac-text);
  border: 1px solid var(--sac-agent-border); border-bottom-left-radius: 5px;
}
.sac-root .sac-who { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--sac-agent-text); }

/* rich (product / image) answers */
.sac-root .sac-rich { display: flex; gap: 10px; align-items: flex-start; }
.sac-root .sac-rich .sac-media { width: 72px; height: 72px; flex-shrink: 0; object-fit: cover; border-radius: 10px; }
.sac-root .sac-rich-body { min-width: 0; flex: 1; }

/* source link pill */
.sac-root a.sac-source {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin-top: 10px; padding: 7px 13px;
  border: 1.5px solid var(--sac-color); border-radius: 999px; background: transparent;
  color: var(--sac-color); font-size: 12.5px; font-weight: 700; text-decoration: none; box-shadow: none;
}
.sac-root a.sac-source span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.sac-root a.sac-source:hover { background: var(--sac-color); color: var(--sac-on); }
.sac-root .sac-msg a:not(.sac-source) { color: var(--sac-color); text-decoration: underline; }

/* typing dots */
.sac-root .sac-typing { display: flex; gap: 5px; padding: 14px 16px; }
.sac-root .sac-typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--sac-muted); animation: sac-blink 1.2s infinite; }
.sac-root .sac-typing span:nth-child(2) { animation-delay: .2s; }
.sac-root .sac-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes sac-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* quick replies & suggestions */
.sac-root .sac-quick { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; max-width: 100%; }
.sac-root .sac-chip {
  padding: 8px 14px !important; border: 1.5px solid var(--sac-color) !important; border-radius: 999px !important;
  background: var(--sac-bg) !important; color: var(--sac-color) !important; font-size: 13px; font-weight: 600; text-align: left;
  transition: background .15s ease, color .15s ease;
}
.sac-root .sac-chip:hover { background: var(--sac-color) !important; color: var(--sac-on) !important; }
.sac-root .sac-chip.sac-chip-ghost { border-color: var(--sac-field-border) !important; color: var(--sac-muted) !important; }

/* handoff buttons */
.sac-root .sac-card { display: flex; flex-direction: column; gap: 9px; min-width: 230px; }
.sac-root .sac-btn {
  width: 100%; padding: 11px 14px !important; border: 1.5px solid var(--sac-color) !important; border-radius: 12px !important;
  background: var(--sac-color) !important; color: var(--sac-on) !important; font-size: 14px; font-weight: 700;
  transition: filter .15s ease, transform .1s ease;
}
.sac-root .sac-btn:hover { filter: brightness(1.08); }
.sac-root .sac-btn:active { transform: scale(.985); }
.sac-root .sac-btn.sac-secondary { background: transparent !important; color: var(--sac-color) !important; }
.sac-root .sac-btn:disabled { opacity: .6; cursor: default; }

/* lead form */
.sac-root .sac-form { display: flex; flex-direction: column; gap: 10px; min-width: 240px; margin: 0; padding: 0; border: 0; background: none; }
.sac-root .sac-form label { display: block; margin: 0 0 4px; font-size: 12px; font-weight: 700; color: var(--sac-muted); }
.sac-root .sac-form input[type="text"],
.sac-root .sac-form input[type="email"],
.sac-root .sac-form input[type="tel"],
.sac-root .sac-form textarea {
  display: block; width: 100% !important; height: auto !important; margin: 0; padding: 10px 12px !important;
  border: 1.5px solid var(--sac-field-border) !important; border-radius: 10px !important;
  background: var(--sac-bg) !important; color: var(--sac-text) !important; font-size: 14px; line-height: 1.4;
}
.sac-root .sac-form textarea { min-height: 84px; resize: vertical; }
.sac-root .sac-form input:focus,
.sac-root .sac-form textarea:focus { outline: none; border-color: var(--sac-color) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--sac-color) 18%, transparent) !important; }
.sac-root .sac-form .sac-consent { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 12.5px; color: var(--sac-muted); }
.sac-root .sac-form .sac-consent input { width: auto !important; margin-top: 3px; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--sac-color); }
.sac-root .sac-error { color: #dc2626; font-size: 13px; font-weight: 600; }
.sac-root .sac-hp { position: absolute !important; left: -9999px !important; top: auto !important; width: 1px !important; height: 1px !important; overflow: hidden; opacity: 0; }

/* feedback */
.sac-root .sac-feedback { display: flex; align-items: center; gap: 7px; margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--sac-border); font-size: 12px; color: var(--sac-muted); }
.sac-root .sac-feedback button {
  padding: 4px 10px !important; border: 1px solid var(--sac-field-border) !important; border-radius: 9px !important;
  background: var(--sac-field-bg) !important; font-size: 14px; line-height: 1.3;
}
.sac-root .sac-feedback button:hover { border-color: var(--sac-color) !important; }

/* live chat bar */
.sac-root .sac-livebar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0;
  padding: 7px 14px; background: var(--sac-agent-bg); border-top: 1px solid var(--sac-agent-border);
  font-size: 12px; font-weight: 600; color: var(--sac-agent-text);
}
.sac-root .sac-end { padding: 4px 10px !important; border: 1px solid currentColor !important; border-radius: 999px !important; color: inherit !important; font-size: 12px; font-weight: 700; }

/* input row */
.sac-root .sac-inputrow { display: flex; align-items: center; gap: 9px; flex-shrink: 0; margin: 0; padding: 12px 14px 8px; background: var(--sac-bg); border-top: 1px solid var(--sac-border); }
.sac-root .sac-input {
  flex: 1; min-width: 0; width: auto !important; height: 44px !important; margin: 0; padding: 0 16px !important;
  border: 1.5px solid var(--sac-field-border) !important; border-radius: 999px !important;
  background: var(--sac-field-bg) !important; color: var(--sac-text) !important; font-size: 14px; line-height: normal;
}
.sac-root .sac-input::placeholder { color: var(--sac-muted); opacity: 1; }
.sac-root .sac-input:focus { outline: none; border-color: var(--sac-color) !important; background: var(--sac-bg) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--sac-color) 16%, transparent) !important; }
.sac-root .sac-send {
  width: 44px !important; height: 44px !important; flex-shrink: 0; padding: 0 !important;
  border: 0 !important; border-radius: 50% !important; background: var(--sac-color) !important; color: var(--sac-on) !important;
  box-shadow: 0 3px 10px rgba(15,23,42,.22) !important; transition: transform .12s ease, opacity .15s ease;
}
.sac-root .sac-send svg { width: 20px; height: 20px; fill: var(--sac-on); pointer-events: none; }
.sac-root .sac-send:hover:not(:disabled) { transform: scale(1.06); }
.sac-root .sac-send:disabled { opacity: .45; cursor: default; box-shadow: none !important; }

/* footer link */
.sac-root .sac-foot { flex-shrink: 0; padding: 0 14px 12px; text-align: center; background: var(--sac-bg); }
.sac-root .sac-human-link { padding: 4px 8px !important; border: 0 !important; background: transparent !important; color: var(--sac-muted) !important; font-size: 12.5px; font-weight: 600; text-decoration: underline; }
.sac-root .sac-human-link:hover { color: var(--sac-color) !important; }

/* ---------- inline (shortcode) mode ---------- */
.sac-root.sac-inline { position: static; display: block; z-index: auto; }
.sac-root.sac-inline .sac-panel { position: relative; width: 100%; max-width: 660px; height: 520px; max-height: none; margin: 0 auto; animation: none; }
.sac-root.sac-inline .sac-toggle,
.sac-root.sac-inline .sac-close,
.sac-root.sac-inline .sac-teaser { display: none !important; }

/* ---------- mobile: full-screen sheet ---------- */
@media (max-width: 520px) {
  .sac-root.sac-pos-bottom-right { right: 14px; bottom: 14px; }
  .sac-root.sac-pos-bottom-left { left: 14px; bottom: 14px; }
  .sac-root.sac-open .sac-panel {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    width: 100%; max-width: none; height: 100vh; height: 100dvh; max-height: none;
    border: 0; border-radius: 0;
  }
  .sac-root.sac-open .sac-header { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .sac-root.sac-open .sac-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .sac-root .sac-input, .sac-root .sac-form input, .sac-root .sac-form textarea { font-size: 16px !important; } /* stops iOS zoom */
  .sac-root.sac-inline .sac-panel { height: 480px; }
}

/* ---------- accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .sac-root *, .sac-root *::before, .sac-root *::after { animation: none !important; transition: none !important; }
}
