/* Sevo widget - scoped under #sevo-root. RTL-first, accessible, unobtrusive. */
#sevo-root {
  --sevo-color: #2E75B6;
  --sevo-offset: 20px;   /* distance from the bottom */
  --sevo-offset-x: 20px; /* distance from the side edge */
  position: fixed;
  bottom: var(--sevo-offset, 20px);
  z-index: 2147483000;
  direction: rtl;
  font-family: inherit;
}
#sevo-root[data-side="right"] { right: var(--sevo-offset-x, var(--sevo-offset, 20px)); }
#sevo-root[data-side="left"]  { left: var(--sevo-offset-x, var(--sevo-offset, 20px)); }

#sevo-launcher {
  background: var(--sevo-launcher-bg, var(--sevo-color));
  color: var(--sevo-launcher-fg, #fff);
  border: 0;
  border-radius: 24px;
  padding: 12px 20px;
  font-size: 16px;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
/* Icon launcher: a round button instead of a text pill (>=56px touch target). */
#sevo-launcher.sevo-launcher-icon {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#sevo-launcher .sevo-launcher-svg { width: 26px; height: 26px; display: block; }
#sevo-launcher:focus-visible,
#sevo-root :focus-visible {
  outline: 3px solid #1a1a1a;
  outline-offset: 2px;
  /* Second, light ring so focus survives dark-theme storefronts too. */
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.9);
}
#sevo-root .sevo-typing { display: inline-block; letter-spacing: 2px; animation: sevo-blink 1.2s steps(1) infinite; }
@keyframes sevo-blink { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #sevo-root .sevo-typing { animation: none; opacity: 0.6; } }

#sevo-panel[hidden] { display: none; }
#sevo-panel {
  position: absolute;
  bottom: 56px;
  /* Subtract the launcher offset too: the panel is anchored at the offset from the edge,
     so a large offset on a narrow screen would otherwise push it past the far edge. */
  width: min(384px, calc(100vw - var(--sevo-offset-x, var(--sevo-offset, 20px)) - 16px));
  /* Deliberately generous when open (the customer chose to open it). The 120px calc() guard
     keeps the panel clear of the top on short screens (the panel bottom sits ~106px above the
     viewport bottom, so a smaller margin clips the header); the fixed cap gives a roomy chat
     on tall ones. */
  height: min(640px, calc(100vh - 120px));
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #d9d9d9;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#sevo-root[data-side="right"] #sevo-panel { right: 0; }
#sevo-root[data-side="left"]  #sevo-panel { left: 0; }

/* Proactive teaser bubble - sits above the launcher, same corner as the panel. */
#sevo-teaser {
  position: absolute;
  bottom: 56px;
  width: max-content;
  max-width: min(260px, calc(100vw - var(--sevo-offset-x, var(--sevo-offset, 20px)) - 16px));
  background: #fff;
  color: #13202f;
  border: 1px solid #e3ebf3;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.45;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
#sevo-root[data-side="right"] #sevo-teaser { right: 0; }
#sevo-root[data-side="left"]  #sevo-teaser { left: 0; }
#sevo-teaser-x {
  background: none;
  border: 0;
  font-size: 18px;
  line-height: 1;
  color: #8a94a2;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

/* Starter suggestion chips under the greeting. */
#sevo-suggests {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 2px 0 6px;
}
.sevo-chip {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  color: var(--sevo-color, #2E75B6);
  border: 1.5px solid var(--sevo-color, #2E75B6);
  border-radius: 999px;
  padding: 7px 13px;
  line-height: 1.2;
  transition: background .12s, color .12s;
}
.sevo-chip:hover {
  background: var(--sevo-color, #2E75B6);
  color: var(--sevo-on-color, #fff);
}

/* Product cards rendered from [[sevo-product:ID]] tags. */
.sevo-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.sevo-pcard {
  display: flex;
  flex-direction: column;
  border: 1px solid #e3ebf3;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.sevo-pcard-link { display: flex; gap: 10px; align-items: center; padding: 8px; text-decoration: none; color: inherit; }
.sevo-pcard-img { width: 58px; height: 58px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.sevo-pcard-info { flex: 1; min-width: 0; }
.sevo-pcard-name { font-weight: 700; font-size: 14px; color: #13202f; line-height: 1.3; }
.sevo-pcard-price { font-size: 13px; color: var(--sevo-btn-color, var(--sevo-color, #2E75B6)); font-weight: 700; margin-top: 2px; }
.sevo-pcard-oos { font-size: 12px; color: #a3342a; margin-top: 2px; }
.sevo-pcard-btn {
  display: block;
  text-align: center;
  text-decoration: none !important;
  background: var(--sevo-btn-color, var(--sevo-color, #2E75B6));
  color: var(--sevo-btn-fg, #fff); /* auto dark/light text so a light button stays readable */
  font-size: 13px;
  font-weight: 700;
  padding: 10px;
  border: 0;
}
.sevo-pcard-btn.ghost { background: var(--sevo-btn-color, var(--sevo-color, #2E75B6)); color: var(--sevo-btn-fg, #fff); }
.sevo-pcard-btn.adding { opacity: 0.75; cursor: default; } /* in-flight add - immediate feedback */
.sevo-pcard-btn.is-added { background: #0f7a5e; color: #fff; } /* dark green - always white text */
.sevo-cards.plain .sevo-pname { font-size: 14px; padding: 2px 0; }
.sevo-cards.plain .sevo-pname a { color: var(--sevo-btn-color, var(--sevo-color, #2E75B6)); font-weight: 700; text-decoration: none; }
.sevo-pname-price { color: #6b7686; font-size: 13px; }

#sevo-header {
  background: #fff;
  color: #1a1a1a;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ececec;
}
/* High specificity + !important so the store theme's own `h2 { color/font }`
   rules can't override the white-on-blue header title. */
#sevo-root #sevo-title {
  margin: 0;
  flex: 1 1 auto; /* take the row so the action buttons group together at the end */
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: #1a1a1a !important;
}
#sevo-close {
  background: transparent;
  border: 0;
  color: #5a6677;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  /* >=44x44 touch target (WCAG 2.5.5 / 2.5.8) */
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Visually hidden but available to screen readers - used by the #sevo-sr announcer. */
.sevo-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

#sevo-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sevo-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.sevo-user { align-self: flex-start; background: var(--sevo-color); color: var(--sevo-on-color, #fff); }
.sevo-bot  { align-self: flex-end;   background: #f0f1f3; color: #1a1a1a; }
/* High specificity + !important so the store theme's `a { text-decoration:none }`
   can't strip the underline. Links must be distinguishable, not by color alone (1.4.1). */
/* Distinguish links by underline - but NOT the product button (a styled block button,
   not an inline link; underlining it looks broken). */
#sevo-root .sevo-msg a:not(.sevo-pcard-btn):not(.sevo-pcard-link) { text-decoration: underline !important; }
/* Bot-bubble link color. Exclude the product button: it carries its own bg + readable
   --sevo-btn-fg, and this !important rule would otherwise force dark-blue text onto the
   blue button (blue-on-blue, ~1.35:1 - the add-to-cart contrast regression). */
#sevo-root .sevo-bot a:not(.sevo-pcard-btn) { color: #1a5fa8 !important; } /* 4.7:1 on the bot bubble */
#sevo-root .sevo-user a { color: #fff !important; }

#sevo-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #ececec;
}
#sevo-input {
  flex: 1;
  resize: none;
  border: 1px solid #767676; /* 4.5:1 on white - UI component contrast (1.4.11) */
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 15px;
}
#sevo-input::placeholder { color: #595959; opacity: 1; } /* 7:1 on white (1.4.3) */
#sevo-send {
  background: var(--sevo-color);
  color: var(--sevo-on-color, #fff);
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-size: 15px;
}
#sevo-mic {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--sevo-color, #2E75B6);
  border: 1px solid #767676; /* matches the input border - UI contrast (1.4.11) */
  border-radius: 8px;
  padding: 0 7px;
  cursor: pointer;
}
#sevo-mic:hover { background: #f2f7fc; }
#sevo-mic.recording { background: #c5221f; color: #fff; border-color: #c5221f; } /* 4.5:1 white-on-red */
@media (prefers-reduced-motion: no-preference) {
  #sevo-mic.recording { animation: sevo-pulse 1.3s ease-in-out infinite; }
  @keyframes sevo-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(197, 34, 31, 0.5); }
    50% { box-shadow: 0 0 0 6px rgba(197, 34, 31, 0); }
  }
}

@media (prefers-reduced-motion: no-preference) {
  #sevo-panel { animation: sevo-in 0.15s ease-out; }
  @keyframes sevo-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  /* Each streamed word fades in with a soft blur (ChatGPT/Claude-style).
     `both` keeps staggered words hidden until their delay elapses. */
  /* Opacity-only fade: no blur/translate (blur made settled text look ~1px bigger then
     "shrink" as it sharpened) and no inline-block (it added stray gaps between word spans). */
  .sevo-fade {
    animation: sevo-fade-in 0.3s ease both;
  }
  @keyframes sevo-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}

/* Reply rating + header credit - TOP LEVEL (must NOT be gated by prefers-reduced-motion). */
#sevo-root .sevo-rate { display: flex; gap: 6px; align-items: center; margin-top: 5px; }
/* Framed chips: without a border the thumbs read as faint emoji, not tappable buttons. */
#sevo-root .sevo-rate-btn { background: #fff; border: 1px solid #cdd6df; cursor: pointer; font-size: 14px; opacity: 0.9; padding: 3px 10px; border-radius: 8px; line-height: 1.2; }
#sevo-root .sevo-rate-btn:hover { opacity: 1; border-color: #9aa7b4; background: #f5f8fb; }
#sevo-root .sevo-rate-btn.sevo-rate-on { opacity: 1; border-color: var(--sevo-color, #2E75B6); background: #eef4fb; }
#sevo-root .sevo-rate-thanks { font-size: 11px; color: #8a94a2; margin-inline-start: 4px; }
/* "Powered by Sevo" credit - slim footer strip under the input (Tidio/Intercom convention).
   The log is flex:1 so this strip shrinks the message area, never the input. #sevo-root +
   !important so the store theme's own `a { color }` can't override it. */
/* #5a6677 on white is ~5.5:1 (WCAG AA for small text); the old #8a94a2 was ~3:1. */
#sevo-footer { display: flex; align-items: center; gap: 4px; padding: 5px 13px 8px; font-size: 11px; line-height: 1; color: #5a6677; }
#sevo-root #sevo-footer a { color: #5a6677 !important; text-decoration: none !important; font-weight: 600; }
#sevo-root #sevo-footer a:hover { text-decoration: underline !important; }
