/*
 * Locomotiva — mobile-first dark theme.
 *
 * Layout is a fixed viewport (100dvh) with a scrolling thread between a pinned
 * topbar and a pinned composer. dvh rather than vh because iOS Safari's URL bar
 * collapses and vh does not follow it, which would otherwise hide the composer.
 */

:root {
  --bg: #0b1020;
  --bg-2: #121a33;
  --bg-3: #18213f;
  --line: #243156;
  --fg: #e8ecf7;
  --fg-dim: #98a3c4;
  --accent: #4b8cff;
  --accent-2: #7bd0a5;
  --danger: #ff6b6b;
  --warn: #ffb454;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px; /* < 16px makes iOS zoom on focus */
  line-height: 1.5;
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ── Brand ──────────────────────────────────────────────────────────────── */

.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.brand-row--lg {
  margin-bottom: 18px;
}

/* No fixed height here. Under border-box a height plus padding-top leaves a
   content box shorter than the logos, which silently crops them. Let the row
   size to its tallest child and control spacing with padding alone. */
.brand-row--foot {
  gap: 10px;
  padding: 8px 0 2px;
  opacity: 0.45;
}

.brand-row--foot .brand-div {
  height: 12px;
}

.brand-row--lg .brand-div {
  height: 34px;
}

.brand-div {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.logo {
  display: block;
  object-fit: contain;
}

.logo-loco {
  height: 24px;
}
/* The Locomotiva asset is a vertical lockup (glyph over wordmark), so it needs
   roughly double the height of the others to read at the same optical weight.
   The footer uses locomotiva-mark.png — the glyph alone — which does not. */
.logo-locomotiva {
  height: 46px;
}
/* No `color` here — bt-logo.svg is an <img>, so it cannot inherit it. The mark's
   colour is set inside the file itself. */
.logo-bt {
  height: 22px;
}
.logo.sm {
  height: 18px;
}
.logo.xs {
  height: 16px;
}
.brand-row--foot .logo-bt {
  height: 14px;
}

/* ── Login ──────────────────────────────────────────────────────────────── */

.login {
  display: grid;
  place-items: center;
  height: 100vh;
  height: 100dvh;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #16224a 0%, var(--bg) 60%);
}

.login-card {
  width: min(380px, 100%);
  padding: 28px 24px calc(24px + var(--safe-b));
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.login-card input {
  width: 100%;
  margin: 18px 0 12px;
  padding: 13px 14px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 13px;
  font-weight: 600;
  color: #06122b;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
}

.login-card button:disabled {
  opacity: 0.55;
}

/* Face ID unlock sits under the primary (password) button as the secondary
 * door: same shape, ghost styling so the eye still reads Unlock as the default.
 * `.login-card .passkey-btn` outranks `.login-card button` by class count, so
 * the accent fill loses without needing !important. */
.login-card .passkey-btn {
  margin-top: 10px;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--line);
}

.muted {
  margin: 4px 0 0;
  color: var(--fg-dim);
  font-size: 14px;
}
.tiny {
  font-size: 12px;
  margin-top: 14px;
}
.error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
}

/* ── App shell ──────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 8px) 10px 8px;
  background: rgba(11, 16, 32, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar-title {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
}

#session-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Short session id in the header — tap copies the full one. Kept small and
   dim: it is a handle for pointing at a thread, not the title itself. */
.session-id {
  flex: none;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}
.session-id:active {
  color: var(--fg);
  border-color: var(--fg-dim);
}

/* Context meter — the window-fill chip next to the session id. The bar shows
   used/max against the autocompact window; colour walks green→amber→red as
   the turn grows, red near the compaction threshold. */
.ctx-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.ctx-chip:active {
  color: var(--fg);
  border-color: var(--fg-dim);
}
.ctx-chip.ctx-refresh {
  opacity: 0.55;
}
.ctx-chip .ctx-bar {
  width: 26px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
  flex: none;
}
.ctx-chip .ctx-fill {
  height: 100%;
  border-radius: 3px;
  background: #3fbf7f;
  transition: width 0.3s ease;
}
.ctx-chip.warn .ctx-fill { background: #d8b23a; }
.ctx-chip.hot .ctx-fill { background: #d8564a; }
.ctx-chip.hot { color: #e8837a; border-color: rgba(216, 86, 74, 0.5); }
/* the moment auto-compact reset the window — draw the eye once */
.ctx-chip.flash {
  animation: ctx-flash 0.8s ease;
}
@keyframes ctx-flash {
  0% { background: rgba(63, 191, 127, 0.25); border-color: #3fbf7f; }
  100% { background: var(--bg-2); border-color: var(--line); }
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  border-radius: 10px;
  flex: none;
}

.icon-btn:active {
  background: var(--bg-3);
}

.icon-btn[aria-pressed='true'] {
  color: var(--accent-2);
}

/* The speaker "waves" only make sense when read-aloud is on. */
#tts-btn[aria-pressed='false'] #tts-waves {
  opacity: 0.25;
}

.icon-btn.mic.listening {
  color: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.4;
  }
}

/* ── Drawer ─────────────────────────────────────────────────────────────── */

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: min(320px, 86vw);
  height: 100vh;
  height: 100dvh;
  padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px);
  background: var(--bg-2);
  border-right: 1px solid var(--line);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.session-list {
  flex: 1;
  margin: 8px -6px;
  padding: 0 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.drawer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px 0;
  color: var(--fg-dim);
  font-size: 13px;
}

.drawer-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.session-search {
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  -webkit-appearance: none;
  appearance: none;
}
.session-search:focus {
  outline: none;
  border-color: var(--accent);
}

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 10px;
  margin-bottom: 4px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
}

.session-item.active {
  background: var(--bg-3);
  border-color: var(--line);
}

.session-item .si-main {
  flex: 1;
  min-width: 0;
}

.session-item .si-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 14px;
}

.session-item .si-date {
  color: var(--fg-dim);
  font-size: 12px;
}

.si-del {
  flex: none;
  padding: 4px 8px;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  font-size: 16px;
}

.drawer-foot {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.drawer-foot .meta {
  margin-bottom: 10px;
  color: var(--fg-dim);
  font-size: 12px;
  font-family: var(--mono);
  line-height: 1.6;
}

.ghost-btn {
  padding: 8px 12px;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
}

.ghost-btn.danger {
  width: 100%;
  color: var(--danger);
}

/* ── Passkeys (drawer) ───────────────────────────────────────────────────
 * The enroll hint and the device list live in .drawer-foot, above the engine
 * meta. Kept visually quiet — it is a settings surface, not the conversation. */
.passkeys {
  margin-bottom: 12px;
}

.pk-hint {
  position: relative;
  margin-bottom: 8px;
}

.pk-hint .ghost-btn {
  width: 100%;
  text-align: left;
  padding-right: 30px;
}

.pk-dismiss {
  position: absolute;
  top: 0;
  right: 0;
  width: 28px;
  height: 100%;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  font-size: 16px;
  line-height: 1;
}

.pk-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.pk-info {
  flex: 1;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.pk-revoke {
  flex: none;
  padding: 5px 9px;
  font-size: 12px;
  color: var(--danger);
}

.pk-wipe {
  margin-top: 10px;
}

/* ── Thread ─────────────────────────────────────────────────────────────── */

.thread {
  flex: 1;
  padding: 14px 12px 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.msg {
  max-width: 44rem;
  margin: 0 auto 14px;
}

/* Bubbles are fully selectable — cursor drag, ⌘C, the native right-click copy,
   and the iOS/Android long-press selection all work. The custom message menu
   deliberately does not ride the text-selection gesture: desktop opens it on
   right-click only when nothing is selected, and touch opens it from the "⋯"
   under the bubble. (Suppressing selection here to feed a hand-timed long-press
   menu is what broke copy/paste once before.) */

/* The touch route to the message menu. Deliberately quiet — it sits under the
   bubble rather than over it — but a full 28px tall so it is a real touch
   target, because on touch the long press belongs to native text selection and
   this is the way in. */
.msg-actions {
  display: block;
  width: -webkit-fit-content;
  width: fit-content;
  min-height: 28px;
  margin-top: 1px;
  padding: 0 10px;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  font-size: 18px;
  line-height: 26px;
  opacity: 0.5;
}

.msg-actions:active {
  opacity: 1;
}

.msg.user .msg-actions {
  margin-left: auto;
}

/* Images sent with a message. */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.msg-images img {
  max-width: 180px;
  max-height: 180px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: zoom-in; /* click opens full-size (same as .md-img) */
}

.msg-imgnote {
  margin-bottom: 6px;
  font-size: 12px;
  opacity: 0.7;
}

/* "arrived mid-turn" — on prompts the transcript says the model folded into a
   running turn, so reopen shows which send steered what. */
.injected-tag {
  font-size: 10.5px;
  opacity: 0.65;
  margin-bottom: 3px;
  letter-spacing: 0.02em;
}

.msg.user .bubble {
  margin-left: auto;
  max-width: 88%;
  padding: 10px 14px;
  background: var(--accent);
  color: #06122b;
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.assistant .bubble {
  padding: 2px 2px;
  overflow-wrap: anywhere;
}

.msg.system .bubble {
  padding: 8px 12px;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}

.msg.system.error .bubble {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.4);
}

/* The gap between "Sent" and the first sign of work has no real content to
   show, so it shows honest uncertainty instead of a dead screen. */
.msg.system.waiting .bubble {
  display: inline-flex;
  gap: 6px;
  padding: 12px 13px;
}
.msg.system.waiting .bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-dim);
  animation: wait-bounce 1.1s ease-in-out infinite;
}
.msg.system.waiting .bubble i:nth-child(2) {
  animation-delay: 0.15s;
}
.msg.system.waiting .bubble i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes wait-bounce {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .msg.system.waiting .bubble i {
    animation: none;
    opacity: 0.6;
  }
}

/* A prompt sitting in the queue behind the running turn — dashed to read as
   "not yet inked", with the cancel affordance beside the bubble. */
.msg.system.queued {
  display: flex;
  gap: 8px;
  align-items: center;
}
.msg.system.queued .bubble {
  border-style: dashed;
  flex: 1;
}
.q-cancel {
  flex: none;
  align-self: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--fg-dim);
  font-size: 13px;
}
.q-cancel:disabled {
  opacity: 0.4;
}

/* Minimal markdown rendering — enough for the answers this agent gives. */
.bubble p {
  margin: 0 0 10px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.bubble li {
  margin-bottom: 4px;
}
.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 16px 0 8px;
  font-size: 16px;
}
.bubble code {
  padding: 1px 5px;
  background: var(--bg-3);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 0.88em;
}
.bubble pre {
  margin: 0 0 10px;
  padding: 12px;
  overflow-x: auto;
  background: #060a16;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.bubble pre code {
  padding: 0;
  background: none;
  font-size: 13px;
  line-height: 1.45;
}
.bubble a {
  color: var(--accent);
  /* explicit, not left to the UA default — bare-URL autolinks must read as
     links on every engine (agent replies are link-heavy) */
  text-decoration: underline;
}
.bubble blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--line);
  color: var(--fg-dim);
}
.bubble hr {
  margin: 14px 0;
  border: none;
  border-top: 1px solid var(--line);
}
/* display:block so a wide table scrolls sideways on a phone instead of
   crushing every column into the viewport width. */
.bubble table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 10px;
  border-collapse: collapse;
  font-size: 13px;
}
.bubble th,
.bubble td {
  padding: 5px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.bubble th {
  background: var(--bg-3);
}
.bubble li > ul,
.bubble li > ol,
.bubble ul ul,
.bubble ol ol,
.bubble ul ol,
.bubble ol ul {
  margin: 2px 0 0;
}

/* The blinking caret while tokens are still arriving. */
.streaming::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ── Tool + thinking blocks ─────────────────────────────────────────────── */

.tool,
.think {
  max-width: 44rem;
  margin: 0 auto 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.tool > summary,
.think > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: var(--fg-dim);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}

.tool > summary::-webkit-details-marker,
.think > summary::-webkit-details-marker {
  display: none;
}

.tool > summary::before,
.think > summary::before {
  content: '▸';
  font-size: 11px;
}

.tool[open] > summary::before,
.think[open] > summary::before {
  content: '▾';
}

.tool .t-name {
  color: var(--accent-2);
  font-family: var(--mono);
  font-weight: 600;
}

.tool.err .t-name {
  color: var(--danger);
}

.tool .t-arg {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: 12px;
  opacity: 0.75;
}

.tool .t-spin {
  flex: none;
  animation: blink 1s steps(2, start) infinite;
}

.tool pre,
.think .t-body {
  margin: 0;
  padding: 10px 12px;
  max-height: 45vh;
  overflow: auto;
  background: #060a16;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.think .t-body {
  font-family: var(--sans);
  color: var(--fg-dim);
  font-style: italic;
}

/* ── Composer ───────────────────────────────────────────────────────────── */

.composer-wrap {
  padding: 6px 10px calc(var(--safe-b) + 8px);
  background: rgba(11, 16, 32, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  padding: 6px 12px;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

/* Staged attachments, above the composer so they are clearly part of the next
   message rather than of the conversation so far. */
.attachments {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.attachments::-webkit-scrollbar {
  display: none;
}

.att {
  position: relative;
  flex: none;
}

.att img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.att-x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 1;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 15px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
}

.composer textarea {
  flex: 1;
  max-height: 40vh;
  padding: 9px 4px;
  color: var(--fg);
  background: transparent;
  border: 0;
  resize: none;
  font: inherit;
  line-height: 1.4;
}

.composer textarea:focus {
  outline: none;
}

.send-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  color: #06122b;
  background: var(--accent);
  border: 0;
  border-radius: 50%;
}

.send-btn:disabled {
  opacity: 0.35;
}

.send-btn.stop {
  background: var(--danger);
  color: #2b0606;
}

/* Two icon buttons now share the composer with the text; keep them compact so a
   narrow phone still has a usable typing area. */
.composer .icon-btn {
  width: 38px;
  height: 38px;
  flex: none;
}

/* The speaker pulses while it is actually reading, so "is it broken or is it
   just quiet?" is answerable at a glance. */
.icon-btn.speaking {
  color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

/* ── Long-press message menu ────────────────────────────────────────────── */

#msg-menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.msg-menu {
  position: fixed;
  z-index: 41;
  display: flex;
  flex-direction: column;
  min-width: 168px;
  padding: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.msg-menu button {
  padding: 12px 14px;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 8px;
  text-align: left;
  font: inherit;
  font-size: 15px;
}

.msg-menu button:active {
  background: var(--bg-2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 84px);
  z-index: 50;
  transform: translateX(-50%);
  padding: 8px 16px;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
}

/* ── Desktop ────────────────────────────────────────────────────────────── */

@media (min-width: 900px) {
  /* Every direct child of .app must be placed explicitly. The telemetry
     strip (2026-10-04) is a later child of .app that the original grid never
     mentioned, so auto-placement stole the 1fr row from the thread: the
     thread fell into an implicit auto row, grew to its full content height,
     and pushed the composer off-screen under a clipped chat. */
  .app {
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: auto 1fr auto;
  }

  /* The drawer stops being an overlay and becomes a permanent sidebar. */
  .drawer {
    position: static;
    display: flex !important;
    width: 300px;
    flex: none;
    grid-row: 1 / 4;
    grid-column: 1;
    height: 100vh;
    height: 100dvh;
  }

  .drawer-scrim {
    display: none !important;
  }

  #menu-btn {
    display: none;
  }

  .app > .topbar {
    grid-column: 2;
    grid-row: 1;
  }

  /* Same cell as the thread: the strip still fades over the top of the chat
     and the thread scrolls beneath it, exactly like on the phone. */
  .app > .tele-bar {
    grid-column: 2;
    grid-row: 2;
    margin-bottom: 0; /* the flow overlap trick is meaningless in grid */
  }

  .app > .thread {
    grid-column: 2;
    grid-row: 2;
    padding: 20px 24px 8px;
  }

  .app > .composer-wrap {
    grid-column: 2;
    grid-row: 3;
    padding: 8px 24px 16px;
  }
}

/* ── Standalone PWA ─────────────────────────────────────────────────────── */

/* An installed PWA has no collapsing URL bar for dvh to chase, and iOS
 * standalone WebKit is known to report 100dvh as the *safe* area rather than
 * the whole window — which leaves a strip of dead background under the
 * composer and floats the input off the bottom edge. Pin the full-height
 * surfaces to the layout viewport instead; the status bar and home indicator
 * are already kept clear by the safe-area padding used throughout. Flagged
 * with a class from the inline boot script (same navigator.standalone guard as
 * the install hint), because iOS before 15.4 has no display-mode media query. */
.pwa .app,
.pwa .login,
.pwa .drawer {
  height: 100vh;
}

/* Install affordance on the login card. Hidden unless the browser offers a real
   install (beforeinstallprompt) — on iOS the adjacent hint text is shown instead,
   since Add to Home Screen cannot be triggered programmatically. */
.install-btn {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* ── Question cards (elicitation) ───────────────────────────────────────── */

/*
 * The agent parks a live turn until one of these is answered, so it must read
 * as an interruption, not as another message: warm-bordered card, tappable
 * options sized for a thumb, and a locked "done" state once answered.
 */
.ask-card {
  max-width: 44rem;
  margin: 0 auto 8px;
  background: var(--bg-2);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 12px;
}

.ask-head {
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.ask-q {
  margin-bottom: 10px;
}

.ask-question {
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.ask-chip {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 2px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--accent-2);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.ask-opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}

.ask-opt {
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 14px;
}

.ask-opt.on {
  border-color: var(--accent);
  background: rgba(75, 140, 255, 0.16);
}

.ask-other {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 14px;
}

.ask-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--fg-dim);
  font-size: 13px;
}

.ask-send {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  border: 0;
  color: #06122e;
  font-weight: 700;
  font-size: 14px;
}

.ask-send:disabled {
  opacity: 0.4;
}

.ask-skip {
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  font-size: 14px;
}

.ask-card.done {
  border-color: var(--line);
  opacity: 0.75;
}

.ask-card.done .ask-head {
  color: var(--fg-dim);
}

/* ── Drawer live-status dots ────────────────────────────────────────────── */

.si-dot {
  flex: none;
  width: 16px;
  text-align: center;
  font-size: 10px;
  color: var(--fg-dim);
}

.si-dot.working {
  color: var(--accent-2);
  animation: blink 1.4s steps(2, start) infinite;
}

.si-dot.idle {
  opacity: 0.45;
}

.si-dot.asking {
  font-size: 13px;
}

/* ── Images in replies (show_image) ─────────────────────────────────────── */

img.md-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  cursor: zoom-in;
  background: var(--bg-3);
}

.img-caption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--fg-dim);
}

/* show_media players (2026-10-04) */
video.md-video {
  display: block;
  width: 100%;
  max-height: 70dvh;
  border-radius: 10px;
  background: #000;
}
audio.md-audio {
  display: block;
  width: 100%;
  margin: 4px 0;
}
.media-bar { display: flex; gap: 8px; margin-top: 6px; }
.media-bar button {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--fg);
  font: 500 12.5px var(--sans);
}
.media-bar button:disabled { opacity: 0.6; }
.media-bar .media-share { border-color: var(--accent); color: var(--accent); }

/* ── Collapsed pre-compaction history ───────────────────────────────────── */

details.precompact {
  margin: 8px auto 12px;
  max-width: 640px;
  padding: 0 12px;
}

details.precompact > summary {
  color: var(--fg-dim);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  text-align: center;
  padding: 6px 0;
}

details.precompact > summary::-webkit-details-marker {
  display: none;
}

details.precompact > summary::before {
  content: '⌄ ';
}

details.precompact[open] > summary::before {
  content: '⌃ ';
}

/* The bubbles inside keep their own layout; the wrapper just dims the fact
   that this stretch is old, and the thread divider says where it ends. */
details.precompact .pre-body {
  opacity: 0.65;
}

/* ── Resend after a stopped turn ────────────────────────────────────────── */

.msg.system .resend-btn {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font: inherit;
  cursor: pointer;
}

.msg.system .resend-btn[disabled] {
  opacity: 0.5;
}

/* ── Push bell ──────────────────────────────────────────────────────────── */

/* Subscribed: fill the bell's clapper hint with the accent. aria-pressed
   already tints the glyph via .icon-btn[aria-pressed='true']. */
#push-btn.on svg {
  filter: drop-shadow(0 0 4px var(--accent-2));
}

/* ── Engine (GPU stack) menu in the drawer footer ── */
.drawer-foot .engine {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}
.engine-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.engine-status { font-family: var(--mono); font-size: 12px; text-align: right; }
.engine-status.ok { color: #6fd38d; }
.engine-status.busy { color: var(--warn); }
.engine-status.off { color: var(--fg-dim); }
.engine-row { display: flex; gap: 6px; align-items: center; }
.engine-row select {
  flex: 1; min-width: 0;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font: inherit;
}
.engine-row .ghost-btn { white-space: nowrap; }
.engine-row .ghost-btn:disabled { opacity: 0.5; }
#engine-desc { margin-top: 6px; line-height: 1.3; }

/* ── Two-card engine panel (2026-10-04) ── */
.engine-card { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); }
.engine-card-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.engine-card-name { font-weight: 600; }
.engine-card-state { font-family: var(--mono); font-size: 11.5px; text-align: right; color: var(--fg-dim); }
.engine-card-state.ok { color: #6fd38d; }
.engine-card-state.busy { color: var(--warn); }
.engine-row select option:disabled { color: #777; }

/* ── Header telemetry chip ── */
.tele-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  cursor: pointer;
  white-space: nowrap;
}
.tele-chip b { font-weight: 600; color: var(--fg); }
.tele-chip .hot { color: var(--warn); }
.tele-chip .crit { color: var(--danger); }
.tele-chip .dim { opacity: 0.6; }
@media (max-width: 480px) { .tele-chip .opt { display: none; } }

/* ── Denser chat text (2026-10-04, operator request). Inputs stay 16px so iOS does not zoom. ── */
.msg .bubble { font-size: 14px; line-height: 1.45; }
.msg .bubble pre, .msg .bubble code { font-size: 12.5px; }

/* ── Telemetry strip (2026-10-04, v2): fades over the top of the thread, Claude-app style ── */
.tele-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  height: 50px;
  margin-bottom: -50px;           /* the thread starts underneath and scrolls beneath the fade */
  padding: 3px 6px 0 6px;
  pointer-events: none;           /* only the two buttons catch taps; the fade itself is see-through */
  background: linear-gradient(to bottom, rgba(11, 16, 32, 0.97) 0%, rgba(11, 16, 32, 0.9) 45%, rgba(11, 16, 32, 0) 100%);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
}
.tele-main {
  pointer-events: auto;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0;
  padding: 7px 2px 4px;
  border: 0;
  background: none;
  color: var(--fg-dim);
  font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: left;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.tele-main::-webkit-scrollbar { display: none; }
.tele-main:empty { visibility: hidden; }
.tele-bar .seg { display: inline-flex; align-items: baseline; gap: 3px; white-space: nowrap; }
.tele-bar .lbl { font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.75; }
.tele-bar b { font-weight: 600; color: var(--fg); font-size: 13px; }
.tele-bar .w { color: var(--fg-dim); }
.tele-bar .hot b { color: var(--warn); }
.tele-bar .crit b { color: var(--danger); }
.tele-bar .dot { width: 6px; height: 6px; border-radius: 50%; background: #6fd38d; display: inline-block; }
.tele-bar .dot.off { background: #556; }
.tele-bar .dot.hot { background: var(--warn); }
.tele-bar .dot.crit { background: var(--danger); }
.tele-dots {
  pointer-events: auto;
  position: relative;
  flex: none;
  width: 38px;
  height: 30px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--fg-dim);
}
.tele-dots:active { background: rgba(255, 255, 255, 0.14); }
.tele-dots.busy { color: var(--accent-2); }
.tele-dots .badge {
  position: absolute;
  top: -4px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent-2);
  color: #0b1020;
  font: 700 11px/17px var(--sans);
  text-align: center;
  animation: act-pulse 1.4s ease-in-out infinite;
}
body.has-tele .thread { padding-top: 54px; }

/* ── Activity sheet (••• in the strip) ── */
.act-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.45); }
.act-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  display: flex;
  flex-direction: column;
  max-height: 72dvh;
  margin: 0 auto;
  max-width: 44rem;
  padding: 8px 14px calc(var(--safe-b) + 14px);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: act-up 0.18s ease-out;
}
@keyframes act-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes act-pulse { 50% { opacity: 0.35; } }
.act-head { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; }
.act-h { flex: none; font-size: 15px; font-weight: 600; }
.act-head .muted { flex: 1; }
.act-body { overflow-y: auto; min-height: 60px; -webkit-overflow-scrolling: touch; }
.act-sec { margin: 10px 0 6px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-dim); }
.act-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.act-dot { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--accent-2); }
.act-row.running .act-dot { animation: act-pulse 1.2s ease-in-out infinite; }
.act-row.failed .act-dot, .act-row.killed .act-dot, .act-row.stopped .act-dot { background: var(--danger); animation: none; }
.act-row.completed .act-dot { background: #556; animation: none; }
.act-main { flex: 1; min-width: 0; }
.act-title { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.act-meta, .act-sum { margin-top: 2px; font-size: 12px; color: var(--fg-dim); }
.act-sum { font-style: italic; }
.act-time { flex: none; margin-top: 2px; font: 12px var(--mono); color: var(--fg-dim); }
.act-empty { padding: 12px 4px; font-size: 14px; }

/* ── Subagent tool calls nested in the Agent card ── */
.tool .t-sub { flex: none; margin-left: 6px; font-size: 11px; color: var(--accent-2); }
.tool .sub-tools { list-style: none; margin: 4px 0 6px; padding: 0 0 0 8px; border-left: 2px solid var(--line); }
.tool .sub-tool { display: flex; gap: 6px; align-items: baseline; min-width: 0; padding: 2px 0; font: 12px var(--mono); color: var(--fg-dim); }
.tool .sub-tool .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: act-pulse 1.2s infinite; }
.tool .sub-tool.done .dot { background: #556; animation: none; }
.tool .sub-tool.err .dot { background: var(--danger); animation: none; }
.tool .sub-tool .sn { flex: none; color: var(--fg); }
.tool .sub-tool .sa { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Drawer footer: sessions first, controls folded (2026-10-04) ── */
.drawer-foot { max-height: 55dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.foot-section { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.foot-section > summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
}
.foot-section > summary::-webkit-details-marker { display: none; }
.foot-section > summary::before { content: '▸'; margin-right: 6px; color: var(--fg-dim); font-size: 11px; }
.foot-section[open] > summary::before { content: '▾'; }
.foot-title { font-weight: 600; }
.foot-summary { font-family: var(--mono); font-size: 11.5px; color: var(--fg-dim); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.foot-section > :not(summary) { padding: 0 10px 10px; }
.drawer-foot .engine { margin: 0; padding: 0; border: 0; }
.drawer-foot .meta { margin: 6px 0 0; }

/* engine rows: no wrapping of names, compact state text */
.drawer-foot .engine-head { justify-content: flex-start; margin: 4px 0 2px; }
.drawer-foot .engine-status { text-align: left; font-size: 11.5px; }
.engine-card-head { align-items: baseline; }
.engine-card-name { white-space: nowrap; flex: none; }
.engine-card-state { font-size: 11px; max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.engine-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* stack banner + preset row (2026-10-09) */
.stack-banner {
  margin: 0 12px 8px;
  padding: 10px 12px;
  border: 1px solid var(--accent, #e0b64a);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent, #e0b64a) 12%, transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92em;
}
.stack-banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.engine-preset-row { margin-bottom: 8px; }
