.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ai-assistant-launcher {
  position: fixed;
  right: 24px;
  bottom: 22px;
  z-index: 175;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 15px 8px 10px;
  border: 1px solid #2b2b27;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 14px 34px rgba(29, 29, 26, .16);
  text-align: left;
}

.ai-assistant-launcher > i {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 6px;
  color: #e9ddad;
  font-size: 19px;
}

.ai-assistant-launcher > span {
  display: grid;
  min-width: 92px;
  line-height: 1.2;
}

.ai-assistant-launcher strong {
  font-size: 13px;
}

.ai-assistant-launcher small {
  margin-top: 3px;
  overflow: hidden;
  color: rgba(255, 255, 255, .64);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-assistant-launcher:hover {
  background: #34342f;
}

.ai-assistant-launcher[aria-expanded="true"] {
  visibility: hidden;
}

.ai-assistant-panel {
  position: fixed;
  right: 24px;
  bottom: 22px;
  z-index: 180;
  display: flex;
  width: min(410px, calc(100vw - 32px));
  height: min(680px, calc(100dvh - 44px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #cfcfc8;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(29, 29, 26, .2);
}

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

.ai-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.ai-assistant-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-assistant-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #d9d1b6;
  border-radius: 7px;
  background: var(--yellow-soft);
  color: var(--ink);
  font-size: 17px;
}

.ai-assistant-heading > div {
  display: grid;
  line-height: 1.25;
}

.ai-assistant-heading strong {
  font-size: 14px;
}

.ai-assistant-close {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
}

.ai-assistant-close:hover {
  background: #f5f5f2;
}

.ai-assistant-context {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 39px;
  padding: 8px 15px;
  border-bottom: 1px solid var(--line);
  background: #fafaf7;
  color: var(--muted);
  font-size: 11px;
}

.ai-assistant-context > i {
  color: #817650;
  font-size: 15px;
}

.ai-assistant-context strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-assistant-messages {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 18px 15px 10px;
  scroll-behavior: smooth;
}

.ai-message {
  display: grid;
  max-width: 92%;
  gap: 5px;
}

.ai-message.user {
  align-self: flex-end;
}

.ai-message.assistant {
  align-self: flex-start;
}

.ai-message-meta {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

.ai-message.user .ai-message-meta {
  text-align: right;
}

.ai-message-body {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7f7f4;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-message.user .ai-message-body {
  border-color: #2b2b27;
  background: var(--ink);
  color: #fff;
}

.ai-message-body.markdown {
  white-space: normal;
}

.ai-message-body.markdown > :first-child {
  margin-top: 0;
}

.ai-message-body.markdown > :last-child {
  margin-bottom: 0;
}

.ai-message-body.markdown p {
  margin: 0 0 9px;
}

.ai-message-body.markdown ul,
.ai-message-body.markdown ol {
  margin: 7px 0 10px;
  padding-left: 20px;
}

.ai-message-body.markdown li {
  padding-left: 2px;
}

.ai-message-body.markdown li + li {
  margin-top: 7px;
}

.ai-message-body.markdown li p {
  margin: 3px 0 0;
}

.ai-message-body.markdown strong {
  color: #25251f;
  font-weight: 800;
}

.ai-message-body.markdown h2,
.ai-message-body.markdown h3,
.ai-message-body.markdown h4 {
  margin: 12px 0 6px;
  color: #25251f;
  font-size: 12px;
  line-height: 1.4;
}

.ai-message-body.markdown a {
  color: #5f572f;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.ai-message-body.markdown code {
  padding: 1px 4px;
  border: 1px solid #deddd5;
  border-radius: 4px;
  background: #efefe9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .92em;
}

.ai-message-body.markdown pre {
  margin: 8px 0 10px;
  padding: 9px 10px;
  overflow-x: auto;
  border: 1px solid #deddd5;
  border-radius: 6px;
  background: #efefe9;
  white-space: pre;
}

.ai-message-body.markdown pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.ai-message-body.markdown blockquote {
  margin: 8px 0 10px;
  padding: 5px 0 5px 9px;
  border-left: 2px solid #b4a86f;
  color: var(--muted);
}

.ai-message-body.markdown hr {
  margin: 10px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.ai-message.error .ai-message-body {
  border-color: #e5c4bd;
  background: var(--red-soft);
  color: #7d2f25;
}

.ai-message-sources {
  display: grid;
  gap: 5px;
  margin-top: 3px;
}

.ai-message-sources > span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

.ai-message-sources a {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr);
  gap: 5px;
  align-items: start;
  color: #4e4a3a;
  font-size: 10px;
  line-height: 1.4;
  text-decoration: none;
}

.ai-message-sources a:hover span {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-message-sources a i {
  margin-top: 1px;
}

.ai-loading {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 18px;
}

.ai-loading i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9e967a;
  animation: ai-loading 1s ease-in-out infinite;
}

.ai-loading i:nth-child(2) {
  animation-delay: .13s;
}

.ai-loading i:nth-child(3) {
  animation-delay: .26s;
}

.ai-assistant-suggestions {
  display: flex;
  gap: 6px;
  padding: 7px 14px 9px;
  overflow-x: auto;
}

.ai-assistant-suggestions button,
.ai-search-toggle {
  min-height: 29px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #595952;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.ai-assistant-suggestions button:hover,
.ai-search-toggle:hover {
  border-color: #bdb7a1;
  background: var(--yellow-soft);
}

.ai-assistant-form {
  margin: 0 14px;
  padding: 9px;
  border: 1px solid #cfcfc8;
  border-radius: 9px;
  background: #fff;
}

.ai-assistant-form:focus-within {
  border-color: #a69b75;
  box-shadow: 0 0 0 3px rgba(211, 185, 87, .16);
}

.ai-assistant-form textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 110px;
  padding: 2px 3px 7px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}

.ai-assistant-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ai-search-toggle[aria-pressed="true"] {
  border-color: #d9d1b6;
  background: var(--yellow-soft);
  color: var(--ink);
}

.ai-send-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 31px;
  padding: 0 10px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.ai-send-button:disabled,
.ai-search-toggle:disabled {
  cursor: wait;
  opacity: .52;
}

.ai-assistant-disclaimer {
  margin: 8px 14px 12px;
  color: #85857e;
  font-size: 9px;
  line-height: 1.45;
}

@keyframes ai-loading {
  0%, 100% { opacity: .35; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 640px) {
  body.assistant-open {
    overflow: hidden;
  }

  .ai-assistant-launcher {
    right: 13px;
    bottom: 13px;
    min-height: 50px;
    padding: 7px 11px 7px 8px;
  }

  .ai-assistant-launcher > i {
    width: 32px;
    height: 32px;
  }

  .ai-assistant-panel {
    inset: 0;
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .ai-assistant-header {
    min-height: 62px;
    padding: 10px 13px;
  }

  .ai-assistant-messages {
    padding: 16px 13px 9px;
  }

  .ai-assistant-suggestions {
    padding-right: 13px;
    padding-left: 13px;
  }

  .ai-assistant-form {
    margin-right: 13px;
    margin-left: 13px;
  }

  .ai-assistant-disclaimer {
    margin-right: 13px;
    margin-bottom: max(10px, env(safe-area-inset-bottom));
    margin-left: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-loading i {
    animation: none;
    opacity: .7;
  }

  .ai-assistant-messages {
    scroll-behavior: auto;
  }
}
