#kredity-chat-root {
  --kchat-green: #1b4332;
  --kchat-accent: #199c68;
  --kchat-bg: #ffffff;
  --kchat-muted: #6b7280;
  --kchat-surface: #eef5f1;
  font-family: "IBM Plex Sans", Arial, sans-serif;
  z-index: 99999;
}

#kredity-chat-toggle {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  overflow: visible;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#kredity-chat-toggle::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.kchat-toggle-avatar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
}

#kredity-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

#kredity-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 162px;
  width: min(380px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 200px));
  max-height: calc(100vh - 200px);
  background: var(--kchat-bg);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.24);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 100000;
}

#kredity-chat-panel.is-open {
  display: flex;
}

.kchat-header {
  background: linear-gradient(135deg, #1b4332 0%, #245744 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.kchat-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.kchat-header-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.kchat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.kchat-header-text strong {
  font-size: 15px;
  line-height: 1.2;
}

.kchat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.88);
}

.kchat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
  animation: kchat-pulse 2s ease-in-out infinite;
}

.kchat-close {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.kchat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--kchat-surface);
}

.kchat-phone-step,
.kchat-messages-wrap {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.kchat-phone-step.is-active,
.kchat-messages-wrap.is-active {
  display: flex;
}

.kchat-composer {
  padding: 10px 12px 12px;
  border-top: 1px solid #dbe5df;
  background: #fff;
  flex-shrink: 0;
}

.kchat-intro-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: flex-start;
  min-height: 180px;
}

.kchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.kchat-bubble-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100% - 40px);
}

.kchat-msg-followup {
  animation: kchat-fade-in 0.35s ease both;
}

.kchat-msg-intro {
  animation: kchat-fade-in 0.35s ease both;
}

.is-hidden {
  display: none !important;
}

.kchat-typing-row {
  opacity: 0.95;
}

.kchat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 14px;
}

.kchat-typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: kchat-dot 1.2s infinite ease-in-out;
}

.kchat-typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.kchat-typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.kchat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border-top: none;
  background: transparent;
}

.kchat-input-row input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 22px;
  padding: 11px 14px;
  font-size: 15px;
  background: #f9fafb;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.kchat-input-row input:focus {
  outline: none;
  border-color: var(--kchat-accent);
  background: #fff;
}

.kchat-send-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--kchat-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.kchat-send-btn:hover {
  background: #158a5c;
  transform: scale(1.04);
}

.kchat-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.kchat-error {
  color: #b91c1c;
  font-size: 12px;
  min-height: 16px;
  margin-top: 6px;
  text-align: center;
}

.kchat-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.kchat-msg-row-user {
  justify-content: flex-end;
}

.kchat-msg-row-assistant {
  justify-content: flex-start;
}

.kchat-msg-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.kchat-msg {
  max-width: calc(100% - 40px);
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.kchat-bubble-group .kchat-msg {
  max-width: 100%;
}

.kchat-msg-user {
  background: var(--kchat-accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.kchat-msg-assistant {
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 5px;
}

.kchat-bubble-group .kchat-msg-assistant:last-child {
  border-bottom-left-radius: 5px;
}

.kchat-msg-typing {
  background: #fff;
  color: var(--kchat-muted);
  border: 1px solid #e5e7eb;
  font-style: italic;
}

@keyframes kchat-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes kchat-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.92);
    opacity: 0.85;
  }
}

@keyframes kchat-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 480px) {
  #kredity-chat-panel {
    right: 12px;
    bottom: 150px;
    width: calc(100vw - 24px);
    height: min(460px, calc(100vh - 170px));
    max-height: calc(100vh - 170px);
  }

  #kredity-chat-toggle {
    right: 12px;
    bottom: 82px;
  }
}
