/* =====================================================================
   PTEKNO - widget chat "Admin PTEKNO" (partials/livechat.php + livechat.js)
   Token mengikuti ptekno-ui.css; nilai cadangan disertakan agar widget
   tetap benar walau dimuat di halaman tanpa ptekno-ui.css.
   Lapisan z: header 40 < drawer 50 < chat 55 < toast 60 < modal 70-80.
   ===================================================================== */

.ptk-chat {
  --c-navy: var(--pk-ink, #0B2E4F);
  --c-navy-d: #072039;
  --c-orange: var(--pk-orange, #F5A623);
  --c-text-2: #3E5269;
  --c-text-3: #5E6E80;
  --c-rule: #DCE2E8;
  --c-red: #B42318;
  --c-gap: 16px;
  /* jarak dari bawah: di atas bottom nav mobile (64px) */
  --c-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  --c-vvh: 100dvh;

  position: fixed;
  right: var(--c-gap);
  bottom: var(--c-bottom);
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--pk-font, "Archivo", ui-sans-serif, system-ui, sans-serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-navy);
  pointer-events: none;
}
.ptk-chat > * { pointer-events: auto; }
.ptk-chat [hidden] { display: none !important; }
@media (min-width: 1024px) {
  .ptk-chat { --c-gap: 24px; --c-bottom: 24px; }
}

/* ---------- tombol peluncur ---------- */
.ptk-chat__launcher {
  position: relative;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--c-navy); color: #fff;
  box-shadow: 0 8px 24px -8px rgba(7, 32, 57, .55);
  cursor: pointer;
  transition: background-color .15s, transform .15s;
}
@media (min-width: 1024px) { .ptk-chat__launcher { width: 60px; height: 60px; } }
.ptk-chat__launcher:hover { background: #12406B; }
.ptk-chat__launcher:focus-visible { outline: 3px solid var(--c-orange); outline-offset: 3px; }
.ptk-chat__launcher .ptk-chat__ic-close { display: none; }
.ptk-chat.is-open .ptk-chat__launcher .ptk-chat__ic-open { display: none; }
.ptk-chat.is-open .ptk-chat__launcher .ptk-chat__ic-close { display: block; }

/* ---------- sapaan ---------- */
.ptk-chat__greet {
  position: relative;
  width: 260px; max-width: calc(100vw - 2 * var(--c-gap));
  background: #fff;
  border: 1px solid var(--c-rule);
  border-radius: 14px;
  box-shadow: 0 12px 32px -14px rgba(7, 32, 57, .35);
}
.ptk-chat__greet::after {
  content: ""; position: absolute; right: 22px; bottom: -7px;
  width: 12px; height: 12px; background: #fff;
  border-right: 1px solid var(--c-rule); border-bottom: 1px solid var(--c-rule);
  transform: rotate(45deg);
}
.ptk-chat__greet-open {
  display: block; width: 100%; text-align: left;
  padding: 14px 40px 14px 16px;
  border: 0; background: none; border-radius: 14px;
  font: inherit; color: inherit; cursor: pointer;
}
.ptk-chat__greet-open:focus-visible { outline: 2px solid #1667C5; outline-offset: 2px; }
.ptk-chat__greet-title { display: block; font-size: 14px; font-weight: 700; }
.ptk-chat__greet-text { display: block; margin-top: 2px; font-size: 13px; color: var(--c-text-2); }
.ptk-chat__greet-close {
  position: absolute; top: 4px; right: 4px;
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: none; color: var(--c-text-3); cursor: pointer;
}
.ptk-chat__greet-close:hover { background: #F1F3F6; color: var(--c-navy); }
.ptk-chat__greet-close:focus-visible { outline: 2px solid #1667C5; }

/* ---------- panel ---------- */
.ptk-chat__panel {
  box-sizing: border-box;
  width: 380px;
  max-width: calc(100vw - 2 * var(--c-gap));
  max-height: min(580px, calc(var(--c-vvh) - var(--c-bottom) - 96px));
  display: flex; flex-direction: column;
  background: #fff;
  border: 1px solid var(--c-rule);
  border-radius: 20px;
  box-shadow: 0 24px 60px -20px rgba(7, 32, 57, .45);
  overflow: hidden;
}
.ptk-chat__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 10px 14px 16px;
  background: var(--c-navy); color: #fff;
}
.ptk-chat__avatar { width: 40px; height: 40px; flex: none; display: block; border-radius: 9px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .28); }
.ptk-chat__who { flex: 1; min-width: 0; }
.ptk-chat__title { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.25; }
.ptk-chat__status { margin: 0; font-size: 13px; color: #C9D5E2; }
.ptk-chat__close {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: none; color: #fff; cursor: pointer;
}
.ptk-chat__close:hover { background: rgba(255, 255, 255, .12); }
.ptk-chat__close:focus-visible { outline: 2px solid var(--c-orange); outline-offset: -2px; }

.ptk-chat__body {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 16px;
  background: #F4F6F8;
}
.ptk-chat__warn {
  margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid #F1D29A; border-radius: 10px; background: #FDF1DC;
  font-size: 13px; color: #5B4313;
}
.ptk-chat__warn a { color: #0F55A6; font-weight: 600; }
.ptk-chat__msg {
  max-width: 92%;
  padding: 12px 14px;
  background: #fff; border: 1px solid var(--c-rule);
  border-radius: 4px 14px 14px 14px;
  color: var(--c-navy);
}
.ptk-chat__msg p { margin: 0; }
.ptk-chat__msg p + p { margin-top: 6px; color: var(--c-text-2); }

/* ---------- formulir ---------- */
.ptk-chat__form {
  margin-top: 14px; padding: 14px;
  background: #fff; border: 1px solid var(--c-rule); border-radius: 14px;
}
.ptk-chat__form-title { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.ptk-chat__row { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; }
.ptk-chat__field { margin-bottom: 10px; }
.ptk-chat__field label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--c-navy); }
.ptk-chat__req { color: var(--c-red); }
.ptk-chat__opt { font-weight: 400; color: var(--c-text-3); }
.ptk-chat__field input,
.ptk-chat__field select {
  display: block; width: 100%; height: 44px; box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid #B9C3CE; border-radius: 8px; background: #fff;
  font-family: inherit; font-size: 16px; font-weight: 400; line-height: 1.2; color: var(--c-navy);
}
.ptk-chat__field select { padding-right: 6px; }
.ptk-chat__field input::placeholder { color: #8D9BAA; }
.ptk-chat__field input:focus,
.ptk-chat__field select:focus { outline: none; border-color: #1667C5; box-shadow: 0 0 0 3px rgba(22, 103, 197, .25); }
.ptk-chat__field input[aria-invalid="true"] { border-color: var(--c-red); }
.ptk-chat__field input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, .2); }
.ptk-chat__hint { margin: 4px 0 0; font-size: 12px; color: var(--c-text-3); }
.ptk-chat__err { margin: 4px 0 0; font-size: 12px; font-weight: 600; color: var(--c-red); }
.ptk-chat__err:empty { display: none; }
.ptk-chat__note { margin: 2px 0 12px; font-size: 12px; color: var(--c-text-3); }
.ptk-chat__submit {
  width: 100%; height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px;
  background: var(--c-navy); color: #fff;
  font-family: inherit; font-size: 15px; font-weight: 700; line-height: 1; cursor: pointer;
}
.ptk-chat__submit:hover { background: #12406B; }
.ptk-chat__submit:focus-visible { outline: 3px solid var(--c-orange); outline-offset: 2px; }
.ptk-chat__submit:disabled { background: #C4CDD7; color: #fff; cursor: not-allowed; }
.ptk-chat__after { margin: 10px 0 0; font-size: 13px; color: var(--c-text-2); }
.ptk-chat__after:empty { display: none; }
.ptk-chat__after a { color: #0F55A6; font-weight: 700; }
.ptk-chat__foot {
  padding: 10px 16px; border-top: 1px solid var(--c-rule);
  font-size: 12px; color: var(--c-text-3); text-align: center; background: #fff;
}

/* ---------- mobile: panel hampir layar penuh ---------- */
@media (max-width: 480px) {
  .ptk-chat { --c-gap: 12px; }
  .ptk-chat__panel {
    position: fixed;
    left: 12px; right: 12px;
    top: calc(12px + env(safe-area-inset-top, 0px));
    bottom: var(--c-bottom);
    width: auto; max-width: none; max-height: none;
    border-radius: 18px;
  }
  /* saat panel terbuka di layar sempit, peluncur disembunyikan; tutup lewat tombol di header */
  .ptk-chat.is-open .ptk-chat__launcher { display: none; }
  .ptk-chat.is-open .ptk-chat__panel { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 340px) {
  .ptk-chat__row { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

/* PDP mobile sudah punya tombol Chat di bilah beli; sembunyikan peluncur agar tidak dobel */
@media (max-width: 1023.98px) {
  .ptk-chat[data-pdp="1"] { --c-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .ptk-chat[data-pdp="1"]:not(.is-open) .ptk-chat__launcher,
  .ptk-chat[data-pdp="1"] .ptk-chat__greet { display: none; }
}

/* Widget tidak dirender (chat belum aktif): tombol chat lain (mis. PDP) disembunyikan agar tidak mati */
body:not(:has(#livechat)) [data-action="toggle-chat"] { display: none !important; }

/* ---------- animasi ringan ---------- */
@media (prefers-reduced-motion: no-preference) {
  .ptk-chat__panel:not([hidden]) { animation: ptk-chat-in .18s ease-out; }
  .ptk-chat__greet:not([hidden]) { animation: ptk-chat-in .2s ease-out; }
}
@keyframes ptk-chat-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ptk-chat__launcher { transition: none; }
}

/* Checkout mobile: bilah "Bayar Sekarang" menempel di bawah; naikkan peluncur
   agar tidak menutupi tombol bayar (menimpa aturan lama di shop/checkout.php). */
@media (max-width: 1023.98px) {
  #livechat.ptk-chat[data-flow="checkout"] { bottom: calc(128px + env(safe-area-inset-bottom, 0px)) !important; }
}
