/* ============================================
   FIT ASSISTANT — Chat Widget Styles
   ============================================ */

/* Collapsed bar at bottom */
.fa-bar {
  position: fixed;
  bottom: 0;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0;
  right: 0;
  z-index: 2500;
  background: linear-gradient(135deg, #1e2a3a 0%, #252a38 50%, #1e2a3a 100%);
  border-top: 2px solid rgba(0, 212, 255, 0.3);
  border-left: none;
  padding: 18px 16px;
  cursor: pointer;
  display: none; /* Hidden until auth ready */
  transition: transform 0.2s ease, box-shadow 0.3s ease;
  box-shadow: 0 -4px 24px rgba(0, 212, 255, 0.12);
  animation: fa-bar-glow-once 2s ease-in-out 0.5s 1;
}
.fa-bar:hover {
  background: linear-gradient(135deg, #1e2a3a 0%, #252a38 50%, #1e2a3a 100%);
  box-shadow: 0 -4px 32px rgba(0, 212, 255, 0.22);
}
.fa-bar-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.fa-bar-icon {
  font-size: 24px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.5));
}
.fa-bar-text {
  text-align: center;
}
.fa-bar-title {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.2px;
}
.fa-bar-subtitle {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* One-time glow pulse on first load */
@keyframes fa-bar-glow-once {
  0%   { box-shadow: 0 -4px 24px rgba(0, 212, 255, 0.12); }
  50%  { box-shadow: 0 -4px 40px rgba(0, 212, 255, 0.35); }
  100% { box-shadow: 0 -4px 24px rgba(0, 212, 255, 0.12); }
}
.fa-bar-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  flex-shrink: 0;
}
.fa-bar-badge.free {
  background: rgba(0, 200, 100, 0.15);
  color: var(--green, #00c864);
}
.fa-bar-badge.credits {
  background: rgba(0, 212, 255, 0.15);
  color: var(--cyan, #00d4ff);
}

/* Half-sheet overlay */
.fa-overlay {
  position: fixed;
  inset: 0;
  z-index: 2600;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.fa-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Half-sheet drawer */
.fa-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2700;
  max-height: 75vh;
  max-height: 75dvh;
  min-height: 300px;
  background: var(--bg-main, #1a1d29);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
}
.fa-drawer.open {
  transform: translateY(0);
}

/* Drag handle */
.fa-handle {
  text-align: center;
  padding: 10px 0 4px;
  cursor: grab;
  flex-shrink: 0;
}
.fa-handle-bar {
  width: 40px;
  height: 4px;
  background: var(--border-light, rgba(255,255,255,0.2));
  border-radius: 2px;
  margin: 0 auto;
}

/* Header */
.fa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 10px;
  border-bottom: 1px solid var(--border-light, rgba(255,255,255,0.1));
  flex-shrink: 0;
}
.fa-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fa-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #fff);
}
.fa-header-mode {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 8px;
  font-weight: 600;
}
.fa-header-mode.help {
  background: rgba(0, 200, 100, 0.15);
  color: var(--green, #00c864);
}
.fa-header-mode.fit {
  background: rgba(0, 212, 255, 0.15);
  color: var(--cyan, #00d4ff);
}
.fa-close-btn {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.fa-close-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary, #fff);
}

/* Mode switcher (in chat view) */
.fa-mode-switcher {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-light, rgba(255,255,255,0.05));
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.fa-switcher-current {
  color: var(--text-secondary, #aaa);
}
.fa-switcher-link {
  color: var(--cyan, #00d4ff);
  text-decoration: none;
  white-space: nowrap;
}
.fa-switcher-link:hover {
  text-decoration: underline;
}

/* Question counter */
.fa-counter {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border-light, rgba(255,255,255,0.05));
  flex-shrink: 0;
}
.fa-counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 4px;
}
.fa-counter-bar {
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.fa-counter-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--cyan, #00d4ff);
  transition: width 0.3s ease;
}
.fa-counter-fill.warn {
  background: var(--yellow, #ffb400);
}
.fa-counter-fill.danger {
  background: var(--red, #ff6464);
}

/* Body area — holds either menu or messages */
.fa-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.fa-body::-webkit-scrollbar {
  width: 5px;
}
.fa-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
}

/* ============================================
   MODE SELECTION MENU
   ============================================ */

.fa-menu {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

/* Mode cards */
.fa-mode-card {
  border: 1px solid var(--border-light, rgba(255,255,255,0.1));
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.fa-mode-card:hover {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.03);
}

/* Help card — subtle */
.fa-mode-card.help {
  border-color: rgba(255,255,255,0.08);
}
.fa-mode-card.help:hover {
  border-color: rgba(0, 200, 100, 0.3);
}

/* Consultation card — premium */
.fa-mode-card.consultation {
  border-color: rgba(0, 212, 255, 0.2);
  background: rgba(0, 212, 255, 0.03);
}
.fa-mode-card.consultation:hover {
  border-color: rgba(0, 212, 255, 0.4);
  background: rgba(0, 212, 255, 0.06);
}

/* Active consultation card */
.fa-mode-card.consultation.active {
  border-color: rgba(0, 212, 255, 0.35);
  background: rgba(0, 212, 255, 0.06);
}

.fa-mode-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.fa-mode-card-icon {
  font-size: 18px;
  flex-shrink: 0;
}
.fa-mode-card-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #fff);
  flex: 1;
}
.fa-mode-card-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  flex-shrink: 0;
}
.fa-mode-card-badge.free {
  background: rgba(0, 200, 100, 0.15);
  color: var(--green, #00c864);
}
.fa-mode-card-badge.credits {
  background: rgba(0, 212, 255, 0.15);
  color: var(--cyan, #00d4ff);
}

.fa-mode-card-body {
  margin-bottom: 12px;
}
.fa-mode-card-body p {
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  line-height: 1.5;
  margin: 0 0 6px;
}
.fa-mode-card-body p:last-child {
  margin-bottom: 0;
}
.fa-mode-card-body .fa-mode-card-detail {
  font-size: 12px;
  color: var(--text-muted, #888);
  margin-top: 4px;
}

.fa-mode-card-btn {
  width: 100%;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   MESSAGES AREA (chat view)
   ============================================ */

.fa-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fa-messages::-webkit-scrollbar {
  width: 5px;
}
.fa-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
}

/* Welcome / start screen */
.fa-welcome {
  text-align: center;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.fa-welcome-icon {
  font-size: 36px;
}
.fa-welcome-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #fff);
}
.fa-welcome-desc {
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  line-height: 1.5;
  max-width: 320px;
}
.fa-welcome-cost {
  font-size: 12px;
  color: var(--text-muted, #888);
  display: flex;
  gap: 12px;
}

/* Message bubbles */
.fa-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
}
.fa-msg.user {
  align-self: flex-end;
  background: var(--cyan, #00d4ff);
  color: #0d0f14;
  border-bottom-right-radius: 4px;
}
.fa-msg.assistant {
  align-self: flex-start;
  background: var(--bg-card, #252a38);
  color: var(--text-primary, #fff);
  border-bottom-left-radius: 4px;
}
.fa-msg.assistant strong,
.fa-msg.assistant b {
  color: var(--cyan, #00d4ff);
}
.fa-msg.error {
  align-self: center;
  background: rgba(255, 100, 100, 0.12);
  color: var(--red, #ff6464);
  font-size: 12px;
  text-align: center;
}

/* Typing indicator */
.fa-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-card, #252a38);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.fa-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted, #888);
  border-radius: 50%;
  animation: fa-bounce 1.2s infinite;
}
.fa-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.fa-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes fa-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Suggestions */
.fa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
  flex-shrink: 0;
}
.fa-suggestion {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.2);
  color: var(--cyan, #00d4ff);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.fa-suggestion:hover {
  background: rgba(0, 212, 255, 0.2);
}

/* Extend CTA */
.fa-extend {
  text-align: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border-light, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.fa-extend-text {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 8px;
}
.fa-extend-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.fa-extend-buy {
  margin-top: 10px;
}
.fa-extend-buy-link {
  color: var(--cyan, #00d4ff);
  font-size: 13px;
  text-decoration: none;
}
.fa-extend-buy-link:hover {
  text-decoration: underline;
}

/* Credits needed CTA (inline in messages) */
.fa-credits-cta {
  align-self: center;
  text-align: center;
  padding: 16px 20px;
  margin: 4px 0;
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 14px;
  max-width: 85%;
}
.fa-credits-cta-text {
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 12px;
  line-height: 1.4;
}
.fa-credits-cta-btn {
  font-size: 14px;
  padding: 10px 24px;
}

/* Input area */
.fa-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-light, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.fa-input {
  flex: 1;
  background: var(--bg-input, rgba(0,0,0,0.3));
  border: 1px solid var(--border-light, rgba(255,255,255,0.1));
  border-radius: 20px;
  padding: 9px 16px;
  color: var(--text-primary, #fff);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 80px;
  font-family: inherit;
}
.fa-input::placeholder {
  color: var(--text-dim, #666);
}
.fa-input:focus {
  border-color: var(--cyan, #00d4ff);
}
.fa-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cyan, #00d4ff);
  border: none;
  color: #0d0f14;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.fa-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Shared button styles */
.fa-btn {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}
.fa-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.fa-btn-primary {
  background: var(--cyan, #00d4ff);
  color: #0d0f14;
}
.fa-btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary, #fff);
  border: 1px solid var(--border-light, rgba(255,255,255,0.12));
}
.fa-btn-secondary:hover {
  background: rgba(255,255,255,0.12);
}
.fa-btn-ghost {
  background: transparent;
  border: 1px solid var(--border-light, rgba(255,255,255,0.15));
  color: var(--text-secondary, #aaa);
}

/* Hide bar when drawer is open */
.fa-bar.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

/* ============================================
   MOBILE RESPONSIVE — Fix 2, 3, 7, 8, 10, 11
   ============================================ */

/*
 * Fix 3: z-index notes
 * .fa-bar = 2500, .fa-overlay = 2600, .fa-drawer = 2700
 * .modal-overlay (styles.css) = 3000 — intentionally above FA (modals should cover chat)
 * No conflicting non-modal elements found at z-index >= 2500
 */

@media (max-width: 768px) {
  /* Fix 2: FA bar — full width, appropriate mobile sizing */
  .fa-bar {
    padding: 14px 12px;
  }
  .fa-bar-title {
    font-size: 16px;
  }
  .fa-bar-subtitle {
    font-size: 12px;
  }

  /* Fix 2 + 8: Drawer — full width on mobile */
  .fa-drawer {
    width: 100vw;
    max-width: 100%;
    left: 0;
    right: 0;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    max-height: 85vh;
    max-height: 85dvh;
  }

  /* Fix 2: Header */
  .fa-header {
    padding: 4px 12px 8px;
  }
  .fa-header-title {
    font-size: 16px;
  }

  /* Fix 7: Close button — minimum 44px touch target */
  .fa-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Fix 2: Messages area — mobile-friendly padding */
  .fa-messages {
    padding: 10px 12px;
    gap: 10px;
  }

  /* Fix 10: Message font sizes for mobile readability */
  .fa-msg {
    font-size: 15px;
    line-height: 1.5;
    max-width: 90%;
    padding: 10px 12px;
  }
  .fa-msg.error {
    font-size: 13px;
  }
  .fa-welcome-title {
    font-size: 17px;
  }
  .fa-welcome-desc {
    font-size: 14px;
    max-width: 100%;
  }
  .fa-welcome-cost {
    font-size: 13px;
  }

  /* Fix 10: Counter and mode switcher text */
  .fa-counter-row {
    font-size: 12px;
  }
  .fa-mode-switcher {
    font-size: 12px;
    padding: 8px 12px;
  }

  /* Fix 2: Menu cards — mobile-friendly padding */
  .fa-menu {
    padding: 12px;
  }
  .fa-mode-card {
    padding: 14px;
  }
  .fa-mode-card-body p {
    font-size: 14px;
  }

  /* Fix 2: Input area — full width, mobile-friendly */
  .fa-input-area {
    padding: 8px 12px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .fa-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 10px 14px;
  }

  /* Fix 7: Send button — 44px touch target */
  .fa-send-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  /* Fix 11: Suggestions — wrap and gap */
  .fa-suggestions {
    padding: 0 12px 8px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .fa-suggestion {
    font-size: 13px;
    padding: 8px 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    white-space: normal;
    max-width: 100%;
  }

  /* Fix 7: Mode card buttons — 44px touch target */
  .fa-mode-card-btn {
    min-height: 44px;
  }
  .fa-btn {
    min-height: 44px;
    padding: 10px 18px;
  }

  /* Fix 10: Credits CTA */
  .fa-credits-cta {
    max-width: 95%;
  }
  .fa-credits-cta-text {
    font-size: 14px;
  }

  /* Fix 2: Extend CTA */
  .fa-extend-actions {
    flex-direction: column;
    gap: 10px;
  }
}

/* ── Affiliate Links ────────────────────────────────────────────────────── */

.fa-affiliate-block {
  padding: 4px 12px 8px;
}

.fa-affiliate-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.fa-affiliate-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted, #aaa);
  border: 1px solid rgba(255, 255, 255, 0.10);
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}

.fa-affiliate-btn:hover {
  background: rgba(0, 212, 255, 0.12);
  color: var(--cyan, #00d4ff);
  border-color: rgba(0, 212, 255, 0.3);
}

.fa-affiliate-disclosure {
  font-size: 11px;
  color: var(--text-muted, #666);
  margin: 4px 0 0;
  line-height: 1.4;
}

/* ── Search Then Link — Opt-in CTA ────────────────────────────────────── */

.fa-shop-cta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 8px;
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.15);
}
.fa-shop-cta-text {
  font-size: 13px;
  color: var(--text-muted, #aaa);
  flex: 1;
}
.fa-shop-cta-btn {
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(0, 212, 255, 0.3);
  background: rgba(0, 212, 255, 0.10);
  color: var(--cyan, #00d4ff);
  transition: background 0.2s;
  white-space: nowrap;
}
.fa-shop-cta-btn:hover:not(:disabled) {
  background: rgba(0, 212, 255, 0.20);
}
.fa-shop-cta-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ── Product Cards ─────────────────────────────────────────────────────── */

.fa-product-cards {
  padding: 4px 0 8px;
}
.fa-product-card {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 8px;
  overflow: hidden;
}
.fa-product-card-header {
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #eee);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}
.fa-product-card-kind {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 212, 255, 0.10);
  color: var(--cyan, #00d4ff);
}
.fa-retailer-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  text-decoration: none;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.2s;
}
.fa-retailer-link:hover {
  background: rgba(0, 212, 255, 0.06);
}
.fa-retailer-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--cyan, #00d4ff);
}
.fa-retailer-cta {
  font-size: 12px;
  color: var(--text-muted, #aaa);
}
.fa-shop-no-results {
  font-size: 12px;
  color: var(--text-muted, #888);
  padding: 6px 12px;
  font-style: italic;
}
