.ai-chat {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 220;
  font-family: var(--font-body);
}

.ai-chat__launcher {
  position: relative;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid var(--paper);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.ai-chat__launcher::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  background: var(--crimson);
  border: 2px solid var(--paper);
}

.ai-chat__launcher:hover,
.ai-chat__launcher:focus-visible {
  background: var(--ink);
  color: var(--paper);
}

.ai-chat__launcher:active {
  transform: scale(0.96);
}

.ai-chat__launcher .icon {
  width: 23px;
  height: 23px;
}

.ai-chat__panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(390px, calc(100vw - 2rem));
  height: min(660px, calc(100svh - 120px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: var(--ink-soft);
  color: var(--paper);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.46);
}

.ai-chat__panel[hidden] {
  display: none;
}

.ai-chat__header {
  min-height: 67px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.85rem 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}

.ai-chat__title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.ai-chat__status {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: var(--moss-light);
}

.ai-chat__title strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.ai-chat__title span {
  display: block;
  margin-top: 0.12rem;
  color: var(--paper-dim);
  font-family: var(--font-meta);
  font-size: 0.58rem;
  line-height: 1.4;
  text-transform: uppercase;
}

.ai-chat__close {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--paper);
  cursor: pointer;
}

.ai-chat__close:hover,
.ai-chat__close:focus-visible {
  background: var(--paper);
  color: var(--ink);
}

.ai-chat__messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.ai-chat__message {
  max-width: 88%;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  line-height: 1.75;
}

.ai-chat__message:last-child {
  margin-bottom: 0;
}

.ai-chat__message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-chat__message--assistant {
  padding-left: 0.8rem;
  border-left: 1px solid var(--moss-light);
  color: var(--paper-dim);
}

.ai-chat__message--user {
  margin-left: auto;
  padding: 0.6rem 0.75rem;
  background: var(--paper);
  color: var(--ink);
}

.ai-chat__message--error {
  border-left-color: var(--crimson);
  color: var(--paper);
}

.ai-chat__sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.55rem;
}

.ai-chat__source {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.35rem;
  border: 1px solid var(--line);
  color: var(--paper-dim);
  font-family: var(--font-meta);
  font-size: 0.56rem;
  line-height: 1.3;
  text-transform: uppercase;
}

a.ai-chat__source:hover,
a.ai-chat__source:focus-visible {
  color: var(--paper);
  border-color: var(--line-strong);
}

.ai-chat__suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.ai-chat__suggestions[hidden] {
  display: none;
}

.ai-chat__suggestion {
  min-height: 52px;
  padding: 0.55rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--paper-dim);
  font-size: 0.72rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.ai-chat__suggestion:hover,
.ai-chat__suggestion:focus-visible {
  color: var(--ink);
  background: var(--paper);
}

.ai-chat__composer {
  padding: 0.75rem;
  border-top: 1px solid var(--line);
  background: var(--ink);
}

.ai-chat__composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 0.45rem;
  align-items: end;
}

.ai-chat__input {
  width: 100%;
  min-height: 46px;
  max-height: 126px;
  resize: none;
  padding: 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--ink-soft);
  color: var(--paper);
  font-size: 0.86rem;
  line-height: 1.5;
}

.ai-chat__input::placeholder {
  color: rgba(233, 225, 207, 0.48);
}

.ai-chat__send {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--paper);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.ai-chat__send:hover,
.ai-chat__send:focus-visible {
  background: transparent;
  color: var(--paper);
}

.ai-chat__send:disabled {
  cursor: wait;
  opacity: 0.45;
}

.ai-chat__footnote {
  margin: 0.5rem 0 0;
  color: rgba(233, 225, 207, 0.48);
  font-size: 0.58rem;
  line-height: 1.45;
}

@media (max-width: 560px) {
  .ai-chat {
    right: 0.75rem;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .ai-chat__panel {
    position: fixed;
    right: 0.5rem;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 0.5rem;
    width: auto;
    height: min(74svh, 650px);
  }

  .ai-chat__launcher {
    width: 54px;
    height: 54px;
  }

  .ai-chat__suggestions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat *,
  .ai-chat *::before,
  .ai-chat *::after {
    transition-duration: 0.01ms !important;
  }
}
