/* ==========================================================================
   cs-bot.css — Rani, asisten CS ARGA (launcher, teaser, panel chat)
   Light only. Animasi hanya transform/opacity, hormati reduced motion.
   ========================================================================== */

/* ---------- Launcher (di dalam .fab-stack) ---------- */
.csb-dock { position: relative; display: grid; justify-items: end; }

.csb-launch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border-radius: var(--pill);
  color: var(--tx-1);
  text-align: left;
  transition: transform var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease), visibility 0s;
}
.csb-launch:active { transform: scale(.96); }

.csb-ava {
  --ava: 56px;
  position: relative;
  flex: none;
  width: var(--ava);
  height: calc(var(--ava) + 26px);
  margin-top: -26px;              /* ruang untuk kepala yang keluar dari lingkaran */
  transform-origin: 50% 100%;
  animation: csb-jiggle 6s var(--ease) 2s infinite;
}
.csb-ava::before {                /* lingkaran bone + ring olive */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--ava);
  border-radius: 50%;
  background: var(--l0);
  border: 2px solid var(--brand);
}
.csb-ava__clip {                  /* bawah bulat mengikuti lingkaran, atas terbuka */
  position: absolute;
  left: 2px; right: 2px; bottom: 2px;
  top: 0;
  overflow: hidden;
  border-radius: 0 0 999px 999px;
}
.csb-ava__clip img {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: calc(var(--ava) + 26px);
  max-width: none;
  height: auto;
  transform: translateX(-50%);
}
.csb-initial {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--ava);
  display: none;
  place-items: center;
  border-radius: 50%;
  background: var(--brand);
  color: #FFFFFF;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--ava) * .45);
}
.is-noimg > .csb-initial { display: grid; }
.is-noimg > .csb-ava__clip { display: none; }

.csb-launch__label { display: none; }
.csb-launch__label strong { display: block; font-weight: 600; font-size: var(--fs-sm); line-height: 1.2; color: var(--tx-1); }
.csb-launch__label small { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--tx-3); line-height: 1.3; }

.csb-sep { display: inline-block; width: 10px; height: 1px; background: currentColor; flex: none; vertical-align: middle; }

@media (min-width: 1024px) {
  .csb-ava { --ava: 64px; }
  .csb-launch {
    background: var(--l1);
    border: 1px solid var(--line-strong);
    padding: 4px 22px 4px 4px;
  }
  .csb-launch:hover { border-color: var(--line-field); }
  .csb-launch__label { display: block; }
}

/* Jiggle: bob 3px, lalu goyang ~0.8s tiap 6 detik */
@keyframes csb-jiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  18% { transform: translateY(-3px) rotate(0deg); }
  36% { transform: translateY(0) rotate(0deg); }
  54% { transform: translateY(-3px) rotate(0deg); }
  78% { transform: translateY(0) rotate(0deg); }
  81% { transform: translateY(0) rotate(-8deg); }
  85% { transform: translateY(0) rotate(8deg); }
  88.5% { transform: translateY(0) rotate(-5deg); }
  91.5% { transform: translateY(0) rotate(0deg); }
}
.csb-launch:hover .csb-ava,
.csb-launch:focus-visible .csb-ava,
.csb-dock.is-paused .csb-ava { animation-play-state: paused; }

/* ---------- Teaser bubble ---------- */
.csb-teaser {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(280px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  background: var(--l1);
  border: 1px solid var(--line-strong);
  border-radius: 14px 14px 4px 14px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(.98);
  transform-origin: 100% 100%;
  transition: opacity var(--dur-3) var(--ease), transform var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
}
.csb-teaser.is-show { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.csb-teaser__body {
  min-height: 44px;
  padding: 12px 4px 12px 14px;
  text-align: left;
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--tx-1);
}
.csb-teaser__body strong { font-weight: 600; }
.csb-teaser__x {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  color: var(--tx-2);
  border-radius: 50%;
}
.csb-teaser__x:hover { color: var(--tx-1); background: var(--l2); }
.csb-teaser__x:active { transform: scale(.96); }
.csb-teaser__x svg { width: 16px; height: 16px; }

/* Launcher disembunyikan saat panel terbuka (mobile) */
.csb-dock.is-open .csb-teaser { opacity: 0; visibility: hidden; }
@media (max-width: 767px) {
  .csb-dock.is-open .csb-launch { opacity: 0; visibility: hidden; transform: scale(.9); }
}

/* ---------- Panel ---------- */
.csb-panel {
  position: fixed;
  z-index: 90;
  right: 20px;
  bottom: 20px;
  width: min(380px, calc(100vw - 24px));
  height: min(600px, calc(100dvh - 40px));
  display: flex;
  flex-direction: column;
  background: var(--l1);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  color: var(--tx-1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(.98);
  transform-origin: 100% 100%;
  transition: opacity var(--dur-3) var(--ease), transform var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
}
.csb-panel.is-open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.csb-panel:focus { outline: none; }
@media (max-width: 767px) {
  .csb-panel {
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: calc(100dvh - 12px);
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    transform: translateY(100%);
  }
  .csb-panel.is-open { transform: none; }
}
.csb-grab { display: none; }
@media (max-width: 767px) {
  .csb-grab { display: block; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(255, 255, 255, .5); z-index: 2; }
}

/* Header olive + foto Rani */
.csb-head {
  position: relative;
  flex: none;
  min-height: 136px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 16px 8px 16px 18px;
  background: var(--brand);
  color: #FFFFFF;
  border-radius: 15px 15px 0 0;
}
.csb-head__info { position: relative; z-index: 2; display: grid; gap: 2px; padding-top: 4px; max-width: calc(100% - 140px); }
.csb-head__name { font-family: var(--font-display); font-weight: 700; font-size: 1.75rem; line-height: 1; text-transform: uppercase; letter-spacing: var(--track-display); color: #FFFFFF; }
.csb-head__role { font-size: var(--fs-sm); font-weight: 500; color: #FFFFFF; }
.csb-head__status { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: var(--fs-xs); color: #E3E8D3; margin-top: 6px; }
.csb-head__actions { position: relative; z-index: 3; display: flex; gap: 2px; }
.csb-head__actions button {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #FFFFFF;
  background: rgba(27, 30, 23, .28);
}
.csb-head__actions button:hover { background: rgba(27, 30, 23, .5); }
.csb-head__actions button:active { transform: scale(.96); }
.csb-head__actions button:focus-visible { outline-color: #FFFFFF; }
.csb-head__actions svg { width: 18px; height: 18px; }
.csb-agent {
  position: absolute;
  right: 98px;                 /* tangan terangkat berhenti tepat di kiri tombol header */
  bottom: 0;
  width: 140px;
  height: 179px;               /* lebih tinggi dari header: kepala menembus tepi atas */
  pointer-events: none;
  z-index: 1;
}
.csb-agent img { position: absolute; right: 0; bottom: 0; width: 140px; height: auto; max-width: none; }
.csb-agent .csb-initial { --ava: 72px; left: auto; right: 16px; bottom: 20px; width: 72px; height: 72px; background: #3B4921; border: 2px solid rgba(255, 255, 255, .35); }
@media (max-width: 767px) { .csb-head { min-height: 132px; } .csb-agent { right: 96px; width: 104px; height: 133px; } .csb-agent img { width: 104px; } .csb-head__info { max-width: calc(100% - 106px); } }
@media (max-width: 359px) { .csb-agent { right: 92px; width: 88px; height: 113px; } .csb-agent img { width: 88px; } .csb-head__info { max-width: calc(100% - 88px); } }

/* Body */
.csb-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  background: var(--l0);
}
.csb-log { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.csb-msg { display: grid; gap: 4px; max-width: 88%; min-width: 0; animation: rise-in var(--dur-3) var(--ease); }
.csb-msg--bot { justify-self: start; }
.csb-msg--user { justify-self: end; justify-items: end; }
.csb-bubble {
  padding: 10px 13px;
  border-radius: 14px 14px 14px 4px;
  background: var(--l2);
  color: var(--tx-1);
  font-size: .9375rem;
  line-height: 1.5;
  min-width: 0;
  overflow-wrap: anywhere;
}
.csb-bubble > * + * { margin-top: 8px; }
.csb-bubble a:not(.btn):not(.csb-pcard__go):not(.csb-btn) { color: var(--brand-deep); font-weight: 600; }
.csb-bubble strong { font-weight: 600; }
.csb-bubble ul, .csb-bubble ol { margin: 0; padding-left: 1.15em; }
.csb-bubble li + li { margin-top: 3px; }
.csb-msg--user .csb-bubble { background: var(--brand); color: #FFFFFF; border-radius: 14px 14px 4px 14px; }
.csb-time { font-size: 11px; color: var(--tx-3); padding-inline: 4px; }
.csb-msg--wide { max-width: 100%; width: 100%; }

/* Quick replies (pill) */
.csb-qr { display: flex; flex-wrap: wrap; gap: 6px; }
.csb-qr button, .csb-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--pill);
  border: 1px solid var(--brand);
  background: var(--l1);
  color: var(--brand-deep);
  font-weight: 600;
  font-size: var(--fs-sm);
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.csb-qr button:hover, .csb-btn:hover { background: var(--brand); color: #FFFFFF; }
.csb-qr button:active, .csb-btn:active { transform: scale(.96); }
.csb-btn svg { width: 16px; height: 16px; flex: none; }
.csb-btn--solid,
.csb-bubble a.csb-btn--solid,
.csb-btn--solid * { background: var(--brand); color: #FFFFFF; }
.csb-btn--solid * { background: transparent; }
.csb-btn--solid:hover { background: var(--brand-hover); }
.csb-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Kartu produk ringkas */
.csb-pcards { display: grid; gap: 6px; }
.csb-pcard {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--l1);
  border: 1px solid var(--line);
}
.csb-pcard img { width: 56px; height: 70px; object-fit: cover; border-radius: 6px; background: var(--l2); }
.csb-pcard__name { font-size: var(--fs-sm); font-weight: 600; line-height: 1.3; }
.csb-pcard .price { font-size: var(--fs-sm); margin-top: 2px; }
.csb-pcard__act { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; align-items: center; }
.csb-pcard__go, .csb-pcard__add {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px;
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--brand-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.csb-pcard__add svg { width: 14px; height: 14px; }

/* Tabel kecil */
.csb-table { width: 100%; overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--l1); }
.csb-table table { font-size: 13px; min-width: 0; }
.csb-table th, .csb-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.csb-table thead th { background: var(--l2); font-weight: 600; }
.csb-table tr:last-child td, .csb-table tr:last-child th { border-bottom: 0; }
.csb-table .num { font-size: 12px; }

/* Ticket promo */
.csb-ticket {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  padding: 12px 20px;
  background: var(--signal-strong);
  color: #FFFFFF;
}
.csb-ticket b { font-family: var(--font-mono); font-weight: 500; font-size: 1.25rem; letter-spacing: .02em; color: #FFFFFF; }
.csb-ticket small { display: block; color: #FFE6DA; font-size: var(--fs-xs); }
.csb-ticket button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--pill);
  background: #FFFFFF;
  color: #8F320C;
  font-weight: 600;
  font-size: var(--fs-sm);
}
.csb-ticket button:active { transform: scale(.96); }
.csb-cd { font-family: var(--font-mono); font-weight: 600; color: #9A3409; } /* 5.6:1 di atas L2 bone */

/* Typing */
.csb-typing { font-size: var(--fs-sm); color: var(--tx-2); padding: 4px 4px 8px; }
.csb-typing i { font-style: normal; animation: csb-dot 1.2s infinite; opacity: .2; }
.csb-typing i:nth-child(2) { animation-delay: .2s; }
.csb-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes csb-dot { 0%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* Footer: input + tautan */
.csb-foot { flex: none; border-top: 1px solid var(--line); padding: 10px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--l1); border-radius: 0 0 15px 15px; }
.csb-form { display: grid; grid-template-columns: minmax(0, 1fr) 48px; gap: 8px; }
.csb-form input {
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  border-radius: var(--pill);
  border: 1px solid var(--line-field);
  background: var(--l0);
  font-size: 1rem;
  color: var(--tx-1);
}
.csb-form input::placeholder { color: var(--tx-3); }
.csb-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); background: var(--l1); }
.csb-form button {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand);
  color: #FFFFFF;
}
.csb-form button:hover { background: var(--brand-hover); }
.csb-form button:active { transform: scale(.96); }
.csb-form button:disabled { background: var(--l3); color: var(--tx-4); }
.csb-form button svg { width: 20px; height: 20px; }
.csb-links { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.csb-links a, .csb-links button {
  min-height: 44px;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--tx-2);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.csb-links a svg { width: 14px; height: 14px; color: var(--wa); }
.csb-links a:hover, .csb-links button:hover { color: var(--tx-1); }

/* Reduced motion: tanpa jiggle & typing anim */
@media (prefers-reduced-motion: reduce) {
  .csb-ava { animation: none; }
  .csb-typing i { animation: none; opacity: 1; }
  .csb-msg { animation: none; }
}

/* Layar desktop pendek: header ringkas, foto tidak keluar dari layar */
@media (min-width: 768px) and (max-height: 720px) {
  .csb-head { min-height: 112px; }
  .csb-agent { width: 104px; height: 133px; }
  .csb-agent img { width: 104px; }
  .csb-head__info { max-width: calc(100% - 106px); }
}
@media (min-width: 768px) and (max-height: 520px) {
  .csb-agent { display: none; }
  .csb-head { min-height: 0; }
  .csb-head__info { max-width: none; }
}
