.wd-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120;
  font-family: inherit;
}

.wd-chat-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: var(--grad, linear-gradient(135deg, #0b63d6, #2563eb));
  color: #fff;
  font: inherit;
  font-weight: 650;
  font-size: 15px;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.38);
}

.wd-chat-toggle svg {
  width: 24px;
  height: 24px;
  flex: none;
}

.wd-chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.wd-chat-panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  display: flex;
  flex-direction: column;
  width: 360px;
  height: 540px;
  max-height: calc(100vh - 100px);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line, #e5eaf2);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

.wd-chat-panel[hidden] {
  display: none;
}

.wd-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--grad, linear-gradient(135deg, #0b63d6, #2563eb));
  color: #fff;
}

.wd-chat-head strong {
  display: block;
  font-size: 16px;
  line-height: 1.4;
}

.wd-chat-head span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.82;
}

.wd-chat-close {
  flex: none;
  width: 28px;
  height: 28px;
  margin: -2px -4px 0 0;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 20px;
  line-height: 28px;
  text-align: center;
  cursor: pointer;
}

.wd-chat-close:hover {
  background: rgba(255, 255, 255, 0.24);
}

.wd-chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 14px;
  background: #f6f9ff;
}

.wd-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}

.wd-msg-agent {
  align-self: flex-start;
  align-items: flex-start;
}

.wd-msg-visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.wd-bubble {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.wd-msg-agent .wd-bubble {
  background: #fff;
  border: 1px solid var(--line, #e5eaf2);
  border-top-left-radius: 4px;
  color: var(--ink, #1f2937);
}

.wd-msg-visitor .wd-bubble {
  background: var(--brand, #0b63d6);
  border-top-right-radius: 4px;
  color: #fff;
}

.wd-time {
  margin-top: 3px;
  font-size: 11px;
  color: #94a3b8;
}

.wd-chat-error {
  margin: 0 14px 8px;
  padding: 8px 10px;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  background: #fff1f2;
  color: #be123c;
  font-size: 12px;
  line-height: 1.5;
}

.wd-chat-error[hidden] {
  display: none;
}

.wd-chat-form {
  padding: 10px 12px;
  border-top: 1px solid var(--line, #e5eaf2);
  background: #fff;
}

.wd-chat-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.wd-chat-meta input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line, #e5eaf2);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  color: var(--ink, #1f2937);
  background: #fff;
}

.wd-chat-meta input:focus,
.wd-chat-row textarea:focus {
  outline: none;
  border-color: var(--brand, #0b63d6);
  box-shadow: 0 0 0 3px rgba(11, 99, 214, 0.1);
}

.wd-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.wd-chat-row textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 8px 10px;
  border: 1px solid var(--line, #e5eaf2);
  border-radius: 10px;
  resize: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink, #1f2937);
  background: #fff;
}

.wd-chat-row textarea::placeholder,
.wd-chat-meta input::placeholder {
  color: #94a3b8;
}

.wd-chat-send {
  flex: none;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--brand, #0b63d6);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.wd-chat-send:disabled {
  opacity: 0.6;
  cursor: default;
}

.wd-chat-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 12px;
  background: #fff;
  color: var(--ink-3, #64748b);
  font-size: 12px;
}

.wd-chat-foot[hidden] {
  display: none;
}

.wd-chat-foot b {
  color: var(--ink-2, #475569);
  font-weight: 600;
  word-break: break-all;
}

.wd-chat-copy {
  padding: 2px 8px;
  border: 1px solid var(--line, #e5eaf2);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-3, #64748b);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.wd-chat-copy:hover {
  border-color: var(--brand, #0b63d6);
  color: var(--brand, #0b63d6);
}

.wd-in {
  animation: wd-in 0.2s ease;
}

@keyframes wd-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 640px) {
  .wd-chat {
    right: 14px;
    bottom: 14px;
  }

  .wd-chat-toggle {
    height: 50px;
    padding: 0 16px 0 14px;
    font-size: 14px;
  }

  .wd-chat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    max-height: none;
    border: 0;
    border-radius: 0;
    z-index: 300;
  }

  body.wd-chat-lock {
    overflow: hidden;
  }

  .wd-chat-meta {
    gap: 6px;
  }

  .wd-chat-row textarea {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wd-in {
    animation: none;
  }
}
