/* ============================================================
   CHAT WIDGET - V2-Pre branded, mobile responsive
   Bubble FAB + slide-up panel
   Connects to V1 backend via Socket.io
   ============================================================ */

.ftx-chat {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9998;
  font-family: var(--font-body, Inter, system-ui, sans-serif);
}

/* ============================================================
   BUBBLE FAB
   ============================================================ */
.ftx-chat-bubble {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #047857);
  border: none;
  box-shadow: 0 8px 24px -6px rgba(16, 185, 129, 0.55), 0 4px 12px rgba(0,0,0,0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}

.ftx-chat-bubble:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 32px -8px rgba(16, 185, 129, 0.7), 0 6px 16px rgba(0,0,0,0.15);
}

.ftx-chat-bubble:active {
  transform: translateY(0) scale(1);
}

.ftx-chat-bubble-icon {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ftx-chat-bubble .ftx-icon-chat { opacity: 1; transform: scale(1) rotate(0deg); }
.ftx-chat-bubble .ftx-icon-x { opacity: 0; transform: scale(0.5) rotate(-90deg); }

.ftx-chat.is-open .ftx-chat-bubble .ftx-icon-chat { opacity: 0; transform: scale(0.5) rotate(90deg); }
.ftx-chat.is-open .ftx-chat-bubble .ftx-icon-x { opacity: 1; transform: scale(1) rotate(0deg); }

/* Pulse ring on bubble */
.ftx-chat-bubble-pulse {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid #10b981;
  opacity: 0;
  animation: ftx-chat-pulse 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes ftx-chat-pulse {
  0% { transform: scale(0.85); opacity: 0.55; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

.ftx-chat.is-open .ftx-chat-bubble-pulse { display: none; }

/* ============================================================
   PANEL
   ============================================================ */
.ftx-chat-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: 600px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 60px -12px rgba(0,0,0,0.22), 0 8px 24px -6px rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.06);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.ftx-chat.is-open .ftx-chat-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   HEADER
   ============================================================ */
.ftx-chat-header {
  background: linear-gradient(135deg, #047857, #10b981);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  flex-shrink: 0;
}

.ftx-chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ftx-chat-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ftx-chat-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4ade80;
  border: 2px solid #047857;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5);
  animation: ftx-status-pulse 2s ease-out infinite;
}

@keyframes ftx-status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  50% { box-shadow: 0 0 0 5px rgba(74, 222, 128, 0); }
}

.ftx-chat-header-text { min-width: 0; }

.ftx-chat-title {
  font-family: var(--font-display, Outfit, sans-serif);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.ftx-chat-subtitle {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 2px;
}

.ftx-chat-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.ftx-chat-close:hover { background: rgba(255,255,255,0.22); }

/* ============================================================
   BODY (form OR conversation)
   ============================================================ */
.ftx-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: #f9fafb;
}

.ftx-chat-greeting {
  background: linear-gradient(135deg, #ecfdf5, white);
  border-left: 3px solid #10b981;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
}

.ftx-chat-greet-line {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: #171717;
}

.ftx-chat-greet-line strong {
  font-weight: 700;
  color: #047857;
}

/* ============================================================
   FORM
   ============================================================ */
.ftx-chat-field {
  margin-bottom: 12px;
}

.ftx-chat-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #404040;
  margin-bottom: 5px;
}

.ftx-chat-optional {
  color: #737373;
  font-weight: 400;
}

.ftx-chat-field input,
.ftx-chat-field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: white;
  color: #171717;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.ftx-chat-field input:focus,
.ftx-chat-field textarea:focus {
  outline: none;
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}

.ftx-chat-field textarea {
  resize: vertical;
  min-height: 56px;
}

.ftx-chat-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.5;
  color: #525252;
  margin-bottom: 14px;
  cursor: pointer;
}

.ftx-chat-consent input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: #10b981;
}

.ftx-chat-consent a {
  color: #047857;
  font-weight: 600;
  text-decoration: underline;
}

.ftx-chat-consent a:hover { color: #10b981; }

.ftx-chat-required { color: #dc2626; font-weight: 700; }

.ftx-chat-error {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.ftx-chat-error.is-visible { display: block; }

.ftx-chat-submit {
  width: 100%;
  padding: 11px 14px;
  background: linear-gradient(135deg, #10b981, #047857);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-display, Outfit, sans-serif);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ftx-chat-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -4px rgba(16,185,129,0.5);
}

.ftx-chat-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ftx-chat-submit-spinner {
  display: none;
  animation: ftx-spin 0.8s linear infinite;
}

.ftx-chat-submit.is-loading .ftx-chat-submit-label { display: none; }
.ftx-chat-submit.is-loading .ftx-chat-submit-spinner { display: block; }

@keyframes ftx-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   CONVERSATION VIEW
   ============================================================ */
.ftx-chat-conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ftx-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ftx-msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  animation: ftx-msg-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ftx-msg.is-visitor {
  align-self: flex-end;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 10px -2px rgba(16,185,129,0.35);
}

.ftx-msg.is-agent {
  align-self: flex-start;
  background: white;
  color: #171717;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px -2px rgba(0,0,0,0.08);
  border: 1px solid #f1f1f1;
}

.ftx-msg.is-system {
  align-self: center;
  background: rgba(16,185,129,0.08);
  color: #047857;
  font-size: 11.5px;
  font-style: italic;
  padding: 5px 11px;
  border-radius: 8px;
  max-width: 90%;
}

.ftx-msg-name {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 3px;
  opacity: 0.7;
}

@keyframes ftx-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.ftx-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 13px;
  background: white;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  border: 1px solid #f1f1f1;
}

.ftx-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  animation: ftx-typing-dot 1.2s ease-in-out infinite;
}

.ftx-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ftx-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ftx-typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================================================
   FOOTER (input bar)
   ============================================================ */
.ftx-chat-footer {
  flex-shrink: 0;
  padding: 12px;
  border-top: 1px solid #e5e5e5;
  background: white;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ftx-chat-footer input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid #e5e5e5;
  border-radius: 22px;
  font-size: 13.5px;
  font-family: inherit;
  background: #f9fafb;
  color: #171717;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ftx-chat-footer input:focus {
  outline: none;
  border-color: #10b981;
  background: white;
}

.ftx-chat-footer button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #10b981, #047857);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ftx-chat-footer button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 14px -3px rgba(16,185,129,0.5);
}

.ftx-chat-footer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   BRANDING STRIP
   ============================================================ */
.ftx-chat-branding {
  font-size: 10.5px;
  color: #a3a3a3;
  text-align: center;
  padding: 6px 8px 8px;
  background: white;
  border-top: 1px solid #f1f1f1;
}

.ftx-chat-branding a {
  color: #10b981;
  font-weight: 600;
  text-decoration: none;
}

/* ============================================================
   MOBILE - full screen on small viewports
   ============================================================ */
@media (max-width: 480px) {
  .ftx-chat {
    bottom: 16px;
    right: 16px;
  }

  .ftx-chat-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }

  .ftx-chat.is-open .ftx-chat-bubble {
    /* Keep bubble visible but in corner */
    z-index: 10000;
  }
}
