/* ============================================================
   Ceki — widget chat "Teman Memilih Jurnal"
   ============================================================
   Tombol mengambang menggantikan tombol WhatsApp. Bila Ceki
   dimatikan dari admin, ceki.js menambah .is-wa dan tombol
   kembali tampil sebagai tautan WhatsApp biasa.
   Warna memakai token design system, jadi ikut mode gelap.
   ============================================================ */

.cj-ceki-fab {
  background: var(--cj-navy, #003366);
  box-shadow: 0 8px 24px rgba(var(--cj-navy-rgb, 0, 51, 102), 0.35);
  padding: 0;
  overflow: hidden;
  width: 60px;
  height: 60px;
}
.cj-ceki-fab img { width: 100%; height: 100%; display: block; border-radius: 50%; }
.cj-ceki-fab .cj-ceki-fab__wa { display: none; }
.cj-ceki-fab.is-wa { background: #25D366; box-shadow: 0 8px 24px rgba(37, 211, 102, 0.4); width: 52px; height: 52px; }
.cj-ceki-fab.is-wa img { display: none; }
.cj-ceki-fab.is-wa .cj-ceki-fab__wa { display: block; width: 26px; height: 26px; }
.cj-ceki-fab.is-open { transform: scale(0.9); }
/* Ikon gagal dimuat: tampilkan ikon chat bawaan, jangan gambar rusak. */
.cj-ceki-fab.is-noicon .cj-ceki-fab__wa { display: block; width: 26px; height: 26px; }

.cj-ceki-fab__hint {
  position: fixed;
  right: 86px;
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  z-index: 800;
  background: var(--cj-surface);
  color: var(--cj-ink);
  border: 1px solid var(--cj-line);
  border-radius: var(--cj-r-pill);
  padding: 7px 14px;
  font: 600 0.8rem/1.2 var(--cj-font-body);
  box-shadow: var(--cj-shadow);
  cursor: pointer;
  animation: ceki-in 0.3s ease;
}

/* ── Panel ─────────────────────────────────────────────────── */
.ceki {
  position: fixed;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  z-index: 900;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--cj-surface);
  color: var(--cj-ink);
  border: 1px solid var(--cj-line);
  border-radius: var(--cj-r-xl);
  box-shadow: var(--cj-shadow-lg);
  font-family: var(--cj-font-body);
  overflow: hidden;
  animation: ceki-in 0.2s ease;
}
.ceki[hidden] { display: none; }
@keyframes ceki-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.ceki__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--cj-navy-deep, #002244);
  color: #fff;
}
.ceki__avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; background: #fff; }
.ceki__title { flex: 1; min-width: 0; }
.ceki__name { font: 800 1rem/1.1 var(--cj-font-head); letter-spacing: 0.02em; }
.ceki__tag { font-size: 0.75rem; opacity: 0.8; }
.ceki__btn {
  background: transparent;
  border: 0;
  color: inherit;
  width: 34px;
  height: 34px;
  border-radius: var(--cj-r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  flex: none;
}
.ceki__btn:hover, .ceki__btn:focus-visible { background: rgba(255, 255, 255, 0.14); outline: none; }

.ceki__log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--cj-surface-alt);
  overscroll-behavior: contain;
}

.ceki-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.ceki-msg p { margin: 0 0 6px; }
.ceki-msg p:last-child, .ceki-msg ul:last-child, .ceki-msg ol:last-child { margin-bottom: 0; }
.ceki-msg ul, .ceki-msg ol { margin: 4px 0 6px; padding-left: 18px; }
.ceki-msg li { margin-bottom: 3px; }
.ceki-msg a { color: var(--cj-blue); text-decoration: underline; text-underline-offset: 2px; }
.ceki-msg--bot {
  align-self: flex-start;
  background: var(--cj-surface);
  border: 1px solid var(--cj-line);
  border-bottom-left-radius: 4px;
}
.ceki-msg--user {
  align-self: flex-end;
  background: var(--cj-navy, #003366);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.ceki-msg--err { border-color: var(--cj-danger); }

.ceki-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.ceki-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cj-muted-soft);
  animation: ceki-dot 1.2s infinite ease-in-out;
}
.ceki-typing i:nth-child(2) { animation-delay: 0.15s; }
.ceki-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ceki-dot { 0%, 80%, 100% { opacity: 0.3; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }

.ceki-wa {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: var(--cj-r-pill);
  background: #1FA855;
  color: #fff !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 0.84rem;
}
.ceki-wa svg { width: 18px; height: 18px; }
.ceki-wa__jam { display: block; margin-top: 4px; font-size: 0.75rem; color: var(--cj-muted); }

.ceki-cta { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ceki-cta__btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--cj-r-md);
  background: var(--cj-navy, #003366);
  color: #fff !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.3;
}
.ceki-cta__btn i { font-size: 0.75rem; flex: none; }
.ceki-cta__btn:hover, .ceki-cta__btn:focus-visible { background: var(--cj-blue, #004080); outline: none; }

/* Penilaian jawaban: sengaja kecil dan pudar — hadir bila dibutuhkan,
   tidak bersaing dengan isi jawaban atau tombol lanjutan di atasnya. */
.ceki-nilai {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--cj-line);
}
.ceki-nilai__tanya {
  font-size: 0.72rem;
  color: var(--cj-muted);
  margin-right: auto;
}
.ceki-nilai__btn {
  border: 1px solid var(--cj-line);
  background: transparent;
  color: var(--cj-muted);
  border-radius: var(--cj-r-pill);
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.ceki-nilai__btn:hover:not(:disabled),
.ceki-nilai__btn:focus-visible { color: var(--cj-blue); border-color: var(--cj-blue); outline: none; }
.ceki-nilai__btn.is-aktif { color: var(--cj-blue); border-color: var(--cj-blue); }
.ceki-nilai__btn:disabled { cursor: default; opacity: .75; }

.ceki__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ceki-chip {
  border: 1px solid var(--cj-line);
  background: var(--cj-surface);
  color: var(--cj-blue);
  border-radius: var(--cj-r-pill);
  padding: 6px 11px;
  font: 600 0.78rem/1.2 var(--cj-font-body);
  cursor: pointer;
}
.ceki-chip:hover, .ceki-chip:focus-visible { border-color: var(--cj-blue); outline: none; }
.ceki-chip--muted { color: var(--cj-muted); border-style: dashed; }

.ceki__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--cj-line);
  background: var(--cj-surface);
}
.ceki__input {
  flex: 1;
  resize: none;
  overflow-y: hidden;
  height: 40px;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--cj-line);
  border-radius: var(--cj-r-md);
  background: var(--cj-surface);
  color: var(--cj-ink);
  font: 400 0.9rem/1.4 var(--cj-font-body);
}
.ceki__input:focus { outline: 2px solid rgba(var(--cj-blue-rgb, 0, 64, 128), 0.35); border-color: var(--cj-blue); }
.ceki__send {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--cj-r-md);
  background: var(--cj-gold, #FDB515);
  color: #002244;
  cursor: pointer;
  font-size: 0.95rem;
}
.ceki__send:disabled { opacity: 0.5; cursor: default; }
.ceki__note {
  padding: 0 12px 10px;
  background: var(--cj-surface);
  font-size: 0.7rem;
  color: var(--cj-muted);
  text-align: center;
}

@media (max-width: 575.98px) {
  .ceki {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  .ceki-msg { max-width: 92%; }
  .ceki__input { font-size: 16px; } /* cegah zoom otomatis iOS */
  .cj-ceki-fab__hint { display: none; }
}

@media print { .ceki, .cj-ceki-fab__hint { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  .ceki, .cj-ceki-fab__hint, .ceki-typing i { animation: none; }
}
