/* "Ask the docs" — on-device documentation assistant (see javascripts/docs-ai.mjs) */

.docs-ai {
  --docs-ai-radius: 14px;
}

/* ---------------------------------------------------------------- launcher */

.docs-ai__launcher {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + var(--tt-consent-offset, 0px));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 999px;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease, bottom 0.3s ease;
}

.docs-ai__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

.docs-ai--open .docs-ai__launcher {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.docs-ai__launcher-label {
  white-space: nowrap;
}

/* ------------------------------------------------------------------- panel */

.docs-ai__panel {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + var(--tt-consent-offset, 0px));
  z-index: 31;
  display: none;
  flex-direction: column;
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(38rem, calc(100vh - 3rem - var(--tt-consent-offset, 0px)));
  overflow: hidden;
  border-radius: var(--docs-ai-radius);
  background-color: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  border: 1px solid var(--md-default-fg-color--lightest);
}

.docs-ai--open .docs-ai__panel {
  display: flex;
}

@media screen and (max-width: 44.9375em) {
  .docs-ai__panel {
    right: 0.75rem;
    left: 0.75rem;
    bottom: calc(0.75rem + var(--tt-consent-offset, 0px));
    width: auto;
    max-height: calc(100vh - 1.5rem - var(--tt-consent-offset, 0px));
  }
  .docs-ai__launcher {
    right: 1rem;
    bottom: calc(1rem + var(--tt-consent-offset, 0px));
  }
}

/* ------------------------------------------------------------------ header */

.docs-ai__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem 0.75rem 1rem;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
}

.docs-ai__heading {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.docs-ai__title {
  font-size: 0.8rem;
  font-weight: 700;
}

.docs-ai__subtitle {
  font-size: 0.6rem;
  opacity: 0.75;
}

.docs-ai__close {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  cursor: pointer;
}

.docs-ai__close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ---------------------------------------------------------------- messages */

.docs-ai__log {
  flex: 1 1 auto;
  min-height: 6rem;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.74rem;
  line-height: 1.5;
}

.docs-ai__msg {
  max-width: 92%;
  padding: 0.5rem 0.7rem;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.docs-ai__msg--user {
  align-self: flex-end;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
  border-bottom-right-radius: 4px;
}

.docs-ai__msg--assistant {
  align-self: flex-start;
  background-color: var(--md-default-fg-color--lightest);
  color: var(--md-default-fg-color);
  border-bottom-left-radius: 4px;
  /* The reply is rendered Markdown; paragraphs/headings supply their own
     spacing, so pre-wrap would double it. Code blocks re-enable pre below. */
  white-space: normal;
}

/* ---- rendered Markdown inside an assistant reply ---- */

.docs-ai__msg--assistant > :first-child {
  margin-top: 0;
}

.docs-ai__msg--assistant > :last-child {
  margin-bottom: 0;
}

.docs-ai__msg--assistant p {
  margin: 0 0 0.45rem;
}

.docs-ai__msg--assistant h3,
.docs-ai__msg--assistant h4,
.docs-ai__msg--assistant h5,
.docs-ai__msg--assistant h6 {
  margin: 0.55rem 0 0.3rem;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.35;
}

.docs-ai__msg--assistant ul,
.docs-ai__msg--assistant ol {
  margin: 0.3rem 0 0.5rem;
  padding-left: 1.15rem;
}

.docs-ai__msg--assistant li {
  margin: 0.15rem 0;
}

.docs-ai__msg--assistant code {
  padding: 0.1rem 0.28rem;
  border-radius: 4px;
  font-family: var(--md-code-font-family, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.66rem;
  background-color: color-mix(in srgb, var(--md-default-fg-color) 10%, transparent);
}

.docs-ai__code {
  margin: 0.4rem 0 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  overflow-x: auto;
  background-color: color-mix(in srgb, var(--md-default-fg-color) 8%, transparent);
  border: 1px solid var(--md-default-fg-color--lightest);
}

.docs-ai__code code {
  padding: 0;
  background: none;
  white-space: pre;
  font-size: 0.64rem;
  line-height: 1.5;
}

.docs-ai__msg--assistant a {
  color: var(--md-typeset-a-color, var(--md-primary-fg-color));
  text-decoration: underline;
}

.docs-ai__msg--error {
  align-self: stretch;
  max-width: 100%;
  background-color: var(--md-typeset-mark-color, #ffecb3);
  color: #5a3d00;
}

.docs-ai__msg--typing::after {
  content: "▋";
  margin-left: 0.15rem;
  animation: docs-ai-blink 1s steps(1) infinite;
}

/* Tool status line — shows when the assistant consults another page. */
.docs-ai__tool {
  align-self: flex-start;
  max-width: 92%;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
  font-size: 0.62rem;
  line-height: 1.4;
  opacity: 0.85;
  background-color: transparent;
  border: 1px dashed var(--md-default-fg-color--lightest);
  color: var(--md-default-fg-color--light);
}

@keyframes docs-ai-blink {
  50% {
    opacity: 0;
  }
}

/* ----------------------------------------------------------------- sources */

.docs-ai__sources:not(:empty) {
  padding: 0 0.85rem 0.6rem;
}

.docs-ai__sources-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
  margin-bottom: 0.3rem;
}

.docs-ai__sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.docs-ai__source {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6rem;
  text-decoration: none;
  background-color: var(--md-default-fg-color--lightest);
  color: var(--md-default-fg-color);
  border: 1px solid var(--md-default-fg-color--lightest);
}

.docs-ai__source:hover {
  border-color: var(--md-primary-fg-color);
  color: var(--md-primary-fg-color);
}

.docs-ai__source-num {
  font-weight: 700;
  color: var(--md-primary-fg-color);
}

.docs-ai__source-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12rem;
}

/* Marks a source that came from a tool call rather than the current page. */
.docs-ai__source-tag {
  flex: none;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.52rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
}

/* -------------------------------------------------------------------- form */

.docs-ai__form {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.6rem 0.7rem;
  border-top: 1px solid var(--md-default-fg-color--lightest);
}

.docs-ai__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 10px;
  background-color: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.45;
}

.docs-ai__input:focus {
  outline: none;
  border-color: var(--md-primary-fg-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--md-primary-fg-color) 25%, transparent);
}

.docs-ai__send {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: none;
  border-radius: 10px;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
  cursor: pointer;
}

.docs-ai__send:disabled,
.docs-ai__input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.docs-ai__note {
  margin: 0;
  padding: 0 0.85rem 0.6rem;
  font-size: 0.58rem;
  line-height: 1.4;
  opacity: 0.6;
}

/* Keep the launcher clear of the "back to top" button on wide screens. */
@media screen and (min-width: 76.25em) {
  .docs-ai__launcher {
    bottom: calc(2.5rem + var(--tt-consent-offset, 0px));
  }
  .docs-ai__panel {
    bottom: calc(2.5rem + var(--tt-consent-offset, 0px));
    max-height: min(38rem, calc(100vh - 4rem - var(--tt-consent-offset, 0px)));
  }
}

/* --------------------------------------------------------- privacy notice */

.tt-consent {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 40;
  width: min(52rem, calc(100vw - 2rem));
  transform: translate(-50%, 1.25rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.tt-consent--visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.tt-consent--hidden {
  opacity: 0;
  transform: translate(-50%, 1rem);
  pointer-events: none;
}

.tt-consent__inner {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--md-default-fg-color--lightest);
  background-color: color-mix(in srgb, var(--md-default-bg-color) 92%, transparent);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}

.tt-consent__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 12px;
  background-color: color-mix(in srgb, var(--md-primary-fg-color) 14%, transparent);
  color: var(--md-primary-fg-color);
}

.tt-consent__body {
  flex: 1 1 auto;
  min-width: 0;
}

.tt-consent__title {
  margin: 0 0 0.15rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tt-consent__text {
  margin: 0;
  font-size: 0.66rem;
  line-height: 1.55;
  opacity: 0.78;
}

.tt-consent__details {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.1rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--md-default-fg-color--lightest);
}

/* An author `display` value outranks the UA rule for [hidden], so the
   collapsed state needs to be stated explicitly. */
.tt-consent__details[hidden] {
  display: none;
}

.tt-consent__detail-title {
  margin: 0.45rem 0 0;
  font-size: 0.64rem;
  font-weight: 700;
  opacity: 0.9;
}

.tt-consent__detail-text {
  margin: 0;
  font-size: 0.62rem;
  line-height: 1.5;
  opacity: 0.72;
}

.tt-consent__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  align-self: stretch;
}

.tt-consent__more,
.tt-consent__accept {
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease,
    transform 0.18s ease;
}

.tt-consent__more {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--md-default-fg-color--lightest);
  background: transparent;
  color: inherit;
  opacity: 0.8;
}

.tt-consent__more:hover {
  border-color: var(--md-primary-fg-color);
  color: var(--md-primary-fg-color);
  opacity: 1;
}

.tt-consent__accept {
  padding: 0.5rem 1rem;
  border: none;
  background-color: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color, #fff);
  white-space: nowrap;
  box-shadow: 0 4px 14px
    color-mix(in srgb, var(--md-primary-fg-color) 35%, transparent);
}

.tt-consent__accept:hover {
  transform: translateY(-1px);
}

@media screen and (max-width: 44.9375em) {
  .tt-consent {
    bottom: 0.75rem;
    width: calc(100vw - 1.5rem);
  }
  .tt-consent__inner {
    flex-wrap: wrap;
    padding: 0.85rem 0.9rem;
  }
  .tt-consent__actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tt-consent,
  .tt-consent__accept,
  .docs-ai__launcher,
  .docs-ai__panel {
    transition: none;
  }
}
