/* KAPLI AI chat — bottom left */

.kapli-chat {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 1100;
  font-family: var(--font-primary);
}

.kapli-chat__toggle {
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 180, 140, 0.35), transparent 55%),
    #121212;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.kapli-chat__toggle:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: rgba(255, 200, 170, 0.55);
}

.kapli-chat__toggle svg {
  width: 24px;
  height: 24px;
}

.kapli-chat.is-open .kapli-chat__toggle {
  display: none;
}

.kapli-chat__panel {
  width: min(380px, calc(100vw - 28px));
  height: min(560px, calc(100vh - 100px));
  display: none;
  flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(14, 14, 14, 0.96);
  backdrop-filter: blur(16px);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
}

.kapli-chat.is-open .kapli-chat__panel {
  display: flex;
  animation: kapli-chat-in 0.28s ease;
}

@keyframes kapli-chat-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.kapli-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: #111;
}

.kapli-chat__identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.kapli-chat__pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgb(255, 170, 140);
  box-shadow: 0 0 14px rgba(255, 150, 120, 0.55);
  flex-shrink: 0;
}

.kapli-chat__titles {
  min-width: 0;
}

.kapli-chat__titles strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.kapli-chat__titles span {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.kapli-chat__close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, transform 0.2s ease;
}

.kapli-chat__close:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: rotate(90deg);
}

.kapli-chat__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kapli-chat__msg {
  max-width: 88%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.kapli-chat__msg--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(243, 243, 243, 0.92);
  border-bottom-left-radius: 6px;
}

.kapli-chat__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(255, 170, 140, 0.22), rgba(255, 120, 100, 0.12));
  border: 1px solid rgba(255, 180, 150, 0.28);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.kapli-chat__msg--system {
  align-self: center;
  max-width: 94%;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  padding: 4px 8px;
}

.kapli-chat__typing {
  display: none;
  align-self: flex-start;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.kapli-chat__typing.is-on {
  display: inline-flex;
}

.kapli-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 180, 150, 0.85);
  animation: kapli-dot 1s infinite ease-in-out;
}

.kapli-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.kapli-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes kapli-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.kapli-chat__lead {
  display: none;
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: #101010;
  gap: 8px;
  flex-direction: column;
}

.kapli-chat__lead.is-on {
  display: flex;
}

.kapli-chat__lead p {
  margin: 0 0 4px;
  font-size: 12px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.62);
}

.kapli-chat__lead input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #161616;
  color: #fff;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.kapli-chat__lead input:focus {
  border-color: rgba(255, 180, 150, 0.55);
}

.kapli-chat__lead-actions {
  display: flex;
  gap: 8px;
}

.kapli-chat__lead button {
  flex: 1;
  padding: 11px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.kapli-chat__lead button[type="submit"] {
  background: linear-gradient(135deg, rgba(255, 170, 140, 0.95), rgba(255, 120, 100, 0.85));
  border-color: transparent;
  color: #1a1210;
  font-weight: 600;
}

.kapli-chat__composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: #111;
}

.kapli-chat__composer input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #171717;
  color: #fff;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.kapli-chat__composer input:focus {
  border-color: rgba(255, 180, 150, 0.5);
}

.kapli-chat__send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(135deg, rgba(255, 170, 140, 0.95), rgba(255, 120, 100, 0.8));
  color: #1a1210;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.kapli-chat__send:hover {
  transform: scale(1.05);
}

.kapli-chat__send:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.kapli-chat__send svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 720px) {
  .kapli-chat {
    left: 12px;
    bottom: 86px;
  }

  .kapli-chat__panel {
    height: min(520px, calc(100vh - 120px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .kapli-chat__panel,
  .kapli-chat__toggle,
  .kapli-chat__close,
  .kapli-chat__typing span {
    animation: none !important;
    transition: none !important;
  }
}
