/* ==========================================================================
   SYNVERTIX TECHNOLOGIES - ENTERPRISE CHATBOT WIDGET STYLES (v7 SPACING FIX)
   ========================================================================== */

/* 1. Keyframe Animations */
@keyframes synvertixPulseDot {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

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

@keyframes synvertixWave {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes synvertixFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes synvertixLauncherBounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
  60% { transform: translateY(-5px); }
}

/* 2. Floating Widget Trigger Launcher Button */
.synvertix-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F5820D 0%, #E06D00 100%);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 10px 30px rgba(245, 130, 13, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  cursor: pointer;
  z-index: 999990;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.synvertix-chat-trigger.synvertix-bounce-on-load {
  animation: synvertixLauncherBounce 2.2s ease 1s 2;
}

.synvertix-chat-trigger:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 14px 36px rgba(245, 130, 13, 0.6);
}

.synvertix-chat-trigger:active {
  transform: translateY(-1px) scale(0.98);
}

.synvertix-chat-trigger:focus-visible {
  outline: 3px solid #38BDF8;
  outline-offset: 4px;
}

/* Launcher Icon Rotation & Toggle Transition */
.synvertix-trigger-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

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

.synvertix-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

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

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

/* Online Indicator Badge */
.synvertix-trigger-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #22C55E;
  border: 2.5px solid #0F172A;
  border-radius: 50%;
  z-index: 2;
  animation: synvertixPulseDot 2.2s infinite;
}

/* 3. Main Chatbot Modal Container (Desktop Bounded Floating Card ~380px x ~580px) */
.synvertix-chat-modal {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: min(600px, calc(100vh - 130px));
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease-out, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.synvertix-chat-modal.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Mobile Drag Handle Bar (Hidden on Desktop) */
.synvertix-drag-handle-bar {
  display: none;
}

/* 4. Modal Header (Pinned Top) */
.synvertix-chat-header {
  flex-shrink: 0;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.synvertix-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.synvertix-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(245, 130, 13, 0.12);
  border: 1px solid rgba(245, 130, 13, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #F5820D;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(245, 130, 13, 0.25);
}

.synvertix-header-title {
  color: #FFFFFF;
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.synvertix-header-subtitle {
  color: #94A3B8;
  font-size: 0.75rem;
  margin: 2px 0 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.synvertix-status-dot {
  width: 7px;
  height: 7px;
  background-color: #22C55E;
  border-radius: 50%;
  display: inline-block;
  animation: synvertixPulseDot 2.2s infinite;
}

.synvertix-chat-close {
  background: transparent;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.synvertix-chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
  transform: scale(1.06);
}

.synvertix-chat-close:focus-visible {
  outline: 2px solid #38BDF8;
}

/* 5. Messages Container (Internal Scroll Thread Only) */
.synvertix-chat-messages {
  flex: 1;
  padding: 16px 14px 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.synvertix-chat-messages::-webkit-scrollbar {
  width: 5px;
}

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

.synvertix-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
}

.synvertix-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* 6. Message Rows & Bounded Cards */
.synvertix-msg-row {
  display: flex;
  animation: synvertixMsgFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.synvertix-msg-row.user {
  align-self: flex-end;
  max-width: 86%;
  justify-content: flex-end;
}

.synvertix-msg-row.assistant {
  align-self: flex-start;
  max-width: 94%;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* Assistant Diamond Avatar next to bubble */
.synvertix-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(245, 130, 13, 0.15);
  border: 1px solid rgba(245, 130, 13, 0.3);
  color: #F5820D;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.synvertix-msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.synvertix-msg-bubble {
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  border-radius: 14px;
}

.synvertix-msg-row.user .synvertix-msg-bubble {
  background: linear-gradient(135deg, rgba(245, 130, 13, 0.95) 0%, rgba(217, 98, 0, 0.95) 100%);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 16px rgba(245, 130, 13, 0.3);
}

.synvertix-msg-row.assistant .synvertix-msg-bubble {
  background: #1E293B;
  color: #E2E8F0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top-left-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Markdown Formatting Inside Assistant Bubble */
.synvertix-msg-bubble p { margin: 0 0 8px 0; }
.synvertix-msg-bubble p:last-child { margin-bottom: 0; }
.synvertix-msg-bubble strong { color: #FFFFFF; font-weight: 700; }
.synvertix-msg-bubble ul, .synvertix-msg-bubble ol { margin: 6px 0; padding-left: 18px; }
.synvertix-msg-bubble li { margin-bottom: 4px; }
.synvertix-msg-bubble a { color: #38BDF8; text-decoration: underline; text-underline-offset: 2px; }
.synvertix-msg-bubble a:hover { color: #F5820D; }

/* 7. Icon-Only Action Row (Copy / 👍 / 👎) */
.synvertix-msg-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  margin-left: 2px;
}

.synvertix-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94A3B8;
  cursor: pointer;
  transition: all 0.2s ease;
}

.synvertix-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
  transform: translateY(-1px);
}

.synvertix-action-btn:active {
  transform: translateY(0);
}

.synvertix-action-btn.copied {
  background: rgba(34, 197, 94, 0.2);
  color: #4ADE80;
  border-color: rgba(34, 197, 94, 0.4);
}

.synvertix-action-btn.active {
  background: rgba(245, 130, 13, 0.2);
  color: #F5820D;
  border-color: rgba(245, 130, 13, 0.4);
}

.synvertix-fb-thanks {
  font-size: 0.72rem;
  color: #22C55E;
  font-weight: 500;
  margin-left: 4px;
  animation: synvertixFadeIn 0.2s ease;
}

/* 8. Custom Redesigned Offline State Card */
.synvertix-offline-card {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(245, 130, 13, 0.3);
  border-radius: 14px;
  padding: 14px;
  margin-top: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.synvertix-offline-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: #F5820D;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(245, 130, 13, 0.12);
  padding: 2px 7px;
  border-radius: 6px;
}

.synvertix-offline-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFFFFF;
  margin: 6px 0 4px 0;
}

.synvertix-offline-desc {
  font-size: 0.82rem;
  color: #CBD5E1;
  margin-bottom: 12px;
  line-height: 1.4;
}

.synvertix-offline-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.synvertix-offline-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.synvertix-offline-btn.primary {
  background: linear-gradient(135deg, #F5820D 0%, #E06D00 100%);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(245, 130, 13, 0.3);
}

.synvertix-offline-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.synvertix-offline-btn.outline {
  background: transparent;
  color: #F5820D;
  border: 1px solid rgba(245, 130, 13, 0.4);
}

.synvertix-offline-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

/* 9. Wave Typing Indicator Animation */
.synvertix-typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: #1E293B;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  border-top-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.synvertix-typing-dot {
  width: 7px;
  height: 7px;
  background-color: #F5820D;
  border-radius: 50%;
  animation: synvertixWave 1.2s infinite ease-in-out;
}

.synvertix-typing-dot:nth-child(1) { animation-delay: 0s; }
.synvertix-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.synvertix-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* 10. Suggested Questions Chips Strip (2-Column Grid Pinned Above Input) */
.synvertix-chips-wrapper {
  flex-shrink: 0;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(10px);
}

.synvertix-chip-btn {
  background: rgba(255, 255, 255, 0.05);
  color: #CBD5E1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 7px 8px;
  border-radius: 18px;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  white-space: normal;
  line-height: 1.3;
  word-break: break-word;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.synvertix-chip-btn:hover {
  background: rgba(245, 130, 13, 0.18);
  border-color: #F5820D;
  color: #FFFFFF;
  transform: translateY(-1px);
  box-shadow: 0 0 12px rgba(245, 130, 13, 0.25);
}

.synvertix-chip-btn:active {
  transform: translateY(0);
}

/* 11. Integrated Chat Input Area (Flex Row with Separated Send Button) */
.synvertix-chat-input-area {
  flex-shrink: 0;
  padding: 10px 12px 14px 12px;
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.synvertix-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.synvertix-input-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 4px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.synvertix-input-box:focus-within {
  border-color: #F5820D;
  box-shadow: 0 0 0 3px rgba(245, 130, 13, 0.25);
  background: rgba(30, 41, 59, 0.95);
}

.synvertix-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  color: #FFFFFF;
  font-size: 0.88rem;
  outline: none;
  padding: 7px 0;
}

.synvertix-chat-input::placeholder {
  color: #64748B;
}

.synvertix-send-btn {
  background: linear-gradient(135deg, #F5820D 0%, #E06D00 100%);
  color: #FFFFFF;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px rgba(245, 130, 13, 0.35);
}

.synvertix-send-btn:hover:not(:disabled) {
  transform: scale(1.06) translateY(-1px);
  box-shadow: 0 6px 18px rgba(245, 130, 13, 0.5);
}

.synvertix-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.synvertix-send-btn:disabled {
  background: #334155;
  color: #64748B;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 12. Mobile & Tablet Responsive Rules */

/* xs (360–479px) and sm (480–767px) -> Content-Aware Mobile Sheet */
@media (max-width: 767px) {
  .synvertix-chat-trigger {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 56px;
    height: 56px;
  }

  /* --- Modal: height is auto up to 92vh, NOT a fixed 92vh ---
     This lets early-conversation state (1 message + chips) be compact
     instead of filling the whole screen with empty space. Once messages
     grow, it expands up to the 92vh cap and the scroll container kicks in. */
  .synvertix-chat-modal {
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    width: 100vw;
    max-width: 100vw;
    /* Use min-height so it's never too tiny, max-height caps it */
    height: auto;
    min-height: 340px;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    /* Flex column: drag handle + header on top, input pinned at bottom,
       middle zone (messages + chips) takes only what it needs */
    justify-content: flex-start;
  }

  .synvertix-chat-modal.open {
    transform: translateY(0);
  }

  .synvertix-drag-handle-bar {
    display: flex;
    justify-content: center;
    padding: 10px 0 2px 0;
    background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
    flex-shrink: 0;
  }

  .synvertix-drag-handle {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
  }

  /* --- Messages area: shrinks to content, scrolls only when tall ---
     Max-height is capped at ~50vh so a long conversation triggers
     internal scroll while early-state keeps it short. flex: 0 1 auto
     means: don't grow beyond content size, but DO shrink if needed. */
  .synvertix-chat-messages {
    flex: 0 1 auto;
    max-height: 52vh;
    overflow-y: auto;
    padding: 14px 12px 8px 12px;
    gap: 12px;
  }

  /* --- Chips: single column, snug below messages ---
     Remove the excessive top padding so chips feel like a natural
     continuation of the conversation, not a separate bottom zone. */
  .synvertix-chips-wrapper {
    flex-shrink: 0;
    grid-template-columns: 1fr;
    padding: 6px 10px 8px 10px;
    gap: 5px;
  }

  /* Input bar: pinned at the very bottom, safe-area aware */
  .synvertix-chat-input-area {
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .synvertix-chat-input {
    font-size: 16px !important;
  }

  .synvertix-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* md (768–1023px) -> Floating Card Dialog Transition */
@media (min-width: 768px) and (max-width: 1023px) {
  .synvertix-chat-modal {
    bottom: 84px;
    right: 20px;
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 100px));
    border-radius: 16px;
  }
}

/* iOS Safe Area Padding */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .synvertix-chat-trigger {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }

  @media (max-width: 767px) {
    .synvertix-chat-trigger {
      bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }
}

/* 13. Accessibility & Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .synvertix-chat-modal,
  .synvertix-chat-trigger,
  .synvertix-msg-row,
  .synvertix-typing-dot,
  .synvertix-chip-btn,
  .synvertix-action-btn,
  .synvertix-trigger-icon {
    animation: none !important;
    transition: opacity 0.15s ease !important;
    transform: none !important;
  }

  .synvertix-chat-modal {
    transform: none !important;
  }

  .synvertix-chat-modal.open {
    transform: none !important;
  }
}
