.assistant-root {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 90;
}

body.has-assistant .message-toast {
  bottom: calc(92px + env(safe-area-inset-bottom));
}

body.assistant-open .message-toast {
  right: auto;
  left: 22px;
  bottom: 22px;
}

.assistant-launcher {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--red);
  color: var(--white);
  box-shadow: 0 14px 32px rgba(21, 35, 49, .22);
  cursor: pointer;
  transition: background-color .15s ease, transform .15s ease;
}

.assistant-launcher:hover {
  background: var(--red-dark);
  transform: translateY(-1px);
}

.assistant-root.is-open .assistant-launcher {
  display: none;
}

.assistant-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: flex;
  width: clamp(320px, 30vw, 560px);
  height: min(70vh, calc(100vh - 44px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 18px 50px rgba(21, 35, 49, .18);
  visibility: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .2s ease, visibility 0s linear .2s;
}

.assistant-root.is-open .assistant-panel {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity .18s ease, transform .2s ease;
}

.assistant-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.assistant-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.assistant-identity>div {
  min-width: 0;
}

.assistant-panel-head h2 {
  margin: 0;
  overflow: hidden;
  font-family: var(--heading-font);
  font-size: .95rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assistant-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .65rem;
  line-height: 1.2;
}

.assistant-status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #37a676;
}

.assistant-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  border: 1px solid rgba(31, 107, 87, .2);
  border-radius: 50%;
  background: #eef7f3;
  color: var(--green);
  font-family: var(--heading-font);
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.assistant-avatar svg {
  width: 60%;
  height: 60%;
}

.assistant-panel-head .assistant-avatar {
  width: 38px;
  height: 38px;
  font-size: .72rem;
}

.assistant-panel-actions {
  display: flex;
  flex: none;
  gap: 4px;
}

.assistant-close,
.assistant-new {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.assistant-close:hover,
.assistant-new:hover {
  background: var(--soft);
  color: var(--ink);
}

.assistant-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
}

.assistant-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.assistant-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.assistant-message.is-user {
  justify-content: flex-end;
}

.assistant-message-main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.assistant-message.is-user .assistant-message-main {
  flex: 0 1 auto;
  align-items: flex-end;
  max-width: 88%;
}

.assistant-bubble {
  width: fit-content;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eef7f8;
  color: var(--ink);
  font-size: .82rem;
  line-height: 1.5;
}

.assistant-message.is-assistant .assistant-bubble {
  border-top-left-radius: 4px;
}

.assistant-message.is-user .assistant-bubble {
  border-bottom-right-radius: 4px;
  background: var(--mine);
  white-space: pre-wrap;
}

.assistant-message.is-assistant .assistant-bubble.is-answer {
  width: 100%;
  padding: 12px;
}

/* The notice card brings its own frame; the bubble around it only places it. */
.assistant-message.is-assistant .assistant-bubble.is-system {
  width: 100%;
  padding: 0;
  background: none;
}

.assistant-time {
  color: var(--muted);
  font-size: .6rem;
  line-height: 1;
}

.assistant-message.is-user .assistant-time {
  text-align: right;
}

.assistant-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .78rem;
}

.assistant-system {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f9fa;
  font-size: .8rem;
  line-height: 1.5;
}

.assistant-system-text {
  margin: 0;
}

.assistant-system-related {
  margin: 0;
  font-size: .75rem;
}

.assistant-system-hint {
  margin: 0;
  color: var(--muted);
}

.assistant-system-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.assistant-system-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  color: var(--blue);
  font-size: .75rem;
  font-weight: 700;
  text-decoration: none;
}

.assistant-system-link:hover {
  text-decoration: underline;
}

.assistant-system-button {
  min-height: 44px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--blue);
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
}

.assistant-system-button:hover {
  border-color: var(--blue);
}

.assistant-thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.assistant-thinking-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: assistant-dot 1s infinite;
}

.assistant-thinking-dots i:nth-child(2) {
  animation-delay: .15s;
}

.assistant-thinking-dots i:nth-child(3) {
  animation-delay: .3s;
}

@keyframes assistant-dot {

  0%,
  80%,
  100% {
    opacity: .35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.assistant-answer {
  display: grid;
  gap: 12px;
}

.assistant-answer-text {
  margin: 0;
  white-space: pre-wrap;
}

.assistant-citation {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.assistant-citation:hover {
  text-decoration: underline;
}

.assistant-sources {
  display: grid;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid rgba(21, 35, 49, .1);
}

.assistant-sources h3 {
  margin: 0;
  color: var(--muted);
  font-size: .6rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.assistant-sources ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.assistant-sources li {
  font-size: .74rem;
}

.assistant-sources a {
  color: var(--blue);
  font-weight: 700;
}

.assistant-source-meta {
  display: block;
  color: var(--muted);
  font-size: .62rem;
}

.assistant-source-lang {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border: 1px solid rgba(21, 35, 49, .18);
  border-radius: 999px;
  color: var(--muted);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .04em;
  vertical-align: middle;
}

.assistant-disclaimer {
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--gold);
  background: var(--cream);
  color: #485965;
  font-size: .68rem;
  line-height: 1.45;
}

.assistant-answer-actions {
  display: flex;
}

.assistant-copy {
  min-height: 44px;
  padding: 5px 10px;
  border: 1px solid rgba(21, 35, 49, .14);
  border-radius: 8px;
  background: var(--white);
  color: var(--blue);
  font-size: .68rem;
  font-weight: 700;
  cursor: pointer;
}

.assistant-copy:hover {
  border-color: var(--blue);
}

.assistant-suggestions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.assistant-suggestions[hidden] {
  display: none;
}

.assistant-suggestions>h3 {
  margin: 0;
  font-size: .72rem;
  font-weight: 800;
}

.assistant-suggestions ul {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.assistant-chip {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #d7e6e8;
  border-radius: 8px;
  background: #f2f8f9;
  color: var(--green);
  font-size: .65rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

.assistant-chip:hover {
  border-color: var(--green);
  background: #eef7f3;
  color: var(--green);
}

.assistant-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.assistant-jump {
  position: relative;
  z-index: 2;
  height: 0;
}

.assistant-scroll {
  position: absolute;
  bottom: 8px;
  left: 50%;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--white);
  color: var(--green);
  box-shadow: 0 8px 20px rgba(21, 35, 49, .16);
  transform: translateX(-50%);
  cursor: pointer;
}

.assistant-scroll::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
}

.assistant-scroll:hover {
  border-color: var(--green);
  background: #eef7f3;
}

.assistant-scroll[hidden] {
  display: none;
}

.assistant-composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid #d7e6e8;
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-size: .82rem;
  line-height: 1.4;
  resize: none;
}

.assistant-composer textarea:disabled {
  border-color: var(--line);
  background: var(--soft);
  color: var(--muted);
  cursor: not-allowed;
}

.assistant-send {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--green);
  color: var(--white);
  font-size: .8rem;
  font-weight: 800;
  cursor: pointer;
}

.assistant-send:hover {
  background: #174f41;
}

.assistant-send:disabled,
.assistant-send:disabled:hover {
  background: var(--soft);
  color: var(--muted);
  cursor: not-allowed;
}

.assistant-composer-meta {
  grid-column: 1 / -1;
  display: flex;
  color: var(--muted);
  font-size: .65rem;
}

.assistant-composer-meta[hidden] {
  display: none;
}

.assistant-count {
  margin-left: auto;
}

.assistant-count[hidden] {
  display: none;
}

@media (max-width: 600px) {
  body.assistant-open .message-toast {
    display: none;
  }

  .assistant-root {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .assistant-panel {
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .assistant-panel-head {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .assistant-composer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {

  .assistant-launcher,
  .assistant-panel {
    transition: none;
  }

  .assistant-thinking-dots i {
    animation: none;
  }
}