:root {
  --nx-ai-accent: #9f7aea;
  --nx-ai-accent-rgb: 159, 122, 234;
  --nx-ai-surface: #111218;
  --nx-ai-surface-raised: #181922;
  --nx-ai-surface-soft: #20212c;
  --nx-ai-border: rgba(255, 255, 255, .1);
  --nx-ai-text: #f7f7fb;
  --nx-ai-muted: #a5a6b4;
}

.nx-ai-launcher {
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 10070;
  display: grid;
  grid-template-columns: 40px auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 7px 16px 7px 8px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 18px;
  background: rgba(17, 18, 24, .96);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .34);
  color: var(--nx-ai-text);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.nx-ai-launcher.is-left { right: auto; left: 20px; }
.nx-ai-launcher.has-custom-position { right: auto !important; bottom: auto !important; }
.nx-ai-launcher.is-dragging { cursor: grabbing; transition: none; }
.nx-ai-launcher:hover:not(.is-dragging) {
  border-color: rgba(var(--nx-ai-accent-rgb), .5);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .42);
}
.nx-ai-launcher:focus-visible,
.nx-ai-icon-button:focus-visible,
.nx-ai-suggestion:focus-visible,
.nx-ai-copy:focus-visible,
.nx-ai-send:focus-visible,
.nx-ai-stop:focus-visible {
  outline: 2px solid var(--nx-ai-accent);
  outline-offset: 2px;
}
.nx-ai-launcher[hidden] { display: none; }

.nx-ai-launcher-orb,
.nx-ai-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid rgba(var(--nx-ai-accent-rgb), .35);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(var(--nx-ai-accent-rgb), .42), rgba(73, 196, 218, .14));
  color: #fff;
}
.nx-ai-launcher-orb { width: 40px; height: 40px; font-size: 15px; }
.nx-ai-launcher-copy { display: grid; min-width: 0; text-align: left; }
.nx-ai-launcher-copy b {
  font: 700 11px/1.25 Orbitron, Poppins, sans-serif;
  letter-spacing: .02em;
}
.nx-ai-launcher-copy small {
  margin-top: 3px;
  color: var(--nx-ai-muted);
  font: 600 9px/1.2 Poppins, sans-serif;
}

.nx-ai-panel {
  position: fixed;
  right: 20px;
  bottom: 88px;
  z-index: 10075;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  width: min(440px, calc(100vw - 40px));
  height: min(720px, calc(100dvh - 116px));
  max-height: calc(100dvh - 116px);
  overflow: hidden;
  border: 1px solid var(--nx-ai-border);
  border-radius: 24px;
  background: var(--nx-ai-surface);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .56);
  color: var(--nx-ai-text);
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 14px, 0) scale(.98);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .24s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .24s;
}
.nx-ai-panel.is-left { right: auto; left: 20px; transform-origin: bottom left; }
.nx-ai-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0) scale(1);
  transition-delay: 0s;
}
.nx-ai-panel > * { min-width: 0; }

.nx-ai-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px;
  border-bottom: 1px solid var(--nx-ai-border);
  background: rgba(255, 255, 255, .015);
}
.nx-ai-avatar { width: 42px; height: 42px; font-size: 15px; }
.nx-ai-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nx-ai-identity { min-width: 0; flex: 1; }
.nx-ai-identity b,
.nx-ai-identity > span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nx-ai-identity b { font: 700 13px/1.25 Orbitron, Poppins, sans-serif; }
.nx-ai-identity > span {
  margin-top: 3px;
  color: var(--nx-ai-muted);
  font: 500 10px/1.35 Poppins, sans-serif;
}
.nx-ai-online {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  width: auto;
  margin-top: 5px !important;
  color: #7ee2b8 !important;
  font: 700 9px/1.2 Poppins, sans-serif !important;
  letter-spacing: .04em;
}
.nx-ai-online i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #65dba8;
}
.nx-ai-online.is-offline { color: #d4b373 !important; }
.nx-ai-online.is-offline i { background: #d4a85e; }
.nx-ai-head-actions { display: flex; gap: 6px; }
.nx-ai-icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 12px;
  background: var(--nx-ai-surface-raised);
  color: var(--nx-ai-muted);
  cursor: pointer;
}
.nx-ai-icon-button:hover { border-color: rgba(var(--nx-ai-accent-rgb), .38); color: #fff; }

.nx-ai-state {
  display: none;
  align-items: flex-start;
  gap: 8px;
  margin: 10px 14px 0;
  padding: 10px 11px;
  border: 1px solid rgba(245, 190, 72, .2);
  border-radius: 12px;
  background: rgba(245, 190, 72, .07);
  color: #e1c98f;
  font: 500 11px/1.5 Poppins, sans-serif;
}
.nx-ai-state.is-visible { display: flex; }

.nx-ai-messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--nx-ai-accent-rgb), .3) transparent;
}
.nx-ai-message { display: flex; align-items: flex-end; gap: 9px; margin-top: 15px; }
.nx-ai-message:first-child { margin-top: 0; }
.nx-ai-message.is-user { justify-content: flex-end; }
.nx-ai-message-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid rgba(var(--nx-ai-accent-rgb), .24);
  border-radius: 9px;
  background: rgba(var(--nx-ai-accent-rgb), .1);
  color: var(--nx-ai-accent);
  font-size: 10px;
}
.nx-ai-bubble {
  min-width: 0;
  max-width: 84%;
  padding: 11px 13px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 16px 16px 16px 5px;
  background: var(--nx-ai-surface-raised);
  color: #dedee7;
  font: 500 12px/1.65 Poppins, sans-serif;
  overflow-wrap: anywhere;
}
.is-user .nx-ai-bubble {
  border-color: rgba(var(--nx-ai-accent-rgb), .3);
  border-radius: 16px 16px 5px 16px;
  background: rgba(var(--nx-ai-accent-rgb), .18);
  color: #fff;
}
.nx-ai-bubble p,
.nx-ai-bubble pre,
.nx-ai-bubble blockquote,
.nx-ai-bubble ul,
.nx-ai-bubble ol { margin: 0 0 9px; }
.nx-ai-bubble > :last-child { margin-bottom: 0; }
.nx-ai-bubble h1,
.nx-ai-bubble h2,
.nx-ai-bubble h3 { margin: 0 0 8px; color: #fff; font: 700 13px/1.4 Poppins, sans-serif; }
.nx-ai-bubble ul,
.nx-ai-bubble ol { padding-left: 19px; }
.nx-ai-bubble code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #0a0b10;
  color: #c9f7ff;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.nx-ai-bubble pre {
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 10px;
  background: #090a0e;
  white-space: pre-wrap;
}
.nx-ai-bubble pre code { padding: 0; background: none; }
.nx-ai-bubble a { color: #c9f7ff; text-decoration: underline; text-underline-offset: 2px; }
.nx-ai-bubble blockquote { padding-left: 9px; border-left: 2px solid var(--nx-ai-accent); color: var(--nx-ai-muted); }
.nx-ai-copy {
  align-self: flex-start;
  width: 32px;
  height: 32px;
  margin-top: 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #7f808e;
  cursor: pointer;
}
.nx-ai-copy:hover { background: rgba(var(--nx-ai-accent-rgb), .1); color: #fff; }

.nx-ai-thinking { display: flex; align-items: center; gap: 9px; color: var(--nx-ai-muted); }
.nx-ai-thinking i {
  width: 24px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(var(--nx-ai-accent-rgb), .25), rgba(var(--nx-ai-accent-rgb), .75), rgba(var(--nx-ai-accent-rgb), .25));
  background-size: 200% 100%;
  animation: nxAiThink 1.15s linear infinite;
}
.nx-ai-thinking span { font-size: 11px; }

.nx-ai-suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 14px 11px;
  scrollbar-width: none;
}
.nx-ai-suggestions::-webkit-scrollbar { display: none; }
.nx-ai-suggestion {
  flex: 0 0 auto;
  min-height: 38px;
  max-width: 250px;
  padding: 8px 12px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 12px;
  background: var(--nx-ai-surface-raised);
  color: #c5c5cf;
  font: 600 10px/1.4 Poppins, sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.nx-ai-suggestion:hover { border-color: rgba(var(--nx-ai-accent-rgb), .4); color: #fff; }

.nx-ai-compose {
  padding: 11px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--nx-ai-border);
  background: #0e0f14;
}
.nx-ai-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: end;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--nx-ai-border);
  border-radius: 16px;
  background: var(--nx-ai-surface-raised);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.nx-ai-input-wrap:focus-within {
  border-color: rgba(var(--nx-ai-accent-rgb), .55);
  box-shadow: 0 0 0 3px rgba(var(--nx-ai-accent-rgb), .08);
}
.nx-ai-input {
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  padding: 10px 8px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--nx-ai-text);
  font: 500 13px/1.5 Poppins, sans-serif;
}
.nx-ai-input::placeholder { color: #797a88; }
.nx-ai-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 12px;
  background: var(--nx-ai-accent);
  color: #fff;
  cursor: pointer;
}
.nx-ai-send:hover { filter: brightness(1.08); }
.nx-ai-send:disabled,
.nx-ai-suggestion:disabled { opacity: .42; cursor: not-allowed; }
.nx-ai-compose-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  color: #787986;
  font: 500 9px/1.4 Poppins, sans-serif;
}
.nx-ai-stop {
  min-height: 28px;
  border: 0;
  background: transparent;
  color: #e4aebc;
  font: 700 9px/1.4 Poppins, sans-serif;
  cursor: pointer;
}
.nx-ai-stop[hidden] { display: none; }

@keyframes nxAiThink { to { background-position: -200% 0; } }

@media (max-width: 699px) {
  .nx-ai-launcher {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    grid-template-columns: 40px auto;
    min-height: 54px;
  }
  .nx-ai-launcher.is-left { left: max(12px, env(safe-area-inset-left)); }
  .nx-ai-panel,
  .nx-ai-panel.is-left {
    inset: 0;
    width: 100vw;
    height: var(--nx-ai-vh, 100dvh);
    max-height: var(--nx-ai-vh, 100dvh);
    padding-top: env(safe-area-inset-top);
    border: 0;
    border-radius: 0;
    transform: translate3d(0, 20px, 0);
    transform-origin: bottom center;
  }
  .nx-ai-panel.is-open { transform: translate3d(0, 0, 0); }
  body.nx-ai-open { overflow: hidden; }
  .nx-ai-head { padding: 10px 10px 9px; }
  .nx-ai-state { margin-inline: 10px; }
  .nx-ai-messages { padding-inline: 10px; }
  .nx-ai-suggestions { padding-inline: 10px; }
  .nx-ai-compose { padding-inline: 8px; }
  .nx-ai-input { font-size: 16px; }
  .nx-ai-bubble { max-width: 89%; font-size: 12px; }
  .nx-ai-icon-button,
  .nx-ai-send { width: 44px; height: 44px; }
}

@media (max-width: 380px) {
  .nx-ai-launcher-copy { display: none; }
  .nx-ai-launcher { grid-template-columns: 40px; padding-right: 8px; }
  .nx-ai-identity > span:not(.nx-ai-online) { max-width: 170px; }
  .nx-ai-head { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .nx-ai-panel,
  .nx-ai-launcher { transition-duration: .01ms; }
  .nx-ai-thinking i { animation: none; }
}

