/* ==========================================================================
   Vertex AI Chat Widget Stylesheet
   Inherits design tokens from css/tokens.css
   Glassmorphism, High-DPI aesthetics, Responsive (Desktop, Tablet, Mobile)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Root Container & Z-Index Layering
   .nav is z-index: 50
   .chat-trigger: z-index: 990
   .chat-widget:  z-index: 1000
   .team-modal:   z-index: 9999 (remains on top of chat widget if open)
   -------------------------------------------------------------------------- */
.chat-widget-root {
  position: fixed;
  z-index: 990;
  pointer-events: none; /* Let clicks pass through empty spaces */
}

/* --------------------------------------------------------------------------
   Teaser Bubble (Notification Tooltip above FAB)
   -------------------------------------------------------------------------- */
.chat-teaser {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 989;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 290px;
  padding: 10px 14px;
  background: rgba(10, 14, 24, 0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 14px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.85), 0 0 24px -6px rgba(34, 211, 238, 0.25);
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility 0s linear 0s;
  cursor: pointer;
}

.chat-teaser::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 26px;
  width: 10px;
  height: 10px;
  background: #0a0e18;
  border-right: 1px solid rgba(34, 211, 238, 0.35);
  border-bottom: 1px solid rgba(34, 211, 238, 0.35);
  transform: rotate(45deg);
}

.chat-teaser.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility 0s linear var(--dur-fast);
}

.chat-teaser__avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.2), rgba(139, 92, 246, 0.25));
  border: 1px solid rgba(34, 211, 238, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
}

.chat-teaser__content {
  flex: 1;
  min-width: 0;
}

.chat-teaser__tag {
  display: inline-block;
  font: 600 11px var(--mono);
  color: var(--cyan);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.chat-teaser__text {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
  font-weight: 500;
}

.chat-teaser__close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-3);
  cursor: pointer;
  padding: 0;
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.chat-teaser__close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   Floating Action Button (Trigger FAB)
   -------------------------------------------------------------------------- */
.chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 990;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, #22d3ee 0%, #3b82f6 50%, #8b5cf6 100%);
  color: #04121a;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 10px 28px -4px rgba(34, 211, 238, 0.5), 0 0 20px -2px rgba(139, 92, 246, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.chat-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 34px -4px rgba(34, 211, 238, 0.65), 0 0 28px rgba(139, 92, 246, 0.5);
  border-color: rgba(255, 255, 255, 0.4);
}

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

/* Pulsing radar ring */
.chat-trigger__pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  opacity: 0.6;
  pointer-events: none;
  animation: chatRadarPulse 2.4s cubic-bezier(0.24, 0, 0.38, 1) infinite;
}

@keyframes chatRadarPulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  70% {
    transform: scale(1.35);
    opacity: 0;
  }
  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.chat-trigger.is-open .chat-trigger__pulse {
  display: none;
}

/* Icon cross-fade toggle */
.chat-trigger__icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.chat-trigger__icon--open {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.chat-trigger__icon--close {
  opacity: 0;
  transform: scale(0.6) rotate(-90deg);
  color: #fff;
}

.chat-trigger.is-open {
  background: #0f1522;
  border-color: rgba(34, 211, 238, 0.45);
  box-shadow: 0 10px 24px -4px rgba(0, 0, 0, 0.7), 0 0 16px rgba(34, 211, 238, 0.3);
}

.chat-trigger.is-open .chat-trigger__icon--open {
  opacity: 0;
  transform: scale(0.6) rotate(90deg);
}

.chat-trigger.is-open .chat-trigger__icon--close {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Notification badge */
.chat-trigger__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font: 700 11px var(--mono);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(248, 113, 113, 0.6);
  animation: chatBadgePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes chatBadgePop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Chat Dialog Window (.chat-widget)
   -------------------------------------------------------------------------- */
.chat-widget {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 1000;
  width: 384px;
  height: min(620px, calc(100vh - 120px));
  height: min(620px, calc(100svh - 120px));
  display: flex;
  flex-direction: column;
  background: rgba(10, 14, 24, 0.88);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(34, 211, 238, 0.25);
  border-radius: 20px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9), 0 0 35px -10px rgba(34, 211, 238, 0.22);
  overflow: hidden;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility 0s linear var(--dur);
}

.chat-widget.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

/* --------------------------------------------------------------------------
   Widget Header
   -------------------------------------------------------------------------- */
.chat-widget__header {
  flex-shrink: 0;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(15, 21, 34, 0.95) 0%, rgba(10, 14, 24, 0.8) 100%);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-widget__identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-widget__avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.22) 0%, rgba(139, 92, 246, 0.22) 100%);
  border: 1px solid rgba(34, 211, 238, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
}

.chat-widget__status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg-2);
  box-shadow: 0 0 8px var(--green);
}

.chat-widget__titles {
  display: flex;
  flex-direction: column;
}

.chat-widget__name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.chat-widget__status-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-2);
  font-family: var(--sans);
  line-height: 1.3;
}

.chat-widget__status-live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  display: inline-block;
}

.chat-widget__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-widget__btn-action {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all var(--dur-fast) var(--ease);
}

.chat-widget__btn-action:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line-2);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   Message Flow Container
   -------------------------------------------------------------------------- */
.chat-widget__messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

.chat-widget__messages::-webkit-scrollbar {
  width: 5px;
}
.chat-widget__messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 999px;
}
.chat-widget__messages::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.4);
}

/* Individual Message Row */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: chatMsgIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes chatMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg--assistant {
  align-self: flex-start;
}

.chat-msg--user {
  align-self: flex-end;
}

.chat-msg__bubble {
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-msg--assistant .chat-msg__bubble {
  background: rgba(15, 21, 34, 0.85);
  border: 1px solid var(--line-2);
  border-radius: 16px 16px 16px 4px;
  color: var(--text);
  box-shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.4);
}

.chat-msg--user .chat-msg__bubble {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px 16px 4px 16px;
  color: #fff;
  box-shadow: 0 4px 14px -3px rgba(37, 99, 235, 0.45);
}

.chat-msg__bubble p {
  margin: 0;
}
.chat-msg__bubble p + p {
  margin-top: 8px;
}
.chat-msg__bubble strong,
.chat-msg__bubble b {
  color: #fff;
  font-weight: 600;
}
.chat-msg__bubble ul {
  margin: 6px 0;
  padding-left: 18px;
  list-style: disc;
}
.chat-msg__bubble li {
  margin: 3px 0;
}
.chat-msg__bubble a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg__bubble a:hover {
  color: #67e8f9;
}

/* Call to action pills inside assistant reply */
.chat-msg__cta-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chat-msg__cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(139, 92, 246, 0.18));
  border: 1px solid rgba(34, 211, 238, 0.4);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--dur-fast) var(--ease);
}

.chat-msg__cta-btn:hover {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.35), rgba(139, 92, 246, 0.35));
  border-color: var(--cyan);
  color: #fff;
  transform: translateY(-1px);
}

/* Meta info / timestamp */
.chat-msg__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 0 4px;
  font: 400 11px var(--mono);
  color: var(--text-3);
}

.chat-msg--assistant .chat-msg__meta {
  align-self: flex-start;
}

.chat-msg--user .chat-msg__meta {
  align-self: flex-end;
}

.chat-msg__source-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(34, 211, 238, 0.1);
  color: var(--cyan);
  border: 1px solid rgba(34, 211, 238, 0.2);
}

/* Lead captured success notice */
.chat-msg__lead-notice {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: #a7f3d0;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------------------------
   Quick Prompts Chips
   -------------------------------------------------------------------------- */
.chat-widget__chips {
  flex-shrink: 0;
  padding: 8px 14px 10px;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  background: rgba(10, 14, 24, 0.6);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chat-widget__chips::-webkit-scrollbar {
  display: none;
}

.chat-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line-2);
  color: var(--text-2);
  font: 500 12px var(--sans);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease);
}

.chat-chip:hover {
  background: rgba(34, 211, 238, 0.14);
  border-color: rgba(34, 211, 238, 0.45);
  color: #fff;
  transform: translateY(-1px);
}

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

.chat-chip__icon {
  font-size: 13px;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */
.chat-widget__typing {
  flex-shrink: 0;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 14, 24, 0.5);
  border-top: 1px dashed rgba(148, 163, 184, 0.1);
}

.chat-widget__typing-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
}

.chat-widget__typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--line-2);
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  opacity: 0.4;
  animation: chatTypingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes chatTypingBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.35;
  }
  40% {
    transform: scale(1.15);
    opacity: 1;
    box-shadow: 0 0 6px var(--cyan);
  }
}

.chat-widget__typing-label {
  font-size: 11.5px;
  color: var(--text-3);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Input Box & Footer
   -------------------------------------------------------------------------- */
.chat-widget__footer {
  flex-shrink: 0;
  padding: 10px 14px 12px;
  background: rgba(10, 15, 26, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-sizing: border-box;
}

.chat-widget__input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(5, 9, 17, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  padding: 5px 6px 5px 14px;
  min-height: 44px;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-radius 0.2s ease;
}

.chat-widget__input-wrap.is-multiline {
  align-items: flex-end;
  border-radius: 16px;
}

.chat-widget__input-wrap:focus-within {
  border-color: rgba(34, 211, 238, 0.7);
  background: rgba(8, 14, 26, 0.96);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.3), 0 4px 16px -2px rgba(34, 211, 238, 0.2);
}

.chat-widget__input {
  flex: 1;
  min-height: 24px;
  max-height: 96px;
  padding: 3px 0;
  margin: 0;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  color: #f1f5f9;
  font: 400 14px/1.45 var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  resize: none;
  box-sizing: border-box;
  overflow-y: hidden;
  overflow-x: hidden;
  caret-color: var(--cyan, #22d3ee);
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.chat-widget__input:focus,
.chat-widget__input:focus-visible,
textarea.chat-widget__input:focus,
textarea.chat-widget__input:focus-visible {
  outline: none !important;
  outline-offset: 0 !important;
  box-shadow: none !important;
  border: none !important;
}

.chat-widget__input::-moz-focus-inner {
  border: 0 !important;
  padding: 0 !important;
}

.chat-widget__input::-webkit-scrollbar {
  width: 4px;
}

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

.chat-widget__input::-webkit-scrollbar-thumb {
  background: rgba(34, 211, 238, 0.35);
  border-radius: 4px;
}

.chat-widget__input::placeholder {
  color: rgba(148, 163, 184, 0.65);
  font-weight: 400;
}

.chat-widget__send-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--cyan, #22d3ee) 0%, #3b82f6 100%);
  color: #04121a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 2px 8px rgba(34, 211, 238, 0.3);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              background 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-tap-highlight-color: transparent;
}

.chat-widget__send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(34, 211, 238, 0.55);
}

.chat-widget__send-btn:not(:disabled):active {
  transform: scale(0.95);
}

.chat-widget__send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  background: rgba(148, 163, 184, 0.15);
  color: rgba(148, 163, 184, 0.5);
  box-shadow: none;
}

.chat-widget__send-btn svg {
  transition: transform 0.18s ease;
}

.chat-widget__send-btn:not(:disabled):hover svg {
  transform: translateX(1px) translateY(-1px);
}

.chat-widget__disclaimer {
  margin-top: 7px;
  text-align: center;
  font: 400 11px var(--mono, ui-monospace, monospace);
  color: rgba(148, 163, 184, 0.6);
  letter-spacing: 0.02em;
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   Responsive Layout & Mobile Adaptation
   -------------------------------------------------------------------------- */

/* Tablet (481px to 768px) */
@media (max-width: 768px) {
  .chat-widget {
    bottom: 84px;
    right: 18px;
    width: 360px;
    height: min(580px, calc(100vh - 104px));
    height: min(580px, calc(100svh - 104px));
  }
  .chat-trigger {
    bottom: 18px;
    right: 18px;
  }
  .chat-teaser {
    bottom: 84px;
    right: 18px;
  }
}

/* Mobile Screen (<= 480px) */
@media (max-width: 480px) {
  .chat-widget {
    position: fixed;
    inset: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    z-index: 1001; /* Layer over header */
    transform-origin: center bottom;
  }

  .chat-widget__header {
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    border-bottom: 1px solid var(--line);
  }

  .chat-widget__footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .chat-trigger {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }

  .chat-teaser {
    display: none !important;
  }

  /* Prevent background scrolling when chat dialog is full screen on mobile */
  html.chat-widget-open {
    overflow: hidden;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .chat-trigger__pulse {
    animation: none;
    display: none;
  }
  .chat-widget {
    transition: opacity var(--dur-fast) linear;
    transform: none !important;
  }
  .chat-typing-dot {
    animation: none;
    opacity: 0.8;
  }
}
