/* ============================================================
   Clubforce Demo Agent – Chat Interface
   Layout: full-width 16:9 demo pane + fixed chat overlay
   ============================================================ */

:root {
  --cfd-navy:    #181075;
  --cfd-blue:    #2050ce;
  --cfd-white:   #ffffff;
  --cfd-surface: #f0f2fa;
  --cfd-border:  #dde1f0;
  --cfd-muted:   #6b7280;
  --cfd-cyan:    #40ffd3;
  --cfd-radius:  12px;
}

/* ── Demo pane: full-width 16:9 ───────────────────────────── */

#cfd-wrapper {
  width: 100%;
  aspect-ratio: 16 / 9;
  position: relative;
  font-family: 'Red Hat Display', system-ui, sans-serif;
  background: var(--cfd-surface);
  border: 1.5px solid var(--cfd-border);
  border-radius: var(--cfd-radius);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(24, 16, 117, 0.07);
}

#cfd-demo-pane {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cfd-demo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  text-align: center;
  padding: 2rem 2.5rem;
  color: var(--cfd-muted);
  font-family: 'Red Hat Display', system-ui, sans-serif;
  max-width: 560px;
}

#cfd-demo-placeholder svg { width: 52px; height: auto; opacity: 0.5; }
#cfd-demo-placeholder > p { font-size: 0.92rem; max-width: 360px; margin: 0; line-height: 1.55; }

#cfd-storylane {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  position: absolute;
  inset: 0;
}

.cfd-storylane-flash {
  animation: cfd-storylane-appear 0.4s ease;
}

/* ── Demo history bar ─────────────────────────────────────── */

#cfd-demo-history {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 0;
  font-family: 'Red Hat Display', system-ui, sans-serif;
}

.cfd-history-item {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.8rem;
  background: var(--cfd-white);
  border: 1.5px solid var(--cfd-border);
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cfd-navy);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cfd-history-item:hover {
  border-color: var(--cfd-blue);
  background: var(--cfd-lavender);
}
.cfd-history-item.cfd-history-active {
  border-color: var(--cfd-blue);
  background: var(--cfd-blue);
  color: var(--cfd-white);
}

/* ── Storylane nav (inside placeholder) ───────────────────── */

#cfd-storylane-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.cfd-nav-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 1rem 0.42rem 0.7rem;
  background: var(--cfd-white);
  border: 1.5px solid var(--cfd-border);
  border-radius: 24px;
  cursor: pointer;
  font-family: 'Red Hat Display', system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--cfd-navy);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(24,16,117,0.07);
}
.cfd-nav-item:hover {
  border-color: var(--cfd-blue);
  background: var(--cfd-lavender);
}
.cfd-nav-item.cfd-nav-active {
  border-color: var(--cfd-blue);
  background: var(--cfd-blue);
  color: var(--cfd-white);
}

.cfd-nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.cfd-nav-icon svg {
  width: 18px;
  height: 18px;
  min-width: 18px;
  display: block;
  overflow: visible;
}
.cfd-nav-item.cfd-nav-active .cfd-nav-icon svg {
  filter: brightness(0) invert(1);
}

/* ── Chat overlay: fixed bottom-right ─────────────────────── */

#cfd-chat-pane {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 360px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: var(--cfd-white);
  border: 1.5px solid var(--cfd-border);
  border-radius: var(--cfd-radius);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(24, 16, 117, 0.2);
  font-family: 'Red Hat Display', system-ui, sans-serif;
}

/* ── Chat header ──────────────────────────────────────────── */

#cfd-chat-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  background: var(--cfd-navy);
  color: var(--cfd-white);
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.cfd-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--cfd-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  color: var(--cfd-white);
  border: 2px solid rgba(255,255,255,0.2);
}
.cfd-avatar::after { content: 'CF'; }

.cfd-agent-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.cfd-agent-info strong { font-size: 0.9rem; font-weight: 700; }

.cfd-online-badge {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--cfd-cyan);
  display: flex;
  align-items: center;
  gap: 4px;
}
.cfd-online-badge::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cfd-cyan);
  animation: cfd-pulse 2s infinite;
}

/* Header action buttons */

.cfd-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#cfd-reset {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: rgba(255,255,255,0.8);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 9px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
#cfd-reset:hover { background: rgba(255,255,255,0.2); color: #fff; }

#cfd-minimise {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
}
#cfd-minimise:hover { background: rgba(255,255,255,0.22); }

#cfd-chevron {
  transition: transform 0.22s ease;
}

/* ── Minimised state ──────────────────────────────────────── */

#cfd-chat-pane.cfd-minimised #cfd-chat-body {
  display: none;
}

#cfd-chat-pane.cfd-minimised #cfd-chat-header {
  border-radius: calc(var(--cfd-radius) - 1px);
}

#cfd-chat-pane.cfd-minimised #cfd-chevron {
  transform: rotate(180deg);
}

/* ── Intake form (in demo pane) ───────────────────────────── */

#cfd-intake-form {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cfd-white);
  overflow-y: auto;
  padding: 2rem 1.5rem;
}

.cfd-intake-inner {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.cfd-intake-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
}

.cfd-intake-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--cfd-navy);
  color: var(--cfd-white);
  font-size: 0.85rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.cfd-intake-brand h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--cfd-navy);
  line-height: 1.2;
}

.cfd-intake-brand p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--cfd-muted);
  line-height: 1.5;
}

#cfd-prechat-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.cfd-prechat-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cfd-prechat-field label {
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--cfd-navy);
  letter-spacing: 0.02em;
}

.cfd-prechat-field input {
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--cfd-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--cfd-navy);
  background: var(--cfd-surface);
  transition: border-color 0.15s, background 0.15s;
}
.cfd-prechat-field input:focus {
  outline: none;
  border-color: var(--cfd-blue);
  background: var(--cfd-white);
}
.cfd-prechat-field input.cfd-field-error {
  border-color: #dc2626;
  background: #fff5f5;
}
.cfd-prechat-field input.cfd-field-error:focus {
  border-color: #dc2626;
}

.cfd-prechat-submit {
  margin-top: 0.25rem;
  padding: 0.75rem 1rem;
  background: var(--cfd-blue);
  color: var(--cfd-white);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.15s;
}
.cfd-prechat-submit:hover { background: var(--cfd-navy); }

.cfd-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  cursor: pointer;
}
.cfd-consent-label.cfd-field-error .cfd-consent-text {
  color: #dc2626;
}
.cfd-consent-label.cfd-field-error input[type="checkbox"] {
  outline: 2px solid #dc2626;
  outline-offset: 1px;
  border-radius: 2px;
}
.cfd-consent-sorry {
  display: none;
  font-size: 0.75rem;
  color: #dc2626;
  margin-top: 0.2rem;
}
.cfd-consent-label.cfd-field-error ~ .cfd-consent-sorry {
  display: block;
}
.cfd-consent-label input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--cfd-blue);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
.cfd-consent-label span {
  font-size: 0.78rem;
  color: var(--cfd-muted);
  line-height: 1.5;
}

.cfd-recaptcha-widget {
  margin-top: 0.75rem;
  transform-origin: left top;
}

.cfd-recaptcha-error {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: #c0392b;
}

.cfd-prechat-error {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #c0392b;
  min-height: 1.2em;
}

/* ── Chat body (collapsible) ──────────────────────────────── */

#cfd-chat-body {
  display: flex;
  flex-direction: column;
  height: 540px;
}

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

#cfd-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

#cfd-messages::-webkit-scrollbar { width: 3px; }
#cfd-messages::-webkit-scrollbar-track { background: transparent; }
#cfd-messages::-webkit-scrollbar-thumb { background: var(--cfd-border); border-radius: 2px; }

.cfd-message {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  animation: cfd-fade-in 0.2s ease;
}
.cfd-message-agent { justify-content: flex-start; }
.cfd-message-user  { justify-content: flex-end; }

.cfd-msg-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--cfd-navy);
  color: var(--cfd-white);
  font-size: 0.58rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.cfd-bubble {
  max-width: 82%;
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
}

.cfd-bubble p           { margin: 0 0 0.3em; }
.cfd-bubble p:last-child { margin-bottom: 0; }
.cfd-bubble strong      { font-weight: 700; }
.cfd-bubble em          { font-style: italic; }
.cfd-bubble ul {
  margin: 0.25em 0 0.2em;
  padding-left: 1.15em;
}
.cfd-bubble ul li { margin-bottom: 0.18em; line-height: 1.5; }
.cfd-bubble ul li:last-child { margin-bottom: 0; }


.cfd-retry-btn {
  margin-top: 0.5rem;
  display: inline-block;
  padding: 5px 14px;
  background: var(--cfd-blue);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.cfd-retry-btn:hover { background: var(--cfd-navy); }

.cfd-message-agent .cfd-bubble {
  background: var(--cfd-surface);
  color: var(--cfd-navy);
  border-bottom-left-radius: 4px;
}
.cfd-message-user .cfd-bubble {
  background: var(--cfd-blue);
  color: var(--cfd-white);
  border-bottom-right-radius: 4px;
}

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

#cfd-typing {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 0.4rem 1rem 0.45rem;
  flex-shrink: 0;
}
.cfd-typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cfd-muted);
  animation: cfd-bounce 1.2s infinite ease-in-out;
  display: inline-block;
}
.cfd-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.cfd-typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.cfd-typing-indicator span:nth-child(3) { animation-delay: 0.36s; }

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

#cfd-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem;
  border-top: 1.5px solid var(--cfd-border);
  background: var(--cfd-white);
  flex-shrink: 0;
}

#cfd-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--cfd-border);
  border-radius: 20px;
  padding: 0.5rem 0.85rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--cfd-navy);
  background: var(--cfd-surface);
  transition: border-color 0.15s;
  line-height: 1.45;
  max-height: 100px;
  overflow-y: auto;
}
#cfd-input:focus { outline: none; border-color: var(--cfd-blue); background: var(--cfd-white); }
#cfd-input:disabled { opacity: 0.5; cursor: not-allowed; }

#cfd-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--cfd-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  padding: 0;
}
#cfd-send:hover  { background: var(--cfd-navy); }
#cfd-send:active { transform: scale(0.9); }
#cfd-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#cfd-send svg { width: 15px; height: 15px; stroke: var(--cfd-white); }

/* ── Animations ───────────────────────────────────────────── */

@keyframes cfd-fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes cfd-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}
@keyframes cfd-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}
@keyframes cfd-storylane-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@media (max-width: 600px) {
  /* Remove 16:9 constraint so the wrapper grows tall enough for the intake
     form to be fully visible without internal scrolling */
  #cfd-wrapper {
    aspect-ratio: unset;
    min-height: 85dvh;
  }

  /* Align form content to the top so it doesn't get clipped on short screens */
  #cfd-intake-form {
    align-items: flex-start;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    overflow-y: visible;
  }

  /* Pull chat pane out of fixed positioning so it sits in normal document
     flow after the wrapper and can't overlap the footer */
  #cfd-chat-pane {
    position: relative;
    bottom: auto;
    right: auto;
    left: auto;
    width: 100%;
    margin-top: 1rem;
    border-radius: var(--cfd-radius);
  }

  #cfd-chat-body { height: 420px; }
}
