/* =========================================================
   Myfrend — Customer Assistant (rule-based) widget
   Vanilla, ringan, selaras brand. Tidak memakai framework.
   Variabel warna mengikuti style.css; ada fallback bila perlu.
   ========================================================= */

.mfa { --mfa-brand: var(--orange, #f5842f); --mfa-brand-2: var(--coral, #ef5b56);
       --mfa-ink: var(--ink, #1c1714); --mfa-muted: var(--muted, #6b6157);
       --mfa-line: var(--line, #f0e4da); --mfa-bg: #fff; --mfa-bot: #f6efe8;
       --mfa-radius: 16px;
       font-family: var(--font, system-ui, sans-serif); }

/* Sembunyikan dari layar sampai JS siap (anti flash) */
.mfa[hidden] { display: none !important; }

/* ---------- Launcher (tombol mengambang) ---------- */
.mfa-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 210;
  width: 60px; height: 60px; border: none; border-radius: 50%; cursor: pointer;
  background: var(--grad-cta, linear-gradient(135deg, #f5842f, #ef5b56)); color: #fff;
  display: grid; place-items: center; box-shadow: 0 12px 28px rgba(239,91,86,.42);
  transition: transform .2s ease, box-shadow .2s ease;
}
.mfa-launcher:hover { transform: scale(1.07); }
.mfa-launcher:active { transform: scale(1); }
.mfa-launcher svg { width: 28px; height: 28px; }
.mfa-launcher .mfa-ic-close { display: none; }
.mfa.is-open .mfa-launcher .mfa-ic-chat { display: none; }
.mfa.is-open .mfa-launcher .mfa-ic-close { display: block; }
/* Titik notifikasi kecil */
.mfa-dot { position: absolute; top: 2px; right: 2px; width: 13px; height: 13px;
  background: var(--green, #25d366); border: 2px solid #fff; border-radius: 50%; }
.mfa.is-open .mfa-dot { display: none; }

/* Geser tombol WhatsApp ke atas agar tidak bertumpuk dgn launcher */
.wa-float { bottom: 92px !important; }

/* ---------- Panel ---------- */
.mfa-panel {
  position: fixed; right: 20px; bottom: 92px; z-index: 209;
  width: 370px; max-width: calc(100vw - 40px);
  height: 540px; max-height: calc(100vh - 130px);
  background: var(--mfa-bg); border-radius: var(--mfa-radius);
  box-shadow: 0 24px 60px rgba(20,12,6,.28); overflow: hidden;
  display: flex; flex-direction: column;
  opacity: 0; transform: translateY(16px) scale(.98); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.mfa.is-open .mfa-panel { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Header ---------- */
.mfa-head {
  background: var(--grad-hero, linear-gradient(140deg, #0c1626, #1d2335)); color: #fff;
  padding: 16px 18px; display: flex; align-items: center; gap: 12px;
}
.mfa-head-ava { width: 40px; height: 40px; border-radius: 50%; background: var(--grad-cta, linear-gradient(135deg,#f5842f,#ef5b56));
  display: grid; place-items: center; flex: 0 0 auto; }
.mfa-head-ava svg { width: 22px; height: 22px; }
.mfa-head-txt { flex: 1; min-width: 0; }
.mfa-head-txt strong { display: block; font-size: 1rem; font-weight: 800; }
.mfa-head-txt span { font-size: .78rem; color: #c2d6ee; display: flex; align-items: center; gap: 6px; }
.mfa-head-txt span::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green, #25d366); }
.mfa-close { background: rgba(255,255,255,.12); border: none; color: #fff; width: 32px; height: 32px;
  border-radius: 8px; cursor: pointer; font-size: 20px; line-height: 1; flex: 0 0 auto; transition: background .15s; }
.mfa-close:hover { background: rgba(255,255,255,.25); }

/* ---------- Body (pesan) ---------- */
.mfa-body { flex: 1; overflow-y: auto; padding: 16px; background: #fbf7f3;
  display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.mfa-body::-webkit-scrollbar { width: 7px; }
.mfa-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 4px; }

.mfa-msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; font-size: .92rem;
  line-height: 1.55; word-wrap: break-word; animation: mfaIn .25s ease; }
@keyframes mfaIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.mfa-msg.bot  { background: var(--mfa-bot); color: var(--mfa-ink); align-self: flex-start; border-bottom-left-radius: 4px; }
.mfa-msg.user { background: var(--mfa-brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.mfa-msg.bot a { color: var(--blue, #cf4a28); font-weight: 600; }
.mfa-msg p { margin: 0; }
.mfa-msg p + p { margin-top: 6px; }

/* Tombol CTA dalam balasan */
.mfa-cta { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  background: var(--grad-cta, linear-gradient(135deg,#f5842f,#ef5b56)); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: .86rem;
  text-decoration: none; transition: transform .15s, box-shadow .2s; }
.mfa-cta:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(239,91,86,.35); }
.mfa-cta.wa { background: var(--green, #25d366); }

/* Saran pertanyaan mirip / fallback (chip) */
.mfa-suggests { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mfa-chip { background: #fff; border: 1.5px solid var(--mfa-line); color: var(--mfa-ink);
  padding: 7px 13px; border-radius: 999px; font-size: .82rem; cursor: pointer;
  font-family: inherit; transition: border-color .15s, color .15s, background .15s; }
.mfa-chip:hover { border-color: var(--mfa-brand); color: var(--mfa-brand); }

/* Indikator mengetik */
.mfa-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.mfa-typing span { width: 7px; height: 7px; border-radius: 50%; background: #b9a999; animation: mfaBlink 1.2s infinite; }
.mfa-typing span:nth-child(2) { animation-delay: .2s; }
.mfa-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes mfaBlink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

/* ---------- Quick buttons (tombol cepat) ---------- */
.mfa-quick { padding: 10px 12px; border-top: 1px solid var(--mfa-line); background: var(--mfa-bg);
  display: flex; flex-wrap: wrap; gap: 7px; }
.mfa-quick-btn { background: #fdf3ec; border: 1.5px solid var(--mfa-line); color: var(--mfa-ink);
  padding: 7px 12px; border-radius: 999px; font-size: .8rem; cursor: pointer; font-family: inherit;
  transition: border-color .15s, color .15s; }
.mfa-quick-btn:hover { border-color: var(--mfa-brand); color: var(--mfa-brand); }

/* ---------- Input ---------- */
.mfa-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--mfa-line); background: var(--mfa-bg); }
.mfa-input { flex: 1; border: 1.5px solid var(--mfa-line); border-radius: 999px; padding: 11px 16px;
  font-size: .92rem; font-family: inherit; color: var(--mfa-ink); outline: none; transition: border-color .15s; }
.mfa-input:focus { border-color: var(--mfa-brand); }
.mfa-send { flex: 0 0 auto; width: 42px; height: 42px; border: none; border-radius: 50%; cursor: pointer;
  background: var(--grad-cta, linear-gradient(135deg,#f5842f,#ef5b56)); color: #fff; display: grid; place-items: center;
  transition: transform .15s; }
.mfa-send:hover { transform: scale(1.06); }
.mfa-send svg { width: 19px; height: 19px; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .mfa-panel { right: 0; left: 0; bottom: 0; width: 100%; max-width: 100%;
    height: 82vh; max-height: 82vh; border-radius: 18px 18px 0 0; }
  .mfa-launcher { right: 16px; bottom: 16px; }
  .wa-float { bottom: 86px !important; right: 16px !important; }
}

/* ---------- Hormati preferensi gerak ---------- */
@media (prefers-reduced-motion: reduce) {
  .mfa-panel, .mfa-msg, .mfa-launcher, .mfa-cta, .mfa-send { transition: none; animation: none; }
}

/* ---------- Dark mode (mengikuti preferensi sistem) ---------- */
@media (prefers-color-scheme: dark) {
  .mfa { --mfa-bg: #16233c; --mfa-ink: #eaf0fa; --mfa-muted: #9fb2cc;
         --mfa-line: rgba(255,255,255,.12); --mfa-bot: #1f3050; }
  .mfa-body { background: #122036; }
  .mfa-msg.bot a { color: var(--cyan-400, #ffa45c); }
  .mfa-chip, .mfa-quick-btn { background: #1f3050; color: #eaf0fa; }
  .mfa-input { background: #1f3050; color: #eaf0fa; }
}
