body { font-family: Arial, sans-serif; background:#0f172a; color:#e5e7eb; margin:0; }
.wrap { max-width: 860px; margin: 24px auto; padding: 0 14px; }
h2 { margin: 0 0 14px; }

.card { background:#111827; border:1px solid #243041; padding:14px; border-radius:12px; }
label { display:block; margin-top:10px; font-size:12px; opacity:.85; }
input { width:100%; padding:10px; border-radius:10px; border:1px solid #243041; background:#0b1220; color:#e5e7eb; }
button { padding:10px 14px; border-radius:10px; border:0; background:#2563eb; color:#fff; margin-top:12px; cursor:pointer; }

.err { background:#7f1d1d; border:1px solid #ef4444; padding:10px; border-radius:10px; margin-bottom:12px; }
.small { font-size:11px; opacity:.7; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12px; }

.topbar { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; background:#111827; border:1px solid #243041; padding:12px; border-radius:12px; margin-bottom:12px; }

.chatbox { height: 60vh; overflow:auto; background:#0b1220; border:1px solid #243041; border-radius:12px; padding:12px; }
.msg { display:flex; margin:10px 0; }
.msg.me { justify-content:flex-end; }
.msg.them { justify-content:flex-start; }
.bubble { max-width: 75%; background:#111827; border:1px solid #243041; padding:10px; border-radius:12px; }
.msg.me .bubble { background:#0b3b8a; border-color:#1d4ed8; }
.meta { font-size:11px; opacity:.75; margin-bottom:6px; }

.composer { display:flex; gap:10px; margin-top:12px; }
.composer input { flex:1; margin:0; }
.composer button { margin:0; }
.toolbar{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top:12px;
}

.toolbar button{
  padding:10px 12px;
  border-radius:10px;
  border:1px solid #243041;
  background:#111827;
  color:#e5e7eb;
  cursor:pointer;
}

.toolbar button:disabled{
  opacity:.6;
  cursor:not-allowed;
}

.chat-img{
  max-width: 320px;
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid #243041;
  display:block;
}

.chat-audio{
  width: 280px;
  max-width: 100%;
}
.emoji-panel{
  margin-top: 10px;
  background:#111827;
  border:1px solid #243041;
  border-radius:12px;
  padding:12px;
}

.emoji-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}

.emoji-title{ font-size:12px; opacity:.85; }
.emoji-close{
  background:transparent;
  border:1px solid #243041;
  color:#e5e7eb;
  border-radius:10px;
  padding:6px 10px;
  cursor:pointer;
}

.emoji-grid{
  display:grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap:8px;
}

.emoji-btn{
  background:#0b1220;
  border:1px solid #243041;
  border-radius:10px;
  padding:10px 0;
  cursor:pointer;
  font-size:18px;
}

.emoji-btn:hover{
  filter: brightness(1.15);
}

.chat-emoji{
  font-size: 40px;
  line-height: 1.1;
}

body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:#0b1220;
  color:#e5e7eb;
  margin:0;
}

.wrap{
  max-width: 980px;
  margin: 0 auto;
  padding: 0 14px;
}

.chat-page{
  min-height: 100vh;
  display:flex;
  flex-direction:column;
}

.chat-topbar{
  position: sticky;
  top: 0;
  z-index: 20;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 12px 10px;
  margin-top: 10px;

  background: rgba(17,24,39,.88);
  border: 1px solid #243041;
  border-radius: 14px;
  backdrop-filter: blur(8px);
}

.chat-peer{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}

.peer-avatar{
  width:42px; height:42px;
  border-radius: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: linear-gradient(180deg, #1d4ed8, #0ea5e9);
  color:#fff;
  font-weight:800;
}

.peer-meta{ min-width:0; }
.peer-name{
  font-weight:800;
  letter-spacing:.2px;
}
.peer-sub{
  font-size:12px;
  opacity:.75;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width: 58vw;
}

.me-pill{
  font-size:12px;
  padding:8px 10px;
  border-radius: 999px;
  border:1px solid #243041;
  background:#0b1220;
}

.wa-chatbox{
  flex:1;
  margin-top: 12px;
  padding: 14px 12px;

  background: radial-gradient(1200px 400px at 20% 0%, rgba(37,99,235,.18), transparent 55%),
              radial-gradient(1000px 340px at 80% 0%, rgba(14,165,233,.14), transparent 55%),
              #0b1220;

  border: 1px solid #243041;
  border-radius: 16px;

  overflow:auto;
}

.msg{
  display:flex;
  margin: 10px 0;
}

.msg.me{ justify-content:flex-end; }
.msg.them{ justify-content:flex-start; }

.bubble{
  position:relative;
  max-width: min(78%, 520px);
  border-radius: 16px;
  padding: 10px 10px 6px;
  border: 1px solid #243041;
  box-shadow: 0 10px 24px rgba(0,0,0,.16);
}

.msg.them .bubble{
  background: rgba(17,24,39,.92);
}

.msg.me .bubble{
  background: rgba(37,99,235,.22);
  border-color: rgba(29,78,216,.55);
}

.msg.them .bubble:before{
  content:"";
  position:absolute;
  left:-6px;
  bottom: 10px;
  width: 14px;
  height: 14px;
  background: rgba(17,24,39,.92);
  border-left: 1px solid #243041;
  border-bottom: 1px solid #243041;
  transform: rotate(45deg);
  border-bottom-left-radius: 4px;
}

.msg.me .bubble:before{
  content:"";
  position:absolute;
  right:-6px;
  bottom: 10px;
  width: 14px;
  height: 14px;
  background: rgba(37,99,235,.22);
  border-right: 1px solid rgba(29,78,216,.55);
  border-bottom: 1px solid rgba(29,78,216,.55);
  transform: rotate(45deg);
  border-bottom-right-radius: 4px;
}

.bubble-content{ padding-right: 46px; }
.bubble-meta{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  gap:6px;
  margin-top: 6px;
  font-size: 11px;
  opacity: .75;
}
.bubble-time{ white-space:nowrap; }


.chat-text{ white-space:pre-wrap; word-break:break-word; }


.chat-img{
  display:block;
  width: 100%;
  max-width: 420px;
  height:auto;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.08);
}

.chat-audio{
  width: 320px;
  max-width: 100%;
}

.chat-emoji{
  font-size: 44px;
  line-height: 1.1;
}

.wa-actions{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 10px;
  margin-top: 10px;

  background: rgba(17,24,39,.88);
  border: 1px solid #243041;
  border-radius: 14px;
  backdrop-filter: blur(8px);
}

.wa-btn{
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 16px;
}

.wa-btn:disabled{ opacity:.55; cursor:not-allowed; }

.wa-status{
  margin-left:auto;
  font-size: 12px;
  opacity:.75;
}

.wa-composer{
  position: sticky;
  bottom: 0;
  z-index: 25;

  display:flex;
  gap:10px;
  align-items:center;

  padding: 10px;
  margin: 10px 0 14px;

  background: rgba(17,24,39,.92);
  border: 1px solid #243041;
  border-radius: 14px;
  backdrop-filter: blur(8px);
}

.wa-input{
  flex:1;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  outline:none;
}

.wa-input:focus{
  border-color: rgba(37,99,235,.7);
  box-shadow: 0 0 0 4px rgba(37,99,235,.14);
}

.wa-send{
  height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  background:#2563eb;
  color:#fff;
  cursor:pointer;
  font-weight:700;
}

.wa-send:hover{ filter: brightness(1.05); }

.wa-emoji{
  position: sticky;
  bottom: 74px;
  z-index: 30;
  margin-top: 10px;
}

.emoji-panel{
  background: rgba(17,24,39,.92);
  border: 1px solid #243041;
  border-radius: 14px;
  padding: 12px;
  backdrop-filter: blur(8px);
}

.emoji-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}

.emoji-title{ font-size:12px; opacity:.85; }
.emoji-close{
  background:transparent;
  border:1px solid #243041;
  color:#e5e7eb;
  border-radius:10px;
  padding:6px 10px;
  cursor:pointer;
}

.emoji-grid{
  display:grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap:8px;
}

.emoji-btn{
  background:#0b1220;
  border:1px solid #243041;
  border-radius:12px;
  padding:10px 0;
  cursor:pointer;
  font-size:18px;
}

.emoji-btn:hover{ filter: brightness(1.12); }

/* Responsive */
@media (max-width: 640px){
  .peer-sub{ max-width: 54vw; }
  .emoji-grid{ grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .bubble{ max-width: 86%; }
  .bubble-content{ padding-right: 40px; }
}

.wa-composer-wa{
  position: sticky;
  bottom: 0;
  z-index: 25;

  display:flex;
  align-items:center;
  gap:10px;

  padding: 10px 12px;
  margin: 10px 0 14px;

  background: rgba(17,24,39,.92);
  border: 1px solid #243041;
  border-radius: 18px;
  backdrop-filter: blur(8px);
}

.wa-icn{
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 16px;
}

.wa-icn:hover{ filter: brightness(1.12); }
.wa-icn:disabled{ opacity:.55; cursor:not-allowed; }

.wa-input-wa{
  flex:1;
  height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  outline:none;
}

.wa-input-wa:focus{
  border-color: rgba(37,99,235,.7);
  box-shadow: 0 0 0 4px rgba(37,99,235,.14);
}

.wa-send-wa{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background:#2563eb;
  color:#fff;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
}

.wa-send-wa:hover{ filter: brightness(1.06); }

.wa-icn-mic{
  background: rgba(14,165,233,.12);
  border-color: rgba(14,165,233,.35);
}

.wa-icn-stop{
  background: rgba(239,68,68,.12);
  border-color: rgba(239,68,68,.35);
}

#recStatus{
  font-size: 12px;
  opacity:.75;
  margin-left: 8px;
}

.wa-emoji{
  position: sticky;
  bottom: 78px;
  z-index: 30;
}

.wrap{
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 14px 24px; 
}

.chat-topbar{
  margin-top: 6px;   
  margin-bottom: 12px;
}

.wa-chatbox{
  margin-top: 0;
  padding: 16px 14px;
}

.wa-composer-wa{
  margin-top: 12px;
  margin-bottom: 0;
}

.chat-page{
  padding-bottom: 14px;
}


.wa-send-wa{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background:#2563eb;
  color:#fff;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
}

.wa-send-wa.is-recording{
  background: rgba(239,68,68,.9);
}


.wa-icn-stop{
  width: 40px;
  height: 40px;
}

@media (max-width: 420px){
  .wa-composer-wa{ gap:8px; padding:10px; border-radius: 16px; }
  .wa-icn{ width:38px; height:38px; font-size:15px; }
  .wa-input-wa{ height: 40px; padding: 0 12px; }
  .wa-send-wa{ width: 42px; height: 42px; }
  .emoji-grid{ grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

.chat-actions{
  display:flex;
  align-items:center;
  gap:10px;
}

.topbar-icn{
  width:40px;height:40px;
  border-radius:999px;
  border:1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}
.topbar-icn:hover{ filter: brightness(1.12); }

.callbar{
  position: sticky;
  top: 74px;          
  z-index: 40;
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #243041;
  background: rgba(17,24,39,.92);
  backdrop-filter: blur(8px);

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.callbar-left{
  display:flex;
  align-items:center;
  gap:10px;
}

.callbar-dot{
  width:10px;height:10px;border-radius:999px;
  background:#22c55e;
  box-shadow: 0 0 0 6px rgba(34,197,94,.12);
}

.callbar-title{ font-weight:800; }
.callbar-sub{ font-size:12px; opacity:.75; }

.callbar-actions{ display:flex; gap:8px; }
.callbar-btn{
  width:42px;height:42px;border-radius:999px;
  border:1px solid #243041;
  background:#0b1220;
  color:#e5e7eb;
  cursor:pointer;
}
.callbar-btn:disabled{ opacity:.55; cursor:not-allowed; }

.callbar-btn-end{
  background: rgba(239,68,68,.14);
  border-color: rgba(239,68,68,.35);
}

.callmodal{
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 16px;
}

.callmodal-card{
  width: min(360px, 92vw);
  border-radius: 16px;
  border: 1px solid #243041;
  background: rgba(17,24,39,.95);
  backdrop-filter: blur(10px);
  padding: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}

.callmodal-title{ font-weight:900; font-size: 16px; }
.callmodal-sub{ margin-top:6px; font-size: 13px; opacity:.8; }

.callmodal-actions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  margin-top: 14px;
}

.callmodal-btn{
  border:0;
  padding: 10px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight:800;
}

.callmodal-reject{ background: rgba(239,68,68,.85); color:#fff; }
.callmodal-accept{ background: rgba(34,197,94,.9); color:#0b1220; }

.callmodal[hidden],
.callbar[hidden]{
  display: none !important;
}

.callmodal:not([hidden]){
  display: flex;
}
.callbar:not([hidden]){
  display: flex;
}

/* 1 tombol: mic/send/stop */
.wa-send-wa{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background:#2563eb;
  color:#fff;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  transition: transform .08s ease, filter .15s ease;
}

.wa-send-wa:active{ transform: scale(.98); }
.wa-send-wa:hover{ filter: brightness(1.06); }

/* state: recording => merah seperti WA */
.wa-send-wa.is-recording{
  background: rgba(239,68,68,.92);
}

/* opsional: ketika mic mode (tidak ada teks) */
.wa-send-wa.is-mic{
  background:#2563eb; /* tetap biru */
}

/* =========================
   CHAT BUBBLES (FIX: auto-fit + meta overlay)
   ========================= */

.msg{
  display:flex;
  margin: 10px 0;
}
.msg.me{ justify-content:flex-end; }
.msg.them{ justify-content:flex-start; }

/* bubble sekarang shrink-to-fit */
.bubble{
  position: relative;
  display: inline-flex;             /* ✅ auto fit */
  flex-direction: column;
  width: fit-content;               /* ✅ lebar sesuai isi */
  max-width: min(78%, 520px);       /* ✅ tetap ada limit */
  padding: 10px 12px 18px;          /* ✅ space bawah untuk jam */
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 10px 24px rgba(0,0,0,.14);
  backdrop-filter: blur(6px);
  overflow: visible;
}

/* warna + feel */
.msg.them .bubble{
  background: rgba(17,24,39,.92);
}
.msg.me .bubble{
  background: linear-gradient(180deg, rgba(37,99,235,.28), rgba(37,99,235,.18));
  border-color: rgba(29,78,216,.45);
}

/* tail lebih kecil & rapi */
.msg.them .bubble:before,
.msg.me .bubble:before{
  content:"";
  position:absolute;
  bottom: 10px;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border-radius: 3px;
  opacity: 1;
}

.msg.them .bubble:before{
  left: -6px;
  background: rgba(17,24,39,.92);
  border-left: 1px solid rgba(255,255,255,.08);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.msg.me .bubble:before{
  right: -6px;
  background: rgba(37,99,235,.22);
  border-right: 1px solid rgba(29,78,216,.45);
  border-bottom: 1px solid rgba(29,78,216,.45);
}

/* content jangan dipaksa lebar + jangan ada padding-right besar */
.bubble-content{
  width: auto;
  padding: 0;                       /* ✅ hapus padding-right 46px */
}

/* text: rapi, ga bikin bubble melebar karena spasi */
.chat-text{
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.25;
  font-size: 14px;
}

/* jam ditaruh absolute, jadi bubble bisa kecil */
.bubble-meta{
  position:absolute;
  right: 10px;
  bottom: 6px;
  display:flex;
  align-items:center;
  gap:6px;
  font-size: 11px;
  opacity: .7;
  pointer-events: none;
}

.bubble-time{
  white-space:nowrap;
}

/* image & audio ikut rapih */
.chat-img{
  display:block;
  width: 100%;
  max-width: 360px;
  height:auto;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.08);
}

.chat-audio{
  width: 300px;
  max-width: 100%;
}

.chat-emoji{
  font-size: 44px;
  line-height: 1.1;
}

/* mobile tightening */
@media (max-width: 420px){
  .bubble{
    max-width: 86%;
    padding: 10px 12px 18px;
    border-radius: 16px;
  }
  .chat-text{ font-size: 14px; }
  .chat-audio{ width: 260px; }
}
.msg.me .bubble { border-top-right-radius: 12px; }
.msg.them .bubble { border-top-left-radius: 12px; }
