/* ===================================================================
   EIF chat assistant widget
   Uses the site's own design tokens, so it stays in step with the theme.
   =================================================================== */

/* ---------- launcher ---------- */
.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 180;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 20px 13px 16px;
  border: 0;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--accent-500), var(--brand-500));
  color: var(--on-accent);
  font-size: .92rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  box-shadow: 0 10px 34px -10px var(--accent-glow), 0 2px 10px rgba(var(--shadow-rgb), .4);
  cursor: pointer;
  transition: transform .35s var(--ease), box-shadow .35s var(--ease), opacity .3s var(--ease);
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 42px -10px var(--accent-glow); }
.chat-fab svg { flex: none; }

/* a soft pulse so it is noticed once, without nagging */
.chat-fab::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: chatPulse 3.4s ease-out 2s 3;
  pointer-events: none;
}
@keyframes chatPulse {
  0%   { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .55); }
  70%  { box-shadow: 0 0 0 18px rgba(var(--accent-rgb), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); }
}

.chat-open .chat-fab { opacity: 0; pointer-events: none; transform: scale(.9); }

/* ---------- panel ---------- */
.chat-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 190;
  width: min(410px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 44px));
  height: min(620px, calc(100svh - 44px));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: linear-gradient(170deg, var(--panel-a), var(--panel-b));
  border: 1px solid var(--border);
  box-shadow: 0 34px 90px -28px rgba(var(--shadow-rgb), .95);
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .34s var(--ease), transform .34s var(--ease), visibility .34s;
  overflow: hidden;
}
.chat-panel.is-open { opacity: 1; visibility: visible; transform: none; }

.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(var(--tint-rgb), .02);
}
.chat-avatar {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(var(--accent-rgb), .22), rgba(var(--brand-rgb), .14));
  border: 1px solid rgba(var(--accent-rgb), .3);
  color: var(--accent-400);
}
.chat-head-txt { min-width: 0; flex: 1; }
.chat-head-txt b { display: block; font-size: .95rem; letter-spacing: -0.015em; }
.chat-head-txt span {
  display: flex; align-items: center; gap: 6px;
  font-size: .74rem; color: var(--muted);
}
.chat-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgb(var(--ok-rgb));
  box-shadow: 0 0 0 0 rgba(var(--ok-rgb), .5);
  animation: pulseDot 2.4s infinite;
}
.chat-x {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: background .25s, color .25s, transform .25s var(--ease);
}
.chat-x:hover { background: var(--surface-2); color: var(--text); transform: rotate(90deg); }

/* ---------- messages ---------- */
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

.chat-msg { display: flex; gap: 9px; max-width: 100%; animation: chatIn .32s var(--ease) both; }
@keyframes chatIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chat-msg--me { justify-content: flex-end; }
.chat-bubble {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: .89rem;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg--me .chat-bubble {
  background: linear-gradient(135deg, var(--accent-500), var(--brand-500));
  color: var(--on-accent);
  border-bottom-right-radius: 5px;
  font-weight: 500;
}
.chat-msg--bot .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-bottom-left-radius: 5px;
}
.chat-bubble strong { color: var(--text); font-weight: 650; }
.chat-bubble ul { margin: 8px 0 0; padding-left: 1.1em; }
.chat-bubble li { margin-bottom: 5px; }
.chat-bubble a { color: var(--accent-400); text-decoration: underline; }

.chat-bot-ico {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-400);
  align-self: flex-start;
}

/* typing indicator */
.chat-typing { display: flex; gap: 4px; padding: 13px 15px; }
.chat-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-400);
  animation: chatBounce 1.3s ease-in-out infinite;
}
.chat-typing i:nth-child(2) { animation-delay: .18s; }
.chat-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- what follows an answer ----------
   Links and chips live inside the scrolling conversation, lined up under
   the bot's message. They used to sit in a fixed bar between the log and
   the composer, where they took a slice of the panel for themselves and
   left the reply in a thin scrolling strip. */
.chat-after {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: -2px 0 0 37px;      /* 28px avatar + 9px gap: aligns with the bubble */
  animation: chatIn .32s var(--ease) both;
}

.chat-links { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chat-links-label {
  flex-basis: 100%;
  font-size: .7rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1px;
}
.chat-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px 7px 13px;
  border-radius: 99px;
  background: linear-gradient(135deg, rgba(var(--accent-rgb), .14), rgba(var(--brand-rgb), .1));
  border: 1px solid rgba(var(--accent-rgb), .34);
  color: var(--accent-400);
  font-size: .78rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color .25s var(--ease), background .25s, transform .25s var(--ease);
}
.chat-link:hover {
  background: linear-gradient(135deg, rgba(var(--accent-rgb), .24), rgba(var(--brand-rgb), .16));
  border-color: var(--accent-500);
  color: var(--text);
  transform: translateY(-1px);
}
.chat-link svg { flex: none; transition: transform .25s var(--ease); }
.chat-link:hover svg { transform: translateX(2px); }

/* ---------- suggestion chips ---------- */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-chip {
  padding: 7px 12px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: .78rem;
  cursor: pointer;
  text-align: left;
  transition: border-color .25s var(--ease), color .25s, background .25s;
}
.chat-chip:hover {
  border-color: var(--accent-500);
  color: var(--text);
  background: var(--surface-2);
}

/* ---------- composer ---------- */
.chat-form {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: rgba(var(--tint-rgb), .02);
}
.chat-form textarea {
  flex: 1;
  min-height: 42px;
  max-height: 110px;
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(var(--bg-rgb), .6);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: .89rem;
  line-height: 1.45;
  resize: none;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.chat-form textarea:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .14);
}
.chat-form textarea::placeholder { color: var(--placeholder); }
.chat-send {
  flex: none;
  width: 42px; height: 42px;
  align-self: flex-end;
  display: grid; place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-500), var(--brand-500));
  color: var(--on-accent);
  cursor: pointer;
  transition: transform .25s var(--ease), opacity .25s;
}
.chat-send:hover:not(:disabled) { transform: translateY(-1px); }
.chat-send:disabled { opacity: .4; cursor: default; }

.chat-note {
  flex: none;
  padding: 0 16px 11px;
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .chat-fab { right: 14px; bottom: 14px; padding: 12px 17px 12px 14px; font-size: .86rem; }
  .chat-panel {
    right: 0; bottom: 0; left: 0;
    width: 100%;
    height: 100vh;
    height: 100svh;
    max-height: none;
    border-radius: 0;
    border-left: 0; border-right: 0; border-bottom: 0;
  }
  .chat-bubble { max-width: 88%; }
}

/* text direction follows the text, so Arabic reads correctly without the
   widget itself moving */
html[lang="ar"] .chat-bubble,
html[lang="ar"] .chat-head-txt,
html[lang="ar"] .chat-chip { letter-spacing: 0; }

@media (prefers-reduced-motion: reduce) {
  .chat-fab::after { animation: none; }
}

/* iPhones with a notch or Dynamic Island, and the home indicator: the
   launcher and the full-screen panel keep clear of them. */
@supports (padding: max(0px)) {
  .chat-fab {
    right: max(22px, calc(env(safe-area-inset-right) + 12px));
    bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  }
  @media (max-width: 560px) {
    .chat-fab {
      right: max(14px, calc(env(safe-area-inset-right) + 8px));
      bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px));
    }
    .chat-panel { padding-bottom: env(safe-area-inset-bottom); }
  }
}


/* ---------- Arabic ----------
   The launcher and the panel are pinned to the right-hand edge. On a
   right-to-left page that is the side the reader starts from, and it is
   also where the event tab now sits, so they swap over. */
html[dir="rtl"] .chat-fab,
html[dir="rtl"] .chat-launcher,
html[dir="rtl"] .chat-panel {
  right: auto;
  left: max(22px, calc(env(safe-area-inset-left) + 12px));
}

@media (max-width: 560px) {
  html[dir="rtl"] .chat-fab {
    right: auto;
    left: max(14px, calc(env(safe-area-inset-left) + 8px));
  }
  /* Full width on a phone, so there is no side to pin it to. */
  html[dir="rtl"] .chat-panel { left: 0; right: 0; }
}

/* A bulleted list indents from the side the text starts on. */
html[dir="rtl"] .chat-bubble ul { padding-left: 0; padding-right: 1.1em; }
