/* ============================================================
   DG Chat Widget — WhatsApp-inspired UI (Feb 2026 redesign)
   Keeps all existing class names/data attrs the JS depends on.
   ============================================================ */
:root {
  --dg-primary: #075E54;
  --dg-primary-hover: #054C43;
  --dg-accent: #25D366;
  --dg-bubble-out: #DCF8C6;
  --dg-bubble-in: #FFFFFF;
  --dg-wallpaper: #E5DDD5;
  --dg-header-text: #FFFFFF;
  --dg-tick-blue: #34B7F1;
  --dg-text: #111B21;
  --dg-text-muted: rgba(0,0,0,0.55);
  --dg-radius-bubble: 8px;
  --dg-shadow-panel: 0 24px 60px -18px rgba(0,0,0,0.35);
}

/* Font stack — Inter primary */
.dg-chat-panel, .dg-chat-btn, .dg-chat-panel * {
  font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---------- Launcher (hidden by default: chat is in header nav now) ---------- */
.dg-chat-btn {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9998;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--dg-accent); color: #fff;
  border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.dg-badge {
  position: absolute; top: -4px; right: -4px;
  background: #dc2626; color: #fff; border-radius: 999px;
  padding: 2px 6px; font-size: 11px; font-weight: 700;
  min-width: 20px; text-align: center;
}

/* ---------- Panel ---------- */
.dg-chat-panel {
  position: fixed; bottom: 20px; right: 20px;
  width: 380px; height: 620px; max-height: calc(100vh - 40px);
  background: var(--dg-wallpaper);
  border-radius: 14px; overflow: hidden;
  box-shadow: var(--dg-shadow-panel);
  display: flex; flex-direction: column;
  z-index: 9999; transform: translateY(20px); opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
/* Docked mode on wide viewports: fills right side vertically, always open */
@media (min-width: 1280px) {
  .dg-chat-panel {
    top: 20px; right: 20px; bottom: 20px;
    width: 400px; height: auto; max-height: none;
    border-radius: 14px;
    /* still hidden until dg-open added by JS auto-dock */
  }
}
.dg-chat-panel.dg-open {
  transform: translateY(0); opacity: 1; pointer-events: auto;
}
@media (max-width: 480px) {
  .dg-chat-panel {
    right: 0; bottom: 0; width: 100%;
    height: 100vh; max-height: 100vh; border-radius: 0;
  }
}

/* Inside embed iframe (mobile preview): make widget fill the frame */
body.is-embed .dg-chat-panel {
  right: 0; bottom: 0; left: 0; top: 0;
  width: 100%; height: 100%; max-height: 100%;
  border-radius: 0;
  transform: none; opacity: 1; pointer-events: auto;
}
body.is-embed .dg-chat-btn { display: none; }

/* ---------- Header (WhatsApp green) ---------- */
.dg-chat-header {
  background: var(--dg-primary);
  color: var(--dg-header-text);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  flex: 0 0 auto;
}
.dg-chat-header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #34B7F1, #128C7E);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
  flex: 0 0 auto;
}
.dg-chat-header-info { flex: 1 1 auto; min-width: 0; }
.dg-chat-header-title {
  font-size: 16px; font-weight: 500; line-height: 1.2;
  color: #fff; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dg-chat-header-status {
  font-size: 12px; opacity: 0.85; color: #fff;
  display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.dg-chat-header-status .dg-online-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4FE380;
  box-shadow: 0 0 0 2px rgba(79,227,128,0.25);
}
.dg-chat-header-icons {
  display: flex; align-items: center; gap: 4px;
}
.dg-chat-icon-btn {
  background: transparent; border: 0; cursor: pointer;
  color: #fff; padding: 8px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.dg-chat-icon-btn:hover { background: rgba(255,255,255,0.15); }
.dg-chat-icon-btn svg { display: block; width: 20px; height: 20px; }

/* ---------- Messages area ---------- */
.dg-chat-messages {
  flex: 1 1 auto; overflow-y: auto;
  padding: 12px 8px 8px;
  background: var(--dg-wallpaper);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.6) 1px, transparent 1px),
    radial-gradient(circle at 85% 60%, rgba(255,255,255,0.4) 1px, transparent 1px),
    linear-gradient(180deg, #E5DDD5 0%, #DFD6CE 100%);
  background-size: 40px 40px, 60px 60px, 100% 100%;
  scroll-behavior: smooth;
  display: flex; flex-direction: column; gap: 4px;
}
.dg-chat-messages::-webkit-scrollbar { width: 6px; }
.dg-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* ---------- Messages / bubbles ---------- */
.dg-msg {
  display: flex; padding: 0 8px;
  animation: dgMsgIn .22s ease-out both;
}
@keyframes dgMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.dg-msg > div { max-width: 78%; min-width: 0; }
.dg-msg-visitor { justify-content: flex-end; }
.dg-msg-visitor > div { align-self: flex-end; }
.dg-msg-admin, .dg-msg-ai, .dg-msg-system { justify-content: flex-start; }

.dg-msg-sender-label {
  font-size: 12px; color: var(--dg-primary);
  font-weight: 600; margin: 0 4px 2px; padding: 0 6px;
  display: flex; align-items: center; gap: 4px;
}
.dg-msg-ai .dg-msg-sender-label {
  color: #6b21a8;
}

.dg-bubble {
  position: relative;
  padding: 6px 9px 6px 9px;
  border-radius: var(--dg-radius-bubble);
  font-size: 14.5px; line-height: 1.4;
  color: var(--dg-text);
  word-wrap: break-word; overflow-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  min-width: 60px;
}
.dg-bubble a { color: #027EB5; text-decoration: underline; }

/* Received (left) */
.dg-msg-admin .dg-bubble,
.dg-msg-ai .dg-bubble,
.dg-msg-system .dg-bubble {
  background: var(--dg-bubble-in);
  border-top-left-radius: 0;
}
.dg-msg-admin .dg-bubble::before,
.dg-msg-ai .dg-bubble::before,
.dg-msg-system .dg-bubble::before {
  content: ''; position: absolute; top: 0; left: -6px;
  width: 0; height: 0;
  border-top: 8px solid var(--dg-bubble-in);
  border-left: 6px solid transparent;
}

/* Sent (right, green) */
.dg-msg-visitor .dg-bubble {
  background: var(--dg-bubble-out);
  border-top-right-radius: 0;
}
.dg-msg-visitor .dg-bubble::before {
  content: ''; position: absolute; top: 0; right: -6px;
  width: 0; height: 0;
  border-top: 8px solid var(--dg-bubble-out);
  border-right: 6px solid transparent;
}

.dg-msg-system .dg-bubble {
  background: rgba(255, 246, 213, 0.95);
  color: #5C4300; font-size: 13px;
  align-self: center; margin: 6px auto;
  border-radius: 8px !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.dg-msg-system { justify-content: center; }
.dg-msg-system .dg-bubble::before { display: none !important; }
.dg-msg-system .dg-msg-sender-label { display: none; }

/* Message meta line (time + ticks) — inline at bottom-right of bubble */
.dg-msg-meta {
  display: inline-flex; align-items: center; gap: 3px;
  float: right; margin: 4px 0 -2px 8px;
  font-size: 11px; color: rgba(0,0,0,0.45);
  font-family: 'Inter', sans-serif;
  line-height: 1;
}
.dg-msg-meta .dg-ticks { display: inline-flex; align-items: center; }
.dg-msg-meta .dg-ticks svg { width: 16px; height: 12px; }
.dg-ticks-sent svg { color: rgba(0,0,0,0.4); }
.dg-ticks-read svg { color: var(--dg-tick-blue); }

/* Hide legacy dg-msg-time div in favor of inline meta */
.dg-msg-time { display: none; }

/* Legacy structured cards fit inside bubble unchanged */
.dg-msg-structured .dg-bubble { padding: 4px; max-width: none; }
.dg-msg-structured > div { max-width: 92%; }

.dg-msg-image {
  max-width: 100%; max-height: 220px; border-radius: 6px;
  display: block; margin: 0;
}

/* ---------- AI Assistant badge (kept from previous) ---------- */
.dg-msg-ai .dg-msg-sender-label::after {
  content: 'AI'; display: inline-block; margin-left: 6px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.05em;
  padding: 1px 5px; border-radius: 4px;
  background: linear-gradient(135deg,#6b21a8,#9333ea); color: #fff; vertical-align: middle;
}

/* ---------- Typing indicator ---------- */
.dg-typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px; margin: 2px 12px; align-self: flex-start;
  background: var(--dg-bubble-in); border-radius: 12px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  width: fit-content;
}
.dg-typing-indicator span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8;
  animation: dgTypingBounce 1.2s infinite ease-in-out;
}
.dg-typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.dg-typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dgTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- FAQ pills ---------- */
.dg-faq-buttons {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px 4px; background: var(--dg-wallpaper);
}
.dg-faq-btn {
  padding: 6px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.85); color: var(--dg-primary);
  border: 1px solid rgba(7,94,84,0.2);
  font-size: 12.5px; cursor: pointer;
  font-family: 'Inter', sans-serif; font-weight: 500;
  transition: background .15s, color .15s;
}
.dg-faq-btn:hover { background: var(--dg-primary); color: #fff; }

/* ---------- Talk to human bar ---------- */
.dg-talk-human-bar {
  padding: 6px 10px; background: rgba(255,255,255,0.6);
  border-top: 1px solid rgba(0,0,0,0.06);
}
.dg-talk-human-btn {
  width: 100%; padding: 8px 12px; border-radius: 999px;
  background: transparent; color: var(--dg-primary);
  border: 1px dashed var(--dg-primary);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
  font-family: 'Inter', sans-serif;
}
.dg-talk-human-btn:hover { background: var(--dg-primary); color: #fff; }

/* ---------- Composer ---------- */
.dg-chat-input-wrap {
  background: #F0F0F0;
  padding: 8px 8px;
  display: flex; align-items: flex-end; gap: 6px;
  flex: 0 0 auto;
  border-top: 1px solid rgba(0,0,0,0.06);
}
.dg-chat-icon-composer {
  background: transparent; border: 0; cursor: pointer;
  padding: 8px; color: #54656F; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; transition: background .15s;
}
.dg-chat-icon-composer:hover { background: rgba(0,0,0,0.06); }
.dg-chat-icon-composer svg { width: 22px; height: 22px; display: block; }

.dg-chat-input-field {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center;
  background: #fff; border-radius: 22px;
  padding: 4px 4px 4px 10px;
}
.dg-chat-input {
  flex: 1 1 auto; min-width: 0;
  border: 0; outline: none; background: transparent;
  resize: none; padding: 8px 6px;
  font-size: 15px; font-family: 'Inter', sans-serif;
  line-height: 1.4; color: var(--dg-text);
  max-height: 100px;
}
.dg-chat-input::placeholder { color: #8696A0; }

/* Send / mic button — round green */
.dg-chat-send {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--dg-accent); color: #fff;
  border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  box-shadow: 0 4px 10px -2px rgba(37,211,102,0.5);
  transition: transform .12s, background .15s;
}
.dg-chat-send:hover { background: #1FBE5B; transform: scale(1.04); }
.dg-chat-send:disabled { opacity: 0.55; cursor: not-allowed; }
.dg-chat-send svg { width: 20px; height: 20px; }

/* ---------- Attachment preview ---------- */
.dg-attachment-preview {
  padding: 8px 12px; background: #F0F0F0;
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid rgba(0,0,0,0.06);
}
.dg-attachment-preview img {
  width: 40px; height: 40px; border-radius: 6px; object-fit: cover;
}
.dg-attachment-preview button {
  margin-left: auto; background: none; border: 0; cursor: pointer;
  color: #dc2626; font-size: 18px;
}
.dg-prefill-highlight { box-shadow: 0 0 0 2px rgba(37,211,102,0.5); }

/* ---------- Existing structured cards keep working ---------- */
.dg-order-card, .dg-qr-card, .dg-download-card {
  background: #fff; border-radius: 8px; overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
  font-family: 'Inter', sans-serif;
}
.dg-order-header, .dg-qr-header, .dg-download-header {
  padding: 10px 12px; background: var(--dg-primary); color: #fff;
  font-weight: 600; font-size: 13px;
}
.dg-order-items { padding: 8px 12px; }
.dg-order-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #eee; font-size: 13px; }
.dg-order-item:last-child { border-bottom: 0; }
.dg-order-total { display: flex; justify-content: space-between; padding: 10px 12px; background: #F0F0F0; font-size: 14px; }

.dg-qr-image { display: block; margin: 12px auto; max-width: 180px; border-radius: 8px; cursor: zoom-in; }
.dg-qr-placeholder { padding: 20px; text-align: center; color: #999; }
.dg-qr-upi, .dg-qr-biz, .dg-qr-amount { padding: 4px 12px; text-align: center; font-size: 13px; }
.dg-qr-instructions { padding: 8px 12px; font-size: 12px; color: #555; margin: 0; }
.dg-mono { font-family: 'JetBrains Mono', monospace; background: #f5f5f5; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.dg-download-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid #eee;
  text-decoration: none; color: var(--dg-primary); font-weight: 500; font-size: 13px;
}
.dg-download-link:hover { background: #f5f5f5; }
.dg-download-link:last-child { border-bottom: 0; }
.dg-download-pending { color: #999; font-style: italic; }
.dg-download-cta { font-size: 12px; opacity: 0.7; }

/* Notification-blocked notice */
.dg-notif-blocked {
  margin: 0 12px 8px;
  padding: 10px 14px;
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  color: #78350F;
  line-height: 1.45;
  animation: dgMsgIn .2s ease-out;
}
.dg-notif-blocked strong { display: block; margin-bottom: 4px; }
.dg-notif-blocked p { margin: 0; font-size: 12px; }

/* Msg-limit banner */
.dg-limit-banner {
  margin: 0 12px 8px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #075E54, #128C7E);
  color: #fff;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  text-align: center;
  animation: dgMsgIn .2s ease-out;
}
.dg-limit-banner strong { display: block; font-size: 13.5px; margin-bottom: 4px; }
.dg-limit-banner p { margin: 0 0 10px; font-size: 12px; opacity: 0.92; line-height: 1.4; }
.dg-limit-wa-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: #25D366;
  color: #fff !important;
  border-radius: 999px;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.3);
  transition: transform .12s, background .18s;
}
.dg-limit-wa-btn:hover { background: #1FBE5B; transform: translateY(-1px); }

/* ---------- Allow-notification modal ---------- */
.dg-notif-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  animation: dgMsgIn .18s ease-out;
  padding: 20px;
}
.dg-notif-modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 26px 24px 20px;
  max-width: 360px; width: 100%;
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.4);
  font-family: 'Inter', sans-serif;
}
.dg-notif-modal-icon {
  font-size: 40px; margin-bottom: 8px;
  animation: dgBellShake 0.9s ease-in-out;
}
@keyframes dgBellShake {
  0%,100% { transform: rotate(0); }
  15%,45% { transform: rotate(-14deg); }
  30%,60% { transform: rotate(14deg); }
  75% { transform: rotate(-6deg); }
  90% { transform: rotate(6deg); }
}
.dg-notif-modal-card h3 {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 1.15rem; font-weight: 700; color: #171717;
  margin: 0 0 6px;
}
.dg-notif-modal-card p {
  font-size: 13.5px; line-height: 1.5; color: #4a4a4a;
  margin: 0 0 18px;
}
.dg-notif-modal-actions {
  display: flex; gap: 8px; justify-content: center;
}
.dg-notif-modal-btn {
  padding: 10px 18px; border-radius: 999px;
  font-family: 'Inter', sans-serif; font-weight: 600; font-size: 13px;
  border: 0; cursor: pointer;
  transition: transform .12s, background .18s;
}
.dg-notif-modal-close {
  background: #F0F0F0; color: #171717;
}
.dg-notif-modal-close:hover { background: #E5E5E5; }
.dg-notif-modal-primary {
  background: #25D366; color: #fff;
  box-shadow: 0 4px 12px -4px rgba(37,211,102,0.5);
}
.dg-notif-modal-primary:hover { background: #1FBE5B; transform: translateY(-1px); }
