/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --wdp-primary:   #1a56db;
  --wdp-primary-d: #1140a6;
  --wdp-bg:        #ffffff;
  --wdp-surface:   #f4f6fb;
  --wdp-text:      #1e1e2e;
  --wdp-muted:     #6b7280;
  --wdp-radius:    16px;
  --wdp-shadow:    0 8px 40px rgba(0,0,0,.18);
  --wdp-z:         9999;
}

/* ── Widget wrapper ────────────────────────────────────────────────────── */
#wdp-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--wdp-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Toggle button ─────────────────────────────────────────────────────── */
#wdp-toggle {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--wdp-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(26,86,219,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
  color: #fff;
}
#wdp-toggle:hover { background: var(--wdp-primary-d); transform: scale(1.06); }
#wdp-toggle svg { width: 26px; height: 26px; }
#wdp-toggle.wdp-open { background: #e63946; }

#wdp-unread {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e63946;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: wdp-pulse 1.4s infinite;
}
#wdp-unread:empty,
#wdp-unread[hidden] { display: none; }

@keyframes wdp-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}

/* ── Chat window ───────────────────────────────────────────────────────── */
#wdp-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--wdp-bg);
  border-radius: var(--wdp-radius);
  box-shadow: var(--wdp-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: wdp-slideup .22s ease;
}
#wdp-window[hidden] { display: none; }

@keyframes wdp-slideup {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ────────────────────────────────────────────────────────────── */
#wdp-header {
  background: var(--wdp-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
#wdp-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
#wdp-header-info { flex: 1; }
#wdp-header-info strong { display: block; font-size: 15px; }
#wdp-header-info span   { font-size: 12px; opacity: .85; }
#wdp-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 4px;
  vertical-align: middle;
}
#wdp-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: .8;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}
#wdp-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

/* ── Messages ──────────────────────────────────────────────────────────── */
#wdp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 280px;
  max-height: 380px;
  background: var(--wdp-surface);
  scroll-behavior: smooth;
}
#wdp-messages::-webkit-scrollbar { width: 4px; }
#wdp-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.wdp-msg { display: flex; }
.wdp-msg--user     { justify-content: flex-end; }
.wdp-msg--assistant { justify-content: flex-start; }

.wdp-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.wdp-msg--user .wdp-bubble {
  background: var(--wdp-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.wdp-msg--assistant .wdp-bubble {
  background: #fff;
  color: var(--wdp-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ── Typing indicator ──────────────────────────────────────────────────── */
#wdp-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px 4px;
  background: var(--wdp-surface);
}
#wdp-typing[hidden] { display: none; }
#wdp-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: wdp-bounce .9s infinite;
}
#wdp-typing span:nth-child(2) { animation-delay: .15s; }
#wdp-typing span:nth-child(3) { animation-delay: .30s; }

@keyframes wdp-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-6px); }
}

/* ── Input row ─────────────────────────────────────────────────────────── */
#wdp-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--wdp-bg);
  border-top: 1px solid #e5e7eb;
}
#wdp-input {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  transition: border-color .15s;
  max-height: 120px;
  overflow-y: auto;
}
#wdp-input:focus { border-color: var(--wdp-primary); }
#wdp-input:disabled { opacity: .6; }

#wdp-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wdp-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
  color: #fff;
}
#wdp-send:hover:not(:disabled) { background: var(--wdp-primary-d); transform: scale(1.05); }
#wdp-send:disabled { opacity: .5; cursor: not-allowed; }
#wdp-send svg { width: 17px; height: 17px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
  #wdp-chat-widget { bottom: 16px; right: 16px; }
  #wdp-window { width: calc(100vw - 32px); right: 0; }
}
