.ssc-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  font-size: 14px;
  font-family: inherit;
  -webkit-text-size-adjust: 100%;
}

.ssc-root * {
  box-sizing: border-box;
}

.ssc-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.45);
  cursor: pointer;
  background: linear-gradient(135deg, #4f46e5 0%, #0891b2 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(79, 70, 229, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ssc-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(79, 70, 229, 0.55);
}

.ssc-toggle-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.ssc-toggle-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.ssc-toggle-label small {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.85;
}

.ssc-panel {
  display: none;
  position: absolute;
  right: 0;
  bottom: 64px;
  width: min(400px, calc(100vw - 24px));
  max-height: min(560px, calc(100vh - 96px));
  background: #0f1424;
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  flex-direction: column;
  animation: ssc-panel-in 0.25s ease;
}

@keyframes ssc-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ssc-panel.ssc-open {
  display: flex;
}

.ssc-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 14px;
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.12) 0%, transparent 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ssc-head-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.ssc-head-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.ssc-title {
  font-weight: 700;
  font-size: 15px;
  color: #f1f5f9;
}

.ssc-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ssc-online {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
  flex-shrink: 0;
}

.ssc-close {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: #94a3b8;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.ssc-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.ssc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 220px;
  max-height: 340px;
  scroll-behavior: smooth;
}

.ssc-msg {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  animation: ssc-msg-in 0.3s ease;
}

@keyframes ssc-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ssc-msg-user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.ssc-msg-user .ssc-msg-body {
  align-items: flex-end;
  margin-left: auto;
  max-width: 82%;
}

.ssc-msg-bot .ssc-msg-body {
  max-width: calc(100% - 38px);
}

.ssc-msg-user .ssc-bubble {
  background: linear-gradient(135deg, #4338ca, #3730a3);
  border-bottom-right-radius: 4px;
}

.ssc-avatar {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.ssc-msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 0 1 auto;
}

.ssc-meta {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 4px;
  padding-left: 2px;
}

.ssc-msg-user .ssc-meta {
  padding-right: 2px;
  padding-left: 0;
}

.ssc-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  line-height: 1.55;
  word-break: normal;
  overflow-wrap: break-word;
  white-space: normal;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom-left-radius: 4px;
  max-width: 100%;
}

.ssc-bubble code {
  font-size: 11px;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 6px;
}

.ssc-bubble strong {
  color: #f8fafc;
}

.ssc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ssc-links a {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.ssc-links a:hover {
  background: rgba(99, 102, 241, 0.28);
  border-color: rgba(129, 140, 248, 0.6);
}

.ssc-typing-wrap .ssc-bubble {
  padding: 14px 18px;
}

.ssc-typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 12px;
}

.ssc-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: ssc-dot 1.2s infinite ease-in-out;
}

.ssc-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.ssc-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ssc-dot {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.ssc-chips-wrap {
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.12);
}

.ssc-chips-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.ssc-chips-toggle:hover {
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.03);
}

.ssc-chips-toggle-icon {
  font-size: 10px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.ssc-chips-wrap.ssc-chips-collapsed .ssc-chips-toggle-icon {
  transform: rotate(-90deg);
}

.ssc-chips-wrap.ssc-chips-collapsed .ssc-chips {
  display: none;
}

.ssc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
  max-height: 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ssc-chip {
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(15, 23, 42, 0.8);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.ssc-chip:hover {
  border-color: #818cf8;
  background: rgba(99, 102, 241, 0.2);
  color: #f1f5f9;
}

.ssc-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
  align-items: flex-end;
}

.ssc-form .ssc-input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  margin: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  resize: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.45;
  font-size: 16px;
  word-break: normal;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.ssc-input:focus {
  border-color: rgba(99, 102, 241, 0.5);
  outline: none;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.ssc-send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  margin: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

.ssc-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* На телефонах кнопка мешает листать кабинет — скрываем весь виджет. */
@media (max-width: 768px) {
  .ssc-root {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .ssc-root {
    right: 0;
    bottom: 0;
    left: 0;
  }

  .ssc-toggle {
    position: fixed;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 301;
  }

  .ssc-toggle-label span:first-child {
    display: none;
  }

  .ssc-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px)));
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .ssc-root:has(.ssc-panel.ssc-open) .ssc-toggle {
    display: none;
  }

  .ssc-root.ssc-chat-open .ssc-toggle {
    display: none;
  }

  .ssc-messages {
    min-height: 0;
    max-height: none;
    flex: 1;
    padding: 12px;
  }

  .ssc-bubble {
    font-size: 15px;
    padding: 12px 14px;
  }

  .ssc-chips {
    padding: 0 12px 8px;
    gap: 8px;
    max-height: 96px;
  }

  .ssc-chips-toggle {
    padding: 10px 12px;
    font-size: 13px;
  }

  .ssc-chip {
    font-size: 13px;
    padding: 8px 12px;
    line-height: 1.35;
  }

  .ssc-head {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }

  .ssc-sub {
    font-size: 11px;
  }
}
