/* ==========================================================================
   KBC Chat Widget — Karisma Bukit Cipari
   File statis. Tidak butuh build, tidak butuh framework.
   Warna disamakan dengan palet situs KBC (#8F3D22 / #2B2620 / #FBF8F2 / #E1D5C0)
   ========================================================================== */

.kbc-chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #8F3D22;
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .18s ease, background .18s ease;
  font-family: inherit;
}
.kbc-chat-fab:hover { background: #A23B2E; transform: translateY(-2px); }
.kbc-chat-fab svg { width: 26px; height: 26px; fill: currentColor; }
.kbc-chat-fab .kbc-fab-close { display: none; }
.kbc-chat-fab[data-open="1"] .kbc-fab-close { display: block; }
.kbc-chat-fab[data-open="1"] .kbc-fab-open  { display: none; }

.kbc-chat-fab__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #B5502E;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #FBF8F2;
}

/* ---------- panel ---------- */
.kbc-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  z-index: 2147483000;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #FBF8F2;
  border: 1px solid #E1D5C0;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(43, 38, 32, .28);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: #2B2620;
  font-size: 14px;
  line-height: 1.55;
}
.kbc-chat-panel[data-open="1"] { display: flex; }

.kbc-chat-head {
  background: #2B2620;
  color: #F3ECE1;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.kbc-chat-head__logo {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: #8F3D22;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.kbc-chat-head__txt { flex: 1; min-width: 0; }
.kbc-chat-head__title { font-weight: 700; font-size: 14px; }
.kbc-chat-head__sub { font-size: 11.5px; color: #A8A39D; margin-top: 1px; }
.kbc-chat-head__sub::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5FD3BC;
  margin-right: 5px;
  vertical-align: middle;
}
.kbc-chat-head__x {
  background: none; border: none; cursor: pointer;
  color: #F3ECE1; font-size: 26px; line-height: 1; padding: 6px 12px;
  /* Jangan sampai kegencet judul di layar sempit: ukuran sentuh 44px */
  flex-shrink: 0;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.kbc-chat-head__x:hover { color: #fff; }
.kbc-chat-head__title {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- body ---------- */
.kbc-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  background: #FBF8F2;
}
.kbc-chat-body::-webkit-scrollbar { width: 7px; }
.kbc-chat-body::-webkit-scrollbar-thumb { background: #E1D5C0; border-radius: 4px; }

.kbc-msg { margin-bottom: 10px; display: flex; }
.kbc-msg--bot  { justify-content: flex-start; }
.kbc-msg--user { justify-content: flex-end; }

.kbc-bubble {
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.kbc-msg--bot .kbc-bubble {
  background: #fff;
  border: 1px solid #E1D5C0;
  border-bottom-left-radius: 4px;
}
/* Bubble bot jadi kolom supaya tombol turun ke bawah teks, bukan
   menyamping. display:block → flex column. */
.kbc-msg--bot .kbc-bubble { display: flex; flex-direction: column; align-items: flex-start; }
.kbc-msg--bot .kbc-bubble > .kbc-actions { align-self: stretch; }
.kbc-msg--user .kbc-bubble {
  background: #8F3D22;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.kbc-msg--sys .kbc-bubble {
  background: #F3ECE1;
  border: 1px dashed #E1D5C0;
  font-size: 12.5px;
  color: #5B5346;
  max-width: 100%;
  border-radius: 10px;
}

.kbc-msg--err .kbc-bubble {
  background: #fff5f3;
  border: 1px solid #E8B7AE;
  color: #A23B2E;
}

/* ---------- link di bubble bot ---------- */
.kbc-msg--bot .kbc-bubble a {
  color: #128C4B;
  font-weight: 600;
  word-break: break-all;
}
.kbc-msg--bot .kbc-bubble a:hover { color: #8F3D22; }

/* ---------- buttons ---------- */
.kbc-actions { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 6px; }
.kbc-btn {
  border: 1px solid #8F3D22;
  background: #fff;
  color: #8F3D22;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s ease, color .15s ease;
  /* Jangan biarkan flex/Flex container situs meregangkan tinggi tombol. */
  align-self: flex-start;
  flex: 0 0 auto;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kbc-btn:hover { background: #8F3D22; color: #fff; }
.kbc-btn--solid { background: #8F3D22; color: #fff; }
.kbc-btn--solid:hover { background: #A23B2E; }
.kbc-btn--wa { border-color: #25D366; color: #128C4B; }
.kbc-btn--wa:hover { background: #25D366; color: #fff; }

.kbc-list { margin: 6px 0 0; padding-left: 18px; }
.kbc-list li { margin-bottom: 3px; }

/* ---------- typing ---------- */
.kbc-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.kbc-typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #A8A39D;
  animation: kbc-blink 1.2s infinite;
}
.kbc-typing i:nth-child(2) { animation-delay: .2s; }
.kbc-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes kbc-blink {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- composer ---------- */
.kbc-chat-foot {
  border-top: 1px solid #E1D5C0;
  background: #fff;
  padding: 9px 10px;
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}
.kbc-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #E1D5C0;
  border-radius: 9px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
  color: #2B2620;
  background: #FBF8F2;
}
.kbc-chat-input:focus { outline: none; border-color: #8F3D22; }
.kbc-chat-send {
  width: 40px;
  border: none;
  border-radius: 9px;
  background: #8F3D22;
  color: #fff;
  cursor: pointer;
  font-size: 17px;
  flex-shrink: 0;
}
.kbc-chat-send:hover { background: #A23B2E; }

.kbc-chat-note {
  padding: 0 10px 8px;
  background: #fff;
  font-size: 10.5px;
  color: #A8A39D;
  border-top: 1px solid #F3ECE1;
  padding-top: 6px;
  text-align: center;
}

@media (max-width: 480px) {
  .kbc-chat-panel {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
  /* iOS notch / home indicator: header jangan ketutup poni,
     input jangan ketutup garis home */
  .kbc-chat-panel {
    top: 0;
    height: 100%;
    height: 100dvh;
    max-height: none;
  }
  /* Cegah auto-zoom iOS: input di bawah 16px memicu zoom tiap fokus */
  .kbc-chat-input { font-size: 16px; }
  .kbc-chat-head {
    padding-top: max(14px, env(safe-area-inset-top));
  }
  .kbc-chat-note {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .kbc-chat-fab { bottom: 16px; right: 16px; }
}

/* ---------- avatar admin ---------- */
.kbc-ava {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: #F3ECE1;
}
.kbc-ava__svg { width: 100%; height: 100%; display: block; }
.kbc-ava__photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- kartu ajakan (teaser) ---------- */
.kbc-teaser {
  position: fixed;
  right: 88px;
  bottom: 26px;
  z-index: 2147483000;
  display: none;
  align-items: center;
  gap: 10px;
  max-width: 250px;
  background: #fff;
  border: 1px solid #E1D5C0;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 12px 32px rgba(43, 38, 32, .22);
  padding: 10px 28px 10px 10px;
  cursor: pointer;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  animation: kbc-teaser-in .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
.kbc-teaser[data-show="1"] { display: flex; }
.kbc-teaser__ava { width: 44px; height: 44px; }
.kbc-teaser__txt { display: flex; flex-direction: column; line-height: 1.35; }
.kbc-teaser__txt b { font-size: 13px; color: #2B2620; }
.kbc-teaser__txt i { font-style: normal; font-size: 11.5px; color: #8F3D22; font-weight: 600; }
.kbc-teaser__x {
  position: absolute;
  top: 2px; right: 8px;
  color: #A8A39D;
  font-size: 17px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
}
.kbc-teaser__x:hover { color: #2B2620; }
@keyframes kbc-teaser-in {
  from { opacity: 0; transform: translateX(16px) scale(.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ---------- FAB: titik online + efek ping ---------- */
.kbc-chat-fab::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid #8F3D22;
  animation: kbc-ping 2.2s ease-out infinite;
  pointer-events: none;
}
.kbc-chat-fab[data-open="1"]::after { display: none; }
.kbc-fab-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #25D366;
  border: 2.5px solid #FBF8F2;
}
.kbc-chat-fab[data-open="1"] .kbc-fab-dot { display: none; }
@keyframes kbc-ping {
  0%   { transform: scale(1); opacity: .7; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ---------- avatar di header panel ---------- */
.kbc-chat-head__logo {
  background: none;
  overflow: hidden;
  border-radius: 50%;
  padding: 0;
}
.kbc-chat-head__logo .kbc-ava { width: 34px; height: 34px; }

@media (max-width: 480px) {
  .kbc-teaser { right: 82px; bottom: 22px; max-width: 215px; padding: 8px 26px 8px 8px; }
  .kbc-teaser__ava { width: 38px; height: 38px; }
  .kbc-teaser__txt b { font-size: 12px; }
}