/*
 * Adviser Connect — Conversational Funnel
 * chat.css  v4.0.0
 *
 * Design intent: premium, soft, British financial services feel.
 * Inherits body font. Uses CSS custom properties for easy theming.
 */

/* ── Custom properties ────────────────────────────────────────────────────── */

:root {
  --ac-radius:       14px;
  --ac-radius-sm:    8px;
  --ac-accent:       #1a4f7a;        /* Deep navy — confidence */
  --ac-accent-mid:   #2567a0;        /* Mid blue — interactive */
  --ac-accent-light: #e8f1f8;        /* Pale blue — bot bubbles */
  --ac-user-bg:      #1a4f7a;        /* User bubble bg */
  --ac-user-text:    #ffffff;
  --ac-bot-text:     #1a1a2e;
  --ac-chip-border:  #c4d6e8;
  --ac-chip-hover:   #dceef9;
  --ac-chip-sel-bg:  #1a4f7a;
  --ac-chip-sel-txt: #ffffff;
  --ac-surface:      #ffffff;
  --ac-border:       #e0e8f0;
  --ac-muted:        #6b7a8d;
  --ac-error:        #c0392b;
  --ac-success:      #1e8449;
  --ac-shadow:       0 4px 32px rgba(26, 79, 122, 0.10), 0 1px 6px rgba(0,0,0,0.06);
  --ac-font:         inherit;
  --ac-font-size:    15px;
  --ac-line-height:  1.6;
}

/* ── Root container ───────────────────────────────────────────────────────── */

.ac-chat-root {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0;
  font-family: var(--ac-font);
  font-size: var(--ac-font-size);
  line-height: var(--ac-line-height);
  color: var(--ac-bot-text);
  -webkit-font-smoothing: antialiased;
}

.ac-chat-inner {
  background: var(--ac-surface);
  border-radius: var(--ac-radius);
  box-shadow: var(--ac-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.ac-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  background: var(--ac-accent);
  color: #fff;
  flex-shrink: 0;
}

.ac-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.ac-header-icon {
  display: flex;
  align-items: center;
  opacity: 0.9;
}

.ac-trust-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  opacity: 0.75;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* ── Messages area ────────────────────────────────────────────────────────── */

.ac-chat-messages {
  flex: 1;
  padding: 24px 22px 12px;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 260px;
  max-height: 520px;
}

/* Custom scrollbar */
.ac-chat-messages::-webkit-scrollbar { width: 4px; }
.ac-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ac-chat-messages::-webkit-scrollbar-thumb { background: var(--ac-border); border-radius: 4px; }

/* ── Message wrappers ─────────────────────────────────────────────────────── */

.ac-msg {
  display: flex;
  animation: acFadeUp 0.25s ease both;
}

.ac-msg-bot  { justify-content: flex-start; }
.ac-msg-user { justify-content: flex-end; }

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

/* ── Bubbles ──────────────────────────────────────────────────────────────── */

.ac-bubble {
  max-width: 82%;
  padding: 11px 16px;
  border-radius: var(--ac-radius);
  font-size: var(--ac-font-size);
  line-height: var(--ac-line-height);
}

.ac-msg-bot .ac-bubble {
  background: var(--ac-accent-light);
  color: var(--ac-bot-text);
  border-bottom-left-radius: 4px;
}

.ac-msg-user .ac-bubble {
  background: var(--ac-user-bg);
  color: var(--ac-user-text);
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ─────────────────────────────────────────────────────── */

.ac-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  min-width: 56px;
}

.ac-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ac-accent);
  opacity: 0.4;
  display: inline-block;
  animation: acTyping 1.2s infinite ease-in-out;
}

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

@keyframes acTyping {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.9); }
  40%            { opacity: 1;   transform: scale(1.1); }
}

/* ── Input area ───────────────────────────────────────────────────────────── */

.ac-chat-input-area {
  padding: 12px 22px 20px;
  border-top: 1px solid var(--ac-border);
  background: var(--ac-surface);
  flex-shrink: 0;
}

/* ── Chip buttons ─────────────────────────────────────────────────────────── */

.ac-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.ac-chip {
  padding: 9px 16px;
  border-radius: 24px;
  border: 1.5px solid var(--ac-chip-border);
  background: #fff;
  color: var(--ac-accent);
  font-size: 14px;
  font-family: var(--ac-font);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  line-height: 1.3;
}

.ac-chip:hover:not(:disabled) {
  background: var(--ac-chip-hover);
  border-color: var(--ac-accent-mid);
  box-shadow: 0 2px 8px rgba(26,79,122,0.10);
}

.ac-chip:focus-visible {
  outline: 2px solid var(--ac-accent-mid);
  outline-offset: 2px;
}

.ac-chip-selected {
  background: var(--ac-chip-sel-bg) !important;
  border-color: var(--ac-chip-sel-bg) !important;
  color: var(--ac-chip-sel-txt) !important;
}

.ac-chip:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* ── Confirm button (multi-select) ────────────────────────────────────────── */

.ac-confirm-btn {
  display: block;
  margin-top: 10px;
  padding: 11px 28px;
  background: var(--ac-accent);
  color: #fff;
  border: none;
  border-radius: var(--ac-radius-sm);
  font-size: 14.5px;
  font-family: var(--ac-font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.01em;
}

.ac-confirm-btn:hover:not(:disabled) {
  background: var(--ac-accent-mid);
  box-shadow: 0 2px 12px rgba(26,79,122,0.20);
}

.ac-confirm-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Text input ───────────────────────────────────────────────────────────── */

.ac-text-input-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ac-text-input {
  flex: 1;
  padding: 11px 15px;
  border: 1.5px solid var(--ac-chip-border);
  border-radius: var(--ac-radius-sm);
  font-size: var(--ac-font-size);
  font-family: var(--ac-font);
  color: var(--ac-bot-text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
}

.ac-text-input::placeholder {
  color: #b0bcc9;
}

.ac-text-input:focus {
  border-color: var(--ac-accent-mid);
  box-shadow: 0 0 0 3px rgba(37,103,160,0.12);
}

.ac-text-input:disabled {
  opacity: 0.5;
  background: #f5f7fa;
}

.ac-send-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ac-accent);
  color: #fff;
  border: none;
  border-radius: var(--ac-radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

.ac-send-btn:hover:not(:disabled) {
  background: var(--ac-accent-mid);
}

.ac-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Validation error ─────────────────────────────────────────────────────── */

.ac-input-error {
  display: none;
  font-size: 13px;
  color: var(--ac-error);
  margin-top: 6px;
  padding-left: 2px;
}

/* ── Calendly container ───────────────────────────────────────────────────── */

.ac-calendly-container {
  border-top: 1px solid var(--ac-border);
  background: #fafcff;
  padding: 20px 22px;
}

.ac-calendly-header {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ac-accent);
  margin-bottom: 14px;
  letter-spacing: 0.01em;
}

.ac-calendly-iframe {
  width: 100%;
  min-height: 620px;
  border: none;
  border-radius: var(--ac-radius-sm);
  overflow: hidden;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .ac-chat-root {
    max-width: 100%;
    /* Push the whole widget up so the site footer doesn't cover the input */
    padding-bottom: 80px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  .ac-chat-inner {
    border-radius: 0;
    box-shadow: none;
    min-height: 100%;
  }

  .ac-chat-messages {
    padding: 16px 14px 8px;
    max-height: none;
    /* Ensure auto-scroll doesn't land under the footer */
    scroll-padding-bottom: 100px;
  }

  .ac-chat-input-area {
    padding: 10px 14px 16px;
    /* Not sticky on mobile — sticky causes it to sit on top of the site footer
       and get covered. Let it flow naturally; the root padding-bottom provides clearance. */
    position: static;
    background: var(--ac-surface);
    border-top: 1px solid var(--ac-border);
  }

  .ac-bubble {
    max-width: 92%;
    padding: 10px 14px;
  }

  .ac-chip {
    font-size: 13.5px;
    padding: 8px 14px;
  }

  .ac-calendly-container {
    padding: 14px;
  }

  .ac-calendly-iframe {
    min-height: 500px;
  }
}

@media (max-width: 380px) {
  .ac-chips { gap: 6px; }
  .ac-chip  { font-size: 13px; padding: 7px 12px; }
}

/* ── Consent block ────────────────────────────────────────────────────────── */

.ac-consent-wrap {
  margin-top: 4px;
}

.ac-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 12px;
}

.ac-consent-cb {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--ac-accent);
  cursor: pointer;
}

.ac-consent-label span {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ac-muted);
}

.ac-consent-link {
  color: var(--ac-accent-mid);
  text-decoration: underline;
}

.ac-consent-link:hover {
  color: var(--ac-accent);
}

.ac-consent-btn {
  width: 100%;
  text-align: center;
}
