:root {
  --green: #00af72;
  --green2: #008a5a;
  --green3: #006b45;

  --human1: #00b894;
  --human2: #009f7f;
  --human3: #007f63;

  --text: #17372b;
  --text-soft: #5f7169;
  --panel-bg: #ffffff;
  --body-bg: #f4faf7;

  --status-online: #4dff9f;
  --status-busy: #ffcc4d;
  --status-offline: #cfd8d5;
}

.sg-widget-root[data-theme="ai"] {
  --theme1: var(--green);
  --theme2: var(--green2);
  --theme3: var(--green3);
}

.sg-widget-root[data-theme="human"] {
  --theme1: var(--human1);
  --theme2: var(--human2);
  --theme3: var(--human3);
}

.sg-widget-root * {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.sg-widget-floating-group {
  position: fixed;
  right: 24px;
  bottom: 24px;
  animation: float 5s ease-in-out infinite;
  transform-origin: right bottom;
  transition: transform .3s, opacity .3s, filter .3s;
  z-index: 1000;
}

.sg-widget-floating-group.morphing-out {
  transform: scale(.7);
  opacity: 0;
  filter: blur(1px);
}

.sg-widget-button {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 100px;
  border: none;
  background: linear-gradient(135deg, var(--theme1), var(--theme2), var(--theme3));
  color: white;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .18);
  transition:
    transform .2s ease,
    box-shadow .25s ease,
    filter .25s ease,
    background .35s ease;
}

.sg-widget-button:hover {
  transform: scale(1.05);
}

.sg-widget-button.is-highlighted {
  box-shadow:
    0 0 0 0 rgba(0, 175, 114, .00),
    0 0 0 8px rgba(0, 175, 114, .10),
    0 0 0 16px rgba(0, 175, 114, .05),
    0 20px 40px rgba(0, 0, 0, .18);
  animation:
    buttonHighlightPulse 1.2s ease-in-out 1,
    buttonSmallNudge .9s ease-in-out 1;
}

.sg-widget-button-pulse {
  position: absolute;
  inset: 0;
  border-radius: 100px;
  background: rgba(0, 175, 114, .25);
  animation: pulse 2.6s infinite;
}

.sg-widget-button-icon {
  position: relative;
  z-index: 2;
}

.sg-widget-teaser {
  position: absolute;
  right: 0;
  bottom: 88px;
  width: 230px;
  background: white;
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: .3s;
  cursor: pointer;
}

.sg-widget-teaser.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sg-widget-teaser::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 28px;
  width: 16px;
  height: 16px;
  background: white;
  transform: rotate(45deg);
}

.sg-widget-teaser-title {
  font-weight: 600;
  color: var(--text);
}

.sg-widget-teaser-text {
  font-size: 14px;
  color: var(--text-soft);
}

.sg-widget-teaser-close {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: none;
  cursor: pointer;
}

.sg-widget-panel {
  position: fixed;
  right: 24px;
  bottom: 104px;
  width: 400px;
  height: 600px;
  border-radius: 22px;
  background: white;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .2);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: scale(.95) translateY(20px);
  transition: .3s;
  overflow: hidden;
  z-index: 999;
}

.sg-widget-panel.open {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

.sg-widget-panel.morphing {
  opacity: 0;
  visibility: visible;
  transform: scale(.74) translateY(8px);
}

.sg-widget-header {
  background: linear-gradient(135deg, var(--theme1), var(--theme2), var(--theme3));
  color: white;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background .4s ease;
}

.sg-widget-header-left {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.sg-widget-header-text {
  min-width: 0;
}

.sg-widget-avatar {
  width: 88px;
  height: 88px;
  min-width: 88px;
  border-radius: 100px;
  background: rgba(255, 255, 255, .2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transition: box-shadow .35s ease, transform .35s ease;
}

.sg-widget-avatar.is-glowing {
  box-shadow:
    0 0 0 0 rgba(255, 255, 255, .00),
    0 0 0 8px rgba(255, 255, 255, .12),
    0 0 24px rgba(255, 255, 255, .22);
  animation: avatarGlow 1.15s ease-in-out 1;
}

.sg-widget-avatar.is-switching .sg-widget-avatar-image,
.sg-widget-avatar.is-switching .sg-widget-avatar-fallback {
  opacity: 0;
  transform: scale(.94);
}

.sg-widget-avatar-image,
.sg-widget-avatar-fallback {
  transition: opacity .28s ease, transform .28s ease;
}

.sg-widget-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sg-widget-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 34px;
}

.sg-widget-title {
  font-weight: 700;
  font-size: 18px;
  line-height: 1.15;
  margin-bottom: 2px;
  transition: opacity .25s ease, transform .25s ease;
}

.sg-widget-status-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.sg-widget-status-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .12);
}

.sg-widget-status-dot.is-online {
  background: var(--status-online);
  animation: onlineDotPulse 1.9s ease-in-out infinite;
}

.sg-widget-status-dot.is-busy {
  background: var(--status-busy);
}

.sg-widget-status-dot.is-offline {
  background: var(--status-offline);
}

.sg-widget-subtitle {
  font-size: 13px;
  color: rgba(255, 255, 255, .92);
  line-height: 1.2;
  transition: opacity .25s ease, transform .25s ease;
}

.sg-widget-close {
  background: rgba(255, 255, 255, .2);
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: white;
  cursor: pointer;
}

.sg-widget-body {
  flex: 1;
  padding: 18px;
  background: #f4faf7;
  overflow: auto;
}

.sg-widget-date {
  font-size: 12px;
  margin-bottom: 10px;
  color: #666;
}

.sg-widget-message {
  padding: 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 85%;
  box-shadow: 0 10px 25px rgba(0, 0, 0, .1);
  margin-bottom: 10px;
}

.sg-widget-message.sg-bot {
  background: white;
  color: var(--text);
}

.sg-widget-message.sg-user {
  background: linear-gradient(135deg, var(--theme1), var(--theme2));
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 8px;
  transition: background .35s ease;
}

.sg-widget-message.is-hidden {
  display: none;
}

.sg-widget-message.is-visible {
  display: block;
  animation: messageAppear .35s ease;
}

.sg-widget-message-line {
  opacity: 0;
  transform: translateY(6px);
  animation: lineAppear .42s ease forwards;
}

.sg-widget-message-line:nth-child(1) { animation-delay: .00s; }
.sg-widget-message-line:nth-child(2) { animation-delay: .22s; margin-top: 14px; }
.sg-widget-message-line:nth-child(3) { animation-delay: .44s; }
.sg-widget-message-line:nth-child(4) { animation-delay: .66s; }

.sg-widget-system-message {
  align-self: center;
  margin: 2px auto 12px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.35;
  color: #6e7d77;
  background: rgba(255, 255, 255, .86);
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .06);
  animation: systemMessageAppear .3s ease;
}

.sg-widget-typing {
  display: none;
  align-items: center;
  gap: 8px;
  background: white;
  padding: 10px 12px;
  border-radius: 16px;
  width: fit-content;
  margin-bottom: 10px;
}

.sg-widget-typing-label {
  color: var(--text);
}

.sg-typing-dots {
  display: flex;
  gap: 4px;
}

.sg-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--theme1);
  border-radius: 50%;
  animation: typing 1.4s infinite;
  transition: background .35s ease;
}

.sg-typing-dots span:nth-child(2) {
  animation-delay: .2s;
}

.sg-typing-dots span:nth-child(3) {
  animation-delay: .4s;
}

.sg-widget-footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #eee;
}

.sg-widget-input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid #ddd;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.sg-widget-input:focus {
  border-color: rgba(0, 175, 114, .55);
  box-shadow: 0 0 0 4px rgba(0, 175, 114, .12);
}

.sg-widget-send {
  background: linear-gradient(135deg, var(--theme1), var(--theme2), var(--theme3));
  border: none;
  color: white;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  transition:
    transform .2s ease,
    box-shadow .2s ease,
    filter .2s ease,
    opacity .2s ease,
    background .35s ease;
  box-shadow: 0 8px 18px rgba(0, 175, 114, .18);
  opacity: 1;
}

.sg-widget-send:hover {
  transform: scale(1.06);
}

.sg-widget-send.is-active {
  box-shadow:
    0 0 0 4px rgba(0, 175, 114, .14),
    0 12px 28px rgba(0, 175, 114, .34);
  transform: scale(1.08);
  filter: saturate(1.05);
}

.sg-widget-send.is-sending {
  transform: scale(.92);
}

.sg-widget-send-icon {
  width: 18px;
  height: 18px;
  display: block;
  margin: 0 auto;
}

.sg-widget-send-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: .6; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

@keyframes typing {
  0% { opacity: .2; }
  50% { opacity: 1; }
  100% { opacity: .2; }
}

@keyframes messageAppear {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes lineAppear {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes systemMessageAppear {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes buttonHighlightPulse {
  0% {
    box-shadow:
      0 0 0 0 rgba(0, 175, 114, .00),
      0 0 0 0 rgba(0, 175, 114, .00),
      0 20px 40px rgba(0, 0, 0, .18);
  }
  45% {
    box-shadow:
      0 0 0 8px rgba(0, 175, 114, .12),
      0 0 0 16px rgba(0, 175, 114, .06),
      0 20px 40px rgba(0, 0, 0, .18);
  }
  100% {
    box-shadow:
      0 0 0 0 rgba(0, 175, 114, .00),
      0 0 0 0 rgba(0, 175, 114, .00),
      0 20px 40px rgba(0, 0, 0, .18);
  }
}

@keyframes buttonSmallNudge {
  0% { transform: scale(1); }
  30% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes onlineDotPulse {
  0% {
    transform: scale(1);
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, .12),
      0 0 0 0 rgba(77, 255, 159, .00);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, .12),
      0 0 0 5px rgba(77, 255, 159, .18);
  }
  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, .12),
      0 0 0 0 rgba(77, 255, 159, .00);
  }
}

@keyframes avatarGlow {
  0% {
    transform: scale(1);
    box-shadow:
      0 0 0 0 rgba(255, 255, 255, .00),
      0 0 0 0 rgba(0, 184, 148, .00);
  }
  45% {
    transform: scale(1.04);
    box-shadow:
      0 0 0 8px rgba(255, 255, 255, .12),
      0 0 24px rgba(0, 184, 148, .25);
  }
  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 0 rgba(255, 255, 255, .00),
      0 0 0 rgba(0, 184, 148, .00);
  }
}
/* === ДЯДЯ САША ПЕЧАТАЕТ (в шапке, с анимацией) === */

.sg-widget-typing-header {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  line-height: 1.3;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
}

/* контейнер точек */
.sg-widget-typing-dots {
  display: inline-flex;
  margin-left: 6px;
}

/* сами точки */
.sg-widget-typing-dots span {
  width: 4px;
  height: 4px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  display: inline-block;
  animation: dsTypingDot 1.4s infinite ease-in-out;
}

/* задержки — создают эффект "волны" */
.sg-widget-typing-dots span:nth-child(1) {
  animation-delay: 0s;
}
.sg-widget-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.sg-widget-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* анимация */
@keyframes dsTypingDot {
  0%, 80%, 100% {
    opacity: 0.2;
    transform: scale(1);
  }
  40% {
    opacity: 1;
    transform: scale(1.4);
  }
}
@media (max-width: 640px) {
  .sg-widget-floating-group {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .sg-widget-panel {
    left: 8px;
    right: 8px;
    width: auto;
    height: calc(100dvh - 16px - env(safe-area-inset-bottom));
    bottom: 8px;
  }

  .sg-widget-avatar {
    width: 74px;
    height: 74px;
    min-width: 74px;
  }

  .sg-widget-avatar-fallback {
    font-size: 30px;
  }

  .sg-widget-header {
    padding: 8px 14px;
  }

  .sg-widget-teaser {
    width: min(260px, calc(100vw - 28px));
    bottom: 82px;
  }
}
/* === ШАПКА ВИДЖЕТА: СТАБИЛЬНАЯ ВЫСОТА И СТРОКА "ПЕЧАТАЕТ" БЕЗ СДВИГА === */

.sg-widget-header {
  min-height: 104px;
}

.sg-widget-header-left {
  align-items: center;
}

.sg-widget-header-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 64px;
  position: relative;
  padding-bottom: 16px;
}

.sg-widget-title {
  margin-bottom: 2px;
}

.sg-widget-status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 16px;
}

.sg-widget-subtitle {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.2;
  transition: opacity .25s ease, transform .25s ease;
}

/* строка "Дядя Саша печатает" всегда занимает своё место,
   но скрывается через opacity/visibility, чтобы шапка не прыгала */
.sg-widget-typing-header {
  position: absolute;
  left: 0;
  bottom: 0;
  min-height: 14px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(2px);
  transition:
    opacity .18s ease,
    visibility .18s ease,
    transform .18s ease;
}

.sg-widget-typing-header.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* контейнер точек */
.sg-widget-typing-dots {
  display: inline-flex;
  margin-left: 6px;
}

/* сами точки */
.sg-widget-typing-dots span {
  width: 4px;
  height: 4px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  display: inline-block;
  animation: dsTypingDot 1.4s infinite ease-in-out;
}

.sg-widget-typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

.sg-widget-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.sg-widget-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dsTypingDot {
  0%, 80%, 100% {
    opacity: 0.2;
    transform: scale(1);
  }
  40% {
    opacity: 1;
    transform: scale(1.4);
  }
}

@media (max-width: 640px) {
  .sg-widget-header {
    min-height: 92px;
  }

  .sg-widget-header-text {
    min-height: 58px;
    padding-bottom: 14px;
  }

  .sg-widget-typing-header {
    font-size: 11px;
  }
}