/* ─── NEXUS Chatbot Styles ──────────────────────────────────────────────── */

/* CSS Houdini property required for conic-gradient border animation.
   Supported: Chrome 85+, Edge 85+, Safari 16.4+, Firefox 128+           */
@property --nx-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

:root {
  --nx-bg:          #020617;
  --nx-accent:      #646cff;
  --nx-accent-2:    #a78bfa;
  --nx-glass:       rgba(2, 6, 23, 0.88);
  --nx-border:      rgba(100, 108, 255, 0.18);
  --nx-font:        Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  --nx-radius:      16px;
  --nx-shadow:      0 24px 48px rgba(0, 0, 0, 0.55), 0 8px 16px rgba(0, 0, 0, 0.3);
  --nx-green:       #22c55e;
  --nx-red:         #ef4444;
  --nx-red-light:   #fca5a5;
  --nx-accent-3:    #818cf8;
  --nx-amber:       #f59e0b;
  --nx-text:        rgba(255, 255, 255, 0.92);
  --nx-text-muted:  rgba(255, 255, 255, 0.45);
  --nx-spring:      cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Keyframes ─────────────────────────────────────────────────────────── */

@keyframes nx-border-spin {
  from { --nx-angle: 0deg; }
  to   { --nx-angle: 360deg; }
}

@keyframes nx-breathe {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.8; transform: scale(0.975); }
}

@keyframes nx-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)     scale(1);   }
}

@keyframes nx-bounce-dot {
  0%, 100% { transform: translateY(0);  opacity: 0.4; }
  50%       { transform: translateY(-5px); opacity: 1;   }
}

@keyframes nx-shimmer {
  0%, 100% { border-color: rgba(100, 108, 255, 0.18); box-shadow: var(--nx-shadow); }
  50%       { border-color: rgba(100, 108, 255, 0.55); box-shadow: var(--nx-shadow), 0 0 24px rgba(100,108,255,0.12); }
}

@keyframes nx-status-glow {
  0%, 100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0);   }
}

@keyframes nx-fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

@keyframes nx-arrive-ripple {
  0%   { box-shadow: var(--nx-shadow), 0 0 0 0   rgba(100, 108, 255, 0.1); }
  60%  { box-shadow: var(--nx-shadow), 0 0 0 10px rgba(100, 108, 255, 0);  }
  100% { box-shadow: var(--nx-shadow); }
}

#nx-panel.nx-arrived {
  animation: nx-arrive-ripple 0.55s ease forwards;
}

/* ─── Launcher Button ───────────────────────────────────────────────────── */

#nx-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999998;

  padding: 11px 22px;
  border-radius: 50px;

  /* Glass base */
  background: var(--nx-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  /* No native border — conic pseudo-element provides it */
  border: none;

  color: var(--nx-text);
  font-family: var(--nx-font);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  outline: none; /* removed by :focus-visible below for keyboard users */

  transition: transform 0.25s var(--nx-spring), box-shadow 0.25s ease;
  animation: nx-breathe 3s ease-in-out infinite;
}

/* Rotating conic-gradient border */
#nx-launcher::before {
  content: '';
  position: absolute;
  inset: -1.5px;
  border-radius: 52px;
  background: conic-gradient(
    from var(--nx-angle),
    transparent 0deg,
    var(--nx-accent) 80deg,
    var(--nx-accent-2) 160deg,
    transparent 220deg,
    transparent 360deg
  );
  animation: nx-border-spin 3s linear infinite;
  z-index: -1;
}

/* Inner fill — sits on top of ::before, creates "border" effect */
#nx-launcher::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 48px;
  background: var(--nx-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: -1;
}

#nx-launcher:hover {
  transform: scale(1.06);
  animation: none;
  box-shadow: 0 0 0 1px rgba(100, 108, 255, 0.4),
              0 8px 32px rgba(100, 108, 255, 0.25);
}

#nx-launcher:active {
  transform: scale(0.97);
}

#nx-launcher:focus-visible {
  outline: 2px solid var(--nx-accent);
  outline-offset: 3px;
}

#nx-close-btn:focus-visible,
#nx-send-btn:focus-visible,
.nx-chip:focus-visible,
.nx-retry-btn:focus-visible {
  outline: 2px solid var(--nx-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── Chat Panel ────────────────────────────────────────────────────────── */

#nx-panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 360px;
  height: 520px;
  z-index: 999999;

  display: flex;
  flex-direction: column;

  border-radius: var(--nx-radius);
  background: var(--nx-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--nx-border);
  box-shadow: var(--nx-shadow);

  font-family: var(--nx-font);
  overflow: hidden;
  transform-origin: bottom right;

  animation: nx-slide-up 0.4s var(--nx-spring) forwards;
}

#nx-panel.nx-hidden {
  display: none;
}

/* Purple shimmer while bot is typing */
#nx-panel.nx-typing {
  animation: nx-shimmer 1.8s ease-in-out infinite;
}

/* ─── Drag Handle (mobile only) ─────────────────────────────────────────── */

#nx-drag-handle {
  display: none;
  justify-content: center;
  padding: 10px 0 2px;
  cursor: grab;
  flex-shrink: 0;
}

.nx-drag-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
}

/* ─── Header ────────────────────────────────────────────────────────────── */

#nx-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--nx-border);
  flex-shrink: 0;
}

.nx-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nx-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--nx-green);
  flex-shrink: 0;
  animation: nx-status-glow 2s ease-in-out infinite;
}

.nx-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--nx-text);
  letter-spacing: 1.5px;
}

.nx-subtitle {
  font-size: 10px;
  color: var(--nx-text-muted);
  font-weight: 400;
  letter-spacing: 0.2px;
  margin-top: 1px;
}

#nx-close-btn {
  background: none;
  border: none;
  color: var(--nx-text-muted);
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

#nx-close-btn:hover {
  color: var(--nx-text);
  background: rgba(255, 255, 255, 0.06);
}

/* ─── Suggestion Chips ──────────────────────────────────────────────────── */

#nx-chips {
  display: flex;
  gap: 6px;
  padding: 9px 14px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--nx-border);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#nx-chips::-webkit-scrollbar {
  display: none;
}

#nx-chips.nx-hidden {
  display: none;
}

.nx-chip {
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid var(--nx-border);
  background: rgba(100, 108, 255, 0.07);
  color: var(--nx-accent-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--nx-font);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.nx-chip:hover {
  background: rgba(100, 108, 255, 0.18);
  border-color: rgba(100, 108, 255, 0.45);
  transform: scale(1.04);
}

.nx-chip:active {
  transform: scale(0.97);
}

/* ─── Messages ──────────────────────────────────────────────────────────── */

#nx-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 108, 255, 0.15) transparent;
  overscroll-behavior: contain;
}

#nx-messages::-webkit-scrollbar       { width: 3px; }
#nx-messages::-webkit-scrollbar-track { background: transparent; }
#nx-messages::-webkit-scrollbar-thumb { background: rgba(100, 108, 255, 0.2); border-radius: 3px; }

/* Empty state */
.nx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  text-align: center;
  padding: 20px;
  pointer-events: none;
}

/* CSS-drawn avatar — no images */
.nx-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--nx-border);
  background: linear-gradient(145deg, rgba(100, 108, 255, 0.15), rgba(167, 139, 250, 0.1));
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

/* Avatar head */
.nx-avatar::before {
  content: '';
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(167, 139, 250, 0.3);
}

/* Avatar shoulders */
.nx-avatar::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 42px;
  height: 22px;
  border-radius: 50% 50% 0 0;
  background: rgba(100, 108, 255, 0.2);
}

.nx-empty-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--nx-text);
  letter-spacing: 0.5px;
}

.nx-empty-sub {
  font-size: 11px;
  color: var(--nx-text-muted);
  line-height: 1.5;
  max-width: 220px;
}

/* Message wrapper */
.nx-message {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: nx-fade-up 0.28s ease forwards;
}

.nx-message.nx-bot  { align-self: flex-start; align-items: flex-start; }
.nx-message.nx-user { align-self: flex-end;   align-items: flex-end;   }

/* Bubble */
.nx-bubble {
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.57;
  color: var(--nx-text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.nx-bot .nx-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--nx-border);
  border-left: 3px solid var(--nx-accent);
  border-radius: 4px 12px 12px 4px;
}

.nx-user .nx-bubble {
  background: linear-gradient(135deg, var(--nx-accent) 0%, var(--nx-accent-3) 100%);
  border-radius: 12px 4px 4px 12px;
}

/* Error bubble */
.nx-message.nx-error .nx-bubble {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-left: 3px solid var(--nx-red);
  border-radius: 4px 12px 12px 4px;
  color: var(--nx-red-light);
}

.nx-timestamp {
  font-size: 10px;
  color: var(--nx-text-muted);
  margin-top: 3px;
  padding: 0 3px;
}

.nx-retry-btn {
  margin-top: 5px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--nx-red-light);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--nx-font);
  transition: background 0.15s;
}

.nx-retry-btn:hover { background: rgba(239, 68, 68, 0.22); }

/* ─── Typing Indicator ──────────────────────────────────────────────────── */

.nx-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--nx-border);
  border-left: 3px solid var(--nx-accent);
  border-radius: 4px 12px 12px 4px;
  align-self: flex-start;
  animation: nx-fade-up 0.28s ease forwards;
}

.nx-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--nx-accent-2);
  animation: nx-bounce-dot 1.2s ease-in-out infinite;
}

.nx-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.nx-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ─── Input Area ────────────────────────────────────────────────────────── */

#nx-input-area {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--nx-border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.18);
}

#nx-textarea {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--nx-border);
  border-radius: 10px;
  color: var(--nx-text);
  font-family: var(--nx-font);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 11px;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.2s;
  scrollbar-width: none;
}

#nx-textarea::-webkit-scrollbar { display: none; }

#nx-textarea::placeholder { color: var(--nx-text-muted); }

#nx-textarea:focus { border-color: rgba(100, 108, 255, 0.45); }

#nx-textarea:focus-visible {
  outline: 2px solid rgba(100, 108, 255, 0.6);
  outline-offset: 1px;
}

.nx-input-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#nx-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--nx-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  padding: 0;
}

#nx-send-btn:hover:not(:disabled) {
  background: var(--nx-accent-2);
  box-shadow: 0 0 14px rgba(100, 108, 255, 0.5);
  transform: scale(1.06);
}

#nx-send-btn:active:not(:disabled) { transform: scale(0.95); }

#nx-send-btn:disabled {
  background: rgba(100, 108, 255, 0.25);
  cursor: not-allowed;
}

#nx-send-btn svg {
  width: 14px;
  height: 14px;
  fill: white;
  pointer-events: none;
}

/* Character arc progress */
#nx-char-arc {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

#nx-char-arc.nx-visible { opacity: 1; }

#nx-char-arc circle {
  transition: stroke-dashoffset 0.15s ease, stroke 0.15s ease;
}

/* ─── Mobile: Bottom Sheet ──────────────────────────────────────────────── */

@media (max-width: 480px) {
  #nx-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 88vh;
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
  }

  #nx-drag-handle {
    display: flex;
  }

  #nx-launcher {
    bottom: 20px;
    right: 20px;
  }

  #nx-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* ─── Reduced Motion ────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  #nx-launcher,
  #nx-launcher::before,
  .nx-status-dot,
  .nx-typing-dot,
  .nx-message,
  .nx-typing-indicator {
    animation: none;
    transition: none;
  }
}
