/* Halden assistant — widget styles. Tokens come from /styles.css. */

#assistant {
  position: fixed;
  inset: auto 24px 24px auto;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  /* The whole widget is one view-transition participant: it is captured as a single
     image on the old page and the new page, which are identical, so it holds still
     while the page content slides underneath. */
  view-transition-name: assistant;
  font-family: var(--font-text);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
}

/* Launcher ----------------------------------------------------------------- */

.asst-launcher {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 0;
  background: var(--ink);
  color: var(--on-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 24px -12px rgb(23 21 15 / .6), 0 1px 3px rgb(23 21 15 / .12);
  transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s;
}
.asst-launcher svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.asst-launcher:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -12px rgb(23 21 15 / .6), 0 1px 3px rgb(23 21 15 / .12); }
.asst-launcher:active { transform: translateY(0) scale(.97); }
#assistant[data-open="true"] .asst-launcher { display: none; }

/* Panel -------------------------------------------------------------------- */

.asst-panel {
  width: 380px;
  height: min(620px, 100dvh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 48px -24px rgb(23 21 15 / .45), 0 2px 8px rgb(23 21 15 / .10);
  overflow: clip;
  transform-origin: 100% 100%;
}
/* Open/close animation only once the live widget has taken over (boot.js adds
   .is-live after the first frame); the markup restored before first paint must not
   animate in, or the view transition would capture it mid-fade. */
.is-live .asst-panel {
  transition: opacity .22s cubic-bezier(.2,.8,.2,1), transform .22s cubic-bezier(.2,.8,.2,1), display .22s allow-discrete;
}
.asst-panel[hidden] { display: none; opacity: 0; transform: translateY(8px) scale(.96); }
@starting-style {
  .is-live .asst-panel:not([hidden]) { opacity: 0; transform: translateY(8px) scale(.96); }
}

.asst-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 12px 16px;
  border-bottom: 1px solid var(--line);
}
.asst-title { display: flex; align-items: center; gap: 10px; }
.asst-title h2 { font: 500 15px/1.2 var(--font-text); margin: 0; letter-spacing: 0; }
.asst-mark {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--ink); color: var(--on-ink);
  display: grid; place-items: center;
  font: italic 19px/1 var(--font-display);
}
.asst-status { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.asst-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--accent); }
#assistant[data-streaming="true"] .asst-dot { animation: asst-pulse 1.2s ease-in-out infinite; }
@keyframes asst-pulse { 50% { opacity: .35; } }

.asst-tools { display: flex; gap: 2px; }
.asst-icon {
  width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, color .15s;
}
.asst-icon[hidden] { display: none; }
.asst-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.asst-icon:hover, .asst-icon[aria-expanded="true"] { background: var(--paper-2); color: var(--ink); }

/* Options popover, anchored to the "more" button (top layer, so no z-index games). */
.asst-icon[data-more] { anchor-name: --asst-more; }
.asst-menu {
  position: fixed;
  position-anchor: --asst-more;
  inset: auto;
  top: anchor(bottom);
  right: anchor(right);
  margin: 6px 0 0;
  width: 300px; padding: 6px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 32px -16px rgb(23 21 15 / .4), 0 1px 4px rgb(23 21 15 / .08);
  opacity: 0; transform: translateY(-4px);
  transition: opacity .16s, transform .16s cubic-bezier(.2,.8,.2,1), display .16s allow-discrete, overlay .16s allow-discrete;
}
.asst-menu:popover-open { opacity: 1; transform: none; }
@starting-style { .asst-menu:popover-open { opacity: 0; transform: translateY(-4px); } }
.asst-menu::backdrop { background: transparent; }

.asst-switch {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start;
  padding: 10px 10px 12px; border-radius: 8px; cursor: pointer;
}
.asst-switch:hover { background: var(--paper-2); }
.asst-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.asst-switch-track {
  margin-top: 2px; width: 32px; height: 18px; border-radius: 999px; background: var(--paper-3); position: relative;
  transition: background .18s;
}
.asst-switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px; background: var(--paper);
  box-shadow: 0 1px 2px rgb(23 21 15 / .25);
  transition: translate .18s cubic-bezier(.2,.8,.2,1);
}
.asst-switch input:checked + .asst-switch-track { background: var(--accent); }
.asst-switch input:checked + .asst-switch-track::after { translate: 14px 0; }
.asst-switch input:focus-visible + .asst-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.asst-switch strong { display: block; font-weight: 500; font-size: 13.5px; }
.asst-switch small { display: block; margin-top: 2px; font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.asst-switch code { font-size: 11.5px; }

.asst-menu-item {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font: 500 13.5px/1.2 var(--font-text); cursor: pointer;
}
.asst-menu-item:hover { background: var(--paper-2); }
.asst-meta { margin: 4px 0 0; padding: 8px 10px 6px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.asst-meta:empty { display: none; }

/* Thread ------------------------------------------------------------------- */

.asst-thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
  scroll-padding-bottom: 8px;
}
.asst-thread:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.asst-empty { color: var(--ink-2); padding: 8px 0 0; }
.asst-empty p { margin: 0 0 14px; max-width: 30ch; }
.asst-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.asst-chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper);
  color: var(--ink); font: 400 13px/1.2 var(--font-text); cursor: pointer; text-align: left;
  transition: background .15s, border-color .15s;
}
.asst-chip:hover { background: var(--paper-2); border-color: var(--paper-3); }

.asst-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.asst-msg { display: flex; }
.asst-msg.is-user { justify-content: flex-end; }
.asst-bubble {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}
.is-user .asst-bubble { background: var(--ink); color: var(--on-ink); border-bottom-right-radius: 4px; }
.is-assistant .asst-bubble { background: var(--paper-2); border-bottom-left-radius: 4px; }
.asst-bubble p { margin: 0; }
.asst-bubble p + p, .asst-bubble ul + p, .asst-bubble p + ul { margin-top: 8px; }
.asst-bubble ul { margin: 0; padding-left: 18px; }
.asst-bubble li + li { margin-top: 4px; }
.asst-bubble code { font-size: .92em; background: rgb(23 21 15 / .06); padding: 1px 4px; border-radius: 4px; }

/* Streaming caret: a 1px bar after the last block of the message being written. */
.is-streaming .asst-bubble > :last-child::after {
  content: "";
  display: inline-block;
  width: 1.5px; height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--ink);
  animation: asst-blink 1s steps(2, jump-none) infinite;
}
.is-streaming .asst-bubble:empty { min-height: 1.5em; min-width: 2.5em; }
.is-streaming .asst-bubble:empty::after { content: ""; display: inline-block; width: 1.5px; height: 1em; margin: 9px 0 0 0; background: var(--ink); animation: asst-blink 1s steps(2, jump-none) infinite; }
@keyframes asst-blink { 50% { opacity: 0; } }

.asst-notice {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  line-height: 1.4;
}

/* Composer ----------------------------------------------------------------- */

.asst-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--line);
}
.asst-composer textarea {
  resize: none;
  min-height: 40px; max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  line-height: 1.4;
  field-sizing: content;
}
.asst-composer textarea::placeholder { color: var(--ink-3); }
.asst-composer textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.asst-send {
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: var(--ink); color: var(--on-ink);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, transform .12s;
}
.asst-send[hidden] { display: none; }
.asst-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.asst-send:hover { background: var(--accent); }
.asst-send:active { transform: scale(.96); }
.asst-stop { background: var(--paper-2); color: var(--ink); }
.asst-stop svg rect { fill: currentColor; stroke: none; }
.asst-stop:hover { background: var(--paper-3); }

/* Mobile: bottom sheet ------------------------------------------------------- */

@media (width < 480px) {
  #assistant { inset: auto 16px 16px auto; }
  #assistant[data-open="true"] { inset: auto 0 0 0; align-items: stretch; }
  .asst-panel { width: auto; height: min(88dvh, 640px); border-radius: 18px 18px 0 0; border-bottom: 0; }
  .asst-menu { width: min(300px, calc(100vw - 24px)); }
}

@media (prefers-reduced-motion: reduce) {
  .asst-panel, .asst-menu, .asst-launcher, .asst-switch-track, .asst-switch-track::after { transition: none; }
  #assistant[data-streaming="true"] .asst-dot { animation: none; }
}
