/* Site-bot widget styles. Scope everything under .sb-root to avoid
   leaking into the host site. No CSS resets, no !important abuse. */

.sb-root {
  position: fixed;
  bottom: 24px;
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #2a221c;
  /* Vek palette — warm-neutral furniture brand (walnut/cream) */
  --sb-primary:       #8a5a3b;
  --sb-primary-dark:  #6d4328;
  --sb-primary-light: #a06840;
  --sb-border:        #e8ded1;
  --sb-muted:         #9a8878;
  --sb-bg:            #ffffff;
  --sb-surface:       #fdf9f5;
  --sb-bubble-bot:    #f6f0e8;
  --sb-bubble-user:   #8a5a3b;
  --sb-shadow:        0 20px 60px rgba(80, 40, 10, 0.16),
                      0 4px 16px rgba(80, 40, 10, 0.10);
  --sb-radius:        16px;
}

.sb-pos-right { right: 24px; }
.sb-pos-left  { left:  24px; }

/* --- floating round toggle button ------------------------------------ */
.sb-toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--sb-primary-light), var(--sb-primary-dark));
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(110, 67, 40, 0.40),
              0 2px 6px rgba(110, 67, 40, 0.25);
  transition: box-shadow .2s ease, transform .15s ease;
  outline: none;
}
.sb-toggle:hover {
  box-shadow: 0 12px 32px rgba(110, 67, 40, 0.50),
              0 2px 8px rgba(110, 67, 40, 0.30);
  transform: translateY(-1px);
}
.sb-toggle:active  { transform: scale(.94); }
.sb-toggle:focus-visible {
  outline: 3px solid var(--sb-primary);
  outline-offset: 3px;
}

/* Photo variant — кнопка с фото оператора call-центра вместо
   градиента + SVG. Border вокруг фото в фирменном цвете
   удерживает кнопку «частью бренда».
   ``background-image: none`` — phasing out the brand gradient inherited
   from ``.sb-toggle``; ``background-color: #fff`` фиксирует чисто белый
   фон в кружке (прозрачные области PNG показывают белый, не градиент). */
.sb-toggle-photo {
  background-color: #fff;
  background-image: none;
  padding: 0;
  border: 3px solid var(--sb-primary-dark);
  overflow: hidden;
}
.sb-toggle-photo .sb-avatar {
  /* Лицо чуть выше центра — поднимем кадр на 4% вверх. */
  object-position: center 35%;
}

/* --- panel ------------------------------------------------------------- */
.sb-panel {
  position: absolute;
  bottom: 74px;
  width: min(380px, 94vw);
  height: min(560px, 72vh);
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  box-shadow: var(--sb-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
}
.sb-pos-right .sb-panel { right: 0; }
.sb-pos-left  .sb-panel { left:  0; transform-origin: bottom left; }

.sb-panel.sb-open {
  display: flex;
  animation: sb-panel-in .22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sb-panel-in {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1)   translateY(0);   }
}

/* --- header ------------------------------------------------------------ */
.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 13px;
  border-bottom: 1px solid var(--sb-border);
  background: linear-gradient(135deg, var(--sb-primary) 0%, var(--sb-primary-dark) 100%);
  color: #fff;
  gap: 10px;
}

.sb-header-info {
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
}

/* Photo avatar (call-center operator). Same <img> reused in
   the floating toggle button and in the chat header — parents
   control the size, this rule just makes it fill + crop circle. */
.sb-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.sb-header-avatar {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  /* Solid white so the avatar PNG (RGBA, transparent background) reads
     as girl-on-white instead of girl-on-dark-gradient. */
  background: #fff;
}

.sb-title-wrap { min-width: 0; }

.sb-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: .01em;
}

.sb-subtitle {
  font-size: 11px;
  opacity: .75;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.sb-online-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #5fe0a0;
  flex-shrink: 0;
}

.sb-close {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  transition: background .15s ease;
  outline: none;
}
.sb-close:hover { background: rgba(255,255,255,.28); }
.sb-close:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: 2px; }

/* --- message log ------------------------------------------------------- */
.sb-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  background: var(--sb-surface);
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}

.sb-log::-webkit-scrollbar        { width: 4px; }
.sb-log::-webkit-scrollbar-track  { background: transparent; }
.sb-log::-webkit-scrollbar-thumb  { background: var(--sb-border); border-radius: 4px; }

.sb-msg { display: flex; gap: 6px; align-items: flex-end; }
.sb-msg-user      { justify-content: flex-end; }
.sb-msg-assistant { justify-content: flex-start; }

.sb-bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.5;
}
.sb-msg-assistant .sb-bubble {
  background: var(--sb-bubble-bot);
  color: #2a1c10;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(100, 60, 20, 0.08);
}
.sb-msg-user .sb-bubble {
  background: var(--sb-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(110, 67, 40, 0.25);
}

.sb-play {
  -webkit-appearance: none;
  appearance: none;
  border: none; background: transparent;
  color: var(--sb-muted);
  cursor: pointer; font-size: 13px;
  padding: 3px 6px;
  border-radius: 6px;
  outline: none;
  transition: color .15s ease, background .15s ease;
}
.sb-play:hover { color: var(--sb-primary); background: rgba(138,90,59,.08); }

/* --- typing indicator -------------------------------------------------- */
.sb-typing .sb-bubble {
  display: inline-flex; gap: 4px; padding: 12px 14px;
  align-items: center;
}
.sb-typing .sb-bubble span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--sb-muted);
  animation: sb-bounce 1.2s infinite;
}
.sb-typing .sb-bubble span:nth-child(2) { animation-delay: .15s; }
.sb-typing .sb-bubble span:nth-child(3) { animation-delay: .30s; }
@keyframes sb-bounce {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-3px); }
}

/* --- footer (holds form + recording bar; only one is visible at a time) */
.sb-footer {
  border-top: 1px solid var(--sb-border);
  background: var(--sb-bg);
}

/* --- form -------------------------------------------------------------- */
.sb-form {
  display: flex; gap: 8px;
  padding: 10px 12px 12px;
  align-items: center;
}
.sb-hidden { display: none !important; }

.sb-input {
  -webkit-appearance: none;
  appearance: none;
  flex: 1; min-width: 0;
  padding: 10px 13px;
  border: 1.5px solid var(--sb-border);
  border-radius: 24px;
  font-family: inherit; font-size: 14px;
  background: var(--sb-surface);
  color: #2a1c10;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.sb-input::placeholder { color: var(--sb-muted); }
.sb-input:focus {
  border-color: var(--sb-primary);
  box-shadow: 0 0 0 3px rgba(138, 90, 59, 0.12);
}

/* Shared round action-button base for send/mic/rec-confirm */
.sb-send, .sb-mic, .sb-rec-confirm, .sb-rec-cancel {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  border-radius: 50%;
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: box-shadow .15s ease, transform .1s ease, background .15s ease;
  outline: none;
  padding: 0;
  color: #fff;
}

.sb-send, .sb-rec-confirm {
  background: linear-gradient(145deg, var(--sb-primary-light), var(--sb-primary-dark));
  box-shadow: 0 2px 8px rgba(110, 67, 40, 0.30);
}
.sb-send:hover, .sb-rec-confirm:hover {
  box-shadow: 0 4px 14px rgba(110, 67, 40, 0.45);
  transform: scale(1.05);
}
.sb-send:active, .sb-rec-confirm:active { transform: scale(.95); }
.sb-send:focus-visible, .sb-rec-confirm:focus-visible {
  outline: 3px solid var(--sb-primary);
  outline-offset: 2px;
}

/* Mic button — same dimensions, neutral fill so it reads as "input control"
   rather than "send action" until pressed. */
.sb-mic {
  background: var(--sb-surface);
  color: var(--sb-primary);
  border: 1.5px solid var(--sb-border);
}
.sb-mic:hover {
  background: var(--sb-bubble-bot);
  border-color: var(--sb-primary-light);
  transform: scale(1.05);
}
.sb-mic:active { transform: scale(.92); }
.sb-mic:focus-visible {
  outline: 3px solid var(--sb-primary);
  outline-offset: 2px;
}

/* --- recording bar ----------------------------------------------------- */
.sb-rec-bar {
  display: flex; align-items: center;
  gap: 10px;
  padding: 10px 12px 12px;
}

.sb-rec-cancel {
  background: transparent;
  color: #c0392b;
  border: 1.5px solid #e7b6b0;
}
.sb-rec-cancel:hover {
  background: #fdecea;
  border-color: #c0392b;
  transform: scale(1.05);
}
.sb-rec-cancel:active { transform: scale(.92); }

.sb-rec-meter {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--sb-surface);
  border: 1.5px solid var(--sb-border);
  border-radius: 24px;
  color: var(--sb-muted);
  font-size: 13px;
  white-space: nowrap;
}

.sb-rec-pulse {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #e74c3c;
  flex-shrink: 0;
  animation: sb-rec-pulse 1s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6);
}

@keyframes sb-rec-pulse {
  0%   { box-shadow: 0 0 0 0    rgba(231, 76, 60, 0.55); transform: scale(1);    }
  70%  { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);    transform: scale(1.08); }
  100% { box-shadow: 0 0 0 0    rgba(231, 76, 60, 0);    transform: scale(1);    }
}

.sb-rec-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sb-rec-label-color, #2a1c10);
  font-weight: 500;
}

.sb-rec-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--sb-primary);
  flex-shrink: 0;
}

/* Typewriter caret — blinks next to the last-typed character while the
   greeting plays. Kept tiny so it doesn't jump the line-height. */
.sb-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  opacity: .75;
  animation: sb-caret-blink 1s steps(2, end) infinite;
}
@keyframes sb-caret-blink {
  0%, 100% { opacity: .75; }
  50%      { opacity: 0;   }
}
@media (prefers-reduced-motion: reduce) {
  .sb-caret { animation: none; opacity: .75; }
}

/* Optimistic "voice message…" placeholder bubble */
.sb-voice-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0.85;
  font-style: italic;
}
.sb-voice-ico {
  font-style: normal;
  font-size: 15px;
}

/* Reduced-motion: drop the pulse */
@media (prefers-reduced-motion: reduce) {
  .sb-rec-pulse { animation: none; }
}

/* --- reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .sb-panel.sb-open { animation: none; }
  .sb-typing .sb-bubble span { animation: none; opacity: .5; }
}

/* --- dark-mode host override ------------------------------------------- */
@media (prefers-color-scheme: dark) {
  .sb-root {
    color: #ede7df;
    --sb-border:       #3a2f28;
    --sb-muted:        #8a7a6e;
    --sb-bg:           #1a1512;
    --sb-surface:      #201a16;
    --sb-bubble-bot:   #2a221c;
    --sb-shadow:       0 20px 60px rgba(0, 0, 0, 0.50),
                       0 4px 16px rgba(0, 0, 0, 0.35);
    --sb-rec-label-color: #ede7df;
  }
  .sb-input {
    background: #251e18;
    color: #ede7df;
    border-color: #3a2f28;
  }
  .sb-msg-assistant .sb-bubble { color: #ede7df; }
  .sb-mic {
    background: #251e18;
    color: var(--sb-primary-light);
  }
  .sb-mic:hover {
    background: #2e2419;
    border-color: var(--sb-primary-light);
  }
  .sb-rec-cancel {
    color: #ff7c6e;
    border-color: #5a2b23;
  }
  .sb-rec-cancel:hover {
    background: #3a1f1a;
    border-color: #ff7c6e;
  }
}
