/* =============================================================================
   Cyberlux Consulting — Chatbot Widget Styles
   Futuristic glassmorphic UI matching the core site design system.
   ============================================================================= */

/* Floating trigger button */
.trace-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--hairline-strong);
  box-shadow: 0 8px 32px rgba(96, 72, 229, 0.3), var(--shadow-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background-color 0.25s var(--ease);
}

.trace-chat-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 36px rgba(96, 72, 229, 0.45), var(--shadow-2);
}

.trace-chat-trigger:not(.open) {
  animation: trace-avatar-pulse 2.5s infinite ease-in-out;
}

.trace-chat-trigger:not(.open):hover {
  animation-play-state: paused;
}

.trace-chat-trigger:active {
  transform: scale(0.95);
}

@keyframes trace-avatar-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(96, 72, 229, 0.6), 0 8px 32px rgba(96, 72, 229, 0.3), var(--shadow-1);
  }
  50% {
    transform: scale(1.04) translateY(-1px);
    box-shadow: 0 0 0 10px rgba(96, 72, 229, 0), 0 8px 32px rgba(96, 72, 229, 0.3), var(--shadow-1);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(96, 72, 229, 0), 0 8px 32px rgba(96, 72, 229, 0.3), var(--shadow-1);
  }
}

.trace-chat-trigger svg {
  width: 30px;
  height: 30px;
  stroke: currentColor;
  fill: none;
  transition: transform 0.3s var(--ease);
}

.trace-chat-trigger-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.trace-chat-trigger.open .trace-chat-trigger-avatar {
  display: none;
}

.trace-chat-trigger.open .trace-chat-trigger-close-icon {
  display: block !important;
}

/* Chat container window */
.trace-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 520px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 130px);
  background: var(--bg-glass-strong);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}

/* Open state */
.trace-chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Decorative corner ticks for Cyberlux futuristic aesthetic */
.trace-chat-window::before,
.trace-chat-window::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid var(--hairline-strong);
  pointer-events: none;
  z-index: 5;
}
.trace-chat-window::before {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}
.trace-chat-window::after {
  bottom: -1px;
  right: -1px;
  border-left: none;
  border-top: none;
}

/* Header */
.trace-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.02);
}

.trace-chat-agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.trace-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(96, 72, 229, 0.2), transparent 70%);
  border: 1px solid var(--hairline-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  overflow: hidden;
}

.trace-chat-avatar svg {
  width: 22px;
  height: 22px;
}

.trace-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.trace-chat-title-container {
  display: flex;
  flex-direction: column;
}

.trace-chat-title {
  font-family: var(--ff-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.2;
}

.trace-chat-status {
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.trace-chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #1f9d6b;
  box-shadow: 0 0 6px #1f9d6b;
  display: inline-block;
  animation: trace-chat-pulse 2s infinite;
}

@keyframes trace-chat-pulse {
  50% { opacity: 0.4; }
}

.trace-chat-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-dim);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.2s, background-color 0.2s;
}

.trace-chat-close:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
}

.trace-chat-close svg {
  width: 18px;
  height: 18px;
}

/* Messages area */
.trace-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}

/* Custom scrollbar for webkit */
.trace-chat-messages::-webkit-scrollbar {
  width: 4px;
}
.trace-chat-messages::-webkit-scrollbar-thumb {
  background: var(--hairline);
  border-radius: 2px;
}

/* Message speech bubbles */
.trace-chat-msg-row {
  display: flex;
  width: 100%;
}

.trace-chat-msg-row.user {
  justify-content: flex-end;
}

.trace-chat-msg-row.agent {
  justify-content: flex-start;
}

.trace-chat-bubble {
  max-width: 82%;
  padding: 12px 16px;
  font-family: var(--ff-display);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-1);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Agent Bubble style */
.trace-chat-msg-row.agent .trace-chat-bubble {
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 16px 16px 16px 4px;
}

[data-theme="light"] .trace-chat-msg-row.agent .trace-chat-bubble {
  background: #ffffff;
  border-color: var(--hairline-mid);
}

/* User Bubble style */
.trace-chat-msg-row.user .trace-chat-bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: 16px 16px 4px 16px;
}

/* Rich Text / Markdown styles inside bubbles */
.trace-chat-bubble p {
  margin: 0;
}
.trace-chat-bubble p + p {
  margin-top: 8px;
}
.trace-chat-bubble ul, .trace-chat-bubble ol {
  margin: 6px 0 0 0;
  padding-left: 20px;
}
.trace-chat-bubble li {
  margin-top: 4px;
}
.trace-chat-bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
}

/* Quick replies / Chips container */
.trace-chat-suggestions {
  padding: 10px 16px 14px 16px; /* Added extra bottom padding for the thin scrollbar */
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  border-top: 1px dashed var(--hairline);
  background: rgba(255, 255, 255, 0.01);
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
  -ms-overflow-style: auto;
}

.trace-chat-suggestions:hover {
  scrollbar-color: var(--hairline-mid) transparent;
}

.trace-chat-suggestions::-webkit-scrollbar {
  height: 4px;
}

.trace-chat-suggestions::-webkit-scrollbar-track {
  background: transparent;
}

.trace-chat-suggestions::-webkit-scrollbar-thumb {
  background: var(--hairline);
  border-radius: 99px;
}

.trace-chat-suggestions:hover::-webkit-scrollbar-thumb {
  background: var(--hairline-mid);
}

.trace-chat-suggestions::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.trace-chat-chip {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--hairline-mid);
  color: var(--ink-mute);
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--ff-display);
  font-size: 11.5px;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease), color 0.2s var(--ease);
  flex: 0 0 auto; /* Don't shrink chips */
  white-space: nowrap;
}

[data-theme="light"] .trace-chat-chip {
  background: #ffffff;
}

.trace-chat-chip:hover {
  border-color: var(--accent);
  background: rgba(96, 72, 229, 0.04);
  color: var(--ink);
}

.trace-chat-chip:active {
  transform: scale(0.97);
}

/* Input area styling */
.trace-chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.02);
}

.trace-chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--hairline-mid);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  color: var(--ink);
  font-family: var(--ff-display);
  font-size: 13.5px;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}

[data-theme="light"] .trace-chat-input {
  background: #ffffff;
}

.trace-chat-input::placeholder {
  color: var(--ink-faint);
}

.trace-chat-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(96, 72, 229, 0.04);
}

.trace-chat-send {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.trace-chat-send:hover {
  transform: scale(1.04);
}

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

.trace-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.trace-chat-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Typing / Loader bubble dots */
.trace-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
}

.trace-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--ink-dim);
  display: inline-block;
  animation: trace-chat-bounce 1.4s infinite ease-in-out both;
}

.trace-chat-typing span:nth-child(1) {
  animation-delay: -0.32s;
}

.trace-chat-typing span:nth-child(2) {
  animation-delay: -0.16s;
}

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

/* Responsive adjustment on mobile screen size */
@media (max-width: 480px) {
  .trace-chat-window {
    bottom: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
  }
  .trace-chat-window::before,
  .trace-chat-window::after {
    display: none !important;
  }
  .trace-chat-trigger {
    bottom: 16px;
    right: 16px;
  }
  .trace-chat-trigger.open {
    display: none !important; /* hide trigger when full screen chat is open on mobile */
  }
}
