* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f2f5;
  color: #222;
}
.hidden { display: none !important; }

/* ---------- QR overlay ---------- */
.qr-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.qr-box {
  background: #fff; padding: 32px; border-radius: 12px;
  text-align: center; max-width: 360px;
}
.qr-box img { width: 240px; height: 240px; margin: 16px 0; }
.qr-note { color: #777; font-size: 13px; }

/* ---------- App layout ---------- */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
  padding: 10px 16px; background: #075e54; color: #fff;
}
.brand { font-weight: 600; font-size: 16px; }
.online-agents { font-size: 12px; opacity: 0.95; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.online-agents .agent-chip {
  background: rgba(255,255,255,0.18); border-radius: 10px; padding: 2px 8px;
}
.online-agents .agent-chip::before { content: "● "; color: #7CFC9A; }
.agent-box { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.agent-box input {
  padding: 6px 10px; border-radius: 6px; border: none; font-size: 14px;
}
.wa-status { font-size: 20px; color: #f44336; } /* merah = belum konek */
.wa-status.online { color: #4caf50; }

.main-layout { flex: 1; display: flex; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 340px; min-width: 220px; max-width: 40vw; flex-shrink: 0;
  background: #fff; border-right: 1px solid #ddd;
  display: flex; flex-direction: column;
}
.status-tabs { display: flex; border-bottom: 1px solid #eee; }
.tab-btn {
  flex: 1; padding: 12px 6px; border: none; background: none;
  cursor: pointer; font-size: 13px; border-bottom: 3px solid transparent;
}
.tab-btn.active { border-bottom-color: #075e54; font-weight: 600; }
.count { color: #888; font-size: 12px; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  padding: 12px 14px; border-bottom: 1px solid #f2f2f2; cursor: pointer;
}
.chat-item:hover { background: #f7f7f7; }
.chat-item.selected { background: #e9f7f2; }
.chat-item .name { font-weight: 600; font-size: 14px; }
.chat-item .preview { font-size: 12px; color: #777; margin-top: 2px; }
.chat-item .meta { font-size: 11px; color: #999; margin-top: 4px; }
.chat-item.attention { border-left: 4px solid #f44336; }
.chat-item.attention .meta { color: #f44336; font-weight: 600; }

/* ---------- Chat window ---------- */
/* min-width: 0 penting - tanpa ini konten panjang (kutipan/teks tanpa spasi)
   memaksa kolom chat lebih lebar dari layar & bagian kanannya kepotong */
.chat-window { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #e5ddd5; }
.chat-header {
  padding: 12px 16px; background: #fff; border-bottom: 1px solid #ddd; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 16px; }
.msg {
  max-width: 60%; padding: 8px 12px; border-radius: 10px; margin-bottom: 8px;
  font-size: 14px; line-height: 1.4; clear: both;
  min-width: 0; overflow-wrap: anywhere;
}
.msg.in { background: #fff; float: left; }
.msg.out { background: #dcf8c6; float: right; }
.msg img { max-width: min(240px, 100%); border-radius: 6px; display: block; margin-top: 4px; }
.msg .agent-tag { font-size: 11px; color: #075e54; font-weight: 600; display: block; }
.msg .time { font-size: 10px; color: #999; display: block; margin-top: 2px; text-align: right; }

.reply-box { background: #fff; border-top: 1px solid #ddd; padding: 10px 14px; }
.drop-hint { font-size: 11px; color: #999; margin-bottom: 6px; }
.reply-row { display: flex; gap: 8px; align-items: center; }
.reply-row input[type=text] {
  flex: 1; padding: 10px 12px; border-radius: 20px; border: 1px solid #ccc; font-size: 14px;
}
.hidden-input { display: none; }
.btn-icon { background: none; border: none; font-size: 20px; cursor: pointer; }
.btn-primary {
  background: #075e54; color: #fff; border: none; padding: 10px 18px;
  border-radius: 20px; cursor: pointer; font-size: 14px;
}
.btn-secondary {
  background: none; border: 1px solid #075e54; color: #075e54;
  padding: 6px 12px; border-radius: 16px; cursor: pointer; font-size: 12px;
}
.reply-row-secondary { margin-top: 8px; text-align: right; }

/* ---------- Login overlay ---------- */
.login-overlay {
  position: fixed; inset: 0;
  background: #075e54;
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.login-box {
  background: #fff; padding: 32px; border-radius: 12px;
  text-align: center; max-width: 320px; width: 90%;
}
.login-box h2 { margin-top: 0; }
.login-box input {
  width: 100%; padding: 10px 12px; margin: 12px 0; border-radius: 6px;
  border: 1px solid #ccc; font-size: 14px; box-sizing: border-box;
}
.login-box .btn-primary { width: 100%; padding: 10px; }
.login-error { color: #f44336; font-size: 13px; margin-top: 10px; }

/* ---------- Tombol Blast di topbar ---------- */
.btn-blast { white-space: nowrap; }
/* tombol outline hijau di atas topbar hijau jadi tak terlihat - pakai putih */
.topbar .btn-blast { color: #fff; border-color: #fff; }

/* ---------- Panel Chat Baru / Blast ---------- */
.blast-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 150;
}
.blast-box {
  background: #fff; border-radius: 12px; padding: 24px;
  max-width: 420px; width: 90%; max-height: 85vh; overflow-y: auto;
}
.blast-header { display: flex; justify-content: space-between; align-items: center; }
.blast-header h2 { margin: 0; font-size: 18px; }
.blast-section { margin: 16px 0; }
.blast-section h3 { font-size: 14px; margin-bottom: 8px; }
.blast-section input[type=text], .blast-section textarea, .blast-section input[type=file] {
  width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #ccc;
  font-size: 14px; box-sizing: border-box; margin-bottom: 8px; font-family: inherit;
}
.blast-hint { font-size: 12px; color: #777; margin: 4px 0 10px; }
.blast-status { font-size: 12px; color: #555; margin-top: 8px; min-height: 16px; }
.blast-queue-status {
  font-size: 12px; color: #075e54; background: #e9f7f2; border-radius: 6px;
  padding: 8px 10px; margin-top: 4px; min-height: 14px;
}
.blast-detail-list {
  margin-top: 8px; max-height: 220px; overflow-y: auto;
  border: 1px solid #eee; border-radius: 6px;
}
.blast-detail-row {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 6px 10px; font-size: 12px; border-bottom: 1px solid #f2f2f2;
}
.blast-detail-row:last-child { border-bottom: none; }
.blast-detail-row .num { font-weight: 600; min-width: 110px; }
.blast-detail-row .err { color: #c62828; }
.blast-detail-row.status-gagal { background: #fff5f5; }
.blast-detail-row.status-terkirim .num { color: #2e7d32; }
.blast-detail-summary {
  font-size: 11px; color: #777; padding: 6px 10px; border-bottom: 1px solid #eee; background: #fafafa;
}
.blast-quota-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.blast-quota-row label { font-size: 12px; color: #555; flex: 1; }
.blast-quota-row input[type=number] {
  width: 70px; padding: 6px 8px; border-radius: 6px; border: 1px solid #ccc;
  font-size: 13px; margin-bottom: 0;
}

/* ---------- Overlay konfirmasi kirim gambar (preview + caption) ---------- */
.image-caption-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 160;
}
.image-caption-box {
  background: #fff; border-radius: 12px; padding: 20px;
  max-width: 360px; width: 90%; text-align: center;
}
.image-caption-box img {
  max-width: 100%; max-height: 280px; border-radius: 8px; margin-bottom: 12px;
  object-fit: contain; background: #eee;
}
.image-caption-box textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #ccc;
  font-size: 14px; font-family: inherit; resize: none; box-sizing: border-box;
}
.image-caption-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px;
}

/* ---------- Badge belum-dibaca grup ---------- */
.chat-item.unread-group .name { font-weight: 700; }
.unread-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #f44336; margin-right: 6px;
}

/* ---------- Kolom pencarian ---------- */
.search-box { padding: 8px 12px; border-bottom: 1px solid #eee; background: #fff; }
.search-box input {
  width: 100%; padding: 8px 10px; border-radius: 16px; border: 1px solid #ddd;
  font-size: 13px; box-sizing: border-box;
}

/* ---------- Textarea multi-baris (ganti input teks biasa) ---------- */
.reply-row textarea {
  flex: 1; padding: 10px 12px; border-radius: 16px; border: 1px solid #ccc;
  font-size: 14px; font-family: inherit; resize: none; max-height: 100px;
  overflow-y: auto; line-height: 1.4; min-width: 0;
}

/* ---------- Reply preview bar (sedang membalas pesan X) ---------- */
.reply-preview {
  display: flex; justify-content: space-between; align-items: center;
  background: #f0f0f0; border-left: 3px solid #075e54; border-radius: 6px;
  padding: 6px 10px; margin-bottom: 8px; font-size: 12px; color: #555;
}
.reply-preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90%; }

/* ---------- Popup aksi pesan (klik pesan -> muncul Reply + reaksi) ---------- */
.msg { cursor: pointer; position: relative; }
.msg-action-bar {
  display: flex; gap: 6px; align-items: center; background: #fff;
  border: 1px solid #ddd; border-radius: 20px; padding: 6px 10px;
  margin: 4px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.15); width: fit-content;
  clear: both;
}
.msg-action-bar .emoji-btn {
  background: none; border: none; font-size: 18px; cursor: pointer; padding: 2px 4px;
  border-radius: 50%;
}
.msg-action-bar .emoji-btn:hover { background: #f0f0f0; }
.msg-action-bar .reply-btn {
  background: none; border: none; font-size: 12px; color: #075e54; cursor: pointer;
  font-weight: 600; padding: 4px 8px; border-left: 1px solid #eee; margin-left: 4px;
}

/* ---------- Kutipan pesan (tampil di atas bubble kalau ini balasan "↩️ Balas") ---------- */
.msg-quote {
  background: rgba(0,0,0,0.06); border-left: 3px solid #075e54; border-radius: 4px;
  padding: 4px 8px; margin-bottom: 4px; font-size: 12px; color: #555;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}

/* ---------- Badge reaksi emoji di bawah bubble pesan ---------- */
.msg-reactions { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.reaction-badge {
  background: #fff; border: 1px solid #ddd; border-radius: 10px;
  padding: 1px 6px; font-size: 12px; cursor: default;
}

/* ---------- Layar sempit / browser di-zoom besar ---------- */
@media (max-width: 900px) {
  .sidebar { width: 260px; }
  .tab-btn { font-size: 12px; padding: 10px 2px; }
  .msg { max-width: 80%; }
}
@media (max-width: 640px) {
  .sidebar { width: 200px; min-width: 160px; }
  .topbar { padding: 8px 10px; }
  .agent-box { margin-left: 0; }
  .msg { max-width: 90%; }
  .reply-box { padding: 8px 10px; }
}

/* ---------- Panel Catatan balasan cepat ---------- */
.notes-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 155;
}
.notes-box {
  background: #fff; border-radius: 12px; padding: 20px;
  max-width: 480px; width: 92%; max-height: 88vh; overflow-y: auto;
}
.notes-header { display: flex; justify-content: space-between; align-items: center; }
.notes-header h2 { margin: 0; font-size: 18px; }
.notes-box input[type=text], .notes-box textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #ccc;
  font-size: 14px; box-sizing: border-box; margin-top: 8px; font-family: inherit;
}
.notes-box textarea { resize: vertical; }
.notes-list { margin-top: 10px; max-height: 260px; overflow-y: auto; border: 1px solid #eee; border-radius: 8px; }
.notes-empty { padding: 14px; color: #999; font-size: 13px; }
.note-item { padding: 8px 10px; border-bottom: 1px solid #f2f2f2; }
.note-item:last-child { border-bottom: none; }
.note-title { font-weight: 600; font-size: 13px; }
.note-preview {
  font-size: 12px; color: #666; margin: 2px 0 6px; white-space: pre-wrap; word-break: break-word;
  max-height: 54px; overflow: hidden;
}
.note-actions { display: flex; gap: 6px; }
.note-actions button { padding: 3px 10px; font-size: 12px; }
.note-actions .btn-danger { color: #c62828; border-color: #c62828; }
.notes-form { margin-top: 14px; border-top: 1px solid #eee; padding-top: 10px; }
.notes-form h3 { font-size: 14px; margin: 0; }
.notes-form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
