#kirsanov-crm-chat-root {
  position: fixed;
  bottom: calc(var(--kcrm-bottom, 20px) + var(--kcrm-callback-stack, 0px));
  z-index: 100001;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: #0f172a;
}

#kirsanov-crm-chat-root *,
#kirsanov-crm-chat-root *::before,
#kirsanov-crm-chat-root *::after {
  box-sizing: border-box;
}

#kirsanov-crm-chat-root.kcrm-position-right {
  right: var(--kcrm-side, 20px);
  left: auto;
}

#kirsanov-crm-chat-root.kcrm-position-left {
  left: var(--kcrm-side, 20px);
  right: auto;
}

#kirsanov-crm-chat-root .kcrm-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--kcrm-accent, #1d4ed8);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(29, 78, 216, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#kirsanov-crm-chat-root .kcrm-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(29, 78, 216, 0.42);
}

#kirsanov-crm-chat-root .kcrm-toggle.is-open {
  background: #334155;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#kirsanov-crm-chat-root .kcrm-panel {
  position: absolute;
  bottom: 72px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: kcrm-slide-up 0.28s ease;
}

@keyframes kcrm-slide-up {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#kirsanov-crm-chat-root.kcrm-position-right .kcrm-panel {
  right: 0;
  left: auto;
}

#kirsanov-crm-chat-root.kcrm-position-left .kcrm-panel {
  left: 0;
  right: auto;
}

#kirsanov-crm-chat-root .kcrm-panel.hidden {
  display: none;
}

#kirsanov-crm-chat-root .kcrm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--kcrm-accent, #1d4ed8);
  color: #fff;
  flex-shrink: 0;
}

#kirsanov-crm-chat-root .kcrm-header-info {
  flex: 1;
  min-width: 0;
}

#kirsanov-crm-chat-root .kcrm-header-info strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#kirsanov-crm-chat-root .kcrm-header-info span {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.92;
}

#kirsanov-crm-chat-root .kcrm-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

#kirsanov-crm-chat-root .kcrm-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  border: 2px solid rgba(255, 255, 255, 0.45);
}

#kirsanov-crm-chat-root .kcrm-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#kirsanov-crm-chat-root .kcrm-close {
  border: none;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
  padding: 0;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

#kirsanov-crm-chat-root .kcrm-close-icon {
  display: block;
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  color: #fff;
  margin-top: -2px;
  pointer-events: none;
}

#kirsanov-crm-chat-root .kcrm-close svg {
  display: block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#kirsanov-crm-chat-root .kcrm-close svg path {
  fill: #fff;
}

#kirsanov-crm-chat-root .kcrm-close:hover {
  background: rgba(255, 255, 255, 0.34);
}

#kirsanov-crm-chat-root .kcrm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #eef2f7;
  background-image:
    radial-gradient(circle at 20% 15%, rgba(148, 163, 184, 0.12) 0, transparent 42%),
    radial-gradient(circle at 85% 70%, rgba(148, 163, 184, 0.1) 0, transparent 38%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23cbd5e1' stroke-width='1.2' opacity='0.35'%3E%3Ccircle cx='18' cy='22' r='3'/%3E%3Cpath d='M78 14l8 8-8 8'/%3E%3Cpath d='M30 88c8-12 22-12 30 0'/%3E%3Ccircle cx='96' cy='96' r='5'/%3E%3C/g%3E%3C/svg%3E");
  background-size: auto, auto, 120px 120px;
  scroll-behavior: smooth;
}

#kirsanov-crm-chat-root .kcrm-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

#kirsanov-crm-chat-root .kcrm-row.in {
  justify-content: flex-end;
}

#kirsanov-crm-chat-root .kcrm-row.out {
  justify-content: flex-start;
}

#kirsanov-crm-chat-root .kcrm-row .kcrm-avatar {
  width: 32px;
  height: 32px;
  font-size: 12px;
  border: none;
  background: #dbeafe;
  color: #1e40af;
}

#kirsanov-crm-chat-root .kcrm-bubble-wrap {
  max-width: calc(100% - 44px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#kirsanov-crm-chat-root .kcrm-row.in .kcrm-bubble-wrap {
  align-items: flex-end;
}

#kirsanov-crm-chat-root .kcrm-row.out .kcrm-bubble-wrap {
  align-items: flex-start;
}

#kirsanov-crm-chat-root .kcrm-time {
  font-size: 11px;
  color: #64748b;
  padding: 0 4px;
}

#kirsanov-crm-chat-root .kcrm-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

#kirsanov-crm-chat-root .kcrm-row.in .kcrm-bubble {
  background: var(--kcrm-accent, #1d4ed8);
  color: #fff;
  border-bottom-right-radius: 4px;
}

#kirsanov-crm-chat-root .kcrm-row.out .kcrm-bubble {
  background: #fff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

#kirsanov-crm-chat-root .kcrm-footer {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
}

#kirsanov-crm-chat-root .kcrm-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 6px 6px 6px 16px;
}

#kirsanov-crm-chat-root .kcrm-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  min-height: 24px;
  max-height: 96px;
  padding: 6px 0;
  font: inherit;
  color: #0f172a;
  outline: none;
}

#kirsanov-crm-chat-root .kcrm-form textarea::placeholder {
  color: #94a3b8;
}

#kirsanov-crm-chat-root .kcrm-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--kcrm-accent, #1d4ed8);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#kirsanov-crm-chat-root .kcrm-send:hover:not(:disabled) {
  transform: scale(1.04);
}

#kirsanov-crm-chat-root .kcrm-send:disabled {
  opacity: 0.55;
  cursor: wait;
}

#kirsanov-crm-chat-root .kcrm-brand {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: #94a3b8;
}

#kirsanov-crm-chat-root .kcrm-status {
  min-height: 0;
  padding: 0 14px 4px;
  font-size: 12px;
  color: #64748b;
  background: #fff;
}

#kirsanov-crm-chat-root .kcrm-row.out.kcrm-bot-row .kcrm-bubble {
  background: #e0f2fe;
  color: #0c4a6e;
}

#kirsanov-crm-chat-root .kcrm-status:not(:empty) {
  padding-bottom: 8px;
}

#kirsanov-crm-chat-root .kcrm-status.kcrm-error {
  color: #b91c1c;
}

#kirsanov-crm-chat-root .kcrm-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

#kirsanov-crm-chat-root .kcrm-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

#kirsanov-crm-chat-root .kcrm-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: kcrm-dot 1.2s infinite ease-in-out;
}

#kirsanov-crm-chat-root .kcrm-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

#kirsanov-crm-chat-root .kcrm-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes kcrm-dot {
  0%, 80%, 100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 768px) {
  #kirsanov-crm-chat-root {
    --kcrm-side: 12px;
  }

  #kirsanov-crm-chat-root.kcrm-position-left {
    left: auto;
    right: var(--kcrm-side, 12px);
  }

  #kirsanov-crm-chat-root .kcrm-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--kcrm-bottom, 20px) + 68px);
    width: auto;
    max-width: none;
    height: min(72vh, 520px);
    max-height: calc(100dvh - 110px);
    z-index: 100002;
  }

  #kirsanov-crm-chat-root.kcrm-position-right .kcrm-panel,
  #kirsanov-crm-chat-root.kcrm-position-left .kcrm-panel {
    left: 10px;
    right: 10px;
  }
}

@media (max-width: 480px) {
  #kirsanov-crm-chat-root .kcrm-panel {
    left: 8px;
    right: 8px;
    height: min(70vh, 480px);
  }
}
