/* KIWL floating live chat widget */
#kiwl-chat-root {
  --kiwl-chat-accent: #ff6310;
  --kiwl-chat-accent-dark: #e5550a;
  --kiwl-chat-bg: #ffffff;
  --kiwl-chat-text: #393939;
  --kiwl-chat-muted: #6b7280;
  --kiwl-chat-border: rgba(0, 0, 0, 0.08);
  --kiwl-chat-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999999;
  font-family: Roboto, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#kiwl-chat-toggle {
  position: relative;
  width: 62px;
  height: 62px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: linear-gradient(145deg, #25d366 0%, #1da851 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(37, 211, 102, 0.55), 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: kiwlChatPulse 2.4s ease-in-out infinite;
  padding: 0;
  overflow: visible;
}

#kiwl-chat-toggle::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(37, 211, 102, 0.45);
  animation: kiwlChatRing 2.4s ease-out infinite;
  pointer-events: none;
}

#kiwl-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 28px rgba(37, 211, 102, 0.65), 0 4px 12px rgba(0, 0, 0, 0.18);
}

#kiwl-chat-toggle .kiwl-toggle-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#kiwl-chat-toggle svg {
  display: block !important;
  width: 32px !important;
  height: 32px !important;
  fill: #ffffff !important;
  flex-shrink: 0;
  pointer-events: none;
}

#kiwl-chat-toggle svg path {
  fill: #ffffff !important;
}

#kiwl-chat-toggle.is-open {
  background: linear-gradient(145deg, #ff6310 0%, #e5550a 100%);
  box-shadow: 0 6px 22px rgba(255, 99, 16, 0.5);
  animation: none;
}

#kiwl-chat-toggle.is-open::before {
  display: none;
}

#kiwl-chat-toggle.is-open svg.kiwl-icon-chat {
  display: none !important;
}

#kiwl-chat-toggle:not(.is-open) svg.kiwl-icon-close {
  display: none !important;
}

#kiwl-chat-toggle .kiwl-chat-online-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  background: #fff;
  border: 2px solid #25d366;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

#kiwl-chat-toggle.is-open .kiwl-chat-online-dot {
  display: none;
}

#kiwl-chat-toggle-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: #fff;
  color: #393939;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.06);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#kiwl-chat-toggle-label::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #fff;
}

#kiwl-chat-toggle.is-open #kiwl-chat-toggle-label {
  opacity: 0;
  transform: translateY(-50%) translateX(8px);
  pointer-events: none;
}

@keyframes kiwlChatPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

@keyframes kiwlChatRing {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.35); opacity: 0; }
}

#kiwl-chat-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(360px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 120px));
  background: var(--kiwl-chat-bg);
  border-radius: 14px;
  box-shadow: var(--kiwl-chat-shadow);
  border: 1px solid var(--kiwl-chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

#kiwl-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.kiwl-chat-header {
  background: linear-gradient(135deg, #ff6310 0%, #eb7021 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.kiwl-chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 13px;
}

.kiwl-chat-header-text strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}

.kiwl-chat-header-text span {
  font-size: 12px;
  opacity: 0.9;
}

.kiwl-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fb;
}

.kiwl-chat-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  color: var(--kiwl-chat-text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--kiwl-chat-border);
  animation: kiwlChatFadeIn 0.35s ease;
}

.kiwl-chat-msg strong {
  color: var(--kiwl-chat-accent);
}

.kiwl-chat-msg-page {
  background: #fff8f4;
  border-color: rgba(255, 99, 16, 0.2);
}

.kiwl-chat-msg-page em {
  display: block;
  font-style: normal;
  font-weight: 600;
  color: #1a1a1a;
  margin: 4px 0;
  word-break: break-word;
}

.kiwl-chat-msg-page small {
  display: block;
  color: var(--kiwl-chat-muted);
  font-size: 12px;
  margin-top: 6px;
  line-height: 1.45;
}

.kiwl-chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--kiwl-chat-border);
  display: flex;
  gap: 4px;
}

.kiwl-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: kiwlChatDot 1.2s infinite ease-in-out;
}

.kiwl-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.kiwl-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

.kiwl-chat-footer {
  padding: 12px 14px 14px;
  background: #fff;
  border-top: 1px solid var(--kiwl-chat-border);
}

.kiwl-chat-wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  background: #25d366;
  color: #fff !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s ease, transform 0.15s ease;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.35);
}

.kiwl-chat-wa-btn:hover {
  background: #1ebe57;
  transform: translateY(-1px);
}

.kiwl-chat-wa-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex-shrink: 0;
}

@keyframes kiwlChatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes kiwlChatDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
  #kiwl-chat-root {
    right: 14px;
    bottom: 14px;
  }
  #kiwl-chat-panel {
    width: calc(100vw - 28px);
  }
  #kiwl-chat-toggle-label {
    display: none;
  }
}
