/* Ask Hyperdesk (ask.js): a button at the bottom right and a chat panel; a bottom sheet on phones. Self-contained so
   it works on the home page (ats-home.css) and the docs (conduit.css). Light only, like the site.

   Liquid glass, as in glass-ui: a frosted surface (blur + saturate) lit along its top edge, a hairline instead of a
   border, and a soft shadow. Proportions: an 8px grid; the panel is 2:3 (416 x 624); corners are concentric, each
   inner radius is the outer one minus the gap between them (panel 32 -> composer 22 at 10px in -> send 18 at 4px
   in), so nested shapes read as one object. */
.hda, .hda-open-btn {
  --a-ink: #29251e;
  --a-muted: #69655f;
  --a-faint: #8c877f;
  --a-coal: #28241e;
  --a-sky: #0b5c75;
  --a-sky-soft: rgb(230 247 252 / 0.85);
  --a-red-ink: #8a2f1c;
  --a-red-soft: rgb(252 239 235 / 0.9);
  /* glass */
  --g-bg: linear-gradient(180deg, rgb(255 255 255 / 0.78), rgb(250 249 247 / 0.66));
  --g-pill: rgb(255 255 255 / 0.72);
  --g-pill-hover: rgb(255 255 255 / 0.92);
  --g-hi: rgb(255 255 255 / 0.95);
  --g-edge: rgb(40 36 30 / 0.1);
  --g-blur: blur(28px) saturate(180%);
  --g-shadow: 0 24px 64px rgb(40 36 30 / 0.16), 0 4px 12px rgb(40 36 30 / 0.06);
  /* proportions */
  --r-panel: 32px;
  --gap: 10px;
  --r-inner: calc(var(--r-panel) - var(--gap));   /* 22px */
  --a-sans: 'PP Neue Montreal', Geist, 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --a-mono: 'Geist Mono', 'Azeret Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-family: var(--a-sans);
  -webkit-font-smoothing: antialiased;
}
.hda [hidden], .hda[hidden] { display: none !important; }
.hda-i { display: inline-flex; flex: none; }

/* ---------- The button: a glass pill ---------- */
.hda-open-btn {
  position: fixed; z-index: 60;
  right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 8px 0 18px;
  border: 0; border-radius: 999px;
  background: var(--g-pill); color: var(--a-ink);
  -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
  box-shadow: inset 0 1px 0 var(--g-hi), inset 0 0 0 0.5px var(--g-hi), 0 0 0 0.5px var(--g-edge), 0 12px 32px rgb(40 36 30 / 0.14), 0 2px 6px rgb(40 36 30 / 0.06);
  font: 500 14px/1 var(--a-sans);
  cursor: pointer;
  transition: transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 160ms ease, background 160ms ease;
}
.hda-open-btn .hda-i { color: var(--a-sky); }
.hda-open-btn:hover { background: var(--g-pill-hover); transform: translateY(-1px); }
.hda-open-btn:active { transform: scale(0.97); }
.hda-open-btn:focus-visible { outline: 2px solid var(--a-sky); outline-offset: 3px; }
.hda-open-btn kbd {
  display: inline-flex; align-items: center; height: 32px; padding: 0 10px; border-radius: 999px;
  background: rgb(40 36 30 / 0.06); color: var(--a-muted);
  font: 500 11px/1 var(--a-mono);
}
.hda-open .hda-open-btn { opacity: 0; transform: scale(0.96); pointer-events: none; }

/* ---------- The panel ---------- */
.hda {
  position: fixed; z-index: 61;
  right: 24px; bottom: 24px;
  display: flex; flex-direction: column;
  width: min(416px, calc(100vw - 48px));
  height: min(624px, calc(100vh - 48px));
  height: min(624px, calc(100dvh - 48px));
  border-radius: var(--r-panel);
  background: var(--g-bg); color: var(--a-ink);
  -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
  box-shadow: inset 0 1px 0 var(--g-hi), inset 0 0 0 0.5px var(--g-hi), 0 0 0 0.5px var(--g-edge), var(--g-shadow);
  overflow: hidden;
  opacity: 0; transform: translateY(16px) scale(0.97); transform-origin: bottom right;
  transition: opacity 140ms ease, transform 140ms ease;
}
.hda.is-in { opacity: 1; transform: none; transition-duration: 240ms; transition-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); }
/* Without a live blur, a near-solid surface keeps the text readable. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .hda { background: rgb(255 255 255 / 0.97); }
  .hda-open-btn { background: #fff; }
}

.hda-head { display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 var(--gap) 0 20px; flex: none; }
.hda-title { display: flex; align-items: center; gap: 8px; margin: 0 auto 0 0; font: 500 15px/20px var(--a-sans); }
.hda-title .hda-i { color: var(--a-sky); }
.hda-new, .hda-x {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; border: 0; border-radius: 999px; background: transparent; color: var(--a-muted);
  font: 500 13px/1 var(--a-sans); cursor: pointer;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.hda-new { padding: 0 14px; }
.hda-x { width: 36px; }
.hda-new:hover, .hda-x:hover { background: var(--g-pill); color: var(--a-ink); box-shadow: inset 0 1px 0 var(--g-hi), 0 0 0 0.5px var(--g-edge); }
.hda-new:focus-visible, .hda-x:focus-visible { outline: 2px solid var(--a-sky); outline-offset: 1px; }

/* The conversation scrolls under a soft fade at both edges instead of hard lines. */
.hda-list {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 20px 16px; display: flex; flex-direction: column; gap: 16px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 12px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 12px, #000 calc(100% - 16px), transparent 100%);
}

.hda-hi { margin: auto 0 0; }
.hda-hi p { margin: 0 0 8px; color: var(--a-muted); font-size: 14px; line-height: 21px; }
.hda-hi .hda-hi-t { color: var(--a-ink); font: 400 24px/30px var(--heading, var(--a-sans)); letter-spacing: -0.02em; }
.hda-sug { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.hda-sug button {
  padding: 12px 16px; border: 0; border-radius: 16px;
  background: var(--g-pill); color: var(--a-ink);
  box-shadow: inset 0 1px 0 var(--g-hi), 0 0 0 0.5px var(--g-edge), 0 1px 3px rgb(40 36 30 / 0.06);
  font: 400 14px/20px var(--a-sans); text-align: left; cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}
.hda-sug button:hover { background: var(--g-pill-hover); }
.hda-sug button:active { transform: scale(0.99); }
.hda-sug button:focus-visible { outline: 2px solid var(--a-sky); outline-offset: 1px; }

.hda-m { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.hda-user { align-items: flex-end; }
.hda-user .hda-b {
  max-width: 85%; padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  background: var(--g-pill); box-shadow: inset 0 1px 0 var(--g-hi), 0 0 0 0.5px var(--g-edge), 0 1px 3px rgb(40 36 30 / 0.06);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.hda-b { font-size: 14px; line-height: 22px; overflow-wrap: anywhere; }
.hda-assistant .hda-b > :first-child { margin-top: 0; }
.hda-assistant .hda-b > :last-child { margin-bottom: 0; }
.hda-b p, .hda-b ul, .hda-b ol, .hda-b pre { margin: 0 0 12px; }
.hda-b ul, .hda-b ol { padding-left: 20px; }
.hda-b ul { list-style: disc; }
.hda-b ol { list-style: decimal; }
.hda-b li { margin: 4px 0; }
.hda-b .hda-h { font-weight: 600; }
.hda-b a { color: var(--a-sky); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgb(11 92 117 / 0.35); }
.hda-b a:hover { text-decoration-color: currentColor; }
.hda-b code { padding: 1px 6px; border-radius: 6px; background: rgb(40 36 30 / 0.06); font: 400 12.5px/1.4 var(--a-mono); }
.hda-b pre { overflow-x: auto; padding: 12px 16px; border-radius: 16px; background: rgb(40 36 30 / 0.92); color: #f3f1ec; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.08); }
.hda-b pre code { padding: 0; background: none; color: inherit; font-size: 12.5px; line-height: 1.6; white-space: pre; }
.hda-err .hda-b { padding: 10px 16px; border-radius: 16px; background: var(--a-red-soft); color: var(--a-red-ink); }

.hda-dots { color: var(--a-faint); font-size: 14px; }
.hda-dots::after { content: '...'; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; animation: hda-dots 1.2s steps(4, end) infinite; }
@keyframes hda-dots { from { width: 0; } to { width: 1.2em; } }

.hda-src { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hda-src span { color: var(--a-faint); font-size: 12px; margin-right: 2px; }
.hda-src a {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px;
  background: var(--a-sky-soft); color: var(--a-sky); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.7), 0 0 0 0.5px rgb(11 92 117 / 0.14);
  font-size: 12px; text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hda-src a:hover { text-decoration: underline; }

/* The composer: a glass pill floating 10px in from the panel's edges. */
.hda-form {
  display: flex; align-items: flex-end; gap: 8px; flex: none;
  margin: 0 var(--gap); padding: 4px 4px 4px 18px; border-radius: var(--r-inner);
  background: var(--g-pill-hover);
  box-shadow: inset 0 1px 0 var(--g-hi), 0 0 0 0.5px var(--g-edge), 0 4px 16px rgb(40 36 30 / 0.08);
  transition: box-shadow 160ms ease;
}
.hda-form:focus-within { box-shadow: inset 0 1px 0 var(--g-hi), 0 0 0 1px rgb(11 92 117 / 0.45), 0 0 0 4px rgb(11 92 117 / 0.1), 0 4px 16px rgb(40 36 30 / 0.08); }
.hda-in {
  flex: 1; min-width: 0; max-height: 160px; padding: 8px 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--a-ink);
  font: 400 15px/20px var(--a-sans);
}
.hda-in::placeholder { color: var(--a-faint); }
.hda-send {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border: 0; border-radius: calc(var(--r-inner) - 4px);
  background: var(--a-coal); color: #fff; cursor: pointer;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.16), 0 2px 6px rgb(40 36 30 / 0.2);
  transition: transform 140ms ease, background 140ms ease;
}
.hda-send:hover { background: #000; }
.hda-send:active { transform: scale(0.94); }
.hda-send:focus-visible { outline: 2px solid var(--a-sky); outline-offset: 2px; }
.hda-foot { margin: 0; padding: 8px 20px 12px; color: var(--a-faint); font-size: 11.5px; line-height: 16px; text-align: center; flex: none; }
.hda-foot a { color: inherit; }

/* ---------- Phones: a glass bottom sheet ---------- */
@media (max-width: 560px) {
  .hda-open-btn { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); height: 44px; padding: 0 18px; }
  .hda-open-btn kbd { display: none; }
  .hda {
    left: 8px; right: 8px; bottom: 8px; width: auto;
    height: calc(88vh - 8px); height: calc(88dvh - 8px);
    transform: translateY(24px); transform-origin: bottom center;
    padding-bottom: env(safe-area-inset-bottom);
  }
  html.hda-open, html.hda-open body { overflow: hidden; }
  .hda-in { font-size: 16px; line-height: 20px; }
  .hda-head { height: 60px; }
  .hda-new, .hda-x { height: 44px; }
  .hda-x { width: 44px; }
  .hda-send { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .hda, .hda.is-in, .hda-open-btn { transition: none; }
  .hda-dots::after { animation: none; width: 1.2em; }
}
@media (prefers-reduced-transparency: reduce) {
  .hda { background: rgb(255 255 255 / 0.98); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .hda-open-btn { background: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media print { .hda, .hda-open-btn { display: none !important; } }
