.support-chat {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2500;
  font-family: inherit;
  --lia-glow: rgba(var(--accent-rgb), 0.42);
  --lia-ring: rgba(var(--accent-rgb), 0.72);
}

.support-chat[data-emotion="happy"] { --lia-glow: rgba(52, 211, 153, 0.46); --lia-ring: rgba(52, 211, 153, 0.78); }
.support-chat[data-emotion="thinking"] { --lia-glow: rgba(96, 165, 250, 0.42); --lia-ring: rgba(96, 165, 250, 0.78); }
.support-chat[data-emotion="annoyed"] { --lia-glow: rgba(251, 146, 60, 0.42); --lia-ring: rgba(251, 146, 60, 0.78); }
.support-chat[data-emotion="angry"] { --lia-glow: rgba(244, 63, 94, 0.46); --lia-ring: rgba(244, 63, 94, 0.82); }
.support-chat[data-emotion="surprised"] { --lia-glow: rgba(250, 204, 21, 0.42); --lia-ring: rgba(250, 204, 21, 0.78); }
.support-chat[data-emotion="sad"],
.support-chat[data-emotion="error"] { --lia-glow: rgba(248, 113, 113, 0.42); --lia-ring: rgba(248, 113, 113, 0.78); }

.back-to-top {
  bottom: max(86px, calc(env(safe-area-inset-bottom) + 86px));
}

.support-chat__fab {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 52px;
  border: 1px solid rgba(var(--accent-rgb), 0.48);
  border-radius: 999px;
  padding: 0 1rem 0 0.55rem;
  background: rgba(18, 22, 30, 0.96);
  color: var(--text-primary);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.support-chat__fab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  font-size: 1.2rem;
}

.support-chat__lia-face,
.support-chat__portrait,
.support-chat__mini-avatar {
  position: relative;
  flex: 0 0 auto;
  overflow: visible;
  border: 0;
  background: transparent;
  filter: drop-shadow(0 0 8px var(--lia-glow)) drop-shadow(0 10px 18px rgba(0, 0, 0, 0.28));
  transition: filter 180ms ease, transform 220ms ease;
}

.support-chat__lia-face img,
.support-chat__portrait img,
.support-chat__mini-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  transform-origin: 50% 72%;
  transition: opacity 140ms ease, transform 220ms ease;
}

.support-chat__lia-face {
  border-radius: 50%;
  color: transparent;
}

.support-chat__fab-text {
  font-weight: 800;
  font-size: 0.9rem;
}

.support-chat__fab-dot {
  position: absolute;
  top: 5px;
  left: 43px;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(18, 22, 30, 0.96);
  border-radius: 50%;
  background: #31d158;
}

.support-chat__panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  display: none;
  width: min(380px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 110px));
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  border-radius: 16px;
  background: rgba(13, 17, 24, 0.98);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.42);
  overflow: hidden;
  backdrop-filter: blur(18px);
}

.support-chat.is-open .support-chat__panel {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto auto auto;
}

.support-chat__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.support-chat__portrait {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  margin: -0.35rem 0 -0.35rem -0.15rem;
}

.support-chat__head strong,
.support-chat__head span {
  display: block;
}

.support-chat__head span {
  margin-top: 0.18rem;
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.support-chat__close {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.2rem;
}

.support-chat__messages {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  overflow-y: auto;
}

.support-chat__message {
  max-width: 88%;
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
  line-height: 1.42;
}

.support-chat__message--bot {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 0.55rem;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text-primary);
}

.support-chat__message a {
  color: var(--accent);
  overflow-wrap: anywhere;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.support-chat__mini-avatar {
  width: 34px;
  height: 34px;
  margin-top: -0.15rem;
  filter: drop-shadow(0 0 5px var(--lia-glow));
}

.support-chat__message--user {
  align-self: flex-end;
  background: rgba(var(--accent-rgb), 0.9);
  color: #fff;
}

.support-chat__quick {
  display: flex;
  gap: 0.45rem;
  padding: 0 1rem 0.75rem;
  overflow-x: auto;
}

.support-chat__quick button {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.65rem;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
}

.support-chat__form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
}

.support-chat__form input {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.support-chat__form button {
  border: 0;
  border-radius: 12px;
  padding: 0 0.85rem;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.support-chat__live {
  display: block;
  padding: 0 1rem 1rem;
  color: var(--accent);
  font-size: 0.84rem;
  text-align: center;
  text-decoration: none;
}

.support-chat[data-emotion="happy"] .support-chat__portrait {
  animation: liaHappy 1.35s ease-in-out infinite;
}

.support-chat[data-emotion="thinking"] .support-chat__portrait {
  animation: liaThinking 1.1s ease-in-out infinite;
}

.support-chat[data-emotion="annoyed"] .support-chat__portrait {
  animation: liaAnnoyed 0.78s ease-in-out infinite;
}

.support-chat[data-emotion="sad"] .support-chat__portrait,
.support-chat[data-emotion="error"] .support-chat__portrait {
  animation: liaSad 1.6s ease-in-out infinite;
}

.support-chat[data-emotion="surprised"] .support-chat__portrait {
  animation: liaSurprised 0.95s ease-in-out infinite;
}

.support-chat[data-emotion="angry"] .support-chat__portrait {
  animation: liaAngry 0.62s ease-in-out infinite;
}

@keyframes liaHappy {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  45% { transform: translateY(-4px) rotate(2deg) scale(1.04); }
  70% { transform: translateY(1px) rotate(-1deg) scale(0.99); }
}

@keyframes liaThinking {
  0%, 100% { transform: translateX(0) rotate(0deg) scale(1); }
  35% { transform: translateX(-2px) rotate(-2deg) scale(1.02); }
  70% { transform: translateX(2px) rotate(1.5deg) scale(1.01); }
}

@keyframes liaAnnoyed {
  0%, 100% { transform: translateX(0) rotate(-1deg); }
  25% { transform: translateX(-2px) rotate(-4deg); }
  50% { transform: translateX(2px) rotate(3deg); }
  75% { transform: translateX(-1px) rotate(-2deg); }
}

@keyframes liaAngry {
  0%, 100% { transform: translateX(0) rotate(-1deg) scale(1.01); }
  25% { transform: translateX(-3px) rotate(-5deg) scale(1.03); }
  50% { transform: translateX(3px) rotate(4deg) scale(1.02); }
  75% { transform: translateX(-2px) rotate(-3deg) scale(1.03); }
}

@keyframes liaSad {
  0%, 100% { transform: translateY(0) scale(1); filter: saturate(0.95); }
  50% { transform: translateY(3px) scale(0.985); filter: saturate(0.72); }
}

@keyframes liaSurprised {
  0%, 100% { transform: scale(1) rotate(0deg); }
  35% { transform: scale(1.08) rotate(-1deg); }
  70% { transform: scale(1.02) rotate(1deg); }
}

@media (prefers-reduced-motion: reduce) {
  .support-chat__lia-face,
  .support-chat__portrait {
    animation: none !important;
  }
}

@media (max-width: 560px) {
  .back-to-top {
    bottom: max(82px, calc(env(safe-area-inset-bottom) + 82px));
  }

  .support-chat {
    right: 12px;
    bottom: 12px;
  }

  .support-chat__fab-text {
    display: none;
  }

  .support-chat__fab {
    width: 56px;
    height: 56px;
    justify-content: center;
    padding: 0;
  }

  .support-chat__panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 70px;
    width: auto;
  }

  .support-chat__portrait {
    width: 60px;
    height: 60px;
    border-radius: 14px;
  }
}
