#kd-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: Arial, sans-serif;
}

#kd-chat-toggle {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, #FFD60A 0%, #FF8C42 100%);
  color: #141414;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 140, 66, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s;
}

#kd-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(255, 140, 66, 0.45);
}

#kd-chat-toggle.kd-pulse {
  animation: kd-toggle-pulse 0.9s ease-out 1;
}

@keyframes kd-toggle-pulse {
  0%   { box-shadow: 0 8px 24px rgba(255, 140, 66, 0.35), 0 0 0 0 rgba(255, 214, 10, 0.55); }
  60%  { box-shadow: 0 8px 24px rgba(255, 140, 66, 0.35), 0 0 0 14px rgba(255, 214, 10, 0); }
  100% { box-shadow: 0 8px 24px rgba(255, 140, 66, 0.35), 0 0 0 0 rgba(255, 214, 10, 0); }
}

#kd-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #E23636;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #141414;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}

#kd-chat-box[hidden] {
  display: none !important;
}

#kd-chat-box {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 350px;
  max-height: 520px;
  background: #141414;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
  opacity: 0;
  transform: translateY(16px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.4,.64,1);
}

#kd-chat-box.kd-box-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#kd-chat-header {
  background: linear-gradient(120deg, #FF8C2B 0%, #FFB92B 100%);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  flex-shrink: 0;
}

#kd-chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #141414;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}

#kd-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  box-sizing: border-box;
}

#kd-chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding-right: 24px;
}

#kd-chat-title {
  font-weight: 800;
  font-size: 15.5px;
  color: #141414;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#kd-chat-status {
  font-size: 12px;
  color: rgba(20,20,20,.72);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

#kd-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1DBE5B;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(29,190,91,.25);
  flex-shrink: 0;
  animation: kd-dot-breathe 2.4s ease-in-out infinite;
}

@keyframes kd-dot-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

#kd-chat-header-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(20,20,20,.12);
  color: #141414;
  font-size: 20px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .15s;
}

#kd-chat-header-close:hover {
  background: rgba(20,20,20,.22);
  transform: rotate(90deg);
}

#kd-chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  min-height: 220px;
  max-height: 340px;
  background: #141414;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

#kd-chat-messages::-webkit-scrollbar {
  width: 6px;
}
#kd-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.12);
  border-radius: 10px;
}

.kd-day-sep {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,.4);
  background: rgba(255,255,255,.05);
  padding: 4px 12px;
  border-radius: 100px;
  margin: 12px 0 10px;
}

.kd-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 5px 0;
  max-width: 88%;
}

.kd-msg-enter {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .28s ease, transform .28s cubic-bezier(.34,1.2,.64,1);
}
.kd-msg-enter-active {
  opacity: 1;
  transform: translateY(0);
}

.kd-msg-user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.kd-msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: contain;
  background: #141414;
  border: 1px solid rgba(255,255,255,.12);
  box-sizing: border-box;
  padding: 2px;
}

.kd-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  min-width: 0;
}

.kd-msg-text {
  word-wrap: break-word;
  white-space: pre-wrap;
}

.kd-msg-time {
  font-size: 10px;
  margin-top: 4px;
  opacity: .55;
  text-align: right;
}

.kd-msg-user .kd-msg-bubble {
  background: linear-gradient(135deg, #FFD60A, #FF8C42);
  color: #141414;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}
.kd-msg-user .kd-msg-time { color: #141414; }

.kd-msg-admin .kd-msg-bubble {
  background: #232323;
  color: #eee;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255,255,255,.06);
}

.kd-msg-welcome { opacity: .97; }

/* --- индикатор "печатает..." --- */
.kd-typing-row .kd-msg-bubble { display: none; }
.kd-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #232323;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
}
.kd-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.5);
  animation: kd-typing-bounce 1.1s infinite ease-in-out;
}
.kd-typing-dots span:nth-child(2) { animation-delay: .15s; }
.kd-typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes kd-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

#kd-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 10px 12px;
  background: #181818;
  flex-shrink: 0;
}

#kd-chat-input {
  flex: 1;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 100px;
  padding: 10px 16px;
  background: #141414;
  color: #eee;
  outline: none;
  font-size: 13.5px;
  transition: border-color .2s, box-shadow .2s;
}

#kd-chat-input:focus {
  border-color: #FFD60A;
  box-shadow: 0 0 0 3px rgba(255,214,10,.12);
}

#kd-chat-form button {
  border: none;
  background: linear-gradient(135deg, #FFD60A, #FF8C42);
  color: #141414;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}

#kd-chat-form button:hover {
  transform: scale(1.06);
}

@media (max-width: 480px) {
  #kd-chat-widget {
    right: 12px;
    bottom: 12px;
  }
  #kd-chat-box {
    width: calc(100vw - 24px);
    right: -4px;
    max-height: 72vh;
    border-radius: 20px;
  }
  #kd-chat-messages {
    max-height: none;
  }
}