/* JLD Chat Widget — scoped under #jld-chat-root.
   Supports data-position="bottom-right" | "bottom-left".
   --jld-primary is set inline via JS from the configured primary color. */

#jld-chat-root {
  --jld-primary: #2D6A4F;
  --jld-bg: #ffffff;
  --jld-text: #1a1a1a;
  --jld-text-muted: #6b7280;
  --jld-border: #e5e7eb;
  --jld-user-bg: #f3f4f6;
  --jld-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);

  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  color: var(--jld-text);
  line-height: 1.5;
}

#jld-chat-root *,
#jld-chat-root *::before,
#jld-chat-root *::after {
  box-sizing: border-box;
}

/* ---- Theme reset --------------------------------------------------
   Many WP themes aggressively style buttons (uppercase, letter-spacing,
   text-shadow, custom borders). These rules neutralize those overrides
   inside the widget so the design stays consistent across sites. */
#jld-chat-root button,
#jld-chat-root input,
#jld-chat-root textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  letter-spacing: normal !important;
  text-transform: none !important;
  text-shadow: none !important;
  text-decoration: none !important;
  text-align: left;
  font-weight: 500;
  font-style: normal;
  background-image: none !important;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
#jld-chat-root button {
  cursor: pointer;
}
#jld-chat-root button:focus {
  outline: none;
}
#jld-chat-root .jld-bubble-text,
#jld-chat-root .jld-header-title,
#jld-chat-root .jld-header-subtitle,
#jld-chat-root .jld-msg {
  text-transform: none !important;
  letter-spacing: normal !important;
}

/* ---- Position variants -------------------------------------------- */
#jld-chat-root[data-position="bottom-right"] #jld-chat-bubble,
#jld-chat-root[data-position="bottom-right"] #jld-chat-window {
  right: 24px;
  left: auto;
}

#jld-chat-root[data-position="bottom-left"] #jld-chat-bubble,
#jld-chat-root[data-position="bottom-left"] #jld-chat-window {
  left: 24px;
  right: auto;
}

/* Floating bubble (closed state) */
#jld-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--jld-bg);
  border-radius: 22px;
  padding: 12px 18px 12px 12px;
  box-shadow: var(--jld-shadow);
  z-index: 999998;
  border: none;
  color: var(--jld-text);
  width: auto;
  max-width: 320px;
  min-height: 56px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

#jld-chat-bubble.jld-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#jld-chat-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.2);
}

#jld-chat-bubble.jld-hidden {
  display: none;
}

.jld-bubble-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--jld-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  line-height: 1;
}

.jld-bubble-text {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--jld-text);
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jld-bubble-close {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--jld-border);
  color: var(--jld-text-muted);
  font-size: 16px;
  line-height: 18px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-weight: 400;
  flex-shrink: 0;
}

.jld-bubble-close:hover {
  color: var(--jld-text);
  background: #f9fafb;
}

/* Chat window */
#jld-chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 48px);
  background: var(--jld-bg);
  border-radius: 16px;
  box-shadow: var(--jld-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  opacity: 0;
  transform: translateY(20px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.jld-chat-header {
  background: var(--jld-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.jld-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
  line-height: 1;
}

.jld-header-info {
  flex: 1;
  min-width: 0;
  color: #fff;
}

.jld-header-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  color: #fff;
}

.jld-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-weight: 400;
  color: #fff;
}

.jld-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  flex-shrink: 0;
}

/* Close button — flat X icon, no background, no border. */
#jld-chat-root .jld-header-close {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #fff;
  width: auto;
  height: auto;
  padding: 4px;
  margin-left: auto; /* pushes to the far right of the header */
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity 0.15s ease;
  border-radius: 0;
}

#jld-chat-root .jld-header-close:hover,
#jld-chat-root .jld-header-close:focus {
  opacity: 1;
  background: transparent !important;
}

#jld-chat-root .jld-header-close svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Messages area */
.jld-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
  scroll-behavior: smooth;
}

.jld-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.jld-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.jld-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: jld-msg-in 0.25s ease;
  font-size: 14px;
  line-height: 1.45;
}

@keyframes jld-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.jld-msg-user {
  align-self: flex-end;
  background: #fff;
  border: 1px solid var(--jld-border);
  border-bottom-right-radius: 4px;
  color: var(--jld-text);
}

.jld-msg-assistant {
  align-self: flex-start;
  background: var(--jld-primary);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.jld-msg-assistant a {
  color: #fff;
  text-decoration: underline;
}

/* Typing indicator */
.jld-typing {
  align-self: flex-start;
  background: var(--jld-primary);
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.jld-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  display: inline-block;
  animation: jld-bounce 1.2s infinite ease-in-out;
}

.jld-typing span:nth-child(2) { animation-delay: 0.15s; }
.jld-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes jld-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---- Input row — pill input + circular send button, one cohesive unit --- */
#jld-chat-root .jld-chat-input {
  border-top: 1px solid var(--jld-border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  flex-shrink: 0;
}

#jld-chat-root .jld-chat-input input[type="text"] {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--jld-border) !important;
  border-radius: 999px !important;
  padding: 0 14px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--jld-text);
  background: #fff !important;
  outline: none;
  box-shadow: none;
  resize: none;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#jld-chat-root .jld-chat-input input[type="text"]:focus {
  border-color: var(--jld-primary) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--jld-primary) 18%, transparent);
}

#jld-chat-root .jld-chat-input input[type="text"]::placeholder {
  color: var(--jld-text-muted);
  opacity: 1;
}

/* Hide scrollbars defensively (some browsers render thin tracks on inputs). */
#jld-chat-root .jld-chat-input input[type="text"]::-webkit-scrollbar { display: none; }

#jld-chat-root .jld-send-btn {
  background: var(--jld-primary) !important;
  border: none !important;
  box-shadow: none !important;
  color: #fff !important;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: filter 0.15s ease;
}

#jld-chat-root .jld-send-btn:hover:not(:disabled),
#jld-chat-root .jld-send-btn:focus:not(:disabled) {
  filter: brightness(0.92);
}

#jld-chat-root .jld-send-btn:active:not(:disabled) {
  filter: brightness(0.85);
}

#jld-chat-root .jld-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#jld-chat-root .jld-send-btn svg {
  width: 14px;
  height: 14px;
  display: block;
  /* Paper-plane glyph is visually heavier on the bottom-left; nudge it
     up and right by a hair so it reads as centered. */
  transform: translate(1px, -1px);
}

/* Mobile */
@media (max-width: 480px) {
  #jld-chat-bubble {
    bottom: 16px;
    max-width: calc(100vw - 32px);
  }
  #jld-chat-root[data-position="bottom-right"] #jld-chat-bubble {
    right: 16px;
  }
  #jld-chat-root[data-position="bottom-left"] #jld-chat-bubble {
    left: 16px;
  }

  #jld-chat-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 0;
  }
}
