/*
 * Modern chatbot UI styles for the Custom AI Chatbot plugin.
 *
 * This stylesheet defines variables for light and dark themes and styles
 * the floating launcher button, the chat panel, messages, typing indicator,
 * and input bar. The design is responsive and right-to-left friendly.
 */

:root {
  --cai-primary: #1f3dff;
  --cai-ink: #0a1640;
  --cai-muted: #667085;
  --cai-bg: #ffffff;
  --cai-border: #e5e7eb;
  --cai-shadow: 0 20px 50px rgba(16, 24, 40, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --cai-ink: #e6e6e6;
    --cai-muted: #a0a0a0;
    --cai-bg: #101828;
    --cai-border: #1f2937;
    --cai-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  }
}

/* Floating launcher button */
#cai-launcher {
  position: fixed;
  inset-inline-end: 18px;
  inset-block-end: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cai-primary), #4f8bff);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--cai-shadow);
  z-index: 99999;
  transition: transform 0.2s ease;

  /* Centre the question mark inside the launcher button and increase its size */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: bold;
}

/* Position the launcher on the chosen side of the screen. The default (no class) is right.
   When cai-side-left is applied, place the launcher on the left side. When cai-side-right,
   ensure it is on the right. Inline logical properties (inset-inline-start/end) allow
   support for RTL/LTR layouts. */
#cai-launcher.cai-side-left {
  inset-inline-start: 18px;
  inset-inline-end: auto;
}
#cai-launcher.cai-side-right {
  inset-inline-end: 18px;
  inset-inline-start: auto;
}
#cai-launcher:hover {
  transform: translateY(-1px);
}

/* Chat panel */
#cai-panel {
  position: fixed;
  inset-inline-end: 18px;
  inset-block-end: 84px;
  width: min(380px, 95vw);
  height: min(70vh, 620px);
  background: var(--cai-bg);
  color: var(--cai-ink);
  border: 1px solid var(--cai-border);
  border-radius: 16px;
  box-shadow: var(--cai-shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 100000;
}
#cai-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Panel header: apply a colorful gradient and white text for a polished appearance */
.cai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(90deg, var(--cai-primary), #4f8bff);
  color: #fff;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
}
.cai-title {
  font-weight: 900;
  font-size: 16px;
}
.cai-close {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #fff;
}

/* Messages area */
.cai-messages {
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 15px;
}
.cai-msg {
  display: flex;
}
.cai-msg.me {
  justify-content: flex-end;
}
.cai-msg .bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--cai-border);
  background: #f3f6ff;
  color: #111827;
}
@media (prefers-color-scheme: dark) {
  .cai-msg .bubble {
    background: #111827;
    color: #e6e6e6;
  }
}
.cai-msg.me .bubble {
  background: var(--cai-primary);
  border-color: var(--cai-primary);
  color: #fff;
}

/* Typing indicator */
.cai-typing {
  display: flex;
  gap: 4px;
  padding: 0 12px;
}
.cai-typing span {
  width: 6px;
  height: 6px;
  background: var(--cai-muted);
  border-radius: 50%;
  animation: cai-blink 1s infinite ease-in-out;
}
.cai-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.cai-typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes cai-blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* Input bar */
.cai-inputbar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--cai-border);
}
#cai-input {
  flex: 1;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--cai-border);
  outline: none;
}
#cai-send {
  min-width: 84px;
  height: 42px;
  border-radius: 10px;
  background: var(--cai-primary);
  color: #fff;
  border: 0;
  cursor: pointer;
}

/* Styled link for sources shown in bot messages */
.cai-source-link {
  color: var(--cai-primary);
  text-decoration: underline;
}

/* Ensure right-to-left layout */
#cai-panel {
  direction: rtl;
}