/* Ask: chat with the site agent, links into your own AI and MCP setup. Builds on the tokens in styles.css.
   Cobalt still means alive: the send button, live dots and the streaming caret. */

/* ---------- Status dot ---------- */
.ask-dot {
  flex: none;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
.ask-dot[data-state="on"] {
  background: var(--accent);
}
.ask-dot[data-state="busy"] {
  background: var(--salmon);
}
.ask-dot[data-state="off"] {
  background: var(--faint);
}
@media (prefers-reduced-motion: no-preference) {
  .ask-dot[data-state="on"],
  .ask-dot[data-state="busy"] {
    animation: pulse 2.4s var(--ease) infinite;
  }
}

/* ---------- Chat layout ---------- */
.ask-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ask-fallback {
  padding: clamp(1.25rem, 3vw, 2rem);
}
.ask-fallback p:not(.eyebrow) {
  margin-top: 0.6rem;
  color: var(--muted);
}

/* Engine switch */
.ask-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1.25rem;
  padding: 0.75rem clamp(0.85rem, 2vw, 1.25rem);
  border-bottom: 1px solid var(--line);
}
.ask-engines {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
}
.ask-engine {
  position: relative;
  display: inline-flex;
}
.ask-engine input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.ask-engine span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 0.85rem;
  border-radius: 8px;
  font: 650 var(--step--1) / 1 var(--sans);
  color: var(--muted);
  transition:
    background-color 0.2s var(--ease),
    color 0.2s var(--ease);
}
.ask-engine input:checked + span {
  background: var(--ink);
  color: var(--paper);
}
.ask-engine input:not(:checked):hover + span {
  color: var(--ink);
}
.ask-engine input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ask-engine-sub {
  margin-left: 0.4rem;
  font-size: var(--step--2);
  font-weight: 500;
  opacity: 0.75;
}
.ask-engine-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  min-width: 0;
}
.ask-download {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.9rem;
  padding: 0.7rem clamp(0.85rem, 2vw, 1.25rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
}
.ask-download-text {
  flex: 1 1 18rem;
  min-width: 0;
  font-size: var(--step--1);
  line-height: 1.45;
}
.ask-download-go {
  flex: none;
  min-height: 36px;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: 650 var(--step--1) / 1.2 var(--sans);
  transition:
    background-color 0.2s,
    border-color 0.2s;
}
.ask-download-go:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.ask-download progress {
  flex: 1 1 100%;
  height: 6px;
  border: 0;
  border-radius: 6px;
  background: var(--paper-2);
  accent-color: var(--accent);
  appearance: none;
  overflow: hidden;
}
.ask-download progress::-webkit-progress-bar {
  background: var(--paper-2);
}
.ask-download progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 6px;
}
.ask-download progress::-moz-progress-bar {
  background: var(--accent);
}

/* Conversation */
.ask-log {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  min-height: clamp(15rem, 34vh, 22rem);
  max-height: min(64vh, 40rem);
  padding: clamp(1rem, 2.4vw, 1.75rem) clamp(0.85rem, 2.4vw, 1.75rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.ask-empty {
  margin-block: auto;
  max-width: 34rem;
}
.ask-empty-title {
  font-size: var(--step-2);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-wrap: balance;
}
.ask-empty p:not(.ask-empty-title) {
  margin-top: 0.75rem;
  color: var(--muted);
}
.ask-msg {
  max-width: 44rem;
}
@media (prefers-reduced-motion: no-preference) {
  .ask-msg {
    animation: ask-rise 0.4s var(--spring) both;
  }
}
@keyframes ask-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.ask-msg-user {
  align-self: flex-end;
  max-width: min(36rem, 88%);
  padding: 0.65rem 1rem;
  border-radius: 16px 16px 4px 16px;
  background: color-mix(in oklab, var(--ink) 7%, var(--white));
  font-weight: 550;
}
.ask-msg-user p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ask-msg-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  color: var(--ink);
}
.ask-avatar {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--accent);
}
.ask-msg-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.ask-msg-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
@media (prefers-reduced-motion: no-preference) {
  .ask-msg-agent[data-streaming] .ask-msg-status::before {
    animation: pulse 1.6s var(--ease) infinite;
  }
}
.ask-msg-agent:not([data-streaming]) .ask-msg-status::before {
  background: var(--faint);
}
.ask-msg-body {
  overflow-wrap: anywhere;
}
.ask-msg-body > * + * {
  margin-top: 0.7rem;
}
.ask-msg-body ul,
.ask-msg-body ol {
  margin-block: 0;
  padding-left: 1.25rem;
}
.ask-msg-body li + li {
  margin-top: 0.3rem;
}
.ask-msg-body li::marker {
  color: var(--accent);
}
.ask-msg-body a {
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.22em;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.ask-msg-body a:hover {
  color: var(--accent-ink);
  text-decoration-color: var(--accent);
}
.ask-msg-body code {
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: var(--paper-2);
}
.ask-msg-body pre {
  margin-block: 0;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  overflow-x: auto;
  font: 0.85rem/1.5 var(--mono);
}
.ask-msg-body pre code {
  padding: 0;
  background: none;
}
.ask-msg-body em {
  font-size: 1.08em;
}
/* Streaming caret after the last block */
.ask-msg-agent[data-streaming] .ask-msg-body > :last-child::after,
.ask-msg-agent[data-streaming] .ask-msg-body > ul:last-child > li:last-child::after,
.ask-msg-agent[data-streaming] .ask-msg-body > ol:last-child > li:last-child::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: -0.15em;
}
.ask-msg-agent[data-streaming] .ask-msg-body > ul:last-child::after,
.ask-msg-agent[data-streaming] .ask-msg-body > ol:last-child::after {
  content: none;
}
@media (prefers-reduced-motion: no-preference) {
  .ask-msg-agent[data-streaming] .ask-msg-body > :last-child::after,
  .ask-msg-agent[data-streaming] .ask-msg-body li:last-child::after {
    animation: ask-blink 1s steps(2, jump-none) infinite;
  }
}
@keyframes ask-blink {
  50% {
    opacity: 0;
  }
}
.ask-msg-hint {
  color: var(--muted);
}
.ask-msg-agent[data-error] .ask-msg-body > p:first-child {
  font-weight: 600;
}
.ask-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.9rem;
}
.ask-sources ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ask-sources a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 30px;
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: var(--step--1);
  font-weight: 600;
  transition:
    border-color 0.2s,
    color 0.2s;
}
.ask-sources a:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}
.ask-msg-body a.ask-chip {
  font-weight: 600;
  text-decoration: none;
}
.ask-fallback-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
/* Shown before anyone asks when GET /api/ask says the cloud chat is down. */
.ask-notice {
  display: grid;
  gap: 0.6rem;
  margin-top: 1.1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--salmon);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.ask-empty .ask-notice p {
  margin-top: 0;
  color: var(--ink);
  font-weight: 600;
}
.ask-empty .ask-notice p.ask-msg-hint {
  color: var(--muted);
  font-weight: 400;
}
.ask-notice a.ask-chip {
  text-decoration: none;
}

/* Suggested questions */
.ask-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0 clamp(0.85rem, 2.4vw, 1.75rem) 0.85rem;
}
.ask-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 600 var(--step--1) / 1.2 var(--sans);
  white-space: nowrap;
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.3s var(--spring);
}
.ask-chip:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-ink);
}
.ask-chip:active:not(:disabled) {
  transform: scale(0.97);
}
.ask-chip:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Composer */
.ask-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin: 0 clamp(0.85rem, 2.4vw, 1.75rem);
  padding: 0.45rem 0.45rem 0.45rem 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--paper);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.ask-composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  /* Invisible here; forced-colors mode drops the shadow and paints this outline instead. */
  outline: 2px solid transparent;
  outline-offset: 2px;
}
.ask-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 2.5rem;
  max-height: 10.5rem;
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  resize: none;
  field-sizing: content;
  line-height: 1.5;
  outline: none;
}
.ask-composer textarea::placeholder {
  color: var(--faint);
}
.ask-composer textarea:disabled {
  cursor: not-allowed;
}
.ask-send,
.ask-stop {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.3s var(--spring);
}
.ask-send {
  background: var(--accent);
  color: var(--on-accent);
}
.ask-send:hover:not(:disabled) {
  background: var(--accent-ink);
}
.ask-send:disabled {
  background: var(--paper-2);
  color: var(--faint);
  cursor: default;
}
.ask-stop {
  background: var(--ink);
  color: var(--paper);
}
.ask-send:active:not(:disabled),
.ask-stop:active {
  transform: scale(0.92);
}
/* The question and character counts appear only near their limits. */
.ask-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem 0.9rem;
  min-height: 3.1rem;
  padding: 0.6rem clamp(0.85rem, 2.4vw, 1.75rem) 0.85rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.ask-foot [data-low="false"] {
  display: none;
}
.ask-foot [data-low="true"] {
  color: var(--rust);
}
.ask-new {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  font: 600 var(--step--2) / 1.4 var(--sans);
}
.ask-new:hover {
  border-color: var(--ink);
}

/* ---------- Your own AI ---------- */
.ask-own {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2.6vw, 1.75rem);
}
.ask-own-form {
  display: grid;
  gap: 0.5rem;
}
.ask-own-form textarea {
  width: 100%;
  min-height: 5.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--paper);
  font-weight: 500;
  line-height: 1.5;
  resize: vertical;
  field-sizing: content;
}
.ask-own-form textarea:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
@media (forced-colors: active) {
  .ask-composer:focus-within,
  .ask-own-form textarea:focus {
    outline-color: Highlight;
  }
}
.ask-own-actions,
.ask-installs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
/* Cursor and VS Code links only open desktop apps. */
@media (hover: none) and (pointer: coarse) {
  .ask-app-link {
    display: none;
  }
}

/* ---------- Connect ---------- */
.ask-connect {
  display: grid;
  gap: var(--gutter);
  align-items: stretch;
}
@media (min-width: 1000px) {
  .ask-connect {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  }
}
.ask-server {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2.6vw, 1.75rem);
}
.ask-url {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--paper);
}
.ask-url code {
  font: 600 clamp(1rem, 2vw, 1.25rem) / 1.3 var(--mono);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.ask-clients {
  min-width: 0;
  padding: clamp(1rem, 2.6vw, 1.75rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}
.ask-clients:not(.is-tabbed) .ask-client + .ask-client {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}
.ask-client h3 {
  font-size: var(--step-1);
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}
.ask-client > * + * {
  margin-top: 0.7rem;
}
.ask-client:focus-visible {
  outline-offset: 6px;
}
.ask-tablist {
  position: relative;
  display: flex;
  gap: 1.2rem;
  margin: -0.35rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.ask-tablist::-webkit-scrollbar {
  display: none;
}
.ask-tab {
  position: relative;
  flex: none;
  padding: 0.55rem 0 0.75rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: 650 var(--step--1) / 1.2 var(--sans);
  white-space: nowrap;
  transition: color 0.2s;
}
.ask-tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s var(--spring);
}
.ask-tab:hover,
.ask-tab[aria-selected="true"] {
  color: var(--ink);
}
.ask-tab[aria-selected="true"]::after {
  transform: scaleX(1);
}
.ask-tab:focus-visible {
  outline-offset: -2px;
}
.ask-cmd {
  position: relative;
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font: 500 0.84rem/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ask-cmd:has(.ask-cmd-copy) {
  padding-right: 4.6rem;
}
.ask-cmd code {
  font: inherit;
}
.ask-cmd code::before {
  content: "$ ";
  color: var(--faint);
  user-select: none;
}
.ask-cmd-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  font: 600 var(--step--2) / 1.3 var(--sans);
  transition: border-color 0.2s;
}
.ask-cmd-copy:hover {
  border-color: var(--ink);
}
[data-copied="true"] {
  border-color: var(--accent) !important;
  color: var(--accent-ink) !important;
}
.ask-howto {
  margin: 0;
  padding-left: 1.3rem;
}
.ask-howto li + li {
  margin-top: 0.4rem;
}
.ask-howto li::marker {
  font: 600 0.8rem var(--mono);
  color: var(--accent);
}
.ask-howto code {
  padding: 0.05em 0.35em;
  border-radius: 5px;
  background: var(--paper-2);
  overflow-wrap: anywhere;
}
.ask-client-note {
  color: var(--muted);
  font-size: var(--step--1);
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .ask-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .ask-engine span {
    padding: 0 0.7rem;
  }
  .ask-engine-sub {
    display: none;
  }
  .ask-log {
    max-height: 70vh;
  }
  .ask-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .ask-chips::-webkit-scrollbar {
    display: none;
  }
  .ask-chips .ask-chip:last-child {
    margin-right: 1.5rem;
  }
  .ask-composer {
    margin-inline: 0.75rem;
  }
  .ask-own-actions .btn,
  .ask-installs .btn {
    flex: 1 1 calc(50% - 0.6rem);
  }
  .ask-cmd:has(.ask-cmd-copy) {
    padding-right: 1rem;
    padding-top: 2.6rem;
  }
}
@media print {
  .ask-panel {
    display: none !important;
  }
}
