/* assistant.css — the BARREN TRAIL assistant: trail launcher, intro bubble,
 * floating chat window, saved-chat sidebar, and the #/assistant page.
 * Uses the tokens in app.css. */

/* ---------------------------------------------------------------- launcher */
.bt-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 82;
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--navy-700); color: #fff;
  box-shadow: 0 0 0 3px var(--gold-500), 0 10px 26px rgba(1, 36, 68, .35);
  transition: transform .25s var(--ease), background .25s;
}
.bt-fab:hover { transform: translateY(-2px); background: var(--blue-600); }
.bt-fab:focus-visible { outline: 3px solid var(--blue-300); outline-offset: 5px; }
.bt-fab .ic { grid-area: 1 / 1; width: 30px; height: 30px; transition: opacity .2s, transform .3s var(--ease); }
.bt-fab .fab-close { width: 26px; height: 26px; opacity: 0; transform: rotate(-90deg); }
.bt-fab .bt-mark { width: 40px; height: 31px; }
.bt-mark .m { fill: #fff; }
.bt-mark .t { fill: var(--gold-500); }
.bt-fab.open .fab-trail { opacity: 0; transform: rotate(90deg); }
.bt-fab.open .fab-close { opacity: 1; transform: none; }

body.on-signin .bt-fab, body.on-signin .bt-bubble, body.on-signin .btc-shell,
body.on-assistant .bt-fab, body.on-assistant .bt-bubble, body.on-assistant .btc-shell { display: none; }

/* ---------------------------------------------------------------- intro bubble */
.bt-bubble {
  position: fixed; right: 24px; bottom: 100px; z-index: 82; width: min(300px, calc(100vw - 48px));
  padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-2);
  opacity: 0; visibility: hidden; transform: translateY(10px) scale(.96); transform-origin: calc(100% - 30px) 100%;
  transition: opacity .25s, transform .35s var(--ease), visibility 0s linear .35s;
}
.bt-bubble.show { opacity: 1; visibility: visible; transform: none; transition: opacity .3s, transform .5s cubic-bezier(.2, 1.3, .3, 1), visibility 0s; }
.bt-bubble::after {
  content: ""; position: absolute; right: 24px; bottom: -8px; width: 14px; height: 14px;
  background: #fff; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg);
}
.bt-bubble-x {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: none; color: var(--ink-3); display: grid; place-items: center; cursor: pointer;
}
.bt-bubble-x:hover { background: var(--surface-2); color: var(--ink); }
.bt-bubble-x .ic { width: 14px; height: 14px; }
.bt-bubble-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--navy-700); }
.bt-bubble-tag .ic { width: 16px; height: 16px; color: var(--gold-500); }
.bt-bubble p { margin: 8px 0 12px; padding-right: 6px; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.bt-bubble-go { border: 0; border-radius: 999px; padding: 8px 14px; background: var(--gold-500); color: var(--navy-900); font-size: 12.5px; font-weight: 700; cursor: pointer; }
.bt-bubble-go:hover { background: var(--gold-400); }

/* ---------------------------------------------------------------- floating window */
.btc-shell {
  position: fixed; right: 24px; bottom: 100px; z-index: 81;
  width: 400px; height: min(640px, calc(100vh - 140px));
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(.97); transform-origin: calc(100% - 30px) 100%;
  transition: opacity .2s, transform .3s var(--ease), visibility 0s linear .3s;
}
.btc-shell.open { opacity: 1; visibility: visible; transform: none; transition: opacity .2s, transform .35s var(--ease), visibility 0s; }
.btc-shell .btc { height: 100%; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 60px rgba(1, 36, 68, .28); }
body.btc-locked { overflow: hidden; }

/* ---------------------------------------------------------------- chat */
.btc { position: relative; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); color: var(--ink); isolation: isolate; }
.btc button { font: inherit; }
.btc :focus-visible { outline: 2px solid var(--blue-300); outline-offset: 1px; }

.btc-head { flex: none; display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 8px; border-bottom: 1px solid var(--line); background: var(--surface); }
.btc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; line-height: 1.25; }
.btc-title b { font-size: 14px; font-weight: 800; }
.btc-title-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btc-icon {
  flex: none; width: 34px; height: 34px; border: 0; border-radius: 9px; background: none; color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s;
}
.btc-icon:hover { background: var(--surface-2); color: var(--navy-700); }
.btc-icon .ic { width: 18px; height: 18px; }
/* the header's buttons (chats, new chat, expand, close) are outlined */
.btc-head .btc-icon { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); transition: background .15s, color .15s, border-color .15s; }
.btc-head .btc-icon:hover { border-color: var(--navy-700); }
.btc[data-mode="page"] .btc-float-only { display: none; }

.btc-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.btc-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 14px; }

/* messages */
.btc-msg { display: flex; align-items: flex-start; gap: 8px; }
.btc-msg.is-user { justify-content: flex-end; }
.btc-bubble { min-width: 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.btc-msg.is-user .btc-bubble { max-width: 85%; padding: 9px 13px; border-radius: 14px 14px 4px 14px; background: var(--navy-700); color: #fff; }
.btc-msg.is-bot .btc-bubble { max-width: calc(100% - 36px); padding: 10px 13px; border-radius: 4px 14px 14px 14px; background: var(--surface-2); }
.btc-avatar {
  flex: none; width: 28px; height: 28px; margin-top: 2px; border-radius: 50%; display: grid; place-items: center;
  background: var(--navy-700); color: #fff; box-shadow: 0 0 0 2px var(--gold-500);
}
.btc-avatar .ic { width: 16px; height: 16px; }
.btc-bubble p { margin: 0 0 8px; }
.btc-bubble p:last-child { margin-bottom: 0; }
.btc-bubble ul, .btc-bubble ol { margin: 4px 0 8px; padding-left: 18px; }
.btc-bubble ul:last-child, .btc-bubble ol:last-child { margin-bottom: 0; }
.btc-bubble li { margin: 5px 0; }
.btc-bubble li::marker { color: var(--gold-500); }
.btc-bubble code { font: 12.5px ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--line); padding: 1px 5px; border-radius: 4px; }
.btc-rec {
  font: 600 12px/1 ui-monospace, "Cascadia Mono", Consolas, monospace !important; vertical-align: 1px;
  padding: 3px 6px; border: 0; border-radius: 6px; background: var(--blue-100); color: var(--navy-700); cursor: pointer;
  transition: background .15s, color .15s;
}
.btc-rec:hover { background: var(--navy-700); color: #fff; }
.btc-msg.error .btc-bubble { background: var(--warn-bg); color: var(--warn-ink); }
.btc-retry { margin-top: 8px; padding: 5px 12px; border: 1px solid currentColor; border-radius: 999px; background: none; color: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }

/* what the answer looked up */
.btc-src { margin-top: 10px; padding-top: 7px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }
.btc-src summary { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; list-style: none; user-select: none; }
.btc-src summary::-webkit-details-marker { display: none; }
.btc-src summary:hover { color: var(--navy-700); }
.btc-src summary .ic { width: 13px; height: 13px; }
.btc-src summary .chev { transition: transform .2s; }
.btc-src[open] summary .chev { transform: rotate(180deg); }
.btc-src ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.btc-src li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 0; }
.btc-src li b { font-weight: 600; color: var(--ink-2); }
.btc-src li em { margin-left: auto; font-style: normal; color: var(--ink-2); }
.btc-src-err { color: var(--warn-ink); }

/* working */
.btc-msg.pending .btc-bubble { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.btc-dots { display: inline-flex; gap: 4px; }
.btc-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--navy-700); animation: btc-dot 1.2s ease-in-out infinite; }
.btc-dots i:nth-child(2) { animation-delay: .15s; }
.btc-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes btc-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }

/* empty chat */
.btc-empty { margin-block: auto; padding: 12px 8px; text-align: center; }
.btc-empty-mark {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: var(--navy-700); color: #fff; box-shadow: 0 0 0 3px var(--gold-500);
}
.btc-empty-mark .ic { width: 30px; height: 30px; }
.btc-empty h3 { margin: 0 0 6px; font-size: 17px; }
.btc-empty p { max-width: 310px; margin: 0 auto 16px; font-size: 13px; color: var(--ink-2); }
.btc-asks { display: flex; flex-direction: column; gap: 8px; max-width: 330px; margin: 0 auto; }
.btc-ask {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  text-align: left; font-size: 13px; font-weight: 600; color: var(--navy-700); cursor: pointer; transition: border-color .15s, background .15s;
}
.btc-ask:hover { border-color: var(--navy-700); background: var(--blue-100); }

/* composer */
.btc-form {
  flex: none; display: flex; align-items: flex-end; gap: 8px; margin: 6px 12px 0; padding: 6px 6px 6px 12px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.btc-form:focus-within { border-color: var(--navy-700); box-shadow: 0 0 0 3px var(--blue-100); }
.btc .btc-input { flex: 1; min-width: 0; max-height: 132px; padding: 6px 0; border: 0; outline: 0; resize: none; background: none; font: inherit; font-size: 14px; line-height: 1.45; color: var(--ink); }
.btc-send { flex: none; width: 34px; height: 34px; border: 0; border-radius: 10px; display: grid; place-items: center; background: var(--gold-500); color: var(--navy-900); cursor: pointer; }
.btc-send:hover { background: var(--gold-400); }
.btc-send:disabled { opacity: .45; cursor: default; }
.btc-send .ic { width: 18px; height: 18px; }
.btc-note { flex: none; margin: 6px 0 10px; text-align: center; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }

/* ---------------------------------------------------------------- saved chats
 * An overlay that slides over the chat and darkens the rest of it; on the
 * desktop Assistant page it is a fixed column instead (below). */
.btc-side {
  position: absolute; inset: 0 auto 0 0; z-index: 3; width: min(300px, 86%);
  display: flex; flex-direction: column; background: var(--surface);
  border-right: 1px solid var(--line); box-shadow: 12px 0 30px rgba(1, 36, 68, .18);
  transform: translateX(-102%); visibility: hidden; pointer-events: none; /* none: clicks reach the chat while it slides away */
  transition: transform .3s var(--ease), visibility 0s linear .3s;
}
.btc.side-open .btc-side { transform: none; visibility: visible; pointer-events: auto; transition: transform .3s var(--ease), visibility 0s; }
.btc-scrim { position: absolute; inset: 0; z-index: 2; background: rgba(1, 36, 68, .45); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .3s, visibility 0s linear .3s; }
.btc.side-open .btc-scrim { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .3s, visibility 0s; }

.btc-side-head { flex: none; display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 14px; border-bottom: 1px solid var(--line); }
.btc-side-head b { flex: 1; font-size: 14px; }
.btc-new {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--navy-700); font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.btc-new:hover { border-color: var(--navy-700); }
.btc-new .ic { width: 14px; height: 14px; }
.btc-list-wrap { flex: 1; min-height: 0; overflow: hidden auto; padding: 8px; }
/* minmax(0, 1fr): an auto column would grow to the longest unbroken title */
.btc-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.btc-item { min-width: 0; display: flex; align-items: center; border-radius: 10px; }
.btc-item:hover, .btc-item.active { background: var(--surface-2); }
.btc-item.active { box-shadow: inset 3px 0 0 var(--gold-500); }
.btc-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; border: 0; background: none; text-align: left; color: var(--ink); cursor: pointer; }
.btc-item-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btc-item-time { font-size: 11.5px; color: var(--ink-3); }
.btc-item-tools { display: flex; padding-right: 4px; opacity: 0; transition: opacity .15s; }
.btc-item:hover .btc-item-tools, .btc-item:focus-within .btc-item-tools { opacity: 1; }
@media (hover: none) { .btc-item-tools { opacity: 1; } }
.btc-item-tools .btc-icon { width: 30px; height: 30px; }
.btc-item-tools .btc-icon .ic { width: 15px; height: 15px; }
.btc-item-tools [data-act="delete"]:hover { background: var(--crit-bg); color: var(--crit); }
.btc-rename { flex: 1; display: flex; align-items: center; gap: 4px; padding: 5px 4px 5px 6px; }
.btc-rename input {
  flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--navy-700); border-radius: 8px; outline: 0;
  box-shadow: 0 0 0 3px var(--blue-100); font: inherit; font-size: 13.5px; color: var(--ink);
}
.btc-item.confirming { flex-wrap: wrap; gap: 8px; padding: 10px; background: var(--crit-bg); box-shadow: none; }
.btc-item.confirming span { flex: 1 0 100%; font-size: 13px; font-weight: 600; color: var(--crit); }
.btc-del-yes, .btc-del-no { padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.btc-del-yes { border: 0; background: var(--crit); color: #fff; }
.btc-del-no { border: 1px solid var(--line); background: #fff; color: var(--ink-2); }
.btc-list-empty { margin: 0; padding: 10px 8px; font-size: 12.5px; color: var(--ink-3); }
.btc-side-note { flex: none; margin: 0; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); }

/* ---------------------------------------------------------------- Assistant page
 * One scroll: the page itself does not scroll here. The chat fills exactly the
 * viewport under the sticky header (--bt-hdr is its live height, set by
 * assistant.js), the footer is hidden, and only the message list and the chat
 * list scroll, each inside its own column. */
html:has(body.on-assistant), body.on-assistant { overflow: hidden; }
body.on-assistant .ftr { display: none; }
.assistant-page { padding: 0; }
.assistant-slot { height: calc(100dvh - var(--bt-hdr, var(--hdr-h))); }
.btc[data-mode="page"] { height: 100%; border: 0; border-radius: 0; box-shadow: none; }

@media (min-width: 900px) {
  .btc[data-mode="page"] { display: grid; grid-template-columns: 290px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .btc[data-mode="page"] .btc-head { grid-column: 2; grid-row: 1; padding-left: 16px; }
  .btc[data-mode="page"] .btc-side {
    position: static; grid-column: 1; grid-row: 1 / span 2; width: auto;
    transform: none; visibility: visible; pointer-events: auto; box-shadow: none; background: var(--surface-2);
  }
  .btc[data-mode="page"] .btc-main { grid-column: 2; grid-row: 2; }
  .btc[data-mode="page"] .btc-side-toggle, .btc[data-mode="page"] .btc-side-close, .btc[data-mode="page"] .btc-scrim { display: none; }
  .btc[data-mode="page"] .btc-item:hover, .btc[data-mode="page"] .btc-item.active { background: var(--surface); }
  .btc[data-mode="page"] .btc-log { padding: 24px 28px 8px; }
  .btc[data-mode="page"] .btc-log > * { width: 100%; max-width: 780px; margin-inline: auto; }
  .btc[data-mode="page"] .btc-form { width: calc(100% - 56px); max-width: 780px; margin: 6px auto 0; }
}

/* ---------------------------------------------------------------- phones */
@media (max-width: 720px) {
  .bt-fab { right: 16px; bottom: 16px; width: 54px; height: 54px; }
  .bt-fab .bt-mark { width: 36px; height: 28px; }
  .bt-bubble { right: 16px; bottom: 86px; }
  .bt-bubble::after { right: 20px; }
  /* the window becomes a full-screen sheet; the launcher would sit on its composer */
  .btc-shell { inset: 0; width: auto; height: auto; transform: translateY(24px); transform-origin: 50% 100%; }
  .btc-shell .btc { border: 0; border-radius: 0; box-shadow: none; }
  body.btc-locked .bt-fab { display: none; }
  .btc .btc-input { font-size: 16px; } /* below 16px iOS zooms the page on focus */
}
