/* Ad Fontes research assistant: quiet, source-first, and intentionally local. */
.af-assistant,
.af-assistant * { box-sizing: border-box; }

.af-assistant {
  --af-paper: var(--card, #fbf8f1);
  --af-ink: var(--ink, #201c17);
  --af-muted: var(--muted, #6b6157);
  --af-line: var(--card-line, #e5dccb);
  --af-rubric: var(--rubric, #8c2b1f);
  --af-gold: var(--gold, #9a7b2e);
  color: var(--af-ink);
  font-family: "Georgia", "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif;
}

.af-assistant-launcher {
  position: fixed;
  right: max(1rem, 3vw);
  bottom: max(1rem, 3vw);
  z-index: 1000;
  display: inline-flex;
  min-height: 3.15rem;
  align-items: center;
  gap: .65rem;
  padding: .62rem .9rem .62rem .72rem;
  color: var(--af-paper);
  background: var(--af-rubric);
  border: 1px solid color-mix(in srgb, var(--af-rubric), #000 18%);
  border-radius: 999px;
  box-shadow: 0 .6rem 1.7rem color-mix(in srgb, var(--af-rubric), transparent 72%);
  font: inherit;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.af-assistant-launcher:hover,
.af-assistant-launcher:focus-visible {
  background: color-mix(in srgb, var(--af-rubric), #000 10%);
  box-shadow: 0 .8rem 2rem color-mix(in srgb, var(--af-rubric), transparent 65%);
  transform: translateY(-2px);
}

.af-assistant-launcher-mark {
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  color: var(--af-rubric);
  background: var(--af-paper);
  border-radius: 50%;
  font-size: .9rem;
  line-height: 1;
}

.af-assistant-launcher-copy { display: grid; gap: .05rem; text-align: left; }
.af-assistant-launcher-copy strong { font-size: .83rem; font-weight: 600; line-height: 1.1; }
.af-assistant-launcher-copy small { color: color-mix(in srgb, var(--af-paper), transparent 25%); font-size: .68rem; }

.af-assistant-panel {
  position: fixed;
  right: max(1rem, 3vw);
  bottom: max(5.2rem, calc(3vw + 4.2rem));
  z-index: 1001;
  display: grid;
  width: min(390px, calc(100vw - 2rem));
  max-height: min(640px, calc(100vh - 7rem));
  overflow: hidden;
  background: var(--af-paper);
  border: 1px solid var(--af-line);
  border-radius: .35rem;
  box-shadow: 0 1.1rem 3.5rem color-mix(in srgb, var(--af-ink), transparent 78%);
}

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

.af-assistant-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.05rem .85rem;
  background: color-mix(in srgb, var(--af-paper), var(--af-rubric) 5%);
  border-bottom: 1px solid var(--af-line);
}

.af-assistant-kicker {
  margin: 0 0 .2rem;
  color: var(--af-gold);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: .62rem;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.af-assistant-title { margin: 0; font-size: 1.12rem; font-weight: 600; line-height: 1.15; }
.af-assistant-close {
  width: 2rem;
  height: 2rem;
  color: var(--af-muted);
  background: transparent;
  border: 1px solid var(--af-line);
  border-radius: 50%;
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.af-assistant-close:hover { color: var(--af-rubric); border-color: var(--af-rubric); }

.af-assistant-messages {
  display: grid;
  align-content: start;
  gap: .8rem;
  min-height: 14rem;
  max-height: 24rem;
  overflow-y: auto;
  padding: 1rem 1.05rem;
  overscroll-behavior: contain;
}

.af-assistant-message { max-width: 92%; font-size: .88rem; line-height: 1.65; }
.af-assistant-message.user { justify-self: end; color: var(--af-paper); background: var(--af-rubric); padding: .62rem .75rem; border-radius: .2rem .2rem 0 .2rem; }
.af-assistant-message.assistant { justify-self: start; color: var(--af-ink); }
.af-assistant-message p { margin: 0 0 .55rem; }
.af-assistant-message p:last-child { margin-bottom: 0; }
.af-assistant-message.pending { color: var(--af-muted); font-style: italic; }

.af-assistant-sources {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .65rem;
  padding-top: .55rem;
  border-top: 1px solid var(--af-line);
}
.af-assistant-sources a { color: var(--af-rubric); font-size: .72rem; text-decoration: underline; text-underline-offset: .15em; }

.af-assistant-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: .38rem;
  padding: 0 1.05rem .8rem;
}
.af-assistant-prompt {
  padding: .35rem .55rem;
  color: var(--af-muted);
  background: transparent;
  border: 1px solid var(--af-line);
  border-radius: 99px;
  font: inherit;
  font-size: .7rem;
  cursor: pointer;
}
.af-assistant-prompt:hover { color: var(--af-rubric); border-color: var(--af-rubric); }

.af-assistant-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .55rem;
  padding: .8rem 1.05rem .7rem;
  border-top: 1px solid var(--af-line);
}
.af-assistant-input {
  width: 100%;
  min-height: 2.7rem;
  max-height: 7rem;
  resize: vertical;
  padding: .65rem .7rem;
  color: var(--af-ink);
  background: transparent;
  border: 1px solid var(--af-line);
  border-radius: .15rem;
  font: inherit;
  font-size: .83rem;
  line-height: 1.45;
}
.af-assistant-input::placeholder { color: var(--af-muted); opacity: .75; }
.af-assistant-input:focus { outline: 2px solid var(--af-rubric); outline-offset: 1px; }
.af-assistant-submit {
  align-self: end;
  min-width: 3.4rem;
  min-height: 2.7rem;
  padding: 0 .75rem;
  color: var(--af-paper);
  background: var(--af-rubric);
  border: 1px solid var(--af-rubric);
  border-radius: .15rem;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.af-assistant-submit:disabled { cursor: wait; opacity: .55; }

.af-assistant-note {
  margin: 0;
  padding: 0 1.05rem .85rem;
  color: var(--af-muted);
  font-size: .68rem;
  line-height: 1.45;
}

.af-assistant-launcher:focus-visible,
.af-assistant-close:focus-visible,
.af-assistant-prompt:focus-visible,
.af-assistant-submit:focus-visible { outline: 2px solid var(--af-rubric); outline-offset: 2px; }

@media (max-width: 520px) {
  .af-assistant-panel { right: .75rem; bottom: 4.7rem; width: calc(100vw - 1.5rem); max-height: calc(100vh - 6rem); }
  .af-assistant-launcher { right: .75rem; bottom: .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .af-assistant-launcher { transition: none; }
}
