/* ==========================================================================
   KGI Chat Widget
   Branded floating assistant, restyled onto the css/kgi.css token system
   ========================================================================== */

/* --- Trigger Button --- */
.kgi-chat-trigger {
  position: fixed;
  bottom: 124px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(41, 196, 169, 0.45);
  z-index: 1200;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.kgi-chat-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(41, 196, 169, 0.55);
  background: var(--color-accent-hover);
}

.kgi-chat-trigger .icon-chat,
.kgi-chat-trigger .icon-close {
  width: 26px;
  height: 26px;
  position: absolute;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

.kgi-chat-trigger .icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}

.kgi-chat-trigger.is-open .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}

.kgi-chat-trigger.is-open .icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Notification dot */
.kgi-chat-trigger::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 13px;
  height: 13px;
  background: var(--alert);
  border-radius: 50%;
  border: 2px solid var(--color-on-dark);
  animation: kgi-pulse 2.4s ease-in-out infinite;
  transition: opacity 0.2s ease;
}

.kgi-chat-trigger.seen::after {
  opacity: 0;
  pointer-events: none;
}

@keyframes kgi-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.6; }
}

/* Push the site's scroll-to-top button above the chat trigger so they never overlap */
.to-top {
  bottom: 196px !important;
}

/* --- Chat Panel --- */
.kgi-chat-panel {
  position: fixed;
  bottom: 196px;
  right: 24px;
  width: 360px;
  max-height: calc(100vh - 120px);
  height: 520px;
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card), 0 20px 60px rgba(23, 29, 41, 0.22);
  display: flex;
  flex-direction: column;
  z-index: 1199;
  overflow: hidden;
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.32s var(--ease),
              opacity 0.28s ease;
}

.kgi-chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.kgi-chat-header {
  position: relative;
  background: var(--color-ink);
  padding: 14px 40px 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.kgi-chat-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-on-dark);
  transition: background 0.2s ease, transform 0.15s ease;
}

.kgi-chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.06);
}

.kgi-chat-close svg {
  width: 15px;
  height: 15px;
}

.kgi-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent-deep) 0%, var(--color-accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 13px;
  color: var(--color-on-dark);
  letter-spacing: -0.02em;
}

.kgi-chat-header-info {
  flex: 1;
  min-width: 0;
}

.kgi-chat-header-name {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  color: var(--color-on-dark);
  line-height: 1.2;
}

.kgi-chat-header-status {
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--color-accent);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.kgi-chat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
  flex-shrink: 0;
}

/* Messages area */
.kgi-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-bg-soft);
  scroll-behavior: smooth;
}

.kgi-chat-messages::-webkit-scrollbar { width: 4px; }
.kgi-chat-messages::-webkit-scrollbar-track { background: transparent; }
.kgi-chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

/* Message bubbles */
.kgi-msg {
  display: flex;
  max-width: 88%;
  animation: kgi-msg-in 0.22s ease;
}

@keyframes kgi-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kgi-msg--bot  { align-self: flex-start; }
.kgi-msg--user { align-self: flex-end; }

.kgi-msg__bubble {
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
}

.kgi-msg--bot .kgi-msg__bubble {
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 1px 4px rgba(23, 29, 41, 0.08);
}

.kgi-msg--user .kgi-msg__bubble {
  background: var(--color-accent);
  color: var(--color-on-dark);
  border-radius: 14px 4px 14px 14px;
}

.kgi-msg__bubble a {
  color: var(--color-accent-deep);
  text-decoration: underline;
  font-weight: 600;
}

.kgi-msg--user .kgi-msg__bubble a {
  color: var(--color-on-dark);
}

.kgi-msg__bubble strong { font-weight: 700; }

/* Typing indicator */
.kgi-typing-wrap {
  align-self: flex-start;
  animation: kgi-msg-in 0.22s ease;
}

.kgi-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 13px 16px;
  background: var(--color-bg);
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 1px 4px rgba(23, 29, 41, 0.08);
}

.kgi-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-disabled);
  display: block;
  animation: kgi-bounce 1.2s ease-in-out infinite;
}
.kgi-typing span:nth-child(2) { animation-delay: 0.18s; }
.kgi-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes kgi-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Quick reply chips */
.kgi-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0;
  align-self: flex-start;
  max-width: 100%;
}

.kgi-qr-btn {
  background: var(--color-bg);
  border: 1.5px solid var(--color-accent);
  color: var(--color-text);
  border-radius: var(--radius-pill);
  padding: 6px 13px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  white-space: nowrap;
}

.kgi-qr-btn:hover {
  background: var(--color-accent);
  color: var(--color-on-dark);
}

/* Input row */
.kgi-chat-input-area {
  padding: 10px 14px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.kgi-chat-input {
  flex: 1;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--color-text);
  resize: none;
  outline: none;
  background: var(--color-bg-soft);
  max-height: 90px;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.kgi-chat-input:focus {
  border-color: var(--color-accent);
  background: var(--color-bg);
}

.kgi-chat-input::placeholder { color: var(--color-text-muted); }

.kgi-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.kgi-chat-send:hover {
  background: var(--color-accent-hover);
  transform: scale(1.06);
}

.kgi-chat-send svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--color-on-dark);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Footer branding */
.kgi-chat-branding {
  padding: 5px 14px 8px;
  background: var(--color-bg);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
  border-top: 1px solid var(--color-border);
}

.kgi-chat-branding a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.kgi-chat-branding a:hover { text-decoration: underline; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .kgi-chat-trigger::after,
  .kgi-msg,
  .kgi-typing-wrap,
  .kgi-typing span {
    animation: none !important;
  }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .kgi-chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 186px;
    height: 68vh;
    max-height: 68vh;
    border-radius: 14px;
  }

  .kgi-chat-trigger {
    right: 16px;
    bottom: 116px;
    width: 54px;
    height: 54px;
  }

  /* On mobile, put scroll-to-top to the left of the chat trigger */
  .to-top {
    bottom: 124px !important;
    right: 84px !important;
  }
}
