/*!
  © 2025 Nicolas Payen / HEA World project.
  Proprietary and confidential — unauthorized use prohibited.
*/
/* 📦 HEA Chat Stylesheet – hea-world.com/hea_chat_engine/styles/hea_chat_styles.css 
   stored as /public/hea_chat_engine/styles/hea_chat_styles.css
   Notes:
   - Uses site tokens: --surface, --surface-2, --line, --user-bubble, --agent-bubble
   - No global html,body layout overrides (scoped to [data-mode] only)
   - Dark mode supports html.dark, :root.dark, and body.dark
*/

/* ======================
   Container / Frame
   ====================== */

/* Base chatbox frame, neutral */
.chatbox {
  display: flex;
  flex-direction: column;
  font-family: 'Inter', sans-serif;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface, #fff);
  box-shadow: 0 12px 24px rgba(0,0,0,.2);
  border: 1px solid var(--line, #eee);
}

/* === POPUP ONLY (chatbox fills the iframe) === */
[data-mode="popup"] html,
[data-mode="popup"] body { 
  min-height: 640px;
  height: 100%;
}

@media (max-width: 768px) {
  [data-mode="popup"] html,
  [data-mode="popup"] body {
    min-height: 560px;
  }
}

[data-mode="popup"] #hea-chat-container {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

[data-mode="popup"] .chatbox {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  min-height: 0;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0,0,0,.2);
  border: 1px solid var(--line, #eee);
}

/* === EMBED + FULLPAGE share “fill available space” === */
/* Avoid global html,body rules; scope to data-mode host */
body[data-mode] { min-height: 100%; }

[data-mode="embed"] main,
[data-mode="fullpage"] main {
  display: flex;
  flex: 1 1 auto;
  padding: 0;
  align-items: stretch;
}

[data-mode="embed"] #hea-chat-container,
[data-mode="fullpage"] #hea-chat-container {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

[data-mode="embed"] .chatbox,
[data-mode="fullpage"] .chatbox {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 0;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
  border: 0;
}

/* messages area flexes properly */
[data-mode="embed"] .chat-messages,
[data-mode="fullpage"] .chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* input sticks to bottom */
[data-mode="embed"] .chat-input-area,
[data-mode="fullpage"] .chat-input-area {
  position: sticky;
  bottom: 0;
  background: var(--surface, #fff);
  border-top: 1px solid var(--line, #eee);
}

/* Remove content caps in EMBED + FULLPAGE */
[data-mode="embed"] #hea-chat-container .chat-message,
[data-mode="embed"] #hea-chat-container .user-message,
[data-mode="embed"] #hea-chat-container .bot-message,
[data-mode="embed"] #hea-chat-container .cta-wrapper {
  max-width: 100% !important;
}

/* Keep caps for POPUP readability + general cap var */
:root { --chat-max-message-width: 560px; }

[data-mode="popup"] #hea-chat-container .chat-message,
[data-mode="popup"] #hea-chat-container .user-message,
[data-mode="popup"] #hea-chat-container .bot-message,
[data-mode="popup"] #hea-chat-container .cta-wrapper {
  max-width: min(var(--chat-max-message-width), 92%);
}

/* Inline marketing page: hide chat header */
body[data-mode="inline"] #hea-chat-container .chat-header {
  display: none !important;
}

[data-mode="popup"] #hea-chat-container .cta-video {
  max-width: min(var(--chat-max-message-width), 92%);
}

/* Optional: keep nice rounded top even without header */
body[data-mode="inline"] #hea-chat-container .chatbox {
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.chromeless #hea-chat-container .chat-header { display: none !important; }

/* Apply caps to messages & CTAs when chat is inline/fullpage */
body[data-mode="inline"] #hea-chat-container .chat-message,
body[data-mode="inline"] #hea-chat-container .user-message,
body[data-mode="inline"] #hea-chat-container .bot-message,
body[data-mode="inline"] #hea-chat-container .cta-wrapper,
body[data-mode="fullpage"] #hea-chat-container .chat-message,
body[data-mode="fullpage"] #hea-chat-container .user-message,
body[data-mode="fullpage"] #hea-chat-container .bot-message,
body[data-mode="fullpage"] #hea-chat-container .cta-wrapper {
  max-width: min(var(--chat-max-message-width), 100%) !important;
  align-self: flex-start;
}

/* make sure the CTA card itself doesn’t stretch past the cap */
#hea-chat-container .cta-wrapper .cta-card {
  width: min(var(--chat-max-message-width), 100%);
}

/* belt & suspenders on media sizing */
#hea-chat-container .cta-wrapper .cta-card-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;        /* reserve space to prevent CLS */
  object-fit: cover;
  max-height: clamp(180px, 32vh, 380px);
}

/* ======================
   Header / Controls
   ====================== */

.chat-header {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: linear-gradient(90deg, var(--brand1, #ff5f6d), var(--brand2, #ffc371));
  color: #fff;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Optional: hide scrollbar from dropdown initially */
.hea-dropdown.hidden {
  display: none;
}

.chat-title {
  font-weight: 600;
  color: #fff;
  font-size: 1rem;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 0.75rem;
  background: #fff;
  border: 2px solid #fff;
}

.chat-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface, #fff);
}

/* ======================
   Messages / Input
   ====================== */

.chat-messages {
  display: flex;  
  flex-direction: column;
  flex: 1 1 auto;
  overflow-y: auto;
  margin: 0;
  padding: 1rem;
  border-top: 1px solid var(--line, #eee);
  border-bottom: 1px solid var(--line, #eee);
  background: var(--surface-2, #fafafa);
  font-size: 0.95rem;
  line-height: 1.4;
}

.chat-input-area {
  display: flex;
  flex: 0 0 auto;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface, #fff);
  border-top: 1px solid var(--line, #eee);
}

/* Input area inner */
.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface, #fff);
}

#user-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid color-mix(in oklab, var(--line, #ccc) 80%, #000);
  font-size: 0.95rem;
  resize: vertical;
  height: 40px;
  background: var(--surface, #fff);
  color: var(--ink, #000);
}

#send-button {
  padding: 0.5rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  align-self: flex-end;
  height: 40px;
  background: var(--btn-bg, #f18f01);
  border: 1px solid var(--btn-border, #d7263d);
  color: #fff;
}

#send-button:hover {
  opacity: 0.9;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.user-message,
.bot-message {
  margin: 0.3rem 0;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  max-width: 90%;
  white-space: pre-wrap;
}

.user-message {
  background: var(--user-bubble, #e6f7ff);
  color: var(--user-text, #000);
  align-self: flex-end;
}

.bot-message {
  background: var(--agent-bubble, #f5f5f5);
  color: var(--agent-text, inherit);
  align-self: flex-start;
}

.user-message.bot.thinking em {
  color: #999;
  font-style: italic;
}

/* ======================
   Popup Controls
   ====================== */

#maximize-chat,
#minimize-chat,
#close-chat {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.2rem;
  padding-left: 6px;
}

.hea-chat-menu { position: relative; }

.hea-dropdown {
  position: absolute;
  top: 2.2rem;
  right: 0;
  min-width: 160px;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #ccc);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 0.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.hea-dropdown a {
  text-decoration: none;
  color: var(--ink, #333);
  font-size: 0.85rem;
  padding: 2px 0;
}

.hea-dropdown .hea-powered {
  font-size: 0.75rem;
  color: var(--muted, #666);
}

.hea-dropdown label.hea-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

/* Hidden utility class */
.hidden { display: none !important; }

/* ======================
   CTAs section (cards)
   ====================== */

.cta-container {
  margin-top: 8px;
  margin: 0.5rem 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.cta-card-img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.cta-card {
  margin: 1rem 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.2s;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #eee);
}

.cta-card:hover { transform: scale(1.02); }

.cta-button {
  background-color: #f85f73;
  border: none;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.cta-button:hover { background-color: #e24a5c; }

/* ---- CTA sizing & layout ---- */
#hea-chat-container .chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start; /* keep bubbles/CTAs from stretching full-width */
}

/* CTA card: block-level, rounded, overflow clipped (scoped) */
#hea-chat-container .cta-wrapper .cta-card {
  display: block;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface, #fff);
  box-shadow: 0 6px 18px rgba(0,0,0,.06);
  border: 1px solid var(--line, #eee);
}

/* Image: responsive, reserved aspect-ratio to avoid CLS */
#hea-chat-container .cta-wrapper .cta-card-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  max-height: clamp(180px, 32vh, 380px);
}

/* Text content under the image */
#hea-chat-container .cta-wrapper .cta-card-content {
  padding: 12px 14px;
  font-size: 0.95rem;
  line-height: 1.35;
}

/* If chat is in transparent/dark, soften card bg automatically */
body.dark #hea-chat-container .cta-wrapper .cta-card,
html.dark #hea-chat-container .cta-wrapper .cta-card,
:root.dark #hea-chat-container .cta-wrapper .cta-card {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
}

/* ======================
   Responsive
   ====================== */
@media (max-width: 768px) {
  #chat-popup {
    width: 100vw;
    height: 90vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    max-height: unset;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 560px;
  }

  .chatbox {
    height: 100%;
    flex-direction: column;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 70px; /* for space below messages */
  }

  .chat-input {
    position: fixed;
    bottom: 0;
    width: 100%;
  }
}

/* ======================
   CTAs: videos (responsive)
   ====================== */
#hea-chat-container .cta-video {
  width: 100%;
  margin: 1rem 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #eee);
  box-shadow: 0 6px 18px rgba(0,0,0,.06);
}

#hea-chat-container .cta-video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  max-height: var(--cta-video-max-h, 260px);
}

#hea-chat-container .cta-video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

#hea-chat-container .cta-video-caption {
  padding: 8px 12px;
  font-weight: 600;
  font-size: .95rem;
}

#hea-chat-container .cta-video small.muted {
  display: block;
  padding: 0 12px 12px;
  font-size: .8rem;
  color: var(--muted, #777);
}

/* Dark/transparent modes for video too */
body.dark #hea-chat-container .cta-video,
html.dark #hea-chat-container .cta-video,
:root.dark #hea-chat-container .cta-video {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
}

/* ======================
   Global sizing vars (tweak here only)
   ====================== */
:root{
  --chat-max-message-width: 560px;   /* max width of any bubble/card */
  --cta-img-max-h-mobile: 180px;     /* mobile image cap */
  --cta-img-max-h-desktop: 220px;    /* desktop/tablet image cap */
  --cta-video-max-h: 260px;          /* video frame cap */
}

/* Keep bubbles/CTAs from stretching full-width (defensive duplicate, scoped) */
#hea-chat-container .chat-messages{
  display:flex;
  flex-direction:column;
  gap:12px;
  align-items:flex-start;
}

/* === Popup fill chain fixes (append at end) === */
[data-mode="popup"] #hea-chat-container{
  display:flex;               /* already set, keep here to override if needed */
  flex-direction:column;
  height:100%;                /* <- critical: container fills iframe */
  min-height:0;
}

[data-mode="popup"] .chatbox{
  display:flex;
  flex-direction:column;
  height:100%;                /* <- critical: chatbox fills container */
  max-height:none;
  min-height:0;
}

[data-mode="popup"] .chat-messages{
  flex:1 1 auto;              /* <- critical: messages area expands */
  min-height:0;               /* allow proper overflow calc */
  overflow-y:auto;
}

/* Avoid the mobile rule that fixes the input to the viewport in popup mode */
@media (max-width: 768px){
  body:not([data-mode="popup"]) .chat-input{
    position:fixed;
    bottom:0;
    width:100%;
  }
}