/*--------------------------------------------------------------
# Kodak AI Chat Widget
# Bubble mengambang di semua halaman, diposisikan di atas #scroll-top.
--------------------------------------------------------------*/

.kchat {
  --kchat-brand: #FFB700;
  --kchat-brand-dark: #e6a500;
  --kchat-ink: #1f1d1e;
  --kchat-surface: #ffffff;
  --kchat-muted: #6b7280;
  --kchat-line: #e8e8e8;
  --kchat-bot-bg: #f3f4f6;
  --kchat-radius: 14px;

  font-family: var(--default-font, "Roboto", sans-serif);
}

/*--------------------------------------------------------------
# Launcher
--------------------------------------------------------------*/

.kchat-launcher {
  position: fixed;
  right: 15px;
  /* #scroll-top berada di bottom:15px dengan tinggi 40px — bubble diletakkan
     di atasnya supaya keduanya tidak bertumpuk. */
  bottom: 68px;
  z-index: 99998;

  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--kchat-brand);
  color: var(--kchat-ink);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background-color .2s ease, box-shadow .2s ease;
}

.kchat-launcher:hover {
  background: var(--kchat-brand-dark);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .26);
}

.kchat-launcher:focus-visible {
  outline: 3px solid var(--kchat-ink);
  outline-offset: 2px;
}

/* Dua ikon ditumpuk; saat panel dibuka/ditutup keduanya bertukar dengan
   putaran + memudar, bukan lompat display:none. */
.kchat-launcher i {
  position: absolute;
  font-size: 24px;
  line-height: 1;
  transition: transform .25s ease, opacity .2s ease;
}

.kchat-launcher-icon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.kchat-launcher-close {
  opacity: 0;
  transform: rotate(-90deg) scale(.4);
}

.kchat.is-open .kchat-launcher-icon {
  opacity: 0;
  transform: rotate(90deg) scale(.4);
}

.kchat.is-open .kchat-launcher-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Denyut singkat tiap kali launcher ditekan (kelas dipasang JS, dilepas
   saat animasi selesai). */
.kchat-launcher.is-bump {
  animation: kchat-bump .3s ease;
}

@keyframes kchat-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(.88); }
  100% { transform: scale(1); }
}

/*--------------------------------------------------------------
# Teaser — sapaan kecil di atas launcher
--------------------------------------------------------------*/

.kchat-teaser {
  position: fixed;
  right: 15px;
  /* tepat di atas launcher (bottom 68px + tinggi 56px + jarak) */
  bottom: 134px;
  z-index: 99998;

  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100vw - 30px);
  padding: 4px 6px 4px 0;

  background: var(--kchat-surface);
  color: var(--kchat-ink);
  border: 1px solid var(--kchat-line);
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);

  opacity: 0;
  transform: translateY(8px) scale(.96);
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .2s ease;
}

.kchat-teaser[hidden] {
  display: none;
}

.kchat-teaser.is-visible {
  opacity: 1;
  transform: none;
}

/* Ekor gelembung mengarah ke launcher */
.kchat-teaser::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: var(--kchat-surface);
  border-right: 1px solid var(--kchat-line);
  border-bottom: 1px solid var(--kchat-line);
  transform: rotate(45deg);
}

.kchat-teaser-text {
  border: none;
  background: transparent;
  padding: 10px 6px 10px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  color: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.kchat-teaser-close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--kchat-muted);
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.kchat-teaser-close:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--kchat-ink);
}

.kchat-teaser-text:focus-visible,
.kchat-teaser-close:focus-visible {
  outline: 2px solid var(--kchat-ink);
  outline-offset: 2px;
}

/*--------------------------------------------------------------
# Panel
--------------------------------------------------------------*/

.kchat-panel {
  position: fixed;
  right: 15px;
  bottom: 136px;
  z-index: 100001;

  width: 370px;
  max-width: calc(100vw - 30px);
  height: 560px;
  max-height: calc(100vh - 190px);

  display: flex;
  flex-direction: column;
  overflow: hidden;

  background: var(--kchat-surface);
  border: 1px solid var(--kchat-line);
  border-radius: var(--kchat-radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .22);

  opacity: 0;
  transform: translateY(12px);
  transition: opacity .18s ease, transform .18s ease;
}

.kchat-panel[hidden] {
  display: none;
}

.kchat.is-open .kchat-panel {
  opacity: 1;
  transform: translateY(0);
}

/*--------------------------------------------------------------
# Header panel
--------------------------------------------------------------*/

.kchat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 12px 16px;
  background: var(--kchat-brand);
  color: var(--kchat-ink);
  flex: 0 0 auto;
}

.kchat-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: auto;
}

.kchat-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.kchat-subtitle {
  font-size: 12px;
  opacity: .75;
  line-height: 1.3;
}

.kchat-icon-btn {
  border: none;
  background: transparent;
  color: var(--kchat-ink);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background-color .15s ease;
}

.kchat-icon-btn:hover {
  background: rgba(0, 0, 0, .1);
}

.kchat-icon-btn:focus-visible {
  outline: 2px solid var(--kchat-ink);
  outline-offset: 1px;
}

/*--------------------------------------------------------------
# Daftar pesan
--------------------------------------------------------------*/

.kchat-body {
  flex: 1 1 auto;
  /* Wajib agar area pesan boleh menyusut saat panel memendek (keyboard mobile),
     bukan mendorong form input keluar dari panel. */
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
}

/* Kolom, bukan baris: tiap pesan = bubble + cap jam di bawahnya.
   Perataan kiri/kanan diatur lewat align-items. */
.kchat-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
}

.kchat-msg-user {
  align-items: flex-end;
}

.kchat-time {
  margin-top: 3px;
  padding: 0 4px;
  font-size: 11px;
  line-height: 1;
  color: var(--kchat-muted);
}

.kchat-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  /* Balasan model dirender sebagai teks (textContent), tapi baris barunya
     tetap dipertahankan lewat CSS. */
  white-space: pre-wrap;
  word-break: break-word;
}

.kchat-msg-bot .kchat-bubble {
  background: var(--kchat-bot-bg);
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

.kchat-msg-user .kchat-bubble {
  background: var(--kchat-ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Kursor berkedip selama balasan bot "diketik" huruf demi huruf */
.kchat-bubble.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: currentColor;
  animation: kchat-blink .8s steps(1) infinite;
}

@keyframes kchat-blink {
  50% { opacity: 0; }
}

/* Indikator "sedang mengetik" */
.kchat-typing .kchat-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 14px;
}

.kchat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--kchat-muted);
  animation: kchat-bounce 1.2s infinite ease-in-out;
}

.kchat-typing span:nth-child(2) {
  animation-delay: .18s;
}

.kchat-typing span:nth-child(3) {
  animation-delay: .36s;
}

@keyframes kchat-bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: .45;
  }

  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {

  .kchat-panel,
  .kchat-launcher,
  .kchat-launcher i,
  .kchat-teaser {
    transition: none;
  }

  .kchat-launcher.is-bump,
  .kchat-typing span,
  .kchat-bubble.is-typing::after {
    animation: none;
  }
}

/*--------------------------------------------------------------
# Persetujuan privasi
--------------------------------------------------------------*/

/* display:flex pada .kchat-msg mengalahkan default [hidden] browser,
   jadi ditegaskan ulang untuk bubble yang disembunyikan JS
   (blok persetujuan & sapaan pembuka). */
.kchat-msg[hidden] {
  display: none;
}

/* Bubble persetujuan berisi markup HTML dari template (bukan teks polos
   balasan model), jadi pre-wrap milik .kchat-bubble akan ikut merender
   newline + indentasi PHP-nya. Dinormalkan khusus di sini. */
.kchat-consent .kchat-bubble {
  white-space: normal;
  max-width: 100%;
}

.kchat-consent-link {
  color: #1d4ed8;
  text-decoration: underline;
  word-break: break-word;
}

.kchat-consent-link:hover {
  color: #1e40af;
}

.kchat-consent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.kchat-consent-actions[hidden] {
  display: none;
}

/* Dua pill sejajar dengan lebar sama; turun ke baris berikutnya
   hanya bila panel benar-benar sempit. */
.kchat-consent-btn {
  flex: 1 1 auto;
  min-width: 110px;
  padding: 8px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--kchat-ink);
  background: transparent;
  color: var(--kchat-ink);
  transition: background .15s ease, border-color .15s ease;
}

.kchat-consent-btn:hover {
  background: rgba(0, 0, 0, .06);
}

.kchat-consent-btn:focus-visible {
  outline: 2px solid var(--kchat-ink);
  outline-offset: 2px;
}

.kchat-consent-agree {
  background: var(--kchat-brand);
  border-color: var(--kchat-brand);
}

.kchat-consent-agree:hover {
  background: var(--kchat-brand-dark);
  border-color: var(--kchat-brand-dark);
}

/*--------------------------------------------------------------
# Notice (sesi berakhir / tidak tersedia / error)
--------------------------------------------------------------*/

.kchat-notice {
  flex: 0 0 auto;
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.5;
  background: #fff8e1;
  color: #7a5b00;
  border-top: 1px solid var(--kchat-line);
}

.kchat-notice[hidden] {
  display: none;
}

.kchat-notice.is-error {
  background: #fdecea;
  color: #8f2a22;
}

.kchat-notice-action {
  display: inline-block;
  margin-top: 6px;
  padding: 5px 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.kchat-notice-action:hover {
  background: rgba(0, 0, 0, .06);
}

/*--------------------------------------------------------------
# Form input
--------------------------------------------------------------*/

.kchat-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--kchat-line);
  background: var(--kchat-surface);
}

.kchat-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--kchat-line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.5;
  max-height: 110px;
  overflow-y: auto;
  color: #1f2937;
  background: #fff;
}

.kchat-input:focus {
  outline: none;
  border-color: var(--kchat-brand);
  box-shadow: 0 0 0 3px rgba(255, 183, 0, .25);
}

.kchat-input:disabled {
  background: #f5f5f5;
  color: var(--kchat-muted);
}

.kchat-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--kchat-brand);
  color: var(--kchat-ink);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s ease;
}

.kchat-send:hover:not(:disabled) {
  background: var(--kchat-brand-dark);
}

.kchat-send:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
}

.kchat-disclaimer {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 12px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--kchat-muted);
  background: var(--kchat-surface);
  text-align: center;
}

/*--------------------------------------------------------------
# Mobile: panel jadi layar penuh
--------------------------------------------------------------*/

@media (max-width: 575.98px) {
  .kchat-panel {
    right: 0;
    left: 0;
    top: 0;
    /* Tinggi dikendalikan lewat `height`, bukan `bottom`, supaya JS bisa
       mengecilkannya mengikuti visualViewport saat keyboard muncul. */
    bottom: auto;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    border: none;
    border-radius: 0;
  }

  /* Di mobile hanya opacity yang dianimasikan. JS mengukur posisi nyata panel
     untuk memasangnya ke area yang terlihat, dan transform yang sedang
     bertransisi akan membuat pengukuran itu meleset. */
  .kchat-panel,
  .kchat.is-open .kchat-panel {
    transform: none;
  }

  .kchat.is-open .kchat-launcher {
    /* Tombol tutup sudah ada di header panel */
    display: none;
  }
}

/*--------------------------------------------------------------
# Mode ringkas — dipasang JS saat panel memendek karena keyboard.
# Mengembalikan ruang vertikal ke riwayat percakapan.
--------------------------------------------------------------*/

.kchat.is-compact .kchat-subtitle,
.kchat.is-compact .kchat-disclaimer {
  display: none;
}

.kchat.is-compact .kchat-header {
  padding-top: 8px;
  padding-bottom: 8px;
}

.kchat.is-compact .kchat-body {
  padding: 10px 12px;
  gap: 8px;
}

.kchat.is-compact .kchat-form {
  padding: 8px 12px 10px;
}
