:root {
  --agent-popup-violet: #8f72ff;
  --agent-popup-cyan: #4ad8e7;
  --agent-popup-panel: rgba(4, 13, 29, 0.94);
  --agent-popup-line: rgba(137, 116, 244, 0.28);
}

.agent-popup-layer {
  position: fixed;
  z-index: 1180;
  inset: 0;
  pointer-events: none;
}

.agent-popup-layer[hidden] {
  display: none !important;
}

.agent-chat-launcher[hidden] {
  display: none !important;
}

.agent-popup-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 4, 14, 0.36);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.agent-popup-panel {
  position: absolute;
  top: calc(var(--header-h) + 14px);
  right: 14px;
  bottom: 14px;
  width: min(500px, calc(100vw - 32px));
  min-height: 420px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  pointer-events: auto;
  isolation: isolate;
  border: 1px solid var(--agent-popup-line);
  border-radius: 24px;
  background:
    radial-gradient(circle at 9% 0%, rgba(123, 87, 255, 0.19), transparent 34%),
    radial-gradient(circle at 100% 18%, rgba(52, 198, 226, 0.1), transparent 36%),
    linear-gradient(145deg, rgba(8, 21, 43, 0.98), var(--agent-popup-panel));
  box-shadow:
    0 34px 90px rgba(0, 2, 10, 0.72),
    0 0 0 1px rgba(255, 255, 255, 0.025) inset,
    0 0 52px rgba(91, 63, 220, 0.15);
  backdrop-filter: blur(28px) saturate(130%);
  opacity: 0;
  transform: translate3d(calc(100% + 32px), 0, 0) scale(0.985);
  transform-origin: right center;
  transition:
    transform 420ms cubic-bezier(0.16, 0.84, 0.22, 1),
    opacity 260ms ease,
    box-shadow 360ms ease;
}

.agent-popup-panel::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -130px;
  right: -100px;
  width: 310px;
  height: 310px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(106, 79, 239, 0.2), transparent 68%);
  filter: blur(8px);
  pointer-events: none;
}

.agent-popup-layer.is-open .agent-popup-panel {
  opacity: 1;
  transform: none;
  box-shadow:
    0 38px 100px rgba(0, 2, 10, 0.76),
    0 0 0 1px rgba(255, 255, 255, 0.035) inset,
    0 0 68px rgba(92, 65, 228, 0.21);
}

.agent-popup-header {
  position: relative;
  z-index: 2;
  min-height: 72px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 12px;
  border-bottom: 1px solid rgba(118, 144, 203, 0.13);
  background: linear-gradient(180deg, rgba(10, 24, 49, 0.9), rgba(5, 15, 32, 0.76));
}

.agent-popup-header::after {
  content: "";
  position: absolute;
  right: 82px;
  bottom: -1px;
  left: 70px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(129, 99, 255, 0.5), rgba(64, 207, 229, 0.3), transparent);
  opacity: 0.62;
}

.agent-popup-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
}

.agent-popup-avatar::before,
.agent-popup-avatar::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(145, 116, 255, 0.28);
  border-right-color: rgba(74, 216, 231, 0.56);
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: agentPopupOrbit 8s linear infinite;
}

.agent-popup-avatar::after {
  inset: 8px 2px;
  opacity: 0.38;
  animation-duration: 11s;
  animation-direction: reverse;
}

.agent-popup-avatar img {
  position: relative;
  z-index: 1;
  width: 45px;
  height: 45px;
  object-fit: contain;
  filter: drop-shadow(0 7px 12px rgba(119, 83, 255, 0.35));
  animation: agentPopupFloat 4.8s ease-in-out infinite;
}

.agent-popup-heading {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.agent-popup-heading small {
  color: #8d7de3;
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.21em;
}

.agent-popup-heading strong {
  overflow: hidden;
  color: #f1f3fb;
  font-size: 15px;
  font-weight: 660;
  letter-spacing: -0.015em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-popup-heading em {
  overflow: hidden;
  color: #76849d;
  font-size: 9px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-popup-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.agent-popup-action {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(126, 105, 227, 0.22);
  border-radius: 12px;
  color: #9ba8c1;
  background: rgba(36, 38, 92, 0.24);
  text-decoration: none;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.agent-popup-action:hover {
  color: #f4f1ff;
  border-color: rgba(145, 117, 255, 0.55);
  background: rgba(91, 68, 201, 0.31);
  box-shadow: 0 0 22px rgba(100, 73, 223, 0.2);
  transform: translateY(-1px);
}

.agent-popup-action:active {
  transform: translateY(1px) scale(0.95);
}

.agent-popup-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.agent-popup-frame-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: rgba(2, 9, 20, 0.62);
}

.agent-popup-frame-shell iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  color-scheme: dark;
  background: transparent;
  opacity: 0;
  transition: opacity 260ms ease;
}

.agent-popup-frame-shell.is-ready iframe {
  opacity: 1;
}

.agent-popup-loader {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(97, 69, 220, 0.13), transparent 30%),
    #030b19;
  opacity: 1;
  transition: opacity 220ms ease, visibility 0s linear 0s;
}

.agent-popup-frame-shell.is-ready .agent-popup-loader {
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 0s linear 220ms;
}

.agent-popup-loader > span {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.agent-popup-loader i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--agent-popup-violet), var(--agent-popup-cyan));
  box-shadow: 0 0 14px rgba(113, 91, 239, 0.5);
  animation: agentPopupLoading 1.15s ease-in-out infinite;
}

.agent-popup-loader i:nth-child(2) {
  animation-delay: 120ms;
}

.agent-popup-loader i:nth-child(3) {
  animation-delay: 240ms;
}

.agent-popup-loader strong {
  color: #d9dfed;
  font-size: 12px;
  font-weight: 640;
}

.agent-popup-loader small {
  color: #67758e;
  font-size: 9px;
}

.agent-chat-launcher {
  position: fixed;
  z-index: 1160;
  right: 24px;
  bottom: 24px;
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: visible;
  isolation: isolate;
  border: 1px solid rgba(144, 119, 255, 0.42);
  border-radius: 23px;
  color: #e9e5ff;
  background:
    radial-gradient(circle at 35% 22%, rgba(124, 95, 255, 0.3), transparent 45%),
    linear-gradient(145deg, rgba(18, 31, 63, 0.96), rgba(7, 14, 32, 0.96));
  box-shadow:
    0 18px 48px rgba(0, 2, 12, 0.58),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 34px rgba(105, 74, 236, 0.2);
  cursor: pointer;
  appearance: none;
  transition:
    opacity 220ms ease,
    transform 260ms cubic-bezier(0.16, 0.82, 0.22, 1),
    border-color 200ms ease,
    box-shadow 220ms ease;
}

.agent-chat-launcher::before,
.agent-chat-launcher::after {
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
}

.agent-chat-launcher::before {
  inset: -7px;
  border: 1px solid rgba(128, 100, 244, 0.27);
  border-top-color: rgba(74, 216, 231, 0.44);
  border-radius: 28px;
  animation: agentLauncherRing 5.8s linear infinite;
}

.agent-chat-launcher::after {
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(102, 75, 231, 0.3), transparent 69%);
  filter: blur(8px);
  opacity: 0.7;
}

.agent-chat-launcher:hover {
  border-color: rgba(160, 139, 255, 0.7);
  box-shadow:
    0 22px 58px rgba(0, 2, 12, 0.64),
    0 0 0 1px rgba(255, 255, 255, 0.065) inset,
    0 0 44px rgba(105, 74, 236, 0.32);
  transform: translateY(-3px) scale(1.025);
}

.agent-chat-launcher:active {
  transform: translateY(1px) scale(0.95);
}

.agent-chat-launcher:focus-visible {
  outline: 2px solid rgba(165, 145, 255, 0.85);
  outline-offset: 4px;
}

.agent-chat-launcher-visual {
  position: relative;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
}

.agent-chat-launcher-visual::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(145, 116, 255, 0.26);
  border-right-color: rgba(74, 216, 231, 0.52);
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: agentPopupOrbit 7.5s linear infinite;
}

.agent-chat-launcher img {
  position: relative;
  z-index: 1;
  width: 58px;
  height: 58px;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(115, 82, 244, 0.42));
  animation: agentPopupFloat 4.4s ease-in-out infinite;
}

.agent-chat-launcher-mark {
  position: absolute;
  z-index: 3;
  right: 1px;
  bottom: 2px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(181, 167, 255, 0.6);
  border-radius: 9px;
  color: #f5f2ff;
  background: linear-gradient(145deg, #7655ed, #4d39b3);
  box-shadow: 0 5px 14px rgba(42, 25, 126, 0.58), inset 0 1px rgba(255, 255, 255, 0.18);
}

.agent-chat-launcher-mark svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.agent-chat-launcher-visual > i {
  position: absolute;
  z-index: 4;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border: 2px solid #0a1429;
  border-radius: 50%;
  background: #58e6c2;
  box-shadow: 0 0 10px rgba(88, 230, 194, 0.78);
}

.agent-chat-launcher-tooltip {
  position: absolute;
  right: calc(100% + 13px);
  top: 50%;
  min-width: 148px;
  display: grid;
  gap: 1px;
  padding: 9px 12px;
  border: 1px solid rgba(127, 106, 224, 0.27);
  border-radius: 13px;
  text-align: left;
  white-space: nowrap;
  background: rgba(6, 16, 35, 0.94);
  box-shadow: 0 14px 34px rgba(0, 2, 12, 0.46);
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transform: translate3d(8px, -50%, 0) scale(0.96);
  transform-origin: right center;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.16, 0.82, 0.22, 1);
}

.agent-chat-launcher-tooltip strong {
  color: #f0edff;
  font-size: 12px;
  font-weight: 700;
}

.agent-chat-launcher-tooltip small {
  color: #7d8aa3;
  font-size: 9px;
}

.agent-chat-launcher:hover .agent-chat-launcher-tooltip,
.agent-chat-launcher:focus-visible .agent-chat-launcher-tooltip {
  opacity: 1;
  transform: translate3d(0, -50%, 0) scale(1);
}

body.agent-popup-open .agent-chat-launcher {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.82);
}

html.agent-embedded,
body.agent-embedded {
  min-width: 0 !important;
  min-height: 100dvh !important;
  background: transparent !important;
}

body.agent-embedded {
  overflow: hidden !important;
}

body.agent-embedded :is(.space-scene, #cursor-aura, .app-header, .app-rail, .mobile-bottom-nav, .agent-page-heading) {
  display: none !important;
}

body.agent-embedded .app-shell,
body.agent-embedded .app-main,
body.agent-embedded #view-root,
body.agent-embedded .agent-view,
body.agent-embedded .agent-shell {
  width: 100% !important;
  height: 100dvh !important;
  min-height: 0 !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

body.agent-embedded #view-root {
  display: block !important;
  animation: none !important;
}

body.agent-embedded .agent-shell {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 0 !important;
}

body.agent-embedded .agent-conversation {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: linear-gradient(150deg, rgba(7, 19, 39, 0.98), rgba(3, 11, 25, 0.98)) !important;
  box-shadow: none !important;
}

body.agent-embedded .agent-toggle-fullscreen {
  display: none !important;
}

body.agent-embedded .agent-history {
  top: 8px !important;
  bottom: 8px !important;
  left: 8px !important;
  max-width: calc(100vw - 16px) !important;
}

body.agent-embedded .agent-history-backdrop {
  inset: 0 !important;
}

body.agent-embedded .agent-messages {
  scrollbar-gutter: stable;
}

@keyframes agentPopupOrbit {
  to {
    transform: rotate(360deg);
  }
}

@keyframes agentPopupFloat {
  50% {
    transform: translateY(-2px) rotate(0.7deg);
    filter: drop-shadow(0 9px 16px rgba(119, 83, 255, 0.45)) saturate(1.08);
  }
}

@keyframes agentPopupLoading {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(3px) scale(0.82);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px) scale(1.06);
  }
}

@keyframes agentLauncherRing {
  50% {
    border-color: rgba(145, 118, 255, 0.42);
    border-top-color: rgba(74, 216, 231, 0.7);
    transform: rotate(180deg) scale(1.035);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 767px) {
  .agent-chat-launcher {
    right: max(15px, env(safe-area-inset-right));
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 82px);
    width: 62px;
    height: 62px;
    border-radius: 21px;
  }

  .agent-chat-launcher::before {
    inset: -5px;
    border-radius: 25px;
  }

  .agent-chat-launcher-visual {
    width: 56px;
    height: 56px;
  }

  .agent-chat-launcher img {
    width: 53px;
    height: 53px;
  }

  .agent-chat-launcher-mark {
    right: 0;
    bottom: 1px;
    width: 22px;
    height: 22px;
    border-radius: 8px;
  }

  .agent-chat-launcher-tooltip {
    display: none;
  }

  .agent-popup-layer {
    pointer-events: auto;
  }

  .agent-popup-layer.is-open .agent-popup-scrim {
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(7px);
  }

  .agent-popup-panel {
    top: max(6px, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
    bottom: max(6px, env(safe-area-inset-bottom));
    left: max(6px, env(safe-area-inset-left));
    width: auto;
    min-height: 0;
    border-radius: 24px;
    opacity: 0;
    transform: translate3d(0, 30px, 0) scale(0.97);
    transform-origin: center bottom;
  }

  .agent-popup-layer.is-open .agent-popup-panel {
    opacity: 1;
    transform: none;
  }

  .agent-popup-header {
    min-height: 66px;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 7px 8px 7px 10px;
  }

  .agent-popup-avatar,
  .agent-popup-avatar img {
    width: 42px;
    height: 42px;
  }

  .agent-popup-heading strong {
    font-size: 14px;
  }

  .agent-popup-heading em {
    font-size: 8px;
  }

  .agent-popup-action {
    width: 42px;
    height: 42px;
  }

  body.agent-popup-open {
    overflow: hidden !important;
  }

  body.agent-popup-open .mobile-bottom-nav {
    opacity: 0 !important;
    transform: translate3d(0, calc(100% + 24px), 0) !important;
    pointer-events: none !important;
  }

  body.agent-embedded .agent-conversation-header {
    border-radius: 0 !important;
  }
}

@media (max-width: 430px) {
  .agent-popup-heading small {
    letter-spacing: 0.16em;
  }

  .agent-popup-heading em {
    max-width: 148px;
  }

  .agent-popup-actions {
    gap: 3px;
  }
}

@media (max-width: 359px) {
  .agent-chat-launcher {
    right: max(11px, env(safe-area-inset-right));
    bottom: calc(max(7px, env(safe-area-inset-bottom)) + 78px);
    width: 57px;
    height: 57px;
    border-radius: 19px;
  }

  .agent-chat-launcher-visual {
    width: 52px;
    height: 52px;
  }

  .agent-chat-launcher img {
    width: 49px;
    height: 49px;
  }

  .agent-popup-panel {
    top: max(3px, env(safe-area-inset-top));
    right: max(3px, env(safe-area-inset-right));
    bottom: max(3px, env(safe-area-inset-bottom));
    left: max(3px, env(safe-area-inset-left));
    border-radius: 20px;
  }

  .agent-popup-header {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 5px;
    padding-inline: 7px;
  }

  .agent-popup-avatar,
  .agent-popup-avatar img {
    width: 38px;
    height: 38px;
  }

  .agent-popup-heading em {
    display: none;
  }

  .agent-popup-action {
    width: 39px;
    height: 39px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .agent-popup-panel,
  .agent-popup-scrim,
  .agent-popup-frame-shell iframe,
  .agent-popup-loader,
  .agent-popup-action,
  .agent-chat-launcher,
  .agent-chat-launcher::before,
  .agent-chat-launcher::after,
  .agent-chat-launcher-visual::before,
  .agent-chat-launcher img,
  .agent-chat-launcher-tooltip,
  .agent-popup-avatar::before,
  .agent-popup-avatar::after,
  .agent-popup-avatar img,
  .agent-popup-loader i {
    animation: none !important;
    transition: none !important;
  }
}

/* Audit: fit the visible viewport when the mobile keyboard is open. */
.agent-popup-panel { min-height: min(420px, calc(100dvh - var(--header-h, 64px) - 28px)); }
.agent-popup-heading em { color: #a8b7d1; font-size: 11px; }
.agent-popup-action:focus-visible,
.agent-popup-retry:focus-visible { outline: 2px solid #b7a3ff; outline-offset: 3px; }
.agent-popup-retry { min-height: 44px; padding: 0 18px; border: 1px solid #8f72ff; border-radius: 12px; color: #f4f1ff; background: #3b287d; font: inherit; cursor: pointer; }
.agent-popup-loader small { max-width: 280px; color: #a8b7d1; font-size: 12px; }
body.agent-embedded #agent-composer-input { font-size: 16px; }
body.agent-embedded .agent-messages { overscroll-behavior: contain; }
@media (max-width: 767px) {
  .agent-popup-layer { top: var(--agent-viewport-top, 0px); bottom: auto; height: var(--agent-viewport-height, 100dvh); }
  .agent-popup-panel { inset: 0; width: 100%; min-height: 0; border: 0; border-radius: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .agent-popup-header { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .agent-popup-action { width: 44px; height: 44px; }
  .agent-popup-heading em { font-size: 11px; }
  .agent-popup-heading small { display: none; }
  .agent-popup-loader { padding: 16px; }
}
