/* ── Premium draggable Chat Spot ── */

.chat-spot {
  position: absolute;
  z-index: 90;
  right: 14px;
  bottom: calc(var(--nav-h) + 12px + var(--safe-b));
  width: 56px;
  height: 56px;
  min-height: 56px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.chat-spot > * {
  pointer-events: auto;
}

.chat-spot.is-custom-pos {
  right: auto;
  bottom: auto;
}

.chat-spot.is-dragging {
  z-index: 95;
}

.chat-spot.is-open {
  width: min(340px, calc(var(--app-w) - 28px));
  min-height: 56px;
}

.chat-spot-bubble {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: grab;
  overflow: hidden;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.28), transparent 42%),
    var(--gradient-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 12px 32px rgba(29, 78, 216, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.14) inset,
    0 0 24px rgba(56, 189, 248, 0.35);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-spot-bubble::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(147, 197, 253, 0.35);
  pointer-events: none;
}

.chat-spot-bubble.has-unread {
  animation: chat-spot-bounce 0.55s ease;
}

@keyframes chat-spot-bounce {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(1.08); }
  70% { transform: scale(0.96); }
}

.chat-spot.is-dragging .chat-spot-bubble {
  cursor: grabbing;
  transform: scale(1.05);
}

.chat-spot-bubble svg {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
}

.chat-spot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 3;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 100px;
  background: linear-gradient(135deg, #f87171, #dc2626);
  border: 2px solid #0a1628;
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  color: #fff;
  box-shadow: 0 3px 12px rgba(239, 68, 68, 0.55);
  transform: scale(0);
  transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.chat-spot-badge.is-active {
  transform: scale(1);
  animation: chat-spot-badge-pop 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes chat-spot-badge-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.chat-spot.is-open .chat-spot-bubble {
  cursor: pointer;
  box-shadow:
    0 12px 32px rgba(29, 78, 216, 0.55),
    0 0 0 2px rgba(147, 197, 253, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.14) inset,
    0 0 28px rgba(56, 189, 248, 0.45);
}

.chat-spot-panel {
  position: absolute;
  right: 0;
  bottom: calc(56px + 20px);
  z-index: 1;
  width: min(340px, calc(100vw - 28px));
  max-width: calc(var(--app-w) - 28px);
  max-height: min(420px, calc(100dvh - var(--header-h) - var(--nav-h) - 80px));
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 130% 90% at 50% -25%, rgba(56, 189, 248, 0.14), transparent 58%),
    linear-gradient(168deg, rgba(17, 24, 39, 0.98), rgba(2, 6, 23, 0.99));
  border: 1px solid rgba(96, 165, 250, 0.24);
  box-shadow:
    0 24px 56px rgba(0, 0, 0, 0.58),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 0 48px rgba(59, 130, 246, 0.18);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: chat-spot-panel-in 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

.chat-spot-panel[hidden] {
  display: none !important;
}

.chat-spot-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(147, 197, 253, 0.5), transparent);
  pointer-events: none;
  z-index: 1;
}

@keyframes chat-spot-panel-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-spot-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.04);
  cursor: grab;
  touch-action: none;
}

.chat-spot.is-dragging .chat-spot-head {
  cursor: grabbing;
}

.chat-spot-head-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-brand);
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.35);
}

.chat-spot-head-main {
  flex: 1;
  min-width: 0;
}

.chat-spot-head-title {
  display: block;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
}

.chat-spot-head-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-emerald);
}

.chat-spot-head-sub .live-dot {
  width: 5px;
  height: 5px;
}

.chat-spot-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-spot-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.78);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-spot-messages {
  flex: 1;
  min-height: 140px;
  max-height: min(260px, 42dvh);
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-spot-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.chat-spot-msg.in {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom-left-radius: 5px;
}

.chat-spot-msg.out {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.16), rgba(29, 78, 216, 0.16));
  border: 1px solid rgba(59, 130, 246, 0.24);
  border-bottom-right-radius: 5px;
}

.chat-spot-msg .sender {
  display: block;
  margin-bottom: 4px;
  font-size: 9px;
  font-weight: 800;
  color: var(--accent-cyan);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-spot-compose {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(0, 0, 0, 0.25);
}

.chat-spot-compose input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  outline: none;
}

.chat-spot-compose input:focus {
  border-color: rgba(96, 165, 250, 0.4);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

.chat-spot-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(29, 78, 216, 0.4);
}

.chat-spot.is-hidden-page {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

@media (min-width: 460px) {
  .chat-spot-compose input {
    min-height: 40px;
    font-size: 13px;
  }

  .chat-spot-send {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-spot-panel {
    animation: none;
  }

  .chat-spot-badge.is-active {
    animation: none;
    transform: scale(1);
  }
}
