/* ========================================
   cybernetik — Support Chat Widget
   Floating bottom-right chat popup
   ======================================== */

/* --- Floating Toggle Button --- */
.chat-widget-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9000;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px hsla(250, 85%, 50%, 0.45);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.3s ease;
}

.chat-widget-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 32px hsla(250, 85%, 50%, 0.6);
}

.chat-widget-btn.active {
  transform: scale(1) rotate(0deg);
}

/* Unread pulse ring */
.chat-widget-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--gradient-primary);
  opacity: 0;
  z-index: -1;
  animation: chat-pulse 2s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%, 100% { transform: scale(1); opacity: 0; }
  50% { transform: scale(1.25); opacity: 0.25; }
}

/* Icons inside button */
.chat-widget-btn .chat-icon-open,
.chat-widget-btn .chat-icon-close {
  position: absolute;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.25s ease;
}

.chat-widget-btn .chat-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.chat-widget-btn.active .chat-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.chat-widget-btn.active .chat-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.chat-widget-btn.active::before {
  animation: none;
  opacity: 0;
}

/* --- Chat Window --- */
.chat-widget-window {
  position: fixed;
  bottom: 6.5rem;
  right: 2rem;
  z-index: 9001;
  width: 380px;
  max-height: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: hsla(230, 25%, 10%, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid hsla(250, 60%, 50%, 0.2);
  box-shadow: 0 16px 64px hsla(0, 0%, 0%, 0.55),
              0 0 40px hsla(250, 85%, 50%, 0.12);

  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s,
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* --- Header --- */
.chat-widget-header {
  background: var(--gradient-primary);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.chat-widget-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, hsla(0,0%,100%,0.12) 0%, transparent 60%);
  pointer-events: none;
}

.chat-widget-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: hsla(0, 0%, 100%, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  position: relative;
}

.chat-widget-avatar::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid hsl(250, 85%, 55%);
}

.chat-widget-header-info {
  position: relative;
}

.chat-widget-header-name {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  line-height: 1.3;
}

.chat-widget-header-status {
  font-size: 0.78rem;
  color: hsla(0, 0%, 100%, 0.75);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* --- Messages Area --- */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 220px;
  max-height: 300px;
  scrollbar-width: thin;
  scrollbar-color: hsla(250, 60%, 50%, 0.25) transparent;
}

.chat-widget-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-widget-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-widget-messages::-webkit-scrollbar-thumb {
  background: hsla(250, 60%, 50%, 0.3);
  border-radius: 10px;
}

/* --- Message Bubbles --- */
.chat-msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.55;
  animation: chat-msg-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  position: relative;
  word-wrap: break-word;
}

@keyframes chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-msg.bot {
  align-self: flex-start;
  background: hsla(230, 20%, 20%, 0.8);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid hsla(230, 20%, 30%, 0.3);
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--gradient-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg-time {
  font-size: 0.7rem;
  margin-top: 0.35rem;
  opacity: 0.55;
}

.chat-msg.user .chat-msg-time {
  text-align: right;
}

/* --- Typing Indicator --- */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.75rem 1rem;
  align-self: flex-start;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-typing-bounce 1.4s infinite ease-in-out both;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes chat-typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Input Area --- */
.chat-widget-input {
  padding: 0.85rem 1rem;
  border-top: 1px solid hsla(230, 20%, 30%, 0.3);
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  background: hsla(230, 25%, 8%, 0.6);
  flex-shrink: 0;
}

.chat-widget-input textarea {
  flex: 1;
  background: hsla(230, 20%, 16%, 0.7);
  border: 1px solid hsla(230, 20%, 30%, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.88rem;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  scrollbar-width: none;
}

.chat-widget-input textarea::-webkit-scrollbar {
  display: none;
}

.chat-widget-input textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px hsla(250, 85%, 60%, 0.12);
}

.chat-widget-input textarea::placeholder {
  color: var(--text-muted);
}

.chat-widget-send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.chat-widget-send:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 12px hsla(250, 85%, 50%, 0.4);
}

.chat-widget-send:active {
  transform: scale(0.95);
}

.chat-widget-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* --- Success / Error State --- */
.chat-widget-status {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  animation: chat-msg-in 0.3s ease both;
}

.chat-widget-status.success {
  color: #34d399;
}

.chat-widget-status.error {
  color: #f87171;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .chat-widget-window {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 5.5rem;
    width: auto;
    max-height: 70vh;
  }

  .chat-widget-btn {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 54px;
    height: 54px;
    font-size: 1.4rem;
  }
}
