.cs-embed, .cs-direct {
  --cs-bg: #000;
  --cs-card: #1c1c1e;
  --cs-text: #fff;
  --cs-muted: #8e8e93;
  --cs-cta: #2ad4e0;
  --cs-line: #3a3a3c;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--cs-text);
  -webkit-tap-highlight-color: transparent;
}

.cs-embed {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-b));
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.cs-embed.cs-embed--hide-toggle .cs-launcher { display: none !important; }

.cs-launcher {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  max-width: calc(100vw - 24px);
}

.cs-toggle {
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--cs-cta);
  color: #000;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.32);
  font-size: 22px;
  padding: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex: none;
  position: relative;
  z-index: 2;
}
.cs-toggle--photo {
  background: #111;
  border: 2px solid #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.38);
}
.cs-toggle__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}
.cs-toggle__fallback {
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
}

/* Teaser ala LiveChat Inc — di kiri avatar, rapi + ekor */
.cs-teaser {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(280px, calc(100vw - 88px));
  border: 0;
  border-radius: 12px;
  padding: 10px 34px 10px 14px;
  background: #fff;
  color: #1c1c1e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  box-shadow:
    0 1px 3px rgba(0,0,0,.06),
    0 8px 24px rgba(0,0,0,.14);
  flex: 0 1 auto;
  animation: cs-teaser-in .35s ease both;
}
.cs-teaser::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: translateY(-50%) rotate(45deg);
  border-radius: 2px;
  box-shadow: 2px -2px 4px rgba(0,0,0,.04);
  z-index: -1;
}
.cs-teaser__text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.cs-teaser__close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #8e8e93;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.cs-teaser__close:hover { background: #f2f2f7; color: #111; }
.cs-teaser--hidden { display: none !important; }

@keyframes cs-teaser-in {
  from { opacity: 0; transform: translateX(8px) scale(.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.cs-embed.cs-chat-open .cs-launcher,
.cs-embed.cs-minimized .cs-launcher { display: none !important; }

.cs-panel {
  width: min(380px, calc(100vw - 20px));
  height: min(640px, calc(100dvh - 100px));
  background: var(--cs-bg);
  border-radius: 18px;
  overflow: hidden;
  display: none;
  flex-direction: column;
  border: 1px solid #111;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}

.cs-panel.cs-open { display: flex; }

.cs-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(8px + var(--safe-t)) 10px 0;
  flex: none;
}
.cs-topbar__left, .cs-topbar__right { display: flex; gap: 4px; align-items: center; }
.cs-icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: #fff; font-size: 18px; cursor: pointer;
}

.cs-agent-card {
  margin: 6px 12px 8px;
  background: var(--cs-card);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex: none;
}
.cs-avatars { position: relative; width: 48px; height: 48px; flex: none; }
.cs-avatars .cs-brand, .cs-avatars .cs-face {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  background: #2563eb; display: grid; place-items: center; overflow: hidden;
  border: 2px solid #0a0a0a;
  color: #fff; font-weight: 800;
}
.cs-avatars .cs-brand { position: absolute; left: 0; top: 0; font-size: 8px; font-weight: 800; color: #fff; }
.cs-avatars .cs-face { position: absolute; right: -1px; bottom: -1px; }
.cs-avatars--solo { width: 52px; height: 52px; }
.cs-avatars--solo .cs-face--solo {
  position: absolute;
  inset: 0;
  width: 52px;
  height: 52px;
  right: auto;
  bottom: auto;
  font-size: 18px;
}
.cs-online {
  position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  background: #22c55e; border: 2px solid #0a0a0a; border-radius: 50%; z-index: 2;
}
.cs-avatars--solo .cs-online { right: 0; bottom: 0; }
.cs-agent-meta { min-width: 0; }
.cs-agent-meta strong {
  display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cs-agent-meta span { color: var(--cs-muted); font-size: 12px; }
.cs-rate { display: flex; gap: 10px; margin-top: 4px; color: var(--cs-muted); font-size: 13px; }

.cs-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cs-body:empty::before {
  content: "Memuat chat...";
  color: #8e8e93;
  font-size: 13px;
  margin: auto;
}
.cs-waiting {
  display: none; margin: 0 12px 8px; padding: 8px 10px; border-radius: 12px;
  background: #3a2a08; color: #fcd34d; font-size: 12px; border: 1px solid #78530f; flex: none;
}
.cs-waiting.on { display: block; }

.cs-row { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; min-width: 0; }
.cs-row--mine { align-self: flex-end; flex-direction: row-reverse; }
.cs-row--full {
  max-width: 100%;
  width: 100%;
  align-items: stretch;
  box-sizing: border-box;
}
.cs-row--full .cs-mini-avatar { margin-top: 4px; }
.cs-row--full > * { min-width: 0; flex: 1 1 auto; }
.cs-mini-avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #2563eb; flex: none;
}
.cs-bubble {
  background: var(--cs-card);
  color: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
/* Balasan CS / AI */
.cs-row:not(.cs-row--mine) .cs-bubble {
  background: #2c2c2e;
  color: #f2f2f7;
  border: 1px solid #3a3a3c;
  border-bottom-left-radius: 6px;
}
/* Pesan member */
.cs-row--mine .cs-bubble {
  background: var(--cs-cta);
  color: #0a0a0a;
  border: 0;
  border-bottom-right-radius: 6px;
}
.cs-bubble__text { word-break: break-word; }
.cs-bubble__text strong { font-weight: 800; }
.cs-bubble__text em { font-style: italic; }
.cs-bubble__text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 6px;
}
.cs-bubble__text a { color: #7dd3fc; text-decoration: underline; }
.cs-row--mine .cs-bubble__text a { color: #0b2748; }
.cs-bubble img.cs-img {
  display: block; max-width: min(220px, 62vw); border-radius: 12px; margin-top: 6px;
}
.cs-event {
  align-self: center; font-size: 11px; color: var(--cs-muted);
  border: 1px dashed #333; border-radius: 999px; padding: 6px 10px; text-align: center;
}

.cs-prechat {
  background: var(--cs-card);
  border-radius: 18px;
  padding: 16px;
  margin: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.cs-prechat__promo {
  font-size: 13px; line-height: 1.55; white-space: pre-wrap; margin-bottom: 16px; color: #f2f2f2;
  overflow-wrap: anywhere; word-break: break-word;
  max-height: min(38vh, 260px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}
.cs-prechat label {
  display: grid; gap: 7px; font-size: 13px; margin-bottom: 12px; color: #ddd;
  min-width: 0; max-width: 100%;
}
.cs-prechat label .req { color: #ff453a; }
.cs-prechat input,
.cs-prechat select {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border-radius: 12px;
  border: 1px solid #3a3a3c;
  background: #111;
  color: #fff;
  padding: 13px 12px;
  font: inherit;
  font-size: 15px;
  appearance: none;
  -webkit-appearance: none;
}
.cs-prechat select {
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.cs-start {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  background: var(--cs-cta);
  color: #000;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  min-height: 48px;
}

.cs-composer {
  padding: 8px 12px calc(8px + var(--safe-b));
  display: none;
  flex-direction: column;
  gap: 6px;
  flex: none;
  background: #000;
}
.cs-composer__row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--cs-card); border-radius: 22px; padding: 8px;
}
.cs-plus, .cs-send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: transparent; color: #fff; font-size: 22px; flex: none;
}
.cs-send { background: #3a3a3c; color: #fff; font-size: 16px; }
.cs-send.active { background: var(--cs-cta); color: #000; }
.cs-input {
  flex: 1; border: 0; outline: none; background: transparent; color: #fff;
  font: inherit; font-size: 15px; resize: none; max-height: 100px;
  padding: 10px 4px; line-height: 1.35;
}
.cs-powered {
  text-align: center; color: var(--cs-muted); font-size: 11px; padding-bottom: 2px;
}
.cs-typing {
  display: none; align-items: center; gap: 6px; color: var(--cs-muted);
  font-size: 12px; padding: 0 14px 8px; flex: none;
}
.cs-typing.on { display: flex; }
.cs-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #666;
  animation: csdot 1.1s infinite ease-in-out;
}
.cs-typing i:nth-child(2) { animation-delay: .15s; }
.cs-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes csdot {
  0%,80%,100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Direct full-page mode */
.cs-direct {
  min-height: 100vh;
  min-height: 100dvh;
  background: #000;
  display: flex;
  justify-content: center;
}
.cs-direct .cs-panel {
  display: flex !important;
  width: min(480px, 100%);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}
.cs-direct .cs-toggle { display: none !important; }
.cs-direct .cs-topbar { padding-top: calc(6px + var(--safe-t)); }
.cs-direct .cs-body { padding-bottom: 8px; }
.cs-direct .cs-row--full { max-width: 100%; }

/* Ended chat bar */
.cs-ended {
  display: none;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0 12px calc(12px + var(--safe-b));
  padding: 14px 12px;
  border-radius: 14px;
  background: #1c1c1e;
  border: 1px solid #3a3a3c;
  text-align: center;
}
.cs-ended.on { display: flex; }
.cs-ended__text { color: var(--cs-muted); font-size: 13px; line-height: 1.4; }
.cs-ended__btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 44px;
  width: 100%;
  max-width: 280px;
  background: var(--cs-cta);
  color: #000;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}

/* Failed optimistic send */
.cs-row--failed .cs-bubble {
  opacity: 0.72;
  outline: 1px dashed #ff453a;
}
.cs-row--failed .cs-bubble__text { color: #ffd5d2; }

/* Minimize restore chip (direct + embed) */
.cs-restore {
  display: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  background: var(--cs-cta);
  color: #0a0a0a;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
  max-width: min(320px, calc(100vw - 24px));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cs-embed.cs-minimized .cs-panel,
.cs-direct.cs-minimized .cs-panel { display: none !important; }
.cs-embed.cs-minimized .cs-launcher { display: none !important; }
.cs-embed.cs-minimized .cs-restore,
.cs-direct.cs-minimized .cs-restore { display: inline-flex; align-items: center; justify-content: center; }
.cs-direct.cs-minimized {
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--safe-b));
  background: #0a0a0a;
}

@media (max-width: 720px) {
  .cs-embed.cs-mobile-hide-bubble .cs-launcher { display: none !important; }
  .cs-embed.cs-mobile-hide-bubble .cs-panel { display: none !important; }
  .cs-teaser {
    max-width: min(250px, calc(100vw - 84px));
    font-size: 13px;
    padding: 10px 32px 10px 12px;
  }
  .cs-toggle { width: 56px; height: 56px; }
  .cs-launcher { gap: 8px; }

  .cs-embed .cs-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    width: 100dvw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  .cs-agent-card { margin: 4px 10px 8px; }
  .cs-body { padding: 4px 10px 10px; gap: 10px; }
  .cs-prechat { padding: 14px; border-radius: 16px; }
  .cs-bubble { font-size: 14px; padding: 11px 12px; }
  .cs-prechat input,
  .cs-prechat select,
  .cs-input { font-size: 16px; } /* prevent iOS zoom */
  .cs-ended { margin: 0 10px calc(10px + var(--safe-b)); }
}
