/* Neural assistant widget */
.neural {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  justify-items: end;
  gap: 0.75rem;
  font-family: var(--font-body);
}

.neural__launcher {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.4rem;
  padding: 0.55rem 1rem 0.55rem 0.55rem;
  border: 1px solid var(--line-strong);
  background: linear-gradient(120deg, rgba(0, 229, 255, 0.16), rgba(0, 194, 168, 0.08) 45%, rgba(4, 12, 24, 0.92));
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 28px rgba(0, 229, 255, 0.18);
  transition: transform 0.25s var(--ease), box-shadow 0.25s ease;
}

.neural__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 36px rgba(0, 229, 255, 0.28);
}

.neural__launcher.is-open {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
}

.neural__launcher-orb {
  width: 2.3rem;
  height: 2.3rem;
  border: 1px solid var(--cyan);
  background:
    radial-gradient(circle at 35% 30%, #fff, transparent 35%),
    radial-gradient(circle at 50% 55%, rgba(0, 229, 255, 0.85), rgba(0, 80, 120, 0.2) 65%, transparent);
  box-shadow: 0 0 18px var(--glow);
  position: relative;
  animation: neuralPulse 2.4s ease-in-out infinite;
}

.neural__launcher-orb::after {
  content: "";
  position: absolute;
  inset: 28%;
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.neural__launcher-copy {
  display: grid;
  text-align: left;
  line-height: 1.15;
}

.neural__launcher-copy strong {
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}

.neural__launcher-copy small {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 400;
}

@keyframes neuralPulse {
  0%,
  100% {
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.25);
  }
  50% {
    box-shadow: 0 0 26px rgba(0, 229, 255, 0.55);
  }
}

.neural__panel {
  width: min(100vw - 2rem, 24.5rem);
  height: min(72vh, 36rem);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  border: 1px solid var(--line-strong);
  background: rgba(3, 10, 20, 0.94);
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), 0 0 40px rgba(0, 229, 255, 0.1);
  overflow: hidden;
  animation: neuralIn 0.45s var(--ease);
}

@keyframes neuralIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.neural__panel[hidden] {
  display: none;
}

.neural__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.08), transparent);
}

.neural__identity {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.neural__avatar {
  width: 2.2rem;
  height: 2.2rem;
  flex: 0 0 auto;
  border: 1px solid var(--cyan);
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.7), transparent 40%),
    radial-gradient(circle, rgba(0, 229, 255, 0.55), rgba(2, 6, 15, 0.2));
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.35);
}

.neural__identity strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.98rem;
}

.neural__identity p {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 13rem;
}

.neural__head-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.neural__status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
}

.neural__status i {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 8px rgba(0, 194, 168, 0.8);
}

.neural__close {
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.neural__close:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.neural__messages {
  padding: 1rem;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 0.7rem;
}

.neural__msg {
  display: flex;
}

.neural__msg--bot {
  justify-content: flex-start;
}

.neural__msg--user {
  justify-content: flex-end;
}

.neural__bubble {
  max-width: 88%;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.45;
  font-weight: 300;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.neural__msg--bot .neural__bubble {
  border-color: rgba(0, 229, 255, 0.22);
  background: rgba(0, 229, 255, 0.06);
}

.neural__msg--user .neural__bubble {
  background: rgba(0, 194, 168, 0.12);
  border-color: rgba(0, 194, 168, 0.28);
}

.neural__bubble--typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  min-height: 1.1rem;
}

.neural__bubble--typing span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--cyan);
  animation: neuralDot 1.1s ease-in-out infinite;
}

.neural__bubble--typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.neural__bubble--typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes neuralDot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.neural__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
}

.neural__chips[hidden] {
  display: none;
}

.neural__chip {
  border: 1px solid var(--line);
  background: rgba(0, 229, 255, 0.04);
  color: var(--ice);
  font-size: 0.75rem;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.neural__chip:hover {
  border-color: var(--line-strong);
  background: rgba(0, 229, 255, 0.1);
}

.neural__composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

.neural__composer input {
  min-width: 0;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  outline: none;
}

.neural__composer input:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(0, 229, 255, 0.1);
}

.neural__composer button {
  padding: 0 1rem;
  border: 1px solid transparent;
  background: linear-gradient(120deg, #00e5ff, #00c2a8);
  color: #021018;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

@media (max-width: 520px) {
  .neural {
    right: max(0.65rem, env(safe-area-inset-right));
    bottom: max(0.65rem, env(safe-area-inset-bottom));
    left: max(0.65rem, env(safe-area-inset-left));
    justify-items: stretch;
  }
  .neural__panel {
    width: 100%;
    height: min(78dvh, 34rem);
    max-height: calc(100dvh - 5.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .neural__launcher {
    width: fit-content;
    justify-self: end;
    max-width: 100%;
  }
  .neural__launcher-copy small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .neural__launcher-orb,
  .neural__bubble--typing span,
  .neural__panel {
    animation: none !important;
  }
}
