/* ─── Kaizen Hilfe Chatbot Widget ────────────────────────────────────────── */

/* Toggle button */
.kh-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  background: var(--tp-theme-primary, #00A3C3);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0,163,195,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.2s, box-shadow 0.2s;
}
.kh-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(0,163,195,0.55);
}
.kh-chat-toggle svg { width: 26px; height: 26px; fill: #fff; pointer-events: none; }
.kh-chat-toggle .kh-close-icon { display: none; }
.kh-chat-toggle.open .kh-open-icon { display: none; }
.kh-chat-toggle.open .kh-close-icon { display: block; }

.kh-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #ff4757;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: khPulse 2s infinite;
}
@keyframes khPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

/* Panel */
.kh-chat-panel {
  position: fixed;
  bottom: 94px;
  right: 24px;
  width: 360px;
  height: 530px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  transform: scale(0.92) translateY(20px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), opacity 0.2s ease;
}
.kh-chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.kh-chat-header {
  background: var(--tp-theme-secondary, #16243E);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.kh-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--tp-theme-primary, #00A3C3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kh-chat-avatar svg { width: 20px; height: 20px; fill: #fff; }
.kh-chat-header-info { flex: 1; min-width: 0; }
.kh-chat-header-name { color: #fff; font-weight: 600; font-size: 14px; margin: 0; line-height: 1.3; }
.kh-chat-header-status { color: rgba(255,255,255,0.55); font-size: 11px; }
.kh-chat-header-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  padding: 4px;
  font-size: 20px;
  line-height: 1;
  transition: color 0.15s;
}
.kh-chat-header-close:hover { color: #fff; }

/* Messages */
.kh-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: #f4f6f9;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.kh-chat-messages::-webkit-scrollbar { width: 4px; }
.kh-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.kh-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kh-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 88%;
}
.kh-msg.bot { align-self: flex-start; }
.kh-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.kh-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--tp-theme-primary, #00A3C3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.kh-msg-avatar svg { width: 13px; height: 13px; fill: #fff; }

.kh-msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}
.kh-msg.bot .kh-msg-bubble {
  background: #fff;
  color: #2d2d2d;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.kh-msg.user .kh-msg-bubble {
  background: var(--tp-theme-primary, #00A3C3);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing */
.kh-typing-wrap { display: flex; align-items: flex-end; gap: 7px; align-self: flex-start; }
.kh-typing {
  background: #fff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.kh-typing span {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: khDot 1.2s infinite ease-in-out;
}
.kh-typing span:nth-child(2) { animation-delay: 0.2s; }
.kh-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes khDot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Quick replies */
.kh-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 2px 33px;
  align-self: flex-start;
  width: 100%;
}
.kh-quick-reply {
  background: #fff;
  border: 1.5px solid var(--tp-theme-primary, #00A3C3);
  color: var(--tp-theme-primary, #00A3C3);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  line-height: 1.4;
}
.kh-quick-reply:hover {
  background: var(--tp-theme-primary, #00A3C3);
  color: #fff;
}
.kh-quick-replies.disabled .kh-quick-reply {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* Input area */
.kh-chat-footer {
  padding: 9px 10px;
  border-top: 1px solid #eaeaea;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.kh-chat-input {
  flex: 1;
  border: 1.5px solid #e0e0e0;
  border-radius: 22px;
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
  background: #f9f9f9;
}
.kh-chat-input:focus { border-color: var(--tp-theme-primary, #00A3C3); background: #fff; }
.kh-chat-input::placeholder { color: #b0b0b0; }
.kh-chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

.kh-chat-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: var(--tp-theme-primary, #00A3C3);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.kh-chat-send:hover { background: #0090ae; }
.kh-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.kh-chat-send svg { width: 15px; height: 15px; fill: #fff; }

/* Summary card */
.kh-summary {
  background: #fff;
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 12.5px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  width: 100%;
}
.kh-summary-row {
  display: flex;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid #f2f2f2;
}
.kh-summary-row:last-child { border-bottom: none; }
.kh-summary-label { color: #999; min-width: 72px; font-size: 11px; }
.kh-summary-value { color: #222; font-weight: 500; flex: 1; }

/* WhatsApp button */
.kh-wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #25D366;
  color: #fff !important;
  border: none;
  border-radius: 25px;
  padding: 11px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  text-decoration: none !important;
  transition: background 0.15s;
  font-family: inherit;
}
.kh-wa-btn:hover { background: #1cb954; }
.kh-wa-btn svg { width: 18px; height: 18px; fill: #fff; flex-shrink: 0; }

.kh-restart-btn {
  background: none;
  border: none;
  color: #999;
  font-size: 11.5px;
  cursor: pointer;
  padding: 4px;
  text-align: center;
  width: 100%;
  margin-top: 4px;
  font-family: inherit;
  transition: color 0.15s;
}
.kh-restart-btn:hover { color: var(--tp-theme-primary, #00A3C3); }

/* Tooltip label above toggle */
.kh-chat-label {
  position: fixed;
  bottom: 90px;
  right: 24px;
  background: var(--tp-theme-secondary, #16243E);
  color: #fff;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 20px;
  white-space: nowrap;
  z-index: 9997;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  animation: khFadeIn 0.4s ease 1.5s both;
  pointer-events: none;
}
.kh-chat-label::after {
  content: '';
  position: absolute;
  bottom: -5px;
  right: 18px;
  width: 10px;
  height: 10px;
  background: var(--tp-theme-secondary, #16243E);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.kh-chat-label.hidden { display: none; }
@keyframes khFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile */
@media (max-width: 480px) {
  .kh-chat-panel {
    width: calc(100vw - 20px);
    right: 10px;
    left: 10px;
    bottom: 82px;
    height: 72vh;
    max-height: 540px;
  }
  .kh-chat-toggle { bottom: 16px; right: 16px; }
  .kh-chat-label { bottom: 82px; right: 16px; }
}
