/* InfrasofTech AI Assistant — floating widget. Fully scoped under .ist-chat /
   #istChatbot so it cannot be affected by, or bleed into, either the legacy
   theme (public/assets/css/main.css) or the landing page's own styles. */
#istChatbot {
  --ist-blue: #1769ff;
  --ist-blue-dark: #0b4fd6;
  --ist-teal: #0e8a72;
  --ist-ink: #0b1530;
  --ist-text: #44506a;
  --ist-line: #e4eaf3;
  --ist-bg: #f6f9ff;
  --ist-radius: 18px;
  /* the site's own "back to top" button (#backTop / #lpBackTop) sits at
     right:22px / bottom:24px and is 42-46px tall — this is the single
     place both the toggle button and the mobile window read from so they
     always clear it, at every breakpoint, without drifting out of sync. */
  --ist-fab-size: 46px;
  --ist-fab-right: max(22px, env(safe-area-inset-right, 0px));
  --ist-fab-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  --ist-fab-offset: calc(var(--ist-fab-bottom) + var(--ist-fab-size) + 12px);
  position: fixed;
  z-index: 2147483000;
  right: var(--ist-fab-right);
  bottom: var(--ist-fab-offset);
  width: var(--ist-fab-size);
  height: var(--ist-fab-size);
  pointer-events: none;
  font-family: "Plus Jakarta Sans", "Figtree", "Inter", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ist-ink);
}
#istChatbot, #istChatbot * {
  box-sizing: border-box;
}

/* ── Floating toggle button ─────────────────────────────────────────── */
.ist-chat-toggle {
  position: relative;
  width: var(--ist-fab-size);
  height: var(--ist-fab-size);
  padding: 0;
  touch-action: manipulation;
  pointer-events: auto;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--ist-blue), var(--ist-blue-dark));
  color: #fff;
  box-shadow: 0 10px 28px rgba(11, 79, 214, 0.38);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.ist-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(11, 79, 214, 0.46);
}
.ist-chat-toggle:focus-visible {
  outline: 3px solid rgba(23, 105, 255, 0.5);
  outline-offset: 3px;
}
.ist-chat-toggle-icon { position: relative; width: 22px; height: 22px; pointer-events: none; }
.ist-chat-toggle-icon svg { position: absolute; inset: 0; transition: opacity 0.2s, transform 0.2s; }
.ist-icon-close { opacity: 0; transform: scale(0.6) rotate(-45deg); }
#istChatbot.is-open .ist-icon-chat { opacity: 0; transform: scale(0.6) rotate(45deg); }
#istChatbot.is-open .ist-icon-close { opacity: 1; transform: scale(1) rotate(0); }
.ist-chat-toggle-pulse {
  display: none;
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(23, 105, 255, 0.45);
  animation: istPulse 2.6s ease-out infinite;
  pointer-events: none;
}
#istChatbot.is-open .ist-chat-toggle-pulse { animation: none; opacity: 0; }
@keyframes istPulse {
  0% { transform: scale(0.85); opacity: 0.8; }
  80%, 100% { transform: scale(1.35); opacity: 0; }
}

/* ── Chat window ────────────────────────────────────────────────────── */
.ist-chat-window {
  position: absolute;
  right: 0;
  bottom: calc(100% + 16px);
  width: min(380px, calc(100vw - var(--ist-fab-right) - 12px));
  height: min(600px, calc(100vh - var(--ist-fab-offset) - var(--ist-fab-size) - 28px));
  height: min(600px, calc(100dvh - var(--ist-fab-offset) - var(--ist-fab-size) - 28px));
  background: #fff;
  border-radius: var(--ist-radius);
  box-shadow: 0 24px 60px rgba(11, 21, 48, 0.22), 0 2px 8px rgba(11, 21, 48, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.92) translateY(12px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
#istChatbot.is-open .ist-chat-window {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
.ist-chat-window[hidden] { display: none; }

.ist-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  background: linear-gradient(120deg, var(--ist-blue), var(--ist-blue-dark));
  color: #fff;
  flex: none;
}
.ist-chat-head-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ist-chat-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 16px;
}
.ist-chat-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c07a;
  border: 2px solid var(--ist-blue-dark);
}
.ist-chat-head-id strong { display: block; font-size: 14.5px; font-weight: 700; }
.ist-chat-head-id small { display: block; opacity: 0.85; font-size: 11.5px; }
.ist-chat-head-actions { display: flex; gap: 4px; flex: none; }
.ist-chat-icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.2s;
}
.ist-chat-icon-btn:hover { background: rgba(255, 255, 255, 0.26); }

.ist-chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--ist-bg);
  scrollbar-width: thin;
}
.ist-chat-body::-webkit-scrollbar { width: 6px; }
.ist-chat-body::-webkit-scrollbar-thumb { background: #c6d4ee; border-radius: 6px; }

/* ── Messages ───────────────────────────────────────────────────────── */
.ist-msg { display: flex; flex-direction: column; max-width: 86%; animation: istRise 0.25s ease; }
.ist-msg.bot { align-self: flex-start; }
.ist-msg.user { align-self: flex-end; align-items: flex-end; }
.ist-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ist-msg.bot .ist-bubble { background: #fff; color: var(--ist-ink); border: 1px solid var(--ist-line); border-bottom-left-radius: 4px; }
.ist-msg.user .ist-bubble { background: linear-gradient(120deg, var(--ist-blue), var(--ist-blue-dark)); color: #fff; border-bottom-right-radius: 4px; }
.ist-msg-time { font-size: 10.5px; color: #93a0bd; margin-top: 3px; padding: 0 3px; }
@keyframes istRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.ist-typing { display: inline-flex; align-items: center; gap: 4px; padding: 11px 14px; background: #fff; border: 1px solid var(--ist-line); border-radius: 14px; border-bottom-left-radius: 4px; width: fit-content; }
.ist-typing span { width: 6px; height: 6px; border-radius: 50%; background: #9fb0d0; animation: istBounce 1.1s infinite ease-in-out; }
.ist-typing span:nth-child(2) { animation-delay: 0.15s; }
.ist-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes istBounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ── Category buttons ───────────────────────────────────────────────── */
.ist-category-row { display: flex; gap: 8px; margin-top: 6px; }
.ist-category-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border: 1.5px solid var(--ist-line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--ist-ink);
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.ist-category-btn:hover { border-color: var(--ist-blue); transform: translateY(-1px); box-shadow: 0 8px 18px rgba(23, 105, 255, 0.14); }
.ist-category-btn .ist-emoji { font-size: 22px; }

/* ── Suggestion chips ───────────────────────────────────────────────── */
.ist-chat-chips { padding: 10px 14px; border-top: 1px solid var(--ist-line); display: flex; flex-wrap: wrap; gap: 7px; background: #fff; flex: none; max-height: 150px; overflow-y: auto; }
.ist-chat-chips[hidden] { display: none; }
.ist-chip {
  border: 1.5px solid var(--ist-line);
  background: #fff;
  color: var(--ist-blue-dark);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.ist-chip:hover { background: #eef4ff; border-color: var(--ist-blue); }
.ist-chip.ist-chip-more { background: var(--ist-ink); color: #fff; border-color: var(--ist-ink); }

/* inline chip rendered inside a message (card action buttons) */
.ist-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--ist-blue);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
}
.ist-action-btn:hover { background: var(--ist-blue-dark); }

/* ── Knowledge / course cards ───────────────────────────────────────── */
.ist-card-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; width: 100%; }
.ist-card {
  background: #fff;
  border: 1px solid var(--ist-line);
  border-radius: 12px;
  padding: 11px 12px;
  width: 100%;
}
.ist-card b { display: block; font-size: 13px; margin-bottom: 2px; }
.ist-card p { margin: 0 0 6px; font-size: 12px; color: var(--ist-text); }
.ist-card-meta { display: flex; gap: 10px; font-size: 11px; color: #7281a3; margin-bottom: 6px; flex-wrap: wrap; }
.ist-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ist-card-actions a, .ist-card-actions button {
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1.5px solid var(--ist-blue);
  color: var(--ist-blue-dark);
  background: #fff;
  text-decoration: none;
  cursor: pointer;
}
.ist-card-actions .ist-card-primary { background: var(--ist-blue); color: #fff; border-color: var(--ist-blue); }

/* ── Lead capture form ──────────────────────────────────────────────── */
.ist-lead-form { display: flex; flex-direction: column; gap: 8px; background: #fff; border: 1px solid var(--ist-line); border-radius: 12px; padding: 12px; margin-top: 4px; width: 100%; }
.ist-lead-form label { font-size: 11.5px; font-weight: 700; color: var(--ist-text); display: flex; flex-direction: column; gap: 4px; }
.ist-optional { font-weight: 500; color: #9aa6c2; }
.ist-lead-form input, .ist-lead-form textarea {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1.5px solid var(--ist-line);
  border-radius: 8px;
  color: var(--ist-ink);
  resize: vertical;
}
.ist-lead-form input:focus, .ist-lead-form textarea:focus { outline: none; border-color: var(--ist-blue); }
.ist-lead-consent { flex-direction: row !important; align-items: flex-start; font-weight: 500 !important; font-size: 11px !important; gap: 6px !important; }
.ist-lead-consent input { width: 15px; height: 15px; margin-top: 1px; flex: none; }
.ist-lead-form button {
  margin-top: 2px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(120deg, var(--ist-blue), var(--ist-blue-dark));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.ist-lead-form button:disabled { opacity: 0.6; cursor: wait; }
.ist-lead-error { color: #d9344b; font-size: 11px; }

/* ── Input bar ──────────────────────────────────────────────────────── */
.ist-chat-input { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--ist-line); background: #fff; flex: none; }
.ist-chat-input input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border: 1.5px solid var(--ist-line);
  border-radius: 999px;
  color: var(--ist-ink);
}
.ist-chat-input input:focus { outline: none; border-color: var(--ist-blue); }
.ist-chat-input button {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--ist-blue), var(--ist-blue-dark));
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s;
}
.ist-chat-input button:hover { transform: scale(1.05); }
.ist-chat-privacy { margin: 0; padding: 6px 14px 10px; font-size: 10px; color: #9aa6c2; text-align: center; flex: none; background: #fff; }

/* ── WhatsApp quick link ────────────────────────────────────────────── */
.ist-whatsapp-link { display: inline-flex; align-items: center; gap: 6px; color: #1aa851; font-weight: 700; font-size: 12px; text-decoration: none; margin-top: 6px; }

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .ist-chat-window {
    position: fixed;
    inset: auto 10px auto 10px;
    width: auto;
    height: min(620px, calc(100vh - var(--ist-fab-offset) - var(--ist-fab-size) - 24px));
    height: min(620px, calc(100dvh - var(--ist-fab-offset) - var(--ist-fab-size) - 24px));
    /* clears the toggle button (itself offset by --ist-fab-offset) plus its
       own height and a gap, so it never sits on top of the toggle/back-to-top */
    bottom: calc(var(--ist-fab-offset) + var(--ist-fab-size) + 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ist-chat-toggle-pulse { animation: none; }
  .ist-msg { animation: none; }
  .ist-typing span { animation: none; }
}
