/* ============================================================
   Clean / official chatbot design
   - Light neutral palette
   - Soft borders and subtle shadows
   - Kept above scroll-up button
   ============================================================ */

:root {
  --ins-chat-scroll-bottom: 20px;
  --ins-chat-scroll-size: 55px;
  --ins-chat-stack-gap: 14px;
  --ins-chat-launcher-size: 3.5rem;
  --ins-chat-edge: 20px;
  --ins-chat-launcher-bottom: calc(
    var(--ins-chat-scroll-bottom) + var(--ins-chat-scroll-size) + var(--ins-chat-stack-gap)
  );
  --ins-chat-panel-bottom: calc(
    var(--ins-chat-launcher-bottom) + var(--ins-chat-launcher-size) + var(--ins-chat-stack-gap)
  );
}

.ins-chatbot-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ins-chatbot-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.18);
  backdrop-filter: blur(2px);
  z-index: 100088;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  pointer-events: none;
}

.ins-chatbot-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* زر الفتح: نفس عمود السهم، أعلى منه */
.ins-chatbot-launcher {
  position: fixed;
  left: var(--ins-chat-edge);
  right: auto;
  bottom: var(--ins-chat-launcher-bottom);
  width: var(--ins-chat-launcher-size);
  height: var(--ins-chat-launcher-size);
  padding: 0;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 100095;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  filter: drop-shadow(0 6px 16px rgba(var(--base-sv-color-rgb, 88, 185, 70), 0.45));
  transition: transform 0.2s ease, filter 0.2s ease;
}

.ins-chatbot-launcher-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #5f9ea0 0%, #4f8b8d 100%);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 6px 18px rgba(79, 139, 141, 0.28);
  color: #fff;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ins-chatbot-launcher:hover .ins-chatbot-launcher-inner {
  transform: scale(1.05);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.3) inset,
    0 8px 24px rgba(79, 139, 141, 0.32);
}

.ins-chatbot-launcher:focus-visible {
  outline: none;
}

.ins-chatbot-launcher:focus-visible .ins-chatbot-launcher-inner {
  box-shadow:
    0 0 0 3px rgba(95, 158, 160, 0.4),
    0 6px 18px rgba(79, 139, 141, 0.3);
}

.ins-chatbot-launcher[aria-expanded='true'] .ins-chatbot-launcher-inner {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35), 0 4px 18px rgba(0, 0, 0, 0.15);
}

.ins-chatbot-launcher-icon {
  font-size: 1.35rem;
  line-height: 1;
}

/* اللوحة: فوق زر الشات */
.ins-chatbot-panel {
  position: fixed;
  left: var(--ins-chat-edge);
  right: auto;
  bottom: var(--ins-chat-panel-bottom);
  width: min(22.5rem, calc(100vw - 2 * var(--ins-chat-edge)));
  max-height: min(36rem, calc(100vh - var(--ins-chat-panel-bottom) - 12px));
  background: #ffffff;
  border-radius: 1rem;
  z-index: 100096;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--sv-body-font, var(--body-font, 'Tajawal', sans-serif));
  color: #1f2937;
  border: 1px solid #e5e7eb;
  box-shadow:
    0 4px 14px rgba(15, 23, 42, 0.06),
    0 16px 36px rgba(15, 23, 42, 0.12);
}

.ins-chatbot-panel::before {
  content: '';
  display: block;
  height: 4px;
  flex-shrink: 0;
  background: linear-gradient(90deg, #e5e7eb, #f3f4f6, #e5e7eb);
}

.ins-chatbot-panel--llm::before {
  background: linear-gradient(90deg, #e5e7eb, #dbeafe, #e5e7eb);
}

.ins-chatbot-panel.is-open {
  display: flex;
  animation: ins-chatbot-rise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ins-chatbot-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ins-chatbot-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.85rem 1rem 0.75rem;
  background: linear-gradient(
    180deg,
    rgba(79, 139, 141, 0.08) 0%,
    rgba(255, 255, 255, 0.98) 100%
  );
  border-bottom: 1px solid #eceff3;
  flex-shrink: 0;
}

.ins-chatbot-head-main {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-width: 0;
}

.ins-chatbot-head-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.ins-chatbot-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #0f172a;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.ins-chatbot-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: #4b5563;
  line-height: 1.35;
  opacity: 0.95;
}

.ins-chatbot-sub--muted {
  color: var(--text-light, #6c757d);
}

.ins-chatbot-mode-pill {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem;
  border-radius: 0.35rem;
  background: linear-gradient(135deg, #eff6ff, #e0ecff);
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  line-height: 1;
  margin-top: 0.15rem;
}

.ins-chatbot-close {
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  color: #475569;
  font-size: 0.95rem;
  border-radius: 0.45rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ins-chatbot-close:hover {
  background: #eef2f7;
  color: #0f172a;
}

.ins-chatbot-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #f8fafc;
  overflow: hidden;
}

.ins-chatbot-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.85rem 0.9rem;
  scroll-behavior: smooth;
}

.ins-chatbot-thread::-webkit-scrollbar {
  width: 5px;
}

.ins-chatbot-thread::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 4px;
}

.ins-chatbot-welcome {
  text-align: center;
  padding: 0.35rem 0.15rem 0.5rem;
}

.ins-chatbot-welcome-lead {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.ins-chatbot-suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.ins-chatbot-chip {
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 0.55rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.84rem;
  text-align: start;
  color: #334155;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
  box-shadow: 0 1px 2px var(--shadow-sm, rgba(0, 0, 0, 0.04));
}

.ins-chatbot-chip:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
  box-shadow: 0 3px 12px rgba(59, 130, 246, 0.14);
}

.ins-chatbot-msg {
  margin-bottom: 0.75rem;
  animation: ins-chatbot-fade 0.28s ease;
}

@keyframes ins-chatbot-fade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ins-chatbot-msg--user {
  text-align: end;
}

.ins-chatbot-msg--assistant {
  text-align: start;
}

.ins-chatbot-msg--error .ins-chatbot-bubble {
  background: #fff8f8;
  border-color: #f5c6cb;
  color: #a71d2a;
}

.ins-chatbot-bubble {
  display: inline-block;
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  border-radius: 0.9rem;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.ins-chatbot-msg--user .ins-chatbot-bubble {
  background: linear-gradient(145deg, #5f9ea0 0%, #4f8b8d 100%);
  color: #fff;
  border: none;
  border-end-end-radius: 0.2rem;
  box-shadow: 0 3px 12px rgba(79, 139, 141, 0.22);
}

.ins-chatbot-msg--assistant .ins-chatbot-bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-end-start-radius: 0.2rem;
  color: #1f2937;
  box-shadow: 0 1px 3px var(--shadow-sm, rgba(0, 0, 0, 0.06));
}

.ins-chatbot-sources {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: #64748b;
  max-width: 92%;
}

.ins-chatbot-msg--user .ins-chatbot-sources {
  margin-inline-start: auto;
}

.ins-chatbot-src {
  display: inline-block;
  margin-inline-end: 0.3rem;
  margin-top: 0.2rem;
  padding: 0.12rem 0.4rem;
  background: #eef2ff;
  color: #4338ca;
  border-radius: 0.3rem;
  font-weight: 600;
}

.ins-chatbot-typing {
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem 0.65rem;
  font-size: 0.76rem;
  color: #64748b;
  flex-shrink: 0;
  background: #f8fafc;
  border-top: 1px solid #e5e7eb;
}

.ins-chatbot-typing.is-visible {
  display: flex;
}

.ins-chatbot-typing-dots {
  display: inline-flex;
  gap: 0.22rem;
}

.ins-chatbot-typing-dots span {
  width: 0.32rem;
  height: 0.32rem;
  border-radius: 50%;
  background: #60a5fa;
  animation: ins-chatbot-dot 1.15s ease-in-out infinite;
}

.ins-chatbot-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.ins-chatbot-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ins-chatbot-dot {
  0%,
  80%,
  100% {
    transform: scale(0.75);
    opacity: 0.45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.ins-chatbot-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

.ins-chatbot-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #dbe3ee;
  border-radius: 0.55rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  color: #1f2937;
  background: #f8fafc;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.ins-chatbot-input::placeholder {
  color: #94a3b8;
}

.ins-chatbot-input:focus {
  outline: none;
  border-color: #60a5fa;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.22);
}

.ins-chatbot-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  min-width: 2.75rem;
  padding: 0 0.85rem;
  border-radius: 0.55rem;
  background: linear-gradient(145deg, #5f9ea0, #4f8b8d);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.12s ease;
  box-shadow: 0 2px 10px rgba(79, 139, 141, 0.26);
}

.ins-chatbot-send:hover:not(:disabled) {
  filter: brightness(1.06);
}

.ins-chatbot-send:active:not(:disabled) {
  transform: scale(0.97);
}

.ins-chatbot-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ins-chatbot-send .fa-paper-plane {
  font-size: 0.88rem;
}

.ins-chatbot-foot {
  flex-shrink: 0;
  padding: 0 0.9rem 0.7rem;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}

.ins-chatbot-footnote {
  font-size: 0.66rem;
  line-height: 1.5;
  color: #64748b;
  margin: 0;
}

@media (max-width: 380px) {
  .ins-chatbot-send-label {
    display: none;
  }

  .ins-chatbot-send {
    padding: 0 0.65rem;
  }
}

@media (max-width: 420px) {
  :root {
    --ins-chat-edge: 14px;
  }

  .ins-chatbot-panel {
    width: calc(100vw - 2 * var(--ins-chat-edge));
  }
}
