/* Sellvia Chat widget — minimal, self-contained styles. */

#sellvia-chat-root {
  --sc-brand: #f57f17;          /* Sellvia amber */
  --sc-brand-dark: #e66100;
  --sc-brand-gradient: linear-gradient(135deg, #f57f17 0%, #e66100 100%);
  --sc-brand-gradient-hover: linear-gradient(135deg, #e66100 0%, #cf5600 100%);
  --sc-bg: #ffffff;
  --sc-surface: #f7f7f8;
  --sc-text: #1d1d1f;
  --sc-text-muted: #6b6b70;
  --sc-border: #e5e5ea;
  --sc-radius: 14px;
  --sc-shadow: 0 8px 32px rgba(0,0,0,.15);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999999;
  color: var(--sc-text);
  line-height: 1.4;
}

/* -------- Toggle button -------- */
#sc-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--sc-brand-gradient);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--sc-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, filter .15s;
}
#sc-toggle:hover {
  background: var(--sc-brand-gradient-hover);
  transform: scale(1.05);
}

/* -------- Panel -------- */
#sc-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--sc-bg);
  border-radius: var(--sc-radius);
  box-shadow: var(--sc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--sc-border);
  transition: width .2s ease, height .2s ease;
}
/* Expanded state — toggleable via the expand button in the header. */
#sellvia-chat-root #sc-panel.is-expanded {
  width: 540px;
  max-width: calc(100vw - 40px);
  height: 720px;
  max-height: calc(100vh - 80px);
}
/* ID specificity (100) would otherwise override the UA [hidden] rule.
   Restore it so the panel stays collapsed until the user opens it. */
#sc-panel[hidden] { display: none; }

#sc-header {
  background: var(--sc-brand-gradient);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#sc-header .sc-title { font-weight: 600; font-size: 15px; }
#sc-header .sc-subtitle { font-size: 12px; opacity: .85; }

#sellvia-chat-root .sc-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
#sellvia-chat-root #sc-expand {
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s, opacity .15s;
}
#sellvia-chat-root #sc-expand:hover { background: rgba(255,255,255,.18); }
#sellvia-chat-root #sc-expand .sc-icon-collapse { display: none; }
#sellvia-chat-root #sc-panel.is-expanded #sc-expand .sc-icon-expand { display: none; }
#sellvia-chat-root #sc-panel.is-expanded #sc-expand .sc-icon-collapse { display: inline-block; }

#sc-close {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
#sc-close:hover { opacity: .8; }

/* Mobile: panel is already full-width, no point in an expand button. */
@media (max-width: 600px) {
  #sellvia-chat-root #sc-expand { display: none; }
}

/* -------- Messages area -------- */
#sc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--sc-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sc-msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.sc-msg strong { font-weight: 600; }
.sc-msg em { font-style: italic; }
.sc-msg-user {
  align-self: flex-end;
  background: var(--sc-brand-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sc-msg-assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--sc-border);
  border-bottom-left-radius: 4px;
}

.sc-action-btn {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--sc-brand);
  color: var(--sc-brand);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.sc-action-btn:hover {
  background: var(--sc-brand-gradient);
  color: #fff;
}

.sc-system-note {
  align-self: center;
  font-size: 12px;
  color: var(--sc-text-muted);
  font-style: italic;
  margin: 4px 0;
}

/* -------- Quick-reply chips (PDF 10.1) --------
   All selectors are scoped under #sellvia-chat-root to beat host-theme CSS
   (sellvia.com globally recolors text and buttons). Do NOT remove the prefix. */
#sellvia-chat-root .sc-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 4px;
  flex-shrink: 0;
}
#sellvia-chat-root .sc-quick-reply {
  background: #fff !important;
  border: 1px solid var(--sc-brand);
  color: var(--sc-brand) !important;
  padding: 7px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.2;
  transition: background-color .15s, color .15s;
  font-family: inherit;
}
#sellvia-chat-root .sc-quick-reply:hover {
  background: var(--sc-brand-gradient) !important;
  color: #fff !important;
  border-color: var(--sc-brand-dark);
}

/* -------- Escalation contact form -------- */
#sellvia-chat-root .sc-contact-form {
  align-self: stretch;
  background: #fff !important;
  border: 1px solid var(--sc-border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
#sellvia-chat-root .sc-contact-form-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--sc-text) !important;
  margin-bottom: 2px;
}
#sellvia-chat-root .sc-contact-input {
  width: 100% !important;
  height: 38px !important;
  min-height: 38px !important;
  max-height: 38px !important;
  box-sizing: border-box !important;
  border: 1px solid var(--sc-border) !important;
  border-radius: 10px !important;
  padding: 0 12px !important;
  margin: 0 !important;
  font-size: 13px !important;
  line-height: 38px !important;
  outline: none !important;
  font-family: inherit !important;
  background: #fff !important;
  color: var(--sc-text) !important;
  box-shadow: none !important;
}
#sellvia-chat-root .sc-contact-input:focus {
  border-color: var(--sc-brand) !important;
  box-shadow: 0 0 0 3px rgba(245, 127, 23, 0.15) !important;
}
#sellvia-chat-root .sc-contact-error {
  font-size: 12px;
  color: #c62828 !important;
}
#sellvia-chat-root .sc-contact-submit {
  background: var(--sc-brand-gradient) !important;
  color: #fff !important;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s;
  font-family: inherit;
  margin-top: 2px;
}
#sellvia-chat-root .sc-contact-submit:hover:not(:disabled) {
  background: var(--sc-brand-gradient-hover) !important;
}
#sellvia-chat-root .sc-contact-submit:disabled { opacity: .65; cursor: wait; }

/* -------- Trust badges strip (PDF §10.4) -------- */
#sellvia-chat-root .sc-trust-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--sc-border);
  border-radius: 10px;
  align-self: flex-start;
  max-width: 100%;
  flex-shrink: 0;
}
/* Text-only fallback (legacy or when image fails to load). */
#sellvia-chat-root .sc-trust-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--sc-text-muted) !important;
  letter-spacing: .02em;
  padding: 4px 8px;
  border: 1px solid var(--sc-border);
  border-radius: 6px;
  background: var(--sc-surface);
}
/* Icon variant — small SVG badge, no border/bg, just the logo. */
#sellvia-chat-root .sc-trust-badge-icon {
  background: transparent !important;
  border: 0 !important;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#sellvia-chat-root .sc-trust-badge-img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  /* Black logos on a white card — keep them as-is, but slightly muted so
     they don't visually compete with Emily's text. */
  opacity: .8;
  transition: opacity .15s;
}
#sellvia-chat-root .sc-trust-badge-icon:hover .sc-trust-badge-img {
  opacity: 1;
}

/* -------- Offer card (PDF 10.2) --------
   Content inside the card was getting recolored to white by the host theme on
   sellvia.com. All text nodes now force explicit colors with !important. */
#sellvia-chat-root .sc-offer-card {
  align-self: stretch;
  background: #fff !important;
  border: 1px solid var(--sc-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: box-shadow .2s, transform .2s;
  color: var(--sc-text) !important;
  /* Flex-column parent (#sc-messages) shrinks children by default; without
     flex-shrink:0 the card collapses to ~0 height when other messages fill the
     panel, and overflow:hidden then clips the entire interior. */
  flex-shrink: 0;
  min-height: 130px;
}
#sellvia-chat-root .sc-offer-card:not(.is-collapsed) {
  min-height: auto;
}
#sellvia-chat-root .sc-offer-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
#sellvia-chat-root .sc-offer-hero {
  height: 130px;
  min-height: 130px;
  flex-shrink: 0;
  background-color: var(--sc-brand);
  background-size: cover;
  background-position: center;
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  box-sizing: border-box;
}
#sellvia-chat-root .sc-offer-hero-fallback {
  background-image: var(--sc-brand-gradient);
}
#sellvia-chat-root .sc-offer-category {
  display: inline-block;
  background: rgba(0, 0, 0, 0.45);
  color: #fff !important;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 3px 9px;
  border-radius: 4px;
}
#sellvia-chat-root .sc-offer-preview {
  padding: 12px 14px 10px;
  background: #fff;
}
#sellvia-chat-root .sc-offer-headline {
  font-size: 14px;
  font-weight: 600;
  color: var(--sc-text) !important;
  line-height: 1.3;
  margin-bottom: 4px;
}
#sellvia-chat-root .sc-offer-metric {
  font-size: 12px;
  color: var(--sc-brand-dark) !important;
  font-weight: 600;
  margin-bottom: 8px;
}
#sellvia-chat-root .sc-offer-expand {
  font-size: 12px;
  color: var(--sc-brand) !important;
  font-weight: 500;
}
#sellvia-chat-root .sc-offer-card:not(.is-collapsed) .sc-offer-expand {
  display: none;
}
#sellvia-chat-root .sc-offer-details {
  padding: 12px 14px 4px;
  border-top: 1px solid var(--sc-border);
  display: none;
  cursor: default;
  background: #fff;
}
#sellvia-chat-root .sc-offer-card:not(.is-collapsed) .sc-offer-details {
  display: block;
}
#sellvia-chat-root .sc-offer-details-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--sc-text) !important;
  margin-bottom: 6px;
}
#sellvia-chat-root .sc-offer-included {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
}
#sellvia-chat-root .sc-offer-included li {
  font-size: 13px;
  color: var(--sc-text) !important;
  padding: 3px 0 3px 14px;
  position: relative;
  line-height: 1.4;
  list-style: none;
}
#sellvia-chat-root .sc-offer-included li::before {
  content: '•';
  color: var(--sc-brand) !important;
  position: absolute;
  left: 2px;
  font-weight: 700;
}
#sellvia-chat-root .sc-offer-trust {
  font-size: 12px;
  color: var(--sc-text-muted) !important;
  font-style: italic;
  margin-bottom: 6px;
}
#sellvia-chat-root .sc-offer-microcopy {
  font-size: 11px;
  color: var(--sc-text-muted) !important;
  margin-bottom: 10px;
}
/* Footer is the always-visible action zone of the card. The visitor never
   has to tap "View details" to convert — CTA + alt-link are right there. */
#sellvia-chat-root .sc-offer-footer {
  padding: 12px 14px 14px;
  background: #fff;
  border-top: 1px solid var(--sc-border);
}
/* When details are open, the existing border-top on .sc-offer-details
   already separates them from the preview, and the footer's border-top
   separates the footer from details. When collapsed, the details block
   is hidden, so the footer's border-top sits directly under the preview. */

#sellvia-chat-root .sc-offer-cta {
  display: block;
  width: 100%;
  background: var(--sc-brand-gradient) !important;
  color: #fff !important;
  border: 0;
  border-radius: 24px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s;
  font-family: inherit;
  text-decoration: none;
}
#sellvia-chat-root .sc-offer-cta:hover {
  background: var(--sc-brand-gradient-hover) !important;
}

/* PDF §10.2 secondary "Show me other options" link below the CTA. */
#sellvia-chat-root .sc-offer-alt {
  display: block;
  text-align: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--sc-text-muted) !important;
  text-decoration: underline;
  cursor: pointer;
}
#sellvia-chat-root .sc-offer-alt:hover {
  color: var(--sc-brand) !important;
}

/* Side-by-side card layout when Emily recommends two offers (PDF §10.2).
   Stacks on mobile and in the default 380px panel; switches to a row in
   expanded mode where there's enough horizontal room. */
#sellvia-chat-root .sc-offer-cards-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
}
/* Stacked mode: do NOT override flex sizing on the cards — they need to
   keep their natural height (hero + preview + footer + optional details).
   The global `.sc-offer-card { flex-shrink: 0 }` rule already protects
   them from being squeezed by the chat panel's flex-column parent. */

/* Side-by-side: only here do we force equal-width 50/50 columns. */
#sellvia-chat-root #sc-panel.is-expanded .sc-offer-cards-row {
  flex-direction: row;
  align-items: stretch;
}
#sellvia-chat-root #sc-panel.is-expanded .sc-offer-cards-row .sc-offer-card {
  flex: 1 1 0;
  min-width: 0;
}

/* -------- Typing indicator -------- */
.sc-typing {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}
.sc-typing span {
  width: 6px;
  height: 6px;
  background: var(--sc-text-muted);
  border-radius: 50%;
  animation: sc-bounce 1.2s infinite;
}
.sc-typing span:nth-child(2) { animation-delay: .15s; }
.sc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sc-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* -------- Input form --------
   Host themes on sellvia.com style generic <input> elements (large padding,
   line-height, min-height for forms). We lock the chat input's box model
   explicitly with !important to match the 40×40 send button. */
#sellvia-chat-root #sc-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--sc-border);
  background: #fff;
  align-items: center;
}
#sellvia-chat-root #sc-input {
  flex: 1 1 auto;
  width: auto !important;
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  box-sizing: border-box !important;
  border: 1px solid var(--sc-border) !important;
  border-radius: 20px !important;
  padding: 0 14px !important;
  margin: 0 !important;
  font-size: 13px !important;
  line-height: 40px !important;
  outline: none !important;
  font-family: inherit !important;
  background: #fff !important;
  color: var(--sc-text) !important;
  box-shadow: none !important;
}
#sellvia-chat-root #sc-input:focus {
  border-color: var(--sc-brand) !important;
  box-shadow: 0 0 0 3px rgba(245, 127, 23, 0.15) !important;
}

#sellvia-chat-root #sc-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  border: 0;
  background: var(--sc-brand-gradient);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .15s;
  padding: 0;
}
#sellvia-chat-root #sc-send:hover:not(:disabled) { background: var(--sc-brand-gradient-hover); }
#sellvia-chat-root #sc-send:disabled { opacity: .5; cursor: not-allowed; }

/* -------- Mobile -------- */
@media (max-width: 480px) {
  #sellvia-chat-root { bottom: 12px; right: 12px; }
  #sc-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 90px);
    bottom: 72px;
  }
}
