/* =========================================================================
   The built-in assistant — the launcher, the panel, and everything that
   renders inside it. Loaded by partials/head.liquid only when the server has
   an AI key (app.ai), so a workspace without the assistant ships none of it.

   Uses app.css's tokens throughout: same paper, same ink, rust only where
   something needs a person's attention (a proposal waiting, a credit warning).
   ========================================================================= */

.ask-launcher {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 70;
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .7rem 1rem;
  border: 1px solid var(--ink); border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg);
  font: 500 .92rem/1 var(--font-sans);
  box-shadow: var(--sh-3);
  cursor: pointer;
}
.ask-launcher:hover { background: var(--accent-soft); }
.ask-launcher svg { width: 16px; height: 16px; }
.ask-launcher[aria-expanded="true"] { display: none; }

.ask-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 85;
  width: min(460px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--sh-pop);
  animation: slide-in .2s cubic-bezier(.4,0,.2,1);
}
.ask-panel[hidden] { display: none !important; }

.ask-panel__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
  padding: 1rem 1.15rem .85rem;
  border-bottom: 1px solid var(--line);
}
.ask-panel__title { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1.15rem; }
.ask-panel__meta { margin: .2rem 0 0; font-size: .8rem; color: var(--muted); }
.ask-panel__meta--low { color: var(--rust-deep); }
.ask-panel__tools { display: flex; align-items: center; gap: .4rem; }
.ask-panel__icon {
  appearance: none; border: 1px solid transparent; background: none; color: var(--muted);
  width: 2rem; height: 2rem; display: inline-grid; place-items: center;
  border-radius: var(--r-sm); cursor: pointer;
}
.ask-panel__icon:hover { color: var(--ink); border-color: var(--line); }
.ask-panel__icon svg { width: 16px; height: 16px; }

.ask-panel__body {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.15rem;
  display: flex; flex-direction: column; gap: .85rem;
}

.ask-panel__intro { color: var(--ink-soft); font-size: .92rem; line-height: 1.55; }
.ask-panel__intro h3 { margin: 0 0 .35rem; font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; color: var(--ink); }
.ask-panel__intro p { margin: 0 0 .5rem; }

.ask-panel__actions {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding: .6rem 1.15rem 0;
}
.ask-chip {
  appearance: none;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
  padding: .4rem .6rem;
  font: 500 .8rem/1.2 var(--font-sans);
  cursor: pointer;
}
.ask-chip:hover:not([disabled]) { border-color: var(--ink); }
.ask-chip[disabled] { opacity: .5; cursor: not-allowed; }

.ask-panel__form {
  display: flex; gap: .5rem; align-items: flex-end;
  padding: .75rem 1.15rem .5rem;
}
.ask-panel__form textarea {
  flex: 1; resize: none; min-height: 2.75rem; max-height: 9rem;
  padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: 400 .92rem/1.45 var(--font-sans);
}
.ask-panel__form textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--rust-ring); }
.ask-panel__foot { margin: 0; padding: 0 1.15rem .85rem; font-size: .76rem; color: var(--faint); }

/* ---- the conversation -------------------------------------------------- */
.ask-msg { font-size: .93rem; line-height: 1.55; color: var(--ink); }
.ask-msg--you {
  align-self: flex-end; max-width: 88%;
  padding: .55rem .75rem;
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  white-space: pre-wrap;
}
.ask-msg--ai { align-self: stretch; }
.ask-md p { margin: 0 0 .6rem; }
.ask-md p:last-child { margin-bottom: 0; }
.ask-md ul, .ask-md ol { margin: .2rem 0 .6rem; padding-left: 1.2rem; }
.ask-md li { margin: .15rem 0; }
.ask-md a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--rust-edge); text-underline-offset: 2px; }
.ask-md a:hover { color: var(--rust-deep); }
.ask-md code { font-size: .85em; background: var(--surface-2); padding: 0 .25rem; border-radius: var(--r-sm); }
.ask-md strong { font-weight: 600; }

.ask-trail { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.ask-trail__item { display: flex; align-items: center; gap: .45rem; font-size: .8rem; color: var(--muted); }
.ask-trail__item::before {
  content: ''; width: .45rem; height: .45rem; border-radius: var(--r-pill);
  background: var(--ok); flex: none;
}
.ask-trail__item--running::before { background: var(--faint); animation: ask-pulse 1s ease-in-out infinite; }
.ask-trail__item--failed::before { background: var(--danger); }
@keyframes ask-pulse { 50% { opacity: .3; } }

.ask-card {
  margin-top: .6rem;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface);
  padding: .75rem .85rem;
}
.ask-card--waiting { border-color: var(--rust-edge); background: var(--rust-soft); }
.ask-card__label { margin: 0 0 .35rem; font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.ask-card__body { margin: 0 0 .5rem; font-size: .9rem; white-space: pre-wrap; color: var(--ink); }
.ask-card__subject { margin: 0 0 .3rem; font-weight: 600; font-size: .9rem; }
.ask-card__why { margin: 0 0 .5rem; font-size: .8rem; color: var(--muted); }
.ask-card__facts { margin: 0 0 .5rem; padding: 0; list-style: none; font-size: .85rem; color: var(--ink-soft); }
.ask-card__facts li { margin: .1rem 0; }
.ask-card__actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.ask-card__status { font-size: .8rem; color: var(--muted); }
.ask-card__status--approved { color: var(--ok); }
.ask-card__status--declined, .ask-card__status--expired { color: var(--faint); }
.ask-card__status--failed, .ask-card__status--blocked { color: var(--danger); }

.ask-note { font-size: .8rem; color: var(--faint); margin: .35rem 0 0; }
.ask-cost { font-size: .72rem; color: var(--faint); margin: .4rem 0 0; font-variant-numeric: tabular-nums; }
.ask-error {
  padding: .6rem .75rem;
  border: 1px solid var(--danger); border-radius: var(--r-md);
  background: var(--danger-bg); color: var(--danger);
  font-size: .88rem;
}
.ask-error a, .ask-error button { margin-left: .35rem; }

.ask-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.ask-history__item {
  appearance: none; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  padding: .55rem .7rem; cursor: pointer;
  font: 400 .88rem/1.35 var(--font-sans);
}
.ask-history__item:hover { border-color: var(--ink); }
.ask-history__meta { display: block; font-size: .75rem; color: var(--muted); margin-top: .15rem; }

@media (max-width: 640px) {
  .ask-launcher { right: 1rem; bottom: 1rem; }
  .ask-launcher span { display: none; }
}
