/* =============================================================================
   Erasys Chatbot Widget Styles
   All classes scoped with .erasys-chat- prefix to avoid theme conflicts.
   ============================================================================= */

/* --- CSS Custom Properties ------------------------------------------------- */
.erasys-chat-root {
  --erasys-primary:    #00609e;
  --erasys-accent:     #1e73be;
  --erasys-dark:       #0a1222;
  --erasys-white:      #ffffff;
  --erasys-bg:         #f4f6f8;
  --erasys-bot-bg:     #eaf3fb;
  --erasys-border:     #dce3ea;
  --erasys-text:       #1a2433;
  --erasys-muted:      #6b7a8d;
  --erasys-radius:     12px;
  --erasys-shadow:     0 8px 32px rgba(0,96,158,0.18), 0 2px 8px rgba(0,0,0,0.10);
  --erasys-shadow-btn: 0 4px 16px rgba(0,96,158,0.35);
  --erasys-z:          2147483646; /* Just below max z-index */
  --erasys-anim:       200ms ease;
}

/* --- Floating bubble button ------------------------------------------------ */
.erasys-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--erasys-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  box-sizing: border-box;
}

.erasys-chat-root.position-bottom-left {
  right: auto;
  left: 24px;
}

.erasys-chat-root *,
.erasys-chat-root *::before,
.erasys-chat-root *::after {
  box-sizing: inherit;
}

.erasys-chat-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--erasys-shadow-btn);
  transition: transform var(--erasys-anim);
  padding: 0;
  outline: none;
  overflow: hidden;
}

.erasys-chat-bubble:hover {
  transform: scale(1.08);
}

.erasys-chat-bubble:focus-visible {
  outline: 3px solid var(--erasys-accent);
  outline-offset: 2px;
}

.erasys-chat-bubble svg {
  width: 26px;
  height: 26px;
  pointer-events: none;
  transition: opacity var(--erasys-anim);
}

.erasys-chat-bubble .erasys-icon-chat,
.erasys-chat-bubble .erasys-icon-close {
  position: absolute;
  transition: opacity var(--erasys-anim), transform var(--erasys-anim);
}

.erasys-chat-bubble .erasys-icon-close {
  opacity: 0;
  transform: rotate(-90deg);
}

.erasys-chat-root.is-open .erasys-chat-bubble .erasys-icon-chat {
  opacity: 0;
  transform: rotate(90deg);
}

.erasys-chat-root.is-open .erasys-chat-bubble .erasys-icon-close {
  opacity: 1;
  transform: rotate(0deg);
}

/* --- Chat window ----------------------------------------------------------- */
.erasys-chat-window {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 360px;
  max-height: 500px;
  border-radius: var(--erasys-radius);
  background: var(--erasys-white);
  box-shadow: var(--erasys-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Collapsed state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity var(--erasys-anim), transform var(--erasys-anim);
  transform-origin: bottom right;
}

.erasys-chat-root.position-bottom-left .erasys-chat-window {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.erasys-chat-root.is-open .erasys-chat-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Header ---------------------------------------------------------------- */
.erasys-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--erasys-primary);
  color: var(--erasys-white);
  flex-shrink: 0;
}

.erasys-chat-header-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.erasys-chat-header-logo svg {
  width: 18px;
  height: 18px;
}

.erasys-chat-header-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
}

.erasys-chat-close-btn {
  background: none;
  border: none;
  color: var(--erasys-white);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  opacity: 0.8;
  transition: opacity var(--erasys-anim);
}

.erasys-chat-close-btn:hover {
  opacity: 1;
}

.erasys-chat-close-btn svg {
  width: 18px;
  height: 18px;
}

/* --- Messages area -------------------------------------------------------- */
.erasys-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--erasys-bg);
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.erasys-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.erasys-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.erasys-chat-messages::-webkit-scrollbar-thumb {
  background: var(--erasys-border);
  border-radius: 10px;
}

/* Message row */
.erasys-chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 90%;
}

.erasys-chat-msg.bot {
  align-self: flex-start;
}

.erasys-chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Avatar */
.erasys-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent; /* Bot avatar image has its own background */
  color: var(--erasys-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
}

.erasys-chat-msg.user .erasys-chat-avatar {
  background: var(--erasys-muted); /* User initial still needs a background */
}

/* Bubble */
.erasys-chat-bubble-text {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.erasys-chat-msg.bot .erasys-chat-bubble-text {
  background: var(--erasys-white);
  color: var(--erasys-text);
  border: 1px solid var(--erasys-border);
  border-bottom-left-radius: 4px;
}

.erasys-chat-msg.user .erasys-chat-bubble-text {
  background: var(--erasys-primary);
  color: var(--erasys-white);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.erasys-chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--erasys-white);
  border: 1px solid var(--erasys-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.erasys-chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--erasys-muted);
  border-radius: 50%;
  animation: erasys-bounce 1.2s infinite ease-in-out;
}

.erasys-chat-typing span:nth-child(1) { animation-delay: 0s; }
.erasys-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.erasys-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes erasys-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* Error message */
.erasys-chat-bubble-text.error {
  background: #fff3f3;
  border-color: #f5c6c6;
  color: #c62828;
}

/* --- Markdown rendered content inside bot bubbles ----------------------- */
.erasys-chat-msg.bot .erasys-chat-bubble-text p {
  margin: 0 0 0.6em;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text p:last-child {
  margin-bottom: 0;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text strong {
  font-weight: 700;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text em {
  font-style: italic;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", monospace;
  font-size: 0.875em;
  background: #e8f0f7;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text ul {
  margin: 0.4em 0 0.6em;
  padding-left: 1.4em;
  list-style: disc;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text ul:last-child {
  margin-bottom: 0;
}
.erasys-chat-msg.bot .erasys-chat-bubble-text li {
  margin-bottom: 0.25em;
}

/* --- Input area ------------------------------------------------------------ */
.erasys-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--erasys-white);
  border-top: 1px solid var(--erasys-border);
  flex-shrink: 0;
}

.erasys-chat-input {
  flex: 1;
  border: 1px solid var(--erasys-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  color: var(--erasys-text);
  background: var(--erasys-bg);
  transition: border-color var(--erasys-anim);
}

.erasys-chat-input:focus {
  border-color: var(--erasys-primary);
  background: var(--erasys-white);
}

.erasys-chat-input::placeholder {
  color: var(--erasys-muted);
}

.erasys-chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--erasys-primary);
  color: var(--erasys-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--erasys-anim), transform var(--erasys-anim);
  padding: 0;
}

.erasys-chat-send-btn:hover:not(:disabled) {
  background: var(--erasys-accent);
  transform: scale(1.08);
}

.erasys-chat-send-btn:disabled {
  background: var(--erasys-border);
  cursor: not-allowed;
}

.erasys-chat-send-btn svg {
  width: 18px;
  height: 18px;
}

/* --- Footer ---------------------------------------------------------------- */
.erasys-chat-footer {
  text-align: center;
  padding: 6px 12px 8px;
  font-size: 11px;
  color: var(--erasys-muted);
  background: var(--erasys-white);
  border-top: 1px solid var(--erasys-border);
  flex-shrink: 0;
}

.erasys-chat-footer a {
  color: var(--erasys-primary);
  text-decoration: none;
}

/* --- Mobile --------------------------------------------------------------- */
@media (max-width: 640px) {
  .erasys-chat-root {
    bottom: 16px;
    right: 16px;
  }

  .erasys-chat-root.position-bottom-left {
    right: auto;
    left: 16px;
  }

  .erasys-chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    width: 100%;
    max-height: 80vh;
    border-radius: var(--erasys-radius) var(--erasys-radius) 0 0;
    transform-origin: bottom center;
  }

  .erasys-chat-root.position-bottom-left .erasys-chat-window {
    left: 0;
  }
}
