/* =====================================================
   ND CHATBOT — NexDev AI Assistant
   Premium glassmorphism chatbot widget
   ===================================================== */

:root {
  --nd-primary:     #00d4ff;
  --nd-secondary:   #9F8BE7;
  --nd-accent:      #00ffcc;
  --nd-bg:          #07070f;
  --nd-surface:     rgba(10, 10, 22, 0.98);
  --nd-glass:       rgba(255, 255, 255, 0.04);
  --nd-border:      rgba(255, 255, 255, 0.07);
  --nd-text:        rgba(255, 255, 255, 0.9);
  --nd-text-muted:  rgba(255, 255, 255, 0.42);
  --nd-radius:      22px;
  --nd-ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --nd-spring:      cubic-bezier(0.34, 1.26, 0.64, 1);
}

/* ---- Widget Container ---- */
.nd-chatbot {
  position: fixed !important;
  bottom: 28px;
  right: 28px;
  z-index: 2147483647; /* max z-index — always on top */
  font-family: 'Mona Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Appended to document.body by JS — immune to ancestor transforms */
}

/* ---- FAB Toggle Button ---- */
.nd-fab {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  background: linear-gradient(135deg, #9F8BE7 0%, #00c6f8 100%);
  box-shadow:
    0 8px 32px rgba(0, 198, 248, 0.38),
    0 2px 10px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  overflow: visible;
  animation: ndFabBreath 3.5s ease-in-out infinite;
  transition: transform 0.3s var(--nd-spring), box-shadow 0.3s var(--nd-ease);
}

.nd-fab:hover {
  transform: scale(1.1);
  box-shadow:
    0 0 0 10px rgba(0, 212, 255, 0.08),
    0 12px 40px rgba(0, 212, 255, 0.5),
    0 4px 14px rgba(0, 0, 0, 0.5);
}

.nd-fab.nd-open { animation: none; }

.nd-fab-icon {
  width: 48px;
  height: 48px;
  transition: opacity 0.2s var(--nd-ease), transform 0.25s var(--nd-ease);
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
}
.nd-fab-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 5%;
  display: block;
}

.nd-fab-close {
  font-size: 26px;
  font-weight: 200;
  color: white;
  line-height: 1;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
  transition: opacity 0.22s var(--nd-ease), transform 0.25s var(--nd-spring);
  position: absolute;
  letter-spacing: -1px;
}

.nd-fab.nd-open .nd-fab-icon  { opacity: 0; transform: scale(0.5) rotate(90deg); }
.nd-fab.nd-open .nd-fab-close { opacity: 1; transform: rotate(0deg) scale(1); }

/* Pulse rings */
.nd-fab-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 212, 255, 0.45);
  animation: ndRingPulse 2.8s ease-out infinite;
  pointer-events: none;
}
.nd-fab-ring-1 { width: 82px; height: 82px; top: -9px; left: -9px; animation-delay: 0s; }
.nd-fab-ring-2 { width: 100px; height: 100px; top: -18px; left: -18px; animation-delay: 0.9s; }

/* Notification badge */
.nd-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border: 2px solid var(--nd-bg);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ndBadgePop 0.45s var(--nd-spring) forwards;
}
.nd-fab-badge.nd-hidden { display: none; }

/* ---- Chat Window ---- */
.nd-chat-box {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 384px;
  height: 588px;
  background: var(--nd-surface);
  border-radius: var(--nd-radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(0, 212, 255, 0.06),
    0 0 100px rgba(0, 212, 255, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(60px) saturate(160%);
  -webkit-backdrop-filter: blur(60px) saturate(160%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.82) translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.42s var(--nd-spring),
    opacity 0.3s var(--nd-ease);
}

.nd-chat-box.nd-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Top accent line */
.nd-chat-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, #9F8BE7 30%, #00d4ff 70%, transparent 100%);
  opacity: 0.85;
  z-index: 1;
}

/* ---- Header ---- */
.nd-cb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px 14px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--nd-border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.nd-header-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
}

.nd-header-avatar img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  object-position: center 5%;
  display: block;
  animation: ndAvatarBreathe 3.5s ease-in-out infinite;
}

.nd-online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: #00e676;
  border: 2px solid var(--nd-bg);
  border-radius: 50%;
  animation: ndDotPulse 2.2s ease-in-out infinite;
}

.nd-header-info { flex: 1; min-width: 0; }

.nd-header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--nd-text);
  margin: 0;
  letter-spacing: 0.2px;
}

.nd-header-status {
  font-size: 11.5px;
  color: var(--nd-text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.nd-status-dot {
  width: 6px;
  height: 6px;
  background: #00e676;
  border-radius: 50%;
  display: inline-block;
  animation: ndDotPulse 2.2s ease-in-out infinite;
}

.nd-header-actions { display: flex; gap: 4px; }

.nd-hdr-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--nd-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  line-height: 1;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.nd-hdr-btn:hover {
  background: var(--nd-glass);
  color: var(--nd-text);
  transform: scale(1.1);
}

/* ---- Messages Area ---- */
.nd-cb-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.nd-cb-messages::-webkit-scrollbar { width: 4px; }
.nd-cb-messages::-webkit-scrollbar-track { background: transparent; }
.nd-cb-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
.nd-cb-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ---- Welcome Screen ---- */
.nd-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px 16px;
  animation: ndFadeInUp 0.55s var(--nd-ease) forwards;
}

.nd-welcome-avatar {
  width: 110px;
  height: 120px;
  position: relative;
  margin-bottom: 16px;
}

.nd-welcome-avatar::before {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,212,255,0.18) 0%, transparent 70%);
  animation: ndGlowPulse 3s ease-in-out infinite;
  pointer-events: none;
}

.nd-welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  filter: drop-shadow(0 0 18px rgba(0,212,255,0.22));
}

.nd-welcome h3 {
  font-size: 16.5px;
  font-weight: 600;
  color: var(--nd-text);
  margin: 0 0 3px;
  text-align: center;
}

.nd-welcome-sub {
  font-size: 11px;
  color: var(--nd-primary);
  margin: 0 0 14px;
  text-align: center;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  font-weight: 500;
}

.nd-welcome-can {
  font-size: 12px;
  color: var(--nd-text-muted);
  margin-bottom: 8px;
  text-align: center;
}

.nd-capabilities {
  width: 100%;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--nd-border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.nd-cap-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: rgba(255,255,255,0.78);
}

.nd-cap-check {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(0,212,255,0.12);
  border: 1px solid rgba(0,212,255,0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 9px;
  color: var(--nd-primary);
  font-weight: 700;
}

/* Quick Action Buttons */
.nd-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}

.nd-quick-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 12.5px;
  color: rgba(255,255,255,0.78);
  cursor: pointer;
  transition: all 0.25s var(--nd-ease);
  font-family: inherit;
  white-space: nowrap;
  outline: none;
}

.nd-quick-btn:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: rgba(0, 212, 255, 0.32);
  color: var(--nd-primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 212, 255, 0.14);
}

.nd-quick-btn:active { transform: translateY(0); }

/* ---- Message Rows ---- */
.nd-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: ndMsgIn 0.32s var(--nd-ease) forwards;
  opacity: 0;
}

.nd-msg-row.nd-user { flex-direction: row-reverse; }

.nd-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
}

.nd-msg-avatar img {
  width: 26px;
  height: 26px;
  object-fit: cover;
  object-position: center 5%;
  display: block;
}

.nd-msg-content {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  gap: 3px;
}

.nd-msg-row.nd-user .nd-msg-content { align-items: flex-end; }

.nd-msg-bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.56;
  word-break: break-word;
  position: relative;
}

/* AI bubble */
.nd-msg-row.nd-ai .nd-msg-bubble {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.9);
  border-bottom-left-radius: 4px;
}

/* User bubble */
.nd-msg-row.nd-user .nd-msg-bubble {
  background: linear-gradient(135deg, #a68df0 0%, #5c4fd4 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 18px rgba(159,139,231,0.28);
}

.nd-msg-bubble a {
  color: var(--nd-primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid rgba(0,212,255,0.28);
  transition: border-color 0.2s;
}
.nd-msg-bubble a:hover { border-bottom-color: var(--nd-primary); }

.nd-msg-row.nd-user .nd-msg-bubble a {
  color: rgba(255,255,255,0.92);
  border-bottom-color: rgba(255,255,255,0.36);
}

.nd-msg-time {
  font-size: 10px;
  color: var(--nd-text-muted);
  padding: 0 3px;
}

/* ---- Date Divider ---- */
.nd-date-div {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 4px;
  opacity: 0;
  animation: ndFadeInUp 0.4s var(--nd-ease) 0.1s forwards;
}
.nd-date-div::before, .nd-date-div::after {
  content: ''; flex: 1; height: 1px; background: var(--nd-border);
}
.nd-date-div span { font-size: 10.5px; color: var(--nd-text-muted); white-space: nowrap; letter-spacing: 0.4px; }

/* ---- Typing Indicator ---- */
.nd-typing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  animation: ndFadeInUp 0.3s var(--nd-ease) forwards;
}

/* NX prominent typing avatar */
.nd-typing-avatar-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.nd-typing-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  z-index: 1;
  animation: ndAvatarBreathe 2.2s ease-in-out infinite;
}

.nd-typing-avatar img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  object-position: center 5%;
  display: block;
}

.nd-typing-avatar-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(159,139,231,0.35) 0%, transparent 68%);
  animation: ndTypingGlow 1.8s ease-in-out infinite;
  z-index: 0;
  pointer-events: none;
}

.nd-typing-name {
  font-size: 11px;
  font-weight: 700;
  color: rgba(159,139,231,0.9);
  padding: 0 3px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.nd-typing-bubble {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.nd-typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--nd-primary);
  opacity: 0.5;
  animation: ndBounce 1.5s ease-in-out infinite;
}
.nd-typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.nd-typing-bubble span:nth-child(3) { animation-delay: 0.36s; }

.nd-typing-label {
  font-size: 10.5px;
  color: var(--nd-text-muted);
  padding: 0 3px;
}

@keyframes ndTypingGlow {
  0%, 100% { opacity: 0.45; transform: scale(1); }
  50%       { opacity: 1;    transform: scale(1.18); }
}

/* ---- Input Area ---- */
.nd-cb-input {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 12px;
  border-top: 1px solid var(--nd-border);
  background: rgba(255,255,255,0.018);
  flex-shrink: 0;
}

.nd-input-action {
  width: 33px;
  height: 33px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--nd-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14.5px;
  flex-shrink: 0;
  transition: all 0.22s var(--nd-ease);
  outline: none;
}

.nd-input-action:hover { background: var(--nd-glass); color: var(--nd-primary); transform: scale(1.12); }
.nd-input-action.nd-voice-on { color: #ff4757; animation: ndVoicePulse 1s ease-in-out infinite; }

.nd-input-field {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 9px 15px;
  font-size: 13.5px;
  color: var(--nd-text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.nd-input-field::placeholder { color: var(--nd-text-muted); }
.nd-input-field:focus {
  border-color: rgba(0,212,255,0.32);
  box-shadow: 0 0 0 3px rgba(0,212,255,0.07);
}

.nd-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #9F8BE7, #00c6f8);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.22s var(--nd-spring), box-shadow 0.22s var(--nd-ease), opacity 0.2s;
  box-shadow: 0 3px 14px rgba(0,212,255,0.3);
  outline: none;
}
.nd-send-btn:hover  { transform: scale(1.14); box-shadow: 0 5px 22px rgba(0,212,255,0.46); }
.nd-send-btn:active { transform: scale(0.94); }
.nd-send-btn:disabled { opacity: 0.38; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- File Upload Label ---- */
.nd-file-label {
  width: 33px;
  height: 33px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--nd-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14.5px;
  flex-shrink: 0;
  transition: all 0.22s var(--nd-ease);
}
.nd-file-label:hover { background: var(--nd-glass); color: var(--nd-secondary); transform: scale(1.12); }
.nd-file-label input { display: none; }

/* ---- Keyframes ---- */

@keyframes ndFabBreath {
  0%, 100% { box-shadow: 0 8px 32px rgba(0,198,248,0.38), 0 2px 10px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 0 0 12px rgba(0,212,255,0.05), 0 14px 44px rgba(0,212,255,0.5), 0 2px 10px rgba(0,0,0,0.5); }
}

@keyframes ndRingPulse {
  0%   { transform: scale(0.82); opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}

@keyframes ndAvatarBreathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.02); }
}

@keyframes ndGlowPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes ndDotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes ndBadgePop {
  0% { transform: scale(0); }
  65% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

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

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

@keyframes ndBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-7px); opacity: 1; }
}

@keyframes ndVoicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,71,87,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(255,71,87,0); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .nd-chatbot { bottom: 20px; right: 20px; }

  .nd-chat-box {
    width: calc(100vw - 32px);
    height: calc(100svh - 110px);
    max-height: 600px;
    right: 0;
    bottom: 76px;
    border-radius: 18px;
  }

  .nd-cb-messages { padding: 12px 12px 6px; }
  .nd-cb-input { padding: 10px; gap: 6px; }
  .nd-input-field { font-size: 14px; padding: 8px 13px; }
  .nd-msg-bubble { font-size: 13px; padding: 8px 12px; }

  /* Welcome screen compact */
  .nd-welcome { padding: 6px 4px 12px; }
  .nd-welcome-avatar { width: 88px; height: 96px; margin-bottom: 12px; }
  .nd-welcome h3 { font-size: 15px; }
  .nd-capabilities { padding: 10px 12px; gap: 6px; }
  .nd-cap-row { font-size: 12px; }
  .nd-quick-btns { gap: 5px; }
  .nd-quick-btn { font-size: 11.5px; padding: 6px 11px; }
}

@media (max-width: 480px) {
  .nd-chatbot { bottom: 16px; right: 16px; }

  .nd-chat-box {
    width: calc(100vw - 28px);
    height: calc(100svh - 100px);
    max-height: 580px;
    right: 0;
    bottom: 74px;
    border-radius: 16px;
  }

  .nd-fab { width: 56px; height: 56px; }
  .nd-fab-icon { width: 42px; height: 42px; }
  .nd-fab-ring-1 { width: 72px; height: 72px; top: -8px; left: -8px; }
  .nd-fab-ring-2 { width: 88px; height: 88px; top: -16px; left: -16px; }
}

@media (max-width: 360px) {
  .nd-chatbot { bottom: 12px; right: 12px; }
  .nd-chat-box { width: calc(100vw - 20px); right: -2px; bottom: 68px; }
  .nd-fab { width: 50px; height: 50px; }
  .nd-fab-icon { width: 38px; height: 38px; }
}
