/* =========================================================
   InheritixAI Chatbot v3.1 — Messenger-style
   inheritixai.com
========================================================= */

#ixc-root, #ixc-root *, #ixc-root *::before, #ixc-root *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-font-smoothing: antialiased;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

#ixc-root {
  --hfrom:  #7c3aed;
  --hto:    #4f46e5;
  --htext:  #ffffff;
  --bg:     #f0f2f5;
  --ubg:    #7c3aed;
  --utxt:   #ffffff;
  --bbg:    #ffffff;
  --btxt:   #050505;
  --sbtn:   #7c3aed;
  --stxt:   #ffffff;
  --ibg:    #ffffff;
  --toggle: #7c3aed;
  --tico:   #ffffff;
}

/* ── Floating Toggle Button ───────────────────────────── */
#ixc-toggle {
  position: fixed;
  bottom: 24px;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--toggle);
  color: var(--tico);
  display: flex; align-items: center; justify-content: center;
  z-index: 2147483646;
  box-shadow: 0 4px 20px rgba(0,0,0,0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}
#ixc-toggle.pos-right { right: 20px; }
#ixc-toggle.pos-left  { left:  20px; }
#ixc-toggle:hover     { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.35); }
#ixc-toggle:active    { transform: scale(0.93); }

#ixc-toggle::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--toggle);
  opacity: 0;
  animation: ixcPulse 2.6s ease-out infinite;
  z-index: -1;
}
#ixc-toggle.open::before { animation: none; opacity: 0; }
@keyframes ixcPulse {
  0%   { transform: scale(1);   opacity: 0.5; }
  100% { transform: scale(1.9); opacity: 0; }
}

#ixc-toggle .ixc-ico {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
#ixc-toggle .ixc-ico-chat  { opacity: 1; transform: scale(1) rotate(0deg); }
#ixc-toggle .ixc-ico-close { opacity: 0; transform: scale(0.3) rotate(-90deg); }
#ixc-toggle.open .ixc-ico-chat  { opacity: 0; transform: scale(0.3) rotate(90deg); }
#ixc-toggle.open .ixc-ico-close { opacity: 1; transform: scale(1) rotate(0deg); }

#ixc-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px;
  background: #e41e3f; color: #fff;
  border-radius: 10px; font-size: 11px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

/* ── Chat Window ──────────────────────────────────────── */
#ixc-window {
  position: fixed;
  bottom: 96px;
  width: 370px; height: 560px;
  border-radius: 20px;
  background: var(--bg);
  box-shadow: 0 12px 48px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.1);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: 2147483645;
  transform: scale(0.88) translateY(20px);
  opacity: 0; pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.22s ease;
}
#ixc-window.pos-right { right: 20px; transform-origin: bottom right; }
#ixc-window.pos-left  { left:  20px; transform-origin: bottom left; }
#ixc-window.open      { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }

/* ── Header ───────────────────────────────────────────── */
#ixc-header {
  background: linear-gradient(135deg, var(--hfrom) 0%, var(--hto) 100%);
  color: var(--htext);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
#ixc-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
#ixc-hinfo    { flex: 1; min-width: 0; }
#ixc-bot-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ixc-status   { font-size: 12px; opacity: 0.82; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
#ixc-status-dot {
  width: 7px; height: 7px; background: #4ade80;
  border-radius: 50%; flex-shrink: 0;
  animation: ixcBlink 2s ease-in-out infinite;
}
@keyframes ixcBlink { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Messages ─────────────────────────────────────────── */
#ixc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#ixc-messages::-webkit-scrollbar       { width: 3px; }
#ixc-messages::-webkit-scrollbar-track { background: transparent; }
#ixc-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.ixc-date-sep {
  text-align: center; font-size: 11px; color: #65676b;
  margin: 8px 0; display: flex; align-items: center; gap: 8px;
}
.ixc-date-sep::before,.ixc-date-sep::after {
  content:''; flex:1; height:1px; background:rgba(0,0,0,0.1);
}

/* ── Message Row ──────────────────────────────────────────
   STRUCTURE (Messenger-accurate):
   
   BOT:
     <div class="ixc-row bot">
       <div class="ixc-row-avatar">🤖</div>
       <div class="ixc-col">          ← inline-flex, shrinks to bubble
         <div class="ixc-bubble">text</div>
         <div class="ixc-time">09:32</div>
       </div>
     </div>
   
   USER:
     <div class="ixc-row user">
       <div class="ixc-col">          ← same, aligned right
         <div class="ixc-bubble">text</div>
         <div class="ixc-time">09:32</div>
       </div>
     </div>
──────────────────────────────────────────────────────── */

.ixc-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 5px;
  animation: ixcSlide 0.18s ease;
}
@keyframes ixcSlide {
  from { opacity:0; transform:translateY(8px); }
  to   { opacity:1; transform:translateY(0); }
}
.ixc-row.bot  { justify-content: flex-start; flex-direction: row; }
.ixc-row.user { justify-content: flex-end;   flex-direction: row; }

.ixc-row-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--hfrom), var(--hto));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
  align-self: flex-end;
}

/* THIS is the key — inline-flex column that shrinks to text width */
.ixc-col {
  display: inline-flex;
  flex-direction: column;
  max-width: 75%;
  min-width: 0;
  width: fit-content;
}
.ixc-row.bot  .ixc-col { align-items: flex-start; }
.ixc-row.user .ixc-col { align-items: flex-end; }

.ixc-bubble {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 10px 10px !important;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.ixc-row.bot .ixc-bubble {
  background: var(--bbg);
  color: var(--btxt);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.ixc-row.user .ixc-bubble {
  background: var(--ubg);
  color: var(--utxt);
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.18);
}

.ixc-time {
  font-size: 10px; color: #65676b;
  margin-top: 3px; padding: 0 3px;
  white-space: nowrap;
}

/* ── Typing indicator ─────────────────────────────────── */
#ixc-typing {
  display: none;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 5px;
}
.ixc-typing-bub {
  background: var(--bbg);
  border-radius: 18px 18px 18px 4px;
  padding: 12px 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: flex; gap: 5px; align-items: center;
}
.ixc-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b0b3b8;
  animation: ixcDot 1.3s ease-in-out infinite;
}
.ixc-dot:nth-child(2) { animation-delay: 0.18s; }
.ixc-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes ixcDot {
  0%,60%,100% { transform:translateY(0); opacity:0.4; }
  30%         { transform:translateY(-5px); opacity:1; }
}

/* ── Input Bar ────────────────────────────────────────── */
#ixc-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px 10px;
  background: var(--bg);
  border-top: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}
#ixc-input {
  flex: 1;
  background: var(--ibg);
  border: none; border-radius: 22px;
  padding: 10px 16px;
  font-size: 15px; line-height: 1.45;
  color: var(--btxt);
  outline: none; resize: none;
  min-height: 40px; max-height: 120px;
  -webkit-appearance: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
#ixc-input::placeholder { color: #8a8d91; }
#ixc-send {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 50%; border: none; cursor: pointer;
  background: var(--sbtn); color: var(--stxt);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; outline: none;
  transition: transform 0.15s, opacity 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  -webkit-tap-highlight-color: transparent;
}
#ixc-send:hover  { transform: scale(1.08); }
#ixc-send:active { transform: scale(0.92); }
#ixc-send:disabled { opacity: 0.38; cursor: not-allowed; transform: none; }

/* ── Footer ───────────────────────────────────────────── */
#ixc-footer {
  padding: 5px 14px 7px;
  text-align: center; font-size: 11px; color: #8a8d91;
  background: var(--bg); flex-shrink: 0;
}
#ixc-footer a { color: var(--hfrom); text-decoration: none; font-weight: 600; }

/* =========================================================
   MOBILE — Messenger layout (≤ 500px)
   Chat fills screen EXCEPT 90px at bottom for X button
   X button floats below the chat window, bottom-left
========================================================= */
@media (max-width: 500px) {

  /* X / open button — always at bottom-left, below the chat */
  #ixc-toggle {
    width: 54px !important;
    height: 54px !important;
    bottom: 20px !important;
    left: 20px !important;
    right: auto !important;
    z-index: 2147483647 !important;
  }

  /* Chat window — top to 90px above bottom, rounded bottom corners */
  #ixc-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 90px !important;
    width: 100vw !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 0 20px 20px !important;
    transform-origin: top center !important;
    transform: translateY(-105%) !important;
  }
  #ixc-window.open { transform: translateY(0) !important; }

  #ixc-header {
    padding: 16px 16px 14px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
  #ixc-avatar   { width: 42px; height: 42px; font-size: 21px; }
  #ixc-bot-name { font-size: 16px; }

  .ixc-bubble { font-size: 16px; }
  .ixc-col    { max-width: 80%; }

  #ixc-input-bar {
    padding: 8px 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  #ixc-input { font-size: 16px; min-height: 44px; }
  #ixc-send  { width: 44px; height: 44px; min-width: 44px; }
  #ixc-footer { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 500px) and (orientation: landscape) {
  #ixc-header { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top,0px)); }
  #ixc-avatar { width: 32px; height: 32px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #ixc-toggle::before, #ixc-status-dot, .ixc-dot, .ixc-row { animation: none; }
}
