/* =========================================
   CHAT WIDGET
   ========================================= */
#chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 5000;
}

/* Floating toggle button */
.chat-fab {
  width: 3.5rem;
  height: 3.5rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 12px 32px -8px rgba(198, 95, 74, 0.55);
  transition: var(--transition-fast);
  position: relative;
  touch-action: manipulation;
}
.chat-fab:hover {
  background: var(--accent-hover);
  transform: translateY(-3px);
}
.chat-fab i.chat-fab-open {
  display: block;
}
.chat-fab i.chat-fab-close {
  display: none;
}
.chat-fab.active i.chat-fab-open {
  display: none;
}
.chat-fab.active i.chat-fab-close {
  display: block;
}
.chat-fab .chat-fab-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 0.75rem;
  height: 0.75rem;
  background: var(--success);
  border: 2px solid var(--white);
  border-radius: 50%;
  animation: chatPulse 2s ease-in-out infinite;
}
@keyframes chatPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(90, 143, 106, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(90, 143, 106, 0); }
}

/* Chat panel */
.chat-panel {
  position: fixed;
  bottom: 6rem;
  right: 1.5rem;
  width: 340px;
  max-width: calc(100vw - 2rem);
  height: 460px;
  max-height: calc(100dvh - 8rem);
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-ambient);
  border: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(24px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: var(--transition);
}
.chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--espresso), #3a2f2a);
  color: var(--white);
}
.chat-panel-header .chat-header-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.chat-header-title {
  flex: 1;
}
.chat-header-title strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.chat-header-title span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  opacity: 0.75;
  margin-top: 0.1rem;
}
.chat-online-dot {
  width: 0.45rem;
  height: 0.45rem;
  background: var(--success);
  border-radius: 50%;
}
.chat-panel-close {
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.8;
  transition: var(--transition-fast);
  padding: 0.25rem;
}
.chat-panel-close:hover {
  opacity: 1;
  transform: rotate(90deg);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  background: var(--bg-alt);
  scrollbar-width: thin;
}
.chat-msg {
  display: flex;
  gap: 0.55rem;
  max-width: 85%;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--espresso);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-top: 0.15rem;
}
.chat-msg-name {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--warm-gray);
  margin-bottom: 0.25rem;
  letter-spacing: 0.01em;
}
.chat-msg.user .chat-msg-name {
  text-align: right;
}
.chat-bubble {
  padding: 0.6rem 0.9rem;
  border-radius: 1.1rem;
  font-size: 0.82rem;
  line-height: 1.5;
  word-break: break-word;
  animation: chatIn 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
.chat-msg.team .chat-bubble {
  background: var(--white);
  color: var(--espresso);
  border: 1px solid var(--border-hairline);
  border-top-left-radius: 0.35rem;
  box-shadow: var(--shadow-soft);
}
.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: var(--white);
  border-top-right-radius: 0.35rem;
}
.chat-msg-time {
  font-size: 0.62rem;
  color: var(--warm-gray);
  margin-top: 0.3rem;
  opacity: 0.85;
}
.chat-msg.user .chat-msg-time {
  text-align: right;
}
@keyframes chatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--white);
  border-top: 1px solid var(--border-hairline);
}
.chat-input-row input {
  flex: 1;
  border: 1px solid var(--border-light);
  background: var(--bg-alt);
  border-radius: var(--radius-full);
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  outline: none;
  color: var(--espresso);
  transition: var(--transition-fast);
}
.chat-input-row input:focus {
  border-color: var(--accent);
  background: var(--white);
}
.chat-send-btn {
  width: 2.6rem;
  height: 2.6rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: var(--transition-fast);
  flex-shrink: 0;
  touch-action: manipulation;
}
.chat-send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.06);
}
.chat-send-btn:active {
  transform: scale(0.94);
}

/* Responsive */
@media (max-width: 1024px) {
  .chat-panel {
    width: 300px;
    height: 400px;
    max-height: calc(100dvh - 6.5rem);
    bottom: 5.25rem;
    right: 1.25rem;
  }
  .chat-panel-header {
    padding: 0.8rem 1rem;
  }
  .chat-messages {
    padding: 0.85rem 0.8rem;
    gap: 0.7rem;
  }
  .chat-input-row {
    padding: 0.65rem 0.8rem;
  }
  .chat-fab {
    width: 3.25rem;
    height: 3.25rem;
    font-size: 1.35rem;
  }
}
@media (max-width: 480px) {
  #chat-widget {
    bottom: 1rem;
    right: 1rem;
  }
  .chat-panel {
    bottom: 5.25rem;
    right: 0.85rem;
    left: 0.85rem;
    top: auto;
    width: auto;
    height: 62dvh;
    max-width: none;
    max-height: 62dvh;
    border-radius: var(--radius-xl);
  }
  .chat-fab {
    width: 3.25rem;
    height: 3.25rem;
    font-size: 1.35rem;
  }
}
