/* ===== GUEST CHAT WIDGET ===== */
.chat-float-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-gold) 0%, #a8884a 100%);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 4px 20px rgba(194, 165, 109, 0.5);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.chat-float-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(194, 165, 109, 0.6);
}
.chat-float-btn .chat-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #e74c3c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* Chat Window */
.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9998;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp 0.3s ease;
}
@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, var(--color-dark) 0%, #1a2730 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chat-header-name { font-weight: 600; font-size: 0.95rem; }
.chat-header-status { font-size: 0.75rem; color: rgba(255,255,255,0.7); }
.chat-header-status .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25D366;
  margin-right: 4px;
}
.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}
.chat-close-btn:hover { color: #fff; }

/* Intro */
.chat-intro {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.chat-intro-inner { text-align: center; }
.chat-intro-icon { font-size: 48px; color: var(--color-gold); margin-bottom: 12px; }
.chat-intro-inner h6 { font-family: var(--font-display); font-size: 1.2rem; }
.chat-intro-inner p { font-size: 0.85rem; color: #666; margin-bottom: 16px; }

/* Messages */
.chat-messages {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-messages-inner {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #e5ddd5;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8c0b5' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Message Bubbles */
.chat-msg {
  display: flex;
  margin-bottom: 4px;
  animation: msgFadeIn 0.2s ease;
}
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.guest { justify-content: flex-end; }
.chat-msg.admin { justify-content: flex-start; }

.chat-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  overflow: hidden;
}
.chat-msg.guest .chat-bubble {
  background: #dcf8c6;
  border-bottom-right-radius: 4px;
}
.chat-msg.admin .chat-bubble {
  background: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.chat-bubble .chat-time {
  font-size: 0.68rem;
  color: #999;
  margin-top: 4px;
  text-align: right;
}
.chat-bubble .chat-attachment {
  margin-bottom: 4px;
}
.chat-bubble .chat-attachment img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  cursor: pointer;
  object-fit: cover;
}
.chat-bubble .chat-attachment video {
  max-width: 100%;
  border-radius: 8px;
  max-height: 200px;
}
.chat-bubble .chat-attachment .file-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}
.chat-bubble .chat-attachment .file-link i { font-size: 24px; color: var(--color-accent); }
.chat-bubble .chat-attachment .file-link span { font-size: 0.8rem; word-break: break-all; }

/* Date separator */
.chat-date-sep {
  text-align: center;
  margin: 12px 0;
}
.chat-date-sep span {
  background: rgba(0,0,0,0.08);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  color: #666;
}

/* Input Area */
.chat-input-area {
  border-top: 1px solid #eee;
  background: #f0f0f0;
}
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}
.chat-attach-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}
.chat-attach-btn:hover { color: var(--color-gold); }
.chat-input {
  flex: 1;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 0.88rem;
  resize: none;
  max-height: 100px;
  outline: none;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chat-send-btn {
  background: var(--color-gold);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send-btn:not(:disabled):hover { transform: scale(1.1); }

/* Preview */
.chat-preview {
  padding: 12px;
  background: #1a1a1a;
  position: relative;
}
.chat-preview-inner {
  position: relative;
}
.chat-preview-close {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}
.chat-preview img, .chat-preview video {
  max-height: 200px;
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}
.chat-preview .file-preview {
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
}
.chat-preview .file-preview i { font-size: 32px; }
.chat-preview .file-preview span { font-size: 0.85rem; word-break: break-all; }
.chat-crop-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

/* Mobile */
@media (max-width: 575.98px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  /* Sembunyikan floating button saat chat window terbuka di mobile */
  .chat-widget.chat-open .chat-float-btn {
    display: none !important;
  }
  /* Input area di mobile: pastikan tidak tertutup keyboard */
  .chat-input-area {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
  /* Tombol close ada di header, tidak perlu di floating button saat fullscreen */
  .chat-float-btn {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
    font-size: 22px;
  }
}

/* ===== ADMIN CHAT ===== */
.admin-chat-container {
  display: flex;
  height: calc(100vh - 60px);
  background: #fff;
  overflow: hidden;
}

/* Sidebar */
.admin-chat-sidebar {
  width: 360px;
  min-width: 360px;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.admin-chat-sidebar-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-dark, #2C3947);
  color: #fff;
}
.admin-chat-sidebar-header h5 { color: #fff; }
.admin-chat-sidebar-header .badge { font-size: 0.7rem; }
.admin-chat-search {
  padding: 8px 12px;
  background: #f6f6f6;
  border-bottom: 1px solid #e0e0e0;
}
.admin-chat-search .form-control {
  border-radius: 20px;
  border: none;
  background: #fff;
  font-size: 0.85rem;
  padding: 8px 16px;
}
.admin-chat-list {
  flex: 1;
  overflow-y: auto;
}

/* Conversation item */
.admin-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #f0f0f0;
}
.admin-conv-item:hover { background: #f5f5f5; }
.admin-conv-item.active { background: #e8edf2; }
.admin-conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-accent, #547A95);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.admin-conv-avatar-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.admin-conv-avatar-initial {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-gold, #C2A56D);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}
.admin-conv-info { flex: 1; min-width: 0; }
.admin-conv-name { font-weight: 600; font-size: 0.9rem; color: var(--color-dark, #2C3947); }
.admin-conv-last {
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.admin-conv-meta {
  text-align: right;
  flex-shrink: 0;
}
.admin-conv-time { font-size: 0.7rem; color: #999; }
.admin-conv-unread {
  background: var(--color-gold, #C2A56D);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  margin-left: auto;
}

/* Main chat area */
.admin-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #e5ddd5;
  overflow: hidden;
}
.admin-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0ebe3;
}
.admin-chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.admin-chat-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-dark, #2C3947);
  color: #fff;
  flex-shrink: 0;
}
.admin-chat-header .fw-bold { color: #fff; }
.admin-chat-header .small { color: rgba(255,255,255,0.7); }
.admin-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  background: #e5ddd5;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8c0b5' fill-opacity='0.12'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.admin-chat-input-area {
  background: #f0f0f0;
  padding: 10px 60px;
  flex-shrink: 0;
  border-top: 1px solid #ddd;
}
.admin-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.admin-chat-input-row .chat-attach-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  transition: color 0.2s;
  flex-shrink: 0;
}
.admin-chat-input-row .chat-attach-btn:hover { color: var(--color-gold); }
.admin-chat-input-row textarea {
  flex: 1;
  border: none;
  border-radius: 20px;
  padding: 10px 18px;
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  outline: none;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  min-height: 42px;
}
.admin-chat-input-row .chat-send-btn {
  background: var(--color-gold, #C2A56D);
  border: none;
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
  flex-shrink: 0;
}
.admin-chat-input-row .chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.admin-chat-input-row .chat-send-btn:not(:disabled):hover { transform: scale(1.1); }

.admin-chat-preview {
  padding: 12px 0;
  background: #1a1a1a;
  position: relative;
  margin-bottom: 8px;
  border-radius: 8px;
}
.admin-chat-preview-inner { position: relative; }
.admin-chat-preview img, .admin-chat-preview video {
  max-height: 160px;
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}

/* Mobile admin chat */
@media (max-width: 991.98px) {
  .admin-chat-sidebar { width: 100%; min-width: 100%; }
  .admin-chat-main { display: none; }
  .admin-chat-container.show-chat .admin-chat-sidebar { display: none; }
  .admin-chat-container.show-chat .admin-chat-main { display: flex; }
  .admin-chat-messages { padding: 12px 16px; }
  .admin-chat-input-area { padding: 10px 12px; }
  .admin-chat-preview { padding: 12px; }
}

@media (max-width: 575.98px) {
  .admin-chat-container { height: calc(100vh - 56px); }
}

/* Notification popup */
.chat-notif-popup {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 340px;
  animation: notifSlideIn 0.3s ease;
  cursor: pointer;
}
@keyframes notifSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
.chat-notif-popup .notif-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-gold);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.chat-notif-popup .notif-body { flex: 1; min-width: 0; }
.chat-notif-popup .notif-name { font-weight: 600; font-size: 0.85rem; }
.chat-notif-popup .notif-text {
  font-size: 0.8rem;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-notif-popup .notif-close {
  background: none;
  border: none;
  color: #999;
  font-size: 16px;
  cursor: pointer;
}

/* Image lightbox */
.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.chat-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}
.chat-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
