/* ============================================================
   MBOISREK -- tampilan versi baru: prompt bar + popup
   Semua selektor di-scope ke #stmt-pb dan properti tombol/input
   diatur eksplisit, supaya tidak tertimpa CSS tema WordPress.
   Variabel --stmt-pb-popup-w dan --stmt-pb-bar-w diisi dari
   Settings lewat inline style (lihat includes/promptbar.php).
   ============================================================ */

#stmt-pb, #stmt-pb * { box-sizing: border-box; }

#stmt-pb {
  --pb-surface: #ffffff; --pb-surface-1: #f4f5f7;
  --pb-text: #1a1d23; --pb-text-2: #5b6472; --pb-text-3: #7a8290;
  --pb-line: #dde1e7; --pb-line-strong: #c4cad3;
  --pb-accent: #e8531f; --pb-on-accent: #ffffff;
  --pb-shadow: 0 4px 20px rgba(0, 0, 0, .14);
  --pb-hair: 1px;
  --pb-hit: 36px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.4; color: var(--pb-text);
  text-align: left; letter-spacing: normal; text-transform: none;
}
#stmt-pb[data-theme="gray"] { /* tema ORANYE: krem lembut (nama internal 'gray' dipertahankan) */
  --pb-surface: #fff6ec; --pb-surface-1: #ffe9d2;
  --pb-text: #2b1a10; --pb-text-2: #6b4a36; --pb-text-3: #8c6c58;
  --pb-line: #f0d3b8; --pb-line-strong: #e3b894;
  --pb-accent: #e8531f; --pb-on-accent: #ffffff;
}
#stmt-pb[data-theme="dark"] {
  --pb-surface: #1c212b; --pb-surface-1: #14181f;
  --pb-text: #eef1f5; --pb-text-2: #9aa3b2; --pb-text-3: #7c8594;
  --pb-line: #2a3140; --pb-line-strong: #3a4256;
  --pb-accent: #ff6a3d; --pb-on-accent: #1a1d23;
}
@media (min-resolution: 2dppx) { #stmt-pb { --pb-hair: .5px; } }
@media (pointer: coarse)      { #stmt-pb { --pb-hit: 42px; } }

/* Reset terarah: tema WP sering memberi gaya agresif ke button/input */
#stmt-pb button, #stmt-pb input {
  font: inherit; margin: 0; letter-spacing: normal; text-transform: none;
  box-shadow: none; text-shadow: none; -webkit-appearance: none; appearance: none;
  min-height: 0; min-width: 0; max-width: none;
}
#stmt-pb button {
  background: transparent; border: 0; padding: 0; color: inherit; cursor: pointer;
  line-height: 1; border-radius: 0; width: auto; height: auto;
}
#stmt-pb button:focus-visible, #stmt-pb input:focus-visible { outline: 2px solid var(--pb-accent); outline-offset: 2px; }
#stmt-pb [hidden] { display: none !important; }
#stmt-pb svg { width: 20px; height: 20px; display: block; flex: none; }

/* ---- Dock: posisi bar saat popup tertutup (tetap di bawah layar) ---- */
#stmt-pb .stmt-pb__dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--stmt-kb, 0px));
  width: min(var(--stmt-pb-bar-w, 640px), calc(100vw - 24px));
  z-index: 99990;
}

/* ---- Bar (dipindah antara dock dan footer panel oleh JS) ---- */
#stmt-pb .stmt-pb__bar {
  display: flex; align-items: center; gap: 4px; width: 100%; margin: 0;
  padding: 5px 5px 5px 18px; border-radius: 28px;
  background: var(--pb-surface); border: var(--pb-hair) solid var(--pb-line-strong);
  box-shadow: var(--pb-shadow);
}
#stmt-pb .stmt-pb__input {
  flex: 1 1 auto; min-width: 0; width: 100%; height: var(--pb-hit); padding: 0;
  border: 0; border-radius: 0; background: transparent; color: var(--pb-text);
  font-size: 14px; outline: none; box-shadow: none;
}
#stmt-pb .stmt-pb__input::placeholder { color: var(--pb-text-3); opacity: 1; text-overflow: ellipsis; }
#stmt-pb .stmt-pb__input { text-overflow: ellipsis; }
#stmt-pb .stmt-pb__input:focus-visible { outline: none; }
#stmt-pb .stmt-pb__bar:focus-within { border-color: var(--pb-accent); }
@media (pointer: coarse) { #stmt-pb .stmt-pb__input { font-size: 16px; } } /* mencegah auto-zoom iOS */

#stmt-pb .stmt-pb__btn {
  flex: none; width: var(--pb-hit); height: var(--pb-hit); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: var(--pb-text-2);
}
#stmt-pb .stmt-pb__btn:hover { background: var(--pb-surface-1); color: var(--pb-text); }
/* Satu ikon aktif pada satu waktu (kelas diatur JS): bingkai + warna aksen. */
#stmt-pb .stmt-pb__btn.is-active { color: var(--pb-accent); box-shadow: inset 0 0 0 1.5px var(--pb-accent); }

/* Tombol kirim: bingkai dan isi adalah dua lapisan (span) terpisah, BUKAN background tombol,
   karena tema WordPress sering menimpa background/border tombol. */
#stmt-pb .stmt-pb__btn--send, #stmt-pb .stmt-pb__btn--send:hover { position: relative; background: transparent; color: var(--pb-text-3); box-shadow: none; }
#stmt-pb .stmt-pb__rg, #stmt-pb .stmt-pb__fl { position: absolute; border-radius: 50%; pointer-events: none; }
#stmt-pb .stmt-pb__rg { inset: 0; background: var(--pb-line-strong); }
#stmt-pb .stmt-pb__fl { inset: 1.5px; background: var(--pb-surface); }
#stmt-pb .stmt-pb__btn--send svg { position: relative; }
#stmt-pb .stmt-pb__btn--send.is-active, #stmt-pb .stmt-pb__btn--send.is-active:hover { color: var(--pb-accent); box-shadow: none; }
#stmt-pb .stmt-pb__btn--send.is-active .stmt-pb__rg { background: var(--pb-accent); }

/* ---- Overlay & panel ---- */
#stmt-pb .stmt-pb__overlay {
  position: fixed; inset: 0; z-index: 2147483000; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .5); animation: stmt-pb-fade .15s ease-out;
}
#stmt-pb .stmt-pb__panel {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  width: min(90vw, var(--stmt-pb-popup-w, 1040px));
  height: min(90vh, 820px); height: min(90dvh, 820px);
  background: var(--pb-surface); color: var(--pb-text);
  border: var(--pb-hair) solid var(--pb-line); border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .35);
}
#stmt-pb .stmt-pb__body { position: relative; flex: 1 1 auto; min-height: 0; }
#stmt-pb .stmt-pb__frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--pb-surface); }
#stmt-pb .stmt-pb__foot {
  flex: none; padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: var(--pb-hair) solid var(--pb-line); background: var(--pb-surface);
}
#stmt-pb .stmt-pb__foot .stmt-pb__bar {
  max-width: var(--stmt-pb-bar-w, 640px); margin: 0 auto;
  background: var(--pb-surface-1); box-shadow: none;
}

/* Layar kecil atau pendek (HP potret & lanskap): popup layar penuh.
   --stmt-kb = tinggi keyboard virtual, diisi JS lewat visualViewport. */
@media (max-width: 640px), (max-height: 500px) {
  #stmt-pb .stmt-pb__overlay { align-items: flex-start; }
  #stmt-pb .stmt-pb__panel {
    width: 100%; border: 0; border-radius: 0;
    height: calc(100vh - var(--stmt-kb, 0px)); height: calc(100dvh - var(--stmt-kb, 0px));
  }
  #stmt-pb .stmt-pb__foot { padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-height: 500px) {
  #stmt-pb .stmt-pb__foot { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
}

/* Layar kecil: ikon di bar dirapatkan supaya kolom ketik lebih lega. */
@media (max-width: 640px) {
  #stmt-pb .stmt-pb__bar { gap: 0; padding: 4px 4px 4px 14px; }
  #stmt-pb .stmt-pb__btn { width: 38px; height: 38px; }
  #stmt-pb .stmt-pb__input { height: 38px; }
  #stmt-pb .stmt-pb__btn svg { width: 19px; height: 19px; }
}

/* ---- Keadaan memuat / gagal ---- */
#stmt-pb .stmt-pb__state {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; background: var(--pb-surface); color: var(--pb-text-2);
}
#stmt-pb .stmt-pb__state p { margin: 0 0 4px; }
#stmt-pb .stmt-pb__sub { font-size: 13px; color: var(--pb-text-3); }
#stmt-pb .stmt-pb__spinner {
  width: 26px; height: 26px; margin-bottom: 12px; border-radius: 50%;
  border: 3px solid var(--pb-line-strong); border-top-color: var(--pb-accent); animation: stmt-pb-spin .9s linear infinite;
}
#stmt-pb .stmt-pb__actions { display: flex; gap: 8px; margin-top: 12px; }
#stmt-pb .stmt-pb__text-btn {
  padding: 8px 14px; border-radius: 8px; border: var(--pb-hair) solid var(--pb-line-strong); color: var(--pb-text); font-size: 13px;
}
#stmt-pb .stmt-pb__text-btn:hover { background: var(--pb-surface-1); }

/* ---- Menu pintasan (di atas segalanya, termasuk overlay) ---- */
#stmt-pb .stmt-pb__menu {
  position: fixed; z-index: 2147483001; width: min(270px, calc(100vw - 16px)); padding: 6px; border-radius: 12px;
  background: var(--pb-surface); color: var(--pb-text); border: var(--pb-hair) solid var(--pb-line-strong);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .28); max-height: calc(100vh - 24px); overflow-y: auto;
}
#stmt-pb .stmt-pb__menu::after {
  content: ""; position: absolute; bottom: -5px; left: var(--stmt-cx, 200px); width: 9px; height: 9px;
  background: var(--pb-surface); border-right: var(--pb-hair) solid var(--pb-line-strong);
  border-bottom: var(--pb-hair) solid var(--pb-line-strong); transform: rotate(45deg);
}
#stmt-pb .stmt-pb__group { padding: 6px 10px 2px; font-size: 11px; color: var(--pb-text-3); }
#stmt-pb .stmt-pb__item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border-radius: 8px;
  text-align: left; justify-content: flex-start; line-height: 1.3;
}
@media (pointer: coarse) { #stmt-pb .stmt-pb__item { padding: 10px; } }
#stmt-pb .stmt-pb__item:hover, #stmt-pb .stmt-pb__item:focus-visible { background: var(--pb-surface-1); }
#stmt-pb .stmt-pb__item svg { width: 18px; height: 18px; color: var(--pb-text-2); }
#stmt-pb .stmt-pb__item b { display: block; font-weight: 600; font-size: 13px; }
#stmt-pb .stmt-pb__item small { display: block; font-size: 11px; color: var(--pb-text-2); }

/* Kunci scroll halaman di belakang popup */
html.stmt-pb-lock, html.stmt-pb-lock body { overflow: hidden !important; }

@keyframes stmt-pb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes stmt-pb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #stmt-pb .stmt-pb__overlay { animation: none; }
  #stmt-pb .stmt-pb__spinner { animation-duration: 2.4s; }
}

/* ---- Tombol wajah MboisBot di kiri bar (hanya ada bila opsi Tur dinyalakan) ---- */
#stmt-pb .stmt-pb__bar--face { padding-left: 5px; }
#stmt-pb .stmt-pb__bar--face .stmt-pb__input { margin-left: 4px; }
#stmt-pb .stmt-pb__face, #stmt-pb .stmt-pb__face:hover { position: relative; flex: none; width: 36px; height: 36px; padding: 0; margin: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; box-shadow: none; display: inline-flex; align-items: center; justify-content: center; }
#stmt-pb .stmt-pb__face:hover { background: var(--pb-surface-1); }
#stmt-pb .stmt-pb__face img { width: 32px; height: 32px; display: block; pointer-events: none; }
#stmt-pb .stmt-pb__face:focus-visible { outline: 2px solid var(--pb-accent); outline-offset: 1px; }
#stmt-pb[data-tour-new] .stmt-pb__face::after { content: ""; position: absolute; top: 2px; right: 1px; width: 9px; height: 9px; border-radius: 50%; background: var(--pb-accent); border: 2px solid var(--pb-surface); box-sizing: content-box; }
@media (max-width: 640px) { #stmt-pb .stmt-pb__face, #stmt-pb .stmt-pb__face:hover { width: 34px; height: 34px; } #stmt-pb .stmt-pb__face img { width: 30px; height: 30px; } #stmt-pb .stmt-pb__bar--face .stmt-pb__input { margin-left: 2px; } }

/* ---- Gelembung idle di atas wajah robot (selalu krem-oranye lembut, tidak ikut tema; tidak menutup sendiri) ---- */
#stmt-pb .stmt-idle {
  position: absolute; left: 0; bottom: calc(100% + 12px); z-index: 99991;
  display: flex; align-items: center; gap: 10px; width: max-content; max-width: min(380px, calc(100vw - 24px));
  padding: 10px 8px 10px 14px; border-radius: 14px; background: #ffe9d2; color: #5a2a0c;
  border: 1px solid #f0b27f; box-shadow: 0 6px 20px rgba(120, 60, 10, .22); font-size: 13px; line-height: 1.4;
  opacity: 0; transform: translateY(6px); transition: opacity .25s ease, transform .25s ease;
}
#stmt-pb .stmt-idle.is-on { opacity: 1; transform: none; }
#stmt-pb .stmt-idle::after { /* ekor menuju wajah robot */
  content: ""; position: absolute; left: 20px; bottom: -6px; width: 10px; height: 10px; background: #ffe9d2;
  border-right: 1px solid #f0b27f; border-bottom: 1px solid #f0b27f; transform: rotate(45deg);
}
#stmt-pb .stmt-idle__t { flex: 1 1 auto; min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
#stmt-pb .stmt-idle__acts { flex: none; display: inline-flex; align-items: center; gap: 4px; }
#stmt-pb .stmt-idle__go, #stmt-pb .stmt-idle__go:hover {
  flex: none; padding: 7px 13px; border-radius: 8px; background: #e8531f; color: #ffffff; font-size: 12.5px; font-weight: 600;
}
#stmt-pb .stmt-idle__x, #stmt-pb .stmt-idle__x:hover { flex: none; width: 24px; height: 24px; border-radius: 50%; color: #7a3207; font-size: 18px; line-height: 1; }
#stmt-pb .stmt-idle__x:hover { background: rgba(122, 50, 7, .1); }
@media (max-width: 480px) {
  #stmt-pb .stmt-idle { flex-direction: column; align-items: stretch; gap: 8px; width: calc(100vw - 24px); }
  #stmt-pb .stmt-idle__acts { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { #stmt-pb .stmt-idle { transition: none; transform: none; } }
