/* ==========================================================================
   Dipon AI Chatbot (DCbot) - Frontend Widget Stylesheet
   Modern Dark Slate Theme & 100% Mobile Responsive (Zero Overflow)
   ========================================================================== */

:root {
  --dcbot-primary: #2563eb;
  --dcbot-primary-hover: #1d4ed8;
  --dcbot-bg-dark: #1e222d;
  --dcbot-header-dark: #151821;
  --dcbot-card-dark: #272c3d;
  --dcbot-bot-bubble: #282d3e;
  --dcbot-user-bubble: #2563eb;
  --dcbot-text-main: #f1f5f9;
  --dcbot-text-muted: #94a3b8;
  --dcbot-border: #33394d;
  --dcbot-input-bg: #2b3042;
  --dcbot-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Base Container */
.dcbot-container {
  position: fixed;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  box-sizing: border-box;
}

.dcbot-container * {
  box-sizing: border-box;
}

.dcbot-pos-bottom-right {
  bottom: 24px;
  right: 24px;
}

.dcbot-pos-bottom-left {
  bottom: 24px;
  left: 24px;
}

/* --------------------------------------------------------------------------
   Floating Launcher Button
   -------------------------------------------------------------------------- */
.dcbot-launcher-btn {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  outline: none;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  user-select: none;
}

.dcbot-launcher-btn:hover {
  transform: scale(1.08) translateY(-2px);
}

.dcbot-launcher-btn:active {
  transform: scale(0.96);
}

.dcbot-launcher-badge {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dcbot-launcher-img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  position: relative;
  z-index: 3;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.dcbot-launcher-circle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 5px;
  z-index: 2;
  transition: background 0.2s ease;
}

.dcbot-chevron-icon {
  color: #ffffff;
  stroke-width: 3.5;
  width: 16px;
  height: 16px;
}

/* Subtle Pulse Glow */
.dcbot-pulse-ring {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 0.4);
  animation: dcbotPulse 2.8s infinite ease-out;
  pointer-events: none;
}

@keyframes dcbotPulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.15);
    opacity: 0;
  }
  100% {
    transform: scale(0.95);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Chat Window (Dark Slate Theme)
   -------------------------------------------------------------------------- */
.dcbot-window {
  position: absolute;
  bottom: 80px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 110px);
  background: var(--dcbot-bg-dark);
  color: var(--dcbot-text-main);
  border-radius: 18px;
  box-shadow: var(--dcbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden !important; /* Mencegah overflow horizontal pada jendela */
  border: 1px solid var(--dcbot-border);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
  box-sizing: border-box;
}

.dcbot-pos-bottom-left .dcbot-window {
  left: 0;
  right: auto;
  transform-origin: bottom left;
}

.dcbot-pos-bottom-right .dcbot-window {
  right: 0;
  left: auto;
  transform-origin: bottom right;
}

/* Maximize / Fullscreen State on Desktop */
.dcbot-window.dcbot-is-maximized {
  width: 85vw !important;
  max-width: 1000px !important;
  height: 85vh !important;
  max-height: 85vh !important;
  bottom: 80px !important;
}

/* Window Header */
.dcbot-header {
  background: var(--dcbot-header-dark);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--dcbot-border);
  user-select: none;
  flex-shrink: 0;
}

.dcbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.dcbot-header-avatar {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.dcbot-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dcbot-status {
  font-size: 12px;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.dcbot-status-dot {
  width: 7px;
  height: 7px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 6px #10b981;
}

.dcbot-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.dcbot-btn-icon {
  background: transparent;
  border: none;
  color: var(--dcbot-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.dcbot-btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.dcbot-btn-close:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* Tombol Hapus / Bersihkan Chat Berwarna Merah Kontras & Terlihat Jelas */
#dcbot-btn-clear.dcbot-btn-clear-colored {
  background: rgba(239, 68, 68, 0.18) !important;
  border: 1px solid rgba(239, 68, 68, 0.45) !important;
  color: #f87171 !important;
}

#dcbot-btn-clear.dcbot-btn-clear-colored svg {
  stroke: #f87171 !important;
}

#dcbot-btn-clear.dcbot-btn-clear-colored:hover {
  background: #ef4444 !important;
  border-color: #ef4444 !important;
  color: #ffffff !important;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.5) !important;
}

#dcbot-btn-clear.dcbot-btn-clear-colored:hover svg {
  stroke: #ffffff !important;
}

/* Tombol Salin Seluruh Percakapan Berwarna Biru Kontras */
#dcbot-btn-copy-all.dcbot-btn-copy-header {
  background: rgba(59, 130, 246, 0.18) !important;
  border: 1px solid rgba(59, 130, 246, 0.45) !important;
  color: #60a5fa !important;
}

#dcbot-btn-copy-all.dcbot-btn-copy-header svg {
  stroke: #60a5fa !important;
}

#dcbot-btn-copy-all.dcbot-btn-copy-header:hover {
  background: #2563eb !important;
  border-color: #2563eb !important;
  color: #ffffff !important;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.5) !important;
}

#dcbot-btn-copy-all.dcbot-btn-copy-header:hover svg {
  stroke: #ffffff !important;
}

/* --------------------------------------------------------------------------
   Messages Body (Anti-Meluber & Anti-Scroll Horizontal)
   -------------------------------------------------------------------------- */
.dcbot-messages-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden !important; /* Mencegah seluruh isi chat bergeser ke kanan */
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  width: 100%;
  box-sizing: border-box;
}

.dcbot-messages-body::-webkit-scrollbar {
  width: 5px;
}

.dcbot-messages-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Message Rows */
.dcbot-message-row {
  display: flex;
  gap: 10px;
  max-width: 92%;
  min-width: 0 !important;
  width: fit-content;
  box-sizing: border-box;
  animation: dcbotFadeIn 0.2s ease-out;
}

@keyframes dcbotFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dcbot-row-bot {
  align-self: flex-start;
}

.dcbot-row-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.dcbot-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Speech Bubbles dengan Auto-Wrap Tuntas */
.dcbot-bubble {
  min-width: 0 !important;
  flex: 1 1 auto;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  box-sizing: border-box;
  max-width: 100%;
  
  /* Proteksi Teks Meluber */
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  word-wrap: break-word !important;
  hyphens: auto;
}

.dcbot-heading {
  margin: 10px 0 6px 0;
  color: #60a5fa;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere !important;
}

.dcbot-heading:first-child {
  margin-top: 0;
}

.dcbot-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 10px 0;
  width: 100%;
}

.dcbot-bubble-bot {
  background: var(--dcbot-bot-bubble);
  color: var(--dcbot-text-main);
  border-top-left-radius: 4px;
  border: 1px solid var(--dcbot-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.dcbot-bubble-user {
  background: var(--dcbot-user-bubble);
  color: #ffffff;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

/* Footer Pada Tiap Balasan Pesan (Tombol Salin & Waktu) */
.dcbot-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  gap: 8px;
  font-size: 11px;
}

.dcbot-bubble-user .dcbot-bubble-footer {
  justify-content: flex-end;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.dcbot-bubble-copy-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
}

.dcbot-bubble-copy-btn svg {
  stroke: #94a3b8;
  transition: stroke 0.2s ease;
}

.dcbot-bubble-copy-btn:hover {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(59, 130, 246, 0.5);
  color: #ffffff;
}

.dcbot-bubble-copy-btn:hover svg {
  stroke: #60a5fa;
}

.dcbot-msg-time {
  display: inline-block;
  font-size: 10px;
  color: var(--dcbot-text-muted);
  text-align: right;
  white-space: nowrap;
}

.dcbot-bubble-user .dcbot-msg-time {
  color: rgba(255, 255, 255, 0.8);
}

/* Markdown formatting inside bubbles */
.dcbot-bubble p {
  margin: 0 0 8px 0;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.dcbot-bubble p:last-child {
  margin-bottom: 0;
}

.dcbot-bubble ul,
.dcbot-bubble ol {
  margin: 6px 0 8px 16px;
  padding: 0;
  max-width: calc(100% - 16px);
}

.dcbot-bubble li {
  margin-bottom: 4px;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.dcbot-bubble strong {
  color: #ffffff;
  font-weight: 600;
}

/* Inline Code & Pre Code Block Tanpa Meluber */
.dcbot-bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13px;
  color: #93c5fd;
  white-space: pre-wrap !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.dcbot-bubble pre {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 12px;
  overflow-x: hidden !important; /* Mencegah munculnya scrollbar horizontal */
  margin: 8px 0;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  white-space: pre-wrap !important; /* Wrap kode / formula otomatis ke bawah */
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}

.dcbot-bubble pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}

/* --------------------------------------------------------------------------
   Suggestions Bar (Starter Chips)
   -------------------------------------------------------------------------- */
.dcbot-suggestions-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 14px;
  background: rgba(21, 24, 33, 0.7);
  border-top: 1px solid var(--dcbot-border);
  scrollbar-width: none;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}

.dcbot-suggestions-bar::-webkit-scrollbar {
  display: none;
}

.dcbot-chip {
  flex-shrink: 0;
  background: var(--dcbot-card-dark);
  color: #93c5fd;
  border: 1px solid #3b82f644;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.dcbot-chip:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */
.dcbot-typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: transparent;
  flex-shrink: 0;
}

.dcbot-typing-bubble {
  background: var(--dcbot-bot-bubble);
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid var(--dcbot-border);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dcbot-typing-bubble span {
  width: 6px;
  height: 6px;
  background-color: #60a5fa;
  border-radius: 50%;
  animation: dcbotTypingBounce 1.2s infinite ease-in-out both;
}

.dcbot-typing-bubble span:nth-child(1) {
  animation-delay: -0.32s;
}

.dcbot-typing-bubble span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes dcbotTypingBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
  }
}

.dcbot-typing-text {
  font-size: 11px;
  color: var(--dcbot-text-muted);
}

/* --------------------------------------------------------------------------
   Input Area & Form
   -------------------------------------------------------------------------- */
.dcbot-input-area {
  background: var(--dcbot-header-dark);
  padding: 10px 14px 8px 14px;
  border-top: 1px solid var(--dcbot-border);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}

.dcbot-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  width: 100%;
}

.dcbot-input {
  flex: 1;
  background: var(--dcbot-input-bg);
  border: 1px solid var(--dcbot-border);
  border-radius: 12px;
  padding: 9px 13px;
  color: #ffffff;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 120px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.dcbot-input:focus {
  border-color: var(--dcbot-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.dcbot-input::placeholder {
  color: #64748b;
}

.dcbot-btn-send {
  background: var(--dcbot-primary);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 0 16px;
  height: 40px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.dcbot-btn-send:hover {
  background: var(--dcbot-primary-hover);
  transform: translateY(-1px);
}

.dcbot-btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.dcbot-footer-brand {
  margin-top: 6px;
  text-align: center;
  font-size: 10px;
  color: #64748b;
}

/* --------------------------------------------------------------------------
   Mobile View (< 768px - Responsif Khusus Smartphone 95% Pengunjung)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .dcbot-pos-bottom-right,
  .dcbot-pos-bottom-left {
    bottom: 16px !important;
    right: 16px !important;
    left: auto !important;
  }

  /* Full Screen App-Like Experience on Mobile Phones */
  .dcbot-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    z-index: 9999999 !important;
  }

  .dcbot-header {
    padding: 12px 14px !important;
    padding-top: max(12px, env(safe-area-inset-top, 12px)) !important;
  }

  /* Sembunyikan tombol maximize di HP karena sudah otomatis full screen */
  #dcbot-btn-maximize {
    display: none !important;
  }

  .dcbot-messages-body {
    padding: 12px 10px !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .dcbot-message-row {
    max-width: 96% !important;
    gap: 8px !important;
  }

  .dcbot-bubble {
    font-size: 14px !important;
    padding: 10px 12px !important;
    max-width: 100% !important;
    line-height: 1.5 !important;
  }

  .dcbot-input-area {
    padding: 10px 12px !important;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)) !important;
  }

  /* Font size 16px agar browser iOS Safari tidak auto-zoom dan membuat layar bergeser */
  .dcbot-input {
    font-size: 16px !important;
    padding: 8px 12px !important;
  }

  .dcbot-btn-send {
    height: 38px !important;
    padding: 0 14px !important;
  }
}
