/* NexusDocs AI assistant widget.
 *
 * Self-contained styles for the launcher button, drawer, message
 * bubbles, citations, and form. Uses CSS custom properties so it
 * adapts to the Zensical theme palette (light and dark).
 */

:root {
  --nexus-assistant-z: 1000;
  --nexus-assistant-radius: 10px;
  --nexus-assistant-bg: var(--md-default-bg-color, #ffffff);
  --nexus-assistant-fg: var(--md-default-fg-color, #1f2328);
  --nexus-assistant-muted: var(--md-default-fg-color--light, #5a6068);
  --nexus-assistant-accent: var(--md-accent-fg-color, #3b6cf6);
  --nexus-assistant-border: var(--md-default-fg-color--lightest, #e2e4e7);
  --nexus-assistant-panel-bg: var(--md-default-bg-color, #ffffff);
  --nexus-assistant-control-bg: var(--md-code-bg-color, #f3f4f6);
  --nexus-assistant-user-bg: rgba(59, 108, 246, 0.1);
  --nexus-assistant-user-fg: var(--md-default-fg-color, #1f2328);
  --nexus-assistant-user-border: rgba(59, 108, 246, 0.22);
  --nexus-assistant-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

[data-md-color-scheme="slate"] {
  --nexus-assistant-bg: hsla(var(--md-hue), 15%, 6%, 1);
  --nexus-assistant-fg: var(--md-default-fg-color, rgba(255, 255, 255, 0.82));
  --nexus-assistant-muted: var(--md-default-fg-color--light, rgba(255, 255, 255, 0.56));
  --nexus-assistant-border: hsla(var(--md-hue), 15%, 90%, 0.12);
  --nexus-assistant-panel-bg: hsla(var(--md-hue), 15%, 7%, 0.98);
  --nexus-assistant-control-bg: hsla(var(--md-hue), 15%, 90%, 0.045);
  --nexus-assistant-user-bg: hsla(195, 100%, 50%, 0.12);
  --nexus-assistant-user-fg: var(--md-default-fg-color, rgba(255, 255, 255, 0.82));
  --nexus-assistant-user-border: hsla(195, 100%, 60%, 0.22);
  --nexus-assistant-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

/* Launcher button ---------------------------------------------------- */

.nexus-assistant-launcher {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: var(--nexus-assistant-z);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 2.35rem;
  padding: 0 0.85rem;
  border-radius: 999px;
  background: var(--nexus-assistant-control-bg);
  color: var(--nexus-assistant-fg);
  border: 1px solid var(--nexus-assistant-border);
  cursor: pointer;
  box-shadow: var(--nexus-assistant-shadow);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease, transform 120ms ease;
}

.nexus-assistant-launcher:hover {
  transform: translateY(-1px);
  border-color: var(--nexus-assistant-accent);
  color: var(--nexus-assistant-accent);
}

.nexus-assistant-launcher:focus-visible {
  outline: 2px solid var(--nexus-assistant-accent);
  outline-offset: 3px;
}

.nexus-assistant-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

.nexus-assistant-launcher-label {
  white-space: nowrap;
}

/* Drawer ------------------------------------------------------------- */

.nexus-assistant-drawer {
  position: fixed;
  right: 1.25rem;
  bottom: 4.25rem;
  z-index: var(--nexus-assistant-z);
  width: min(460px, calc(100vw - 2.5rem));
  max-height: min(640px, calc(100vh - 6.5rem));
  background: var(--nexus-assistant-panel-bg);
  color: var(--nexus-assistant-fg);
  border: 1px solid var(--nexus-assistant-border);
  border-radius: var(--nexus-assistant-radius);
  box-shadow: var(--nexus-assistant-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  font-family: var(--md-text-font, system-ui, sans-serif);
  font-size: 0.88rem;
  line-height: 1.45;
}

.nexus-assistant-drawer.nexus-assistant-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.nexus-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--nexus-assistant-border);
  background: var(--nexus-assistant-panel-bg);
}

.nexus-assistant-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.nexus-assistant-header-text strong {
  font-weight: 600;
  font-size: 0.9rem;
}

.nexus-assistant-header-text small {
  color: var(--nexus-assistant-muted);
  font-size: 0.72rem;
  margin-top: 2px;
  max-width: 18rem;
}

.nexus-assistant-close {
  background: transparent;
  border: 0;
  color: var(--nexus-assistant-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  display: inline-flex;
}

.nexus-assistant-close:hover {
  background: var(--nexus-assistant-control-bg);
  color: var(--nexus-assistant-fg);
}

/* Messages ----------------------------------------------------------- */

.nexus-assistant-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.85rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
}

.nexus-assistant-empty {
  margin: auto;
  color: var(--nexus-assistant-muted);
  text-align: center;
  max-width: 310px;
  font-size: 0.84rem;
}

.nexus-assistant-msg {
  display: flex;
}

.nexus-assistant-msg-user {
  justify-content: flex-end;
}

.nexus-assistant-msg-assistant {
  justify-content: flex-start;
}

.nexus-assistant-bubble {
  max-width: 88%;
  padding: 0.48rem 0.68rem;
  border-radius: 9px;
  background: var(--nexus-assistant-control-bg);
  color: var(--nexus-assistant-fg);
  border: 1px solid transparent;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.nexus-assistant-msg-user .nexus-assistant-bubble {
  background: var(--nexus-assistant-user-bg);
  color: var(--nexus-assistant-user-fg);
  border-color: var(--nexus-assistant-user-border);
}

.nexus-assistant-msg-error .nexus-assistant-bubble {
  border: 1px solid #f0b4a8;
  background: #fff1ed;
  color: #842a17;
}

@media (prefers-color-scheme: dark) {
  .nexus-assistant-msg-error .nexus-assistant-bubble {
    background: #2a1611;
    color: #f0b4a8;
  }
}

.nexus-assistant-retry {
  margin-top: 4px;
  background: transparent;
  border: 1px solid var(--nexus-assistant-border);
  color: var(--nexus-assistant-muted);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.nexus-assistant-retry:hover {
  background: var(--nexus-assistant-control-bg);
}

/* Citations ---------------------------------------------------------- */

.nexus-assistant-citations {
  margin-top: 0.5rem;
  padding: 0.48rem 0.68rem;
  background: var(--nexus-assistant-control-bg);
  border: 1px solid var(--nexus-assistant-border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--nexus-assistant-muted);
}

.nexus-assistant-citations strong {
  color: var(--nexus-assistant-fg);
  display: block;
  margin-bottom: 0.25rem;
}

.nexus-assistant-citations ol {
  margin: 0;
  padding-left: 1.25rem;
}

.nexus-assistant-citations li {
  margin-bottom: 2px;
}

.nexus-assistant-citations a {
  color: var(--nexus-assistant-accent);
  text-decoration: none;
}

.nexus-assistant-citations a:hover {
  text-decoration: underline;
}

/* Form --------------------------------------------------------------- */

.nexus-assistant-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  border-top: 1px solid var(--nexus-assistant-border);
  background: var(--nexus-assistant-panel-bg);
}

.nexus-assistant-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--nexus-assistant-border);
  border-radius: 7px;
  padding: 0.42rem 0.55rem;
  background: var(--nexus-assistant-control-bg);
  color: var(--nexus-assistant-fg);
  font: inherit;
  line-height: 1.4;
  max-height: 6rem;
}

.nexus-assistant-input:focus {
  outline: 2px solid var(--nexus-assistant-accent);
  outline-offset: -1px;
  border-color: var(--nexus-assistant-accent);
}

.nexus-assistant-send {
  background: var(--nexus-assistant-control-bg);
  color: var(--nexus-assistant-accent);
  border: 1px solid var(--nexus-assistant-border);
  border-radius: 7px;
  padding: 0 0.65rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nexus-assistant-send:hover {
  border-color: var(--nexus-assistant-accent);
}

.nexus-assistant-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Reduced motion ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .nexus-assistant-drawer,
  .nexus-assistant-launcher,
  .nexus-assistant-messages {
    transition: none;
  }
}

/* Mobile ------------------------------------------------------------- */

@media (max-width: 480px) {
  .nexus-assistant-drawer {
    right: 0.5rem;
    bottom: 4rem;
    width: calc(100vw - 1rem);
  }
  .nexus-assistant-launcher {
    right: 0.75rem;
    bottom: 0.75rem;
    height: 2.25rem;
    padding: 0 0.75rem;
    font-size: 0.8rem;
    gap: 0.4rem;
  }
}
