/* mobile.css — the mobile web app's OWN stylesheet. Self-contained: real Inter
 * font, real token VALUES (copied from the design system, not invented), real
 * button, and the mobile layout. NO desktop CSS. */

/* ── Real font (so type isn't the thin system fallback) ───────────────────── */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(/fonts/Inter-latin.woff2) format('woff2');
}

/* ── Tokens (values from the design system) ───────────────────────────────── */
:root, [data-theme="light"] {
  color-scheme: light;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f0f0f0;
  --border: #e5e5e5;
  --border-2: #d4d4d4;
  --text: #1f2937;
  --text-2: #4b5563;
  --text-3: #6b7280;
  --text-faint: #9ca3af;
  --white: #111111;
  --hover: #f0f0f0;
  --accent: #af5fff;
  --accent-hover: #c184ff;
  --accent-text: #cda2ff;
  --accent-bg: #f5ecfd;
  --success: #16a34a;        /* connected-green (matches styles.css light) */
  --danger: #e5484d;         /* matches styles.css light */
  --warning: #f59e0b;        /* needs-input amber (matches desktop .input) */
  --overlay-bg: rgba(0, 0, 0, 0.3);
  --grad-accent: linear-gradient(to top right, #af5fff, #ec4899);
  --radius: 10px;
  --radius-sm: 8px;
  --transition: 0.15s ease;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1a1c;
  --surface: #252528;
  --surface-2: #2e2e32;
  --surface-3: #29292c;
  --border: #3f3f46;
  --border-2: #4a4a52;
  --text: #f1f1f1;
  --text-2: #c4c4c4;
  --text-3: #a7a7a7;
  --text-faint: #808080;
  --white: #ffffff;
  --hover: #303035;
  --accent: #af5fff;
  --accent-hover: #c184ff;
  --accent-text: #cda2ff;
  --accent-bg: #241a2e;
  --success: #3fb950;        /* connected-green (matches styles.css dark) */
  --danger: #f85149;         /* matches styles.css dark */
  --warning: #f59e0b;        /* needs-input amber (matches desktop .input) */
  --overlay-bg: rgba(0, 0, 0, 0.6);
}
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100dvh; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
#glyphh-mobile-root { height: 100dvh; }

/* ── Button (the real .btn-primary) ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font: 600 0.8125rem var(--font-sans);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-lg { padding: 0.875rem 1.25rem; font-size: 0.9375rem; border-radius: 10px; }
.btn-primary {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  /* Theme's primary CONTRAST — white pill in dark, black pill in light — never a
     hardcoded colour, so it stays legible in every theme. Accent lives only in
     the gradient sweep on press (::before). */
  background: var(--white);
  color: var(--bg);
  border: none;
}
.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--grad-accent);
  transform: translateX(-100%);
}
.btn-primary:hover:not(:disabled)::before,
.btn-primary:active:not(:disabled)::before { transform: translateX(0); transition: transform 280ms ease; }

/* ── App frame ── */
.m-app { position: fixed; inset: 0; overflow: hidden; background: var(--surface); }

/* PHONE: rail + main sit in a shell that SLIDES to push the content out — the
   rail never overlaps. The overshoot easing gives open/close a "bump". */
.m-shell {
  display: flex;
  height: 100%;
  width: calc(300px + 100vw);
  transform: translateX(-300px);
  transition: transform 0.36s cubic-bezier(0.34, 1.4, 0.5, 1);
  will-change: transform;
}
.m-app[data-drawer="open"] .m-shell { transform: translateX(0); }

.m-rail {
  flex: 0 0 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0 3px 0 calc(var(--safe-left) + 3px);
}
.m-main { flex: 0 0 100vw; width: 100vw; display: flex; flex-direction: column; background: var(--bg); position: relative; }

.m-rail-brand { display: flex; align-items: center; padding: 14px 0 8px 26px; }
.m-wordmark { height: 30px; width: auto; display: block; }

/* + New Session — the one primary action, full-width under the wordmark. */
.m-rail-new { width: auto; margin: 6px 14px 4px; justify-content: center; }
.m-rail-new svg { width: 18px; height: 18px; }

/* Blurs the pushed-out content while the drawer is open; tap to close. */
.m-scrim {
  position: absolute;
  inset: 0;
  z-index: 8;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  background: color-mix(in srgb, var(--bg) 22%, transparent);
}
.m-app[data-drawer="open"] .m-scrim { opacity: 1; pointer-events: auto; }

/* Splash on load — the full brand logo (swapped by theme), fading to the app. */
.m-splash {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: var(--bg);     /* exactly like the desktop #splash */
  display: grid;
  place-items: center;
  animation: m-splash-out 2.2s ease forwards;
}
/* The desktop splash's flowing-data-streams backdrop (#splash-flow), behind
   the wordmark. The canvas paints its own tint + vignette. */
.m-splash-flow { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
@keyframes m-splash-out { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.m-splash-logo {
  grid-area: 1 / 1;
  position: relative;
  z-index: 1;                /* above the vignette */
  width: 288px;
  max-width: 76vw;
  height: auto;
  display: block;
}
/* The muse ground is always dark → always the white wordmark. */
.m-splash-logo-black { display: none; }
.m-splash-logo-white { display: block; }

/* Rail destination(s) — the single Connections shortcut. */
.m-rail-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.m-nav-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  font: 700 22px/1 var(--font-sans);
  text-align: left;
  cursor: pointer;
}
.m-nav-item:hover { background: var(--hover); color: var(--text); }
.m-nav-item[aria-current="page"] { background: var(--hover); }
.m-nav-item svg { width: 25px; height: 25px; flex: 0 0 25px; }

/* Recents. */
.m-recents { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 20px; }
.m-recents-label {
  padding: 0 14px 10px;
  font: 700 14px/1 var(--font-sans);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.m-recents-list { overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.m-recent {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  text-align: left;
  cursor: pointer;
}
/* The session's locus glyph beside its title (same laptop/cloud as All Sessions). */
.m-recent-locus { display: inline-flex; flex: 0 0 auto; color: var(--text-3); margin-right: 7px; }
.m-recent-locus svg { width: 13px; height: 13px; }

.m-recent:hover { background: var(--hover); }
.m-recent-title {
  font: 600 22px/1.3 var(--font-sans);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* "All Chats ›" — under the last recent; opens the sessions list in main. */
.m-all-chats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 11px 14px;
  margin-top: 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-faint);
  font: 700 14px/1 var(--font-sans);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}
.m-all-chats:hover { background: var(--hover); color: var(--text); }
.m-all-chats svg { width: 15px; height: 15px; flex: 0 0 15px; opacity: 0.7; }

/* Rail footer: profile circle (left) + New Chat right-justified. */
.m-rail-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 12px 8px calc(var(--safe-bottom) + 14px) 14px;
  border-top: 1px solid var(--border);
}
.m-avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  background: var(--surface-3);
  color: var(--text-2);
  font: 600 13px/1 var(--font-sans);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.m-avatar:hover { color: var(--text); }
/* The profile avatar inside the rail chip — fills the circle; a load error
   hides it and the initials underneath take over (his report, 2026-09-01). */
.m-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.m-rail-footer .btn { margin-left: auto; }
/* Org switcher (multi-org members) — sits beside the avatar in the rail footer. */
.m-org-switch {
  flex: 1; min-width: 0; height: 34px; border-radius: 8px;
  border: 1px solid var(--border-2); background: var(--surface-3);
  color: var(--text); font: 500 13px var(--font-sans); padding: 0 8px;
}
.m-rail-footer .btn svg { width: 18px; height: 18px; }

/* Main content — no header; fills from the top. */
.m-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px calc(var(--safe-bottom) + 16px);
}

/* New-chat home — the agent's ghost empty state. VERBATIM from the app's
   .code-ghost / .code-ghost-mark / .code-ghost-quote (help/code.ts). */
.m-home { position: relative; height: 100%; display: flex; flex-direction: column; }
.m-ghost {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}
.m-ghost-mark {
  width: 104px;
  height: 104px;
  opacity: 0.82;             /* the real mascot, lightly softened */
  color: var(--accent);      /* the inline time-of-day mascot SVG is accent-colored */
  user-select: none;
  -webkit-user-drag: none;
}
.m-ghost-mark svg, .m-ghost-mark img { width: 100%; height: 100%; display: block; object-fit: contain; }
.m-ghost-quote {
  max-width: 460px;
  text-align: center;
  color: var(--white);
  opacity: 0.85;
  font-size: 18px;
  line-height: 1.6;
  transition: opacity 0.5s ease;
}

/* Transparent header: the list scrolls UNDER it, blurred beneath the bar.
   Shared by the unified session list, the home screen, and the session view. */
.m-chats-head {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;                 /* title + icons ride ABOVE the top blur band */
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 16px 12px calc(var(--safe-left) + 16px);
  background: transparent;    /* the masked blur band supplies the frost */
}
.m-chats-icon {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.m-chats-icon:active { background: var(--hover); }
.m-chats-icon svg { width: 22px; height: 22px; }
.m-chats-title { flex: 1; text-align: center; font: 700 20px/1 var(--font-sans); color: var(--text); }

/* Loading / empty placeholder for lists + the session message area. */
.m-list-note { padding: 32px 16px; text-align: center; color: var(--text-3); font: 400 16px/1.45 var(--font-sans); }

/* Header blur zone: a backdrop-blurred band that the list scrolls fuzzily under,
   masked so the frost fades out downward. Only used pinned to the TOP (under the
   header) via .m-chats-fade-top — the base holds the shared position/blur.
   pointer-events off so taps fall through. */
.m-chats-fade {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(var(--safe-top) + 56px);
  z-index: 4;
  pointer-events: none;
  -webkit-backdrop-filter: blur(6.5px);
  backdrop-filter: blur(6.5px);
  -webkit-mask-image: linear-gradient(to top, transparent 0%, #000 42%);
  mask-image: linear-gradient(to top, transparent 0%, #000 42%);
}
/* Retained modifier — the base already carries the top values; kept so existing
   `m-chats-fade m-chats-fade-top` markup stays valid. */
.m-chats-fade-top { top: 0; }
/* Bottom blur: the list scrolls fuzzily DOWN under the search bar to the page bottom
   (mirror of the top fade — anchored to the bottom, mask flipped). */
.m-chats-fade-bottom {
  top: auto;
  bottom: 0;
  height: calc(var(--safe-bottom) + 88px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 42%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 42%);
}

/* Floating New chat + bottom search bar (both ride ABOVE the blur zone). */
/* Exact twin of the rail's New Chat button: .btn .btn-primary .btn-lg + 18px
   icon (position/shadow are the only extras). */
.m-fab {
  position: absolute;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 78px);
  z-index: 6;
  box-shadow: 0 6px 20px var(--overlay-bg);
}
.m-fab svg { width: 18px; height: 18px; }
.m-search {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 999px;
  /* Translucent pill — the frosted list shows through behind it. */
  background: color-mix(in srgb, var(--surface-2) 74%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  color: var(--text-faint);
  font: 400 18px/1 var(--font-sans);
}
.m-search svg { width: 20px; height: 20px; }

/* ── Code view: Desktops strip + Sessions list ───────────────────────────── */
/* Header + footer reuse the chats classes (.m-chats-head / .m-chats-fade /
   .m-search / .m-fab); only the scroll body is bespoke. Top/bottom padding
   matches .m-chats-list so content clears the shared header + search. */
.m-code { position: relative; height: 100%; }
.m-code-scroll {
  height: 100%;
  overflow-y: auto;
  padding: calc(var(--safe-top) + 74px) 16px calc(var(--safe-bottom) + 108px) calc(var(--safe-left) + 16px);
}
.m-code-label { font: 500 17px/1 var(--font-sans); color: var(--text-3); margin: 4px 2px 12px; }

/* Desktops — a horizontally-scrollable strip of machine cards. */
.m-desktops {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px 26px;
  padding: 2px 16px;
}
.m-desktops::-webkit-scrollbar { display: none; }
.m-desktop {
  flex: 0 0 auto;
  width: 208px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.m-desktop-icon { position: relative; width: 30px; height: 30px; color: var(--text-2); margin-bottom: 4px; }
.m-desktop-icon svg { width: 30px; height: 30px; }
.m-desktop-badge {
  position: absolute;
  top: -2px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-faint);
  border: 2px solid var(--surface);
}
.m-desktop[data-status="connected"] .m-desktop-badge { background: var(--success); }
.m-desktop-name { font: 600 21px/1.2 var(--font-sans); color: var(--text); }
.m-desktop-status { font: 500 16px/1 var(--font-sans); color: var(--text-faint); }
.m-desktop[data-status="connected"] .m-desktop-status { color: var(--success); }

/* Sessions — label + filter, then a stack of cards. */
.m-code-sessions-head { display: flex; align-items: center; justify-content: space-between; }
.m-code-filter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  cursor: pointer;
  font: 600 17px/1 var(--font-sans);
  color: var(--text-2);
  margin: 4px 2px 12px;
}
.m-code-filter svg { width: 18px; height: 18px; }

.m-code-list { display: flex; flex-direction: column; gap: 12px; }
.m-code-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.m-code-card:active { background: var(--hover); }
.m-code-thumb {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-code-thumb[data-kind="plain"] { border: 1.6px dashed var(--border-2); background: var(--surface-2); }
.m-code-thumb[data-kind="branch"] { background: var(--accent-bg); color: var(--accent); }
.m-code-thumb svg { width: 22px; height: 22px; }
.m-code-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.m-code-top { display: flex; align-items: baseline; gap: 10px; }
.m-code-name {
  flex: 1;
  min-width: 0;
  font: 600 20px/1.2 var(--font-sans);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-code-when { flex: 0 0 auto; font: 400 15px/1 var(--font-sans); color: var(--text-faint); }
.m-code-meta { display: flex; align-items: center; gap: 6px; font: 400 15px/1 var(--font-sans); color: var(--text-faint); min-width: 0; }
.m-code-meta svg { flex: 0 0 16px; width: 16px; height: 16px; }
.m-code-meta[data-where="connected"] svg { color: var(--success); }
.m-code-state { font-weight: 500; }
.m-code-meta[data-where="connected"] .m-code-state { color: var(--success); }
.m-code-meta[data-where="off"] svg, .m-code-meta[data-where="off"] .m-code-state { color: var(--text-3); }
.m-code-dot { color: var(--text-faint); }
.m-code-loc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Sliding nav stack: home → list slides in from the left; list ↔ session
   slides horizontally. ────────────────────────────────────────────────────── */
.m-nav { position: absolute; inset: 0; overflow: hidden; animation: m-nav-in 0.28s ease; }
@keyframes m-nav-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
/* Home-compose → session: the keyboard is collapsing (vertical viewport settle)
   at the same instant — the horizontal slide composes into a DIAGONAL. Skip it. */
.m-nav[data-noanim="true"] { animation: none; }
.m-nav-track { display: flex; width: 200%; height: 100%; transition: transform 0.3s ease; }
.m-nav[data-screen="session"] .m-nav-track { transform: translateX(-50%); }
.m-nav-panel { flex: 0 0 50%; width: 50%; height: 100%; position: relative; overflow: hidden; }

/* ── Session (agent) view ────────────────────────────────────────────────── */
.m-sv { position: relative; height: 100%; display: flex; flex-direction: column; }
.m-sv-head {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 14px 10px calc(var(--safe-left) + 14px);
  background: var(--overlay-bg);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}
.m-sv-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.m-sv-name {
  max-width: 100%;
  text-align: center;
  font: 700 18px/1.2 var(--font-sans);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-sv-sub { display: inline-flex; align-items: center; gap: 5px; color: var(--text-3); font: 500 12.5px/1 var(--font-sans); }
.m-sv-sub svg { width: 13px; height: 13px; }
.m-sv-changes { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font: 600 12.5px/1 ui-monospace, monospace; cursor: pointer; }
.m-sv-changes svg { width: 14px; height: 14px; color: var(--text-3); }
.m-sv-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;        /* we pin to the bottom ourselves; don't fight it */
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* Bottom pad clears whichever bottom overlay is TALLER — the floating composer
     (its REAL height, measured into --composer-h, varies with the chips row,
     attachment strip, multi-line input; it already includes safe-bottom) OR the
     frosted fade band (.m-sv-fade = safe-bottom + 118px, which on iPhone is TALLER
     than a single-line composer). Clearing only the composer left the last lines
     buried in the fade/home-indicator zone (his bug: can't see the output summary).
     +28px breathing room so the summary always rests fully above the band. */
  padding: calc(var(--safe-top) + 74px) 16px calc(max(var(--composer-h, 200px), var(--safe-bottom) + 118px) + 28px) calc(var(--safe-left) + 16px);
}
/* Session composer FLOATS over the transcript + frosted band (like the chats
   New chat / search), and the box is translucent-frosted so text fuzzes behind. */
.m-sv .m-composer { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; }
.m-sv .m-composer-box {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}
/* Frosted bottom band — the transcript dissolves upward under the composer. */
.m-sv-fade {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--safe-bottom) + 118px);
  z-index: 5; pointer-events: none;
  -webkit-backdrop-filter: blur(11px);
  backdrop-filter: blur(11px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 38%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 38%, #000 100%);
}
/* Scroll-to-latest — centered, appears only when scrolled up. */
.m-scrolldown {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 126px); z-index: 7;
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border);
  display: grid; place-items: center; cursor: pointer;
  background: color-mix(in srgb, var(--surface-2) 84%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  color: var(--text-2); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}
.m-scrolldown svg { width: 22px; height: 22px; }
.m-msg { max-width: 84%; font: 400 20px/1.5 var(--font-sans); }
.m-msg-user {
  align-self: flex-end;
  padding: 11px 16px;
  border-radius: 20px 20px 6px 20px;
  background: var(--surface-3);
  color: var(--text);
}
.m-msg-glyphh { align-self: flex-start; max-width: 100%; width: 100%; color: var(--text); word-break: break-word; }

/* ── Markdown (agent messages) ───────────────────────────────────────────── */
.m-md { display: flex; flex-direction: column; gap: 12px; font: 400 20px/1.55 var(--font-sans); }
.m-md > :first-child { margin-top: 0; }
.m-md-p { margin: 0; }
.m-md-h { margin: 6px 0 0; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
.m-md-h1 { font-size: 26px; } .m-md-h2 { font-size: 23px; } .m-md-h3 { font-size: 21px; } .m-md-h4 { font-size: 20px; color: var(--text-2); }
.m-md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.m-md strong { font-weight: 700; }
.m-md em { font-style: italic; }
.m-md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.m-md-ul, .m-md-ol { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.m-md-ul { list-style: disc; } .m-md-ol { list-style: decimal; }
.m-md-li { padding-left: 2px; }
.m-md-li::marker { color: var(--text-3); }
/* Task-list items: a real checkbox glyph, marker suppressed. */
.m-md-task { list-style: none; margin-left: -1.4em; display: flex; align-items: flex-start; gap: 10px; }
.m-md-check { flex: 0 0 22px; width: 22px; height: 22px; margin-top: 1px; border-radius: 7px; border: 2px solid var(--border-2); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.m-md-check.on { background: var(--success); border-color: var(--success); }
.m-md-check svg { width: 15px; height: 15px; fill: none; stroke: currentColor; }
.m-md-quote { margin: 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--border-2); color: var(--text-2); }
.m-md-hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.m-md-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 12px; }
.m-md-table { border-collapse: collapse; width: 100%; font-size: 16px; }
.m-md-table th, .m-md-table td { padding: 9px 13px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.m-md-table th { background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.m-md-table tr:last-child td { border-bottom: 0; }

/* ── Code blocks ─────────────────────────────────────────────────────────── */
.m-cb { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface); }
.m-cb-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.m-cb-lang { font: 600 12px/1 var(--font-sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.m-cb-spacer { flex: 1; }
.m-cb-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-2); font: 500 13px/1 var(--font-sans); cursor: pointer; }
.m-cb-btn:active { background: var(--hover); }
.m-cb-btn svg { width: 14px; height: 14px; }
.m-cb-chev { display: inline-flex; transition: transform 0.2s ease; }
.m-cb-chev[data-folded="false"] { transform: rotate(180deg); }
.m-cb-pre { margin: 0; padding: 13px 15px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.m-cb-pre code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14.5px; line-height: 1.6; background: none; border: 0; padding: 0; white-space: pre; color: var(--text); }
.tk-kw { color: var(--accent); font-weight: 600; }
.tk-str { color: var(--success); }
.tk-com { color: var(--text-faint); font-style: italic; }
.tk-num { color: color-mix(in srgb, var(--accent) 55%, var(--text)); }
/* Diff blocks: per-line +/- colouring. */
.m-cb-diff .m-cb-pre code { white-space: pre; }
.df-line { display: block; margin: 0 -15px; padding: 0 15px; }
.df-add { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.df-del { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.df-hunk { color: var(--accent); }
.df-meta { color: var(--text-faint); }
.m-diffbadge { display: inline-flex; gap: 6px; font: 600 12.5px/1 ui-monospace, monospace; }
.m-diff-add { color: var(--success); } .m-diff-del { color: var(--danger); }

/* ── Tool group (Work / Code) ────────────────────────────────────────────── */
.m-tools { border: 1px solid var(--border); border-radius: 13px; background: color-mix(in srgb, var(--surface) 60%, transparent); overflow: hidden; }
.m-tools-head { display: flex; align-items: center; gap: 9px; width: 100%; padding: 11px 14px; background: none; border: 0; cursor: pointer; text-align: left; color: var(--text-2); font: 500 16px/1 var(--font-sans); }
.m-tools-head:active { background: var(--hover); }
.m-tools-chev { display: inline-flex; color: var(--text-3); transition: transform 0.2s ease; }
.m-tools-chev svg { width: 16px; height: 16px; }
.m-tools-chev[data-open="true"] { transform: rotate(90deg); }
.m-tools-summary { flex: 1; }
.m-tools-livedot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: m-pulse 1.1s ease-in-out infinite; }
@keyframes m-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.m-tools-list { list-style: none; margin: 0; padding: 2px 6px 6px; display: flex; flex-direction: column; gap: 1px; }
.m-tool-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 8px; background: none; border: 0; border-radius: 9px; cursor: pointer; text-align: left; color: var(--text); font: 400 15.5px/1.3 var(--font-sans); }
.m-tool-row:active { background: var(--hover); }
.m-tool-glyph { flex: 0 0 18px; display: inline-flex; align-items: center; justify-content: center; }
.m-tool-glyph svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.6; }
.m-tool-ok { color: var(--success); display: inline-flex; }
.m-tool-bad { color: var(--danger); font-weight: 700; }
.m-tool-spin { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-2); border-top-color: var(--accent); animation: m-spin 0.7s linear infinite; }
@keyframes m-spin { to { transform: rotate(360deg); } }
.m-tool-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-tool-row[data-status="denied"] .m-tool-name, .m-tool-row[data-status="failed"] .m-tool-name { color: var(--text-2); }
.m-tool-more { flex: 0 0 16px; color: var(--text-faint); display: inline-flex; }
.m-tool-more svg { width: 16px; height: 16px; }
.m-tool-err { padding: 2px 8px 8px 38px; color: var(--danger); font: 400 13.5px/1.4 ui-monospace, monospace; }

/* Streaming plain text — matches the markdown body font so the swap to formatted
   output on completion isn't jarring. */
/* Interleaved tool-action row (Work/Code): a muted summary + diff + chevron. */
.m-toolrow { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; max-width: 100%; margin: -2px 0; padding: 4px 0; background: none; border: 0; cursor: pointer; text-align: left; }
.m-toolrow:active { opacity: 0.55; }
.m-toolrow-spin { flex: 0 0 13px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-2); border-top-color: var(--accent); animation: m-spin 0.7s linear infinite; }
.m-toolrow-lead { color: var(--text-3); font: 400 19px/1.35 var(--font-sans); }
.m-toolrow-lead code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; color: var(--text-2); }
.m-toolrow-bad .m-toolrow-lead { color: var(--danger); }
.m-toolrow-diff { display: inline-flex; gap: 6px; font: 600 16px/1 ui-monospace, monospace; }
.m-toolrow-chev { display: inline-flex; color: var(--text-faint); }
.m-toolrow-chev svg { width: 17px; height: 17px; }

/* Tool-actions tray (reuses the selector sheet's nested track). */
.m-sel-x { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.m-sel-x svg { width: 18px; height: 18px; }
.m-action-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px 4px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; text-align: left; color: var(--text); font: 500 17px/1.25 var(--font-sans); }
.m-action-row:last-child { border-bottom: 0; }
.m-action-row:active { background: var(--hover); }
.m-action-ico { flex: 0 0 22px; color: var(--text-2); display: inline-flex; }
.m-action-ico svg { width: 20px; height: 20px; }
/* The shared per-app icon (server resolver — same image as desktop/web). */
.m-action-appicon { width: 22px; height: 22px; border-radius: 5px; object-fit: cover; display: block; }
.m-action-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-action-name code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; color: var(--text-2); }
.m-action-chev { flex: 0 0 18px; color: var(--text-faint); display: inline-flex; }
.m-action-chev svg { width: 16px; height: 16px; }
.m-action-file { margin-top: 6px; font: 400 15px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-2); word-break: break-all; }

/* Folder picker (Choose directory) */
.m-fp-cur { padding: 6px 6px 10px; font: 400 13.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-3); word-break: break-all; }
.m-fp-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 4px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; text-align: left; color: var(--text); font: 500 17px/1.2 var(--font-sans); }
.m-fp-row:last-child { border-bottom: 0; }
.m-fp-row:active { background: var(--hover); }
.m-fp-row svg { width: 20px; height: 20px; color: var(--text-3); flex: 0 0 20px; }
.m-fp-up { color: var(--text-2); }
.m-fp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-fp-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 12px 16px calc(var(--safe-bottom) + 14px); border-top: 1px solid var(--border); }
.m-fp-new { display: inline-flex; align-items: center; gap: 6px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font: 600 15px/1 var(--font-sans); cursor: pointer; }
.m-fp-new svg { width: 16px; height: 16px; }
.m-fp-new:disabled { opacity: 0.5; }
.m-fp-choose { flex: 1; justify-content: center; }
.m-fp-create { display: flex; gap: 8px; flex: 1; }
.m-fp-create .m-prompt-input { flex: 1; }

/* Per-message footer: copy affordance + per-turn usage. */
.m-msg-foot { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.m-msg-copy { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 9px; background: none; color: var(--text-3); font: 500 13px/1 var(--font-sans); cursor: pointer; opacity: 0.75; }
.m-msg-copy:active { background: var(--hover); opacity: 1; }
.m-msg-copy svg { width: 14px; height: 14px; }
.m-msg-usage { color: var(--text-faint); font: 400 12.5px/1 var(--font-sans); font-variant-numeric: tabular-nums; }

/* Stop button (replaces send while a turn is streaming) — same primary-contrast
   pill as send, with a square in the page-bg colour so the glyph reads on it. */
.m-composer-stop { background: var(--white); }
.m-stop-sq { width: 15px; height: 15px; border-radius: 4px; background: var(--bg); display: inline-block; }

/* Composer image attachments (pending) + mic listening state. */
.m-attach-strip { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 4px 8px; }
.m-attach-chip { position: relative; width: 62px; height: 62px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.m-attach-chip img { width: 100%; height: 100%; object-fit: cover; }
.m-attach-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,0.6); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.m-attach-x svg { width: 13px; height: 13px; }
.m-mic-live { color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 16%, transparent) !important; animation: m-pulse 1.1s ease-in-out infinite; }
/* Image thumbnails inside a sent user bubble. */
.m-msg-imgs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.m-msg-imgs img { max-width: 160px; max-height: 160px; border-radius: 12px; display: block; }

/* Long-press message action rows. */
.m-act-row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px 8px; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); font: 500 18px/1 var(--font-sans); cursor: pointer; text-align: left; }
.m-act-row:last-child { border-bottom: 0; }
.m-act-row:active { background: var(--hover); }
.m-act-row svg { width: 22px; height: 22px; color: var(--text-2); flex: 0 0 22px; }

/* ── Tool detail tray (rows in the selector-sheet body) ──────────────────── */
.m-tray-kv { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.m-tray-k { flex: 0 0 84px; color: var(--text-3); font: 500 14px/1 var(--font-sans); text-transform: uppercase; letter-spacing: 0.04em; font-size: 12px; }
.m-tray-v { color: var(--text); font: 400 16px/1.3 var(--font-sans); word-break: break-word; }
.m-tray-status { font: 600 14px/1 var(--font-sans); text-transform: capitalize; }
.m-tray-status-ok { color: var(--success); } .m-tray-status-running { color: var(--accent); }
.m-tray-status-failed, .m-tray-status-denied { color: var(--danger); }
.m-tray-block { padding: 12px 4px; }
.m-tray-thought { margin-top: 6px; color: var(--text-2); font: 400 16px/1.5 var(--font-sans); white-space: pre-wrap; }
.m-tray-err { margin-top: 6px; padding: 10px 12px; background: color-mix(in srgb, var(--danger) 10%, transparent); border-radius: 10px; color: var(--danger); font: 400 13.5px/1.5 ui-monospace, monospace; white-space: pre-wrap; overflow-x: auto; }

.m-composer { flex: 0 0 auto; padding: 8px 12px calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px); }
/* Mic failure notice — floats above the composer box; tap to dismiss. */
.m-mic-err {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px;
  padding: 9px 12px; border-radius: 12px; cursor: pointer;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 34%, transparent);
  color: var(--text); font-size: 13px; line-height: 1.35;
}
.m-mic-err svg { width: 16px; height: 16px; flex: 0 0 auto; opacity: 0.75; }
.m-mic-err span { flex: 1; min-width: 0; }
.m-composer-box {
  position: relative;   /* anchors the mic drop-up (.m-micmenu) */
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px 12px 16px;
  border-radius: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.m-composer-input {
  width: 100%; box-sizing: border-box; border: 0; background: none; resize: none; outline: none;
  color: var(--text); font: 400 19px/1.3 var(--font-sans);
  min-height: 26px; max-height: 140px; padding: 2px 4px; overflow-y: auto;
}
.m-composer-input::placeholder { color: var(--text-faint); }
.m-composer-tools { display: flex; align-items: center; gap: 8px; }
.m-composer-spacer { flex: 1; }
/* Single config chip (loop / model) — one line, ellipsizes, never wraps. */
.m-pill-cfg { flex: 0 1 auto; min-width: 0; justify-content: flex-start; }
/* Auto = FULL auto (no gates) — the pill warns in the danger red. */
.m-pill-auto { color: #ff7a70; border-color: rgba(255, 122, 112, 0.45); }
/* The 2nd (loop/model) chip beside permission is tablet-only; phone keeps it in
   the top dropdown / dots menu where there's no room in the composer row. */
.m-pill-loopmodel { display: none; }
.m-tool-pill > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-tool-pill > svg { flex: 0 0 18px; }
.m-tool-btn {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.m-tool-btn svg { width: 20px; height: 20px; }
.m-tool-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 19px;
  background: var(--surface-3);
  color: var(--text);
  font: 500 16px/1 var(--font-sans);
  cursor: pointer;
}
.m-tool-pill svg { width: 18px; height: 18px; }
.m-tool-mic {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 0;
  background: none;
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.m-tool-mic svg { width: 22px; height: 22px; }
/* The mic's caret (voice options) — slimmer, points up, sits flush to the mic. */
.m-tool-mic-caret { flex: 0 0 20px; width: 20px; margin-left: -6px; }
.m-tool-mic-caret svg { width: 14px; height: 14px; transform: rotate(-90deg); }
/* The mic drop-up: mode / device / reply options (desktop's chip menu). */
.m-micmenu {
  position: absolute;
  right: 8px;
  bottom: calc(100% + 8px);
  z-index: 40;
  min-width: 230px;
  max-width: calc(100vw - 24px);
  max-height: 46vh;
  overflow-y: auto;
  background: var(--surface, var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  padding: 6px;
}
.m-micmenu-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3, var(--text-2));
  padding: 8px 10px 4px;
}
.m-micmenu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.m-micmenu-row.on { color: var(--accent); }
.m-micmenu-row svg { width: 16px; height: 16px; flex: 0 0 16px; }
.m-micmenu-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-micmenu-note {
  font-size: 12px;
  color: var(--text-2);
  padding: 6px 10px 8px;
}
.m-composer-send {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  /* The theme's primary CONTRAST: white pill in dark, black pill in light — the
     send/stop affordance, visible in every theme. Foreground is the page bg. */
  background: var(--white);
  color: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.m-composer-send svg { width: 20px; height: 20px; }
.m-composer-send:disabled { opacity: 0.4; cursor: default; }

/* Send button ring while a turn is in flight. */
@keyframes m-spin { to { transform: rotate(360deg); } }
.m-send-spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--bg) 40%, transparent); border-top-color: var(--bg); animation: m-spin 0.7s linear infinite; }

/* Brand working spinner (createGlyphhSpinner) — the tumbling wireframe cube +
   typed phrase, matched to the app. Shown as a thread row while the agent is
   connecting or thinking. Mobile-friendly: the phrase flexes + ellipsizes. */
.m-working { display: flex; align-items: center; gap: 10px; padding: 10px 2px; align-self: flex-start; max-width: 100%; }
.m-working-label { font: 500 16px/1 var(--font-sans); color: var(--text-2); animation: m-pulse 1.4s ease-in-out infinite; }

.m-set-row-toggle { width: 100%; cursor: default; }
.m-field-err { color: var(--danger); }

/* Per-session activity indicator — LEADING (thumbnail/icon slot), theme colours:
   neutral spinner while working, amber (--warning) while waiting on input. */
.m-actlead { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.m-actlead-spin { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--border-2); border-top-color: var(--text-2); animation: m-spin 0.75s linear infinite; }
.m-actlead-wait { color: var(--warning, #f59e0b); }
.m-actlead-wait svg { width: 20px; height: 20px; }
/* Code card meta reads amber while awaiting input. */
.m-code-meta[data-where="input"] .m-code-loc { color: var(--warning, #f59e0b); }

/* On-open connecting pill — centred just above the composer, frosted. */
.m-connecting {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 132px); z-index: 6;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 15px 7px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.5); backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--border); box-shadow: 0 8px 24px var(--overlay-bg);
  color: var(--text-2); font: 500 14px/1 var(--font-sans); white-space: nowrap;
}
.m-composer-input:disabled { opacity: 0.55; cursor: default; }
.m-gs-host { display: inline-flex; min-width: 0; }
.glyphh-spinner { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); }
.gs-cube { display: block; flex-shrink: 0; }
.gs-phrase { font: 400 13.5px/1.2 var(--font-sans); color: var(--text-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-meta { font: 400 13.5px/1.2 var(--font-sans); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gs-phrase.typing::after { content: "\258d"; margin-left: 1px; color: var(--accent); animation: gs-caret 0.7s step-end infinite; }
@keyframes gs-caret { 50% { opacity: 0; } }

/* ── Agent prompt (parked approval / ask) — portaled bottom sheet ─────────── */
.m-prompt-overlay { position: fixed; inset: 0; z-index: 260; display: flex; align-items: flex-end; pointer-events: none; }
.m-prompt-overlay .m-prompt { pointer-events: auto; }
.m-prompt-scrim { position: absolute; inset: 0; background: var(--overlay-bg); }
.m-prompt {
  position: relative; width: 100%; box-sizing: border-box;
  max-height: 80%; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(var(--safe-bottom) + 18px);
  box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.34);
  animation: m-sheet-up 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.m-prompt-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border-2); margin: 0 auto 14px; }
.m-prompt-kind {
  display: inline-block; padding: 3px 10px; border-radius: 999px; margin-bottom: 10px;
  font: 600 12px/1 var(--font-sans); text-transform: capitalize; letter-spacing: 0.02em;
  background: var(--accent-bg); color: var(--accent-text);
}
.m-prompt-kind[data-kind="dangerous"] { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.m-prompt-title { font: 700 20px/1.25 var(--font-sans); color: var(--text); }
.m-prompt-detail { margin-top: 8px; font: 400 15px/1.5 var(--font-sans); color: var(--text-3); white-space: pre-wrap; word-break: break-word; }
.m-prompt-q { margin-top: 14px; }
.m-prompt-qtext { font: 500 16px/1.4 var(--font-sans); color: var(--text); margin-bottom: 8px; }
.m-prompt-opts { display: flex; flex-wrap: wrap; gap: 8px; }
/* Option chips: unselected = surface + a quiet border; selected = a strong
   CONTRAST border (var(--white) = near-black in light, white in dark) + bold —
   so the choice reads in BOTH modes (a white fill vanished on the light sheet).
   Both states carry a 2px border so selecting never nudges the layout. */
.m-prompt-opt {
  padding: 9px 14px; border-radius: 12px; border: 2px solid var(--border-2);
  background: var(--surface); color: var(--text); font: 500 15px/1 var(--font-sans); cursor: pointer;
}
.m-prompt-opt[data-on="true"] { border-color: var(--white); color: var(--text); font-weight: 700; }
.m-prompt-input {
  width: 100%; box-sizing: border-box; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 400 16px/1.3 var(--font-sans); outline: none;
}
.m-prompt-actions { display: flex; gap: 10px; margin-top: 18px; }
/* Secondary button (Deny / Cancel): surface + border-2, per the theme. */
.m-prompt-btn {
  flex: 1; padding: 14px; border-radius: 14px; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); font: 600 16px/1 var(--font-sans); cursor: pointer;
}
.m-prompt-btn:disabled { opacity: 0.4; cursor: default; }
/* Primary button (Send / Approve): the theme's white pill (white in dark mode). */
.m-prompt-primary { background: var(--white); border-color: var(--white); color: var(--bg); }
.m-prompt-timer { margin-top: 12px; text-align: center; font: 400 13px/1 var(--font-sans); color: var(--text-faint); }

/* ── TABLET+ (iPad) : persistent sidebar, bigger type ── */
@media (min-width: 768px) {
  /* iPad-in-browser: `viewport-fit=cover` makes env(safe-area-inset-top) report
     the device inset even though the browser chrome already owns that strip, so
     the header's `safe-top + …` padding opened an empty band above the wordmark.
     The tablet is never notched-standalone here — zero the top inset so the
     header sits flush under the toolbar. (Phones stay <768px, untouched.) */
  :root { --safe-top: 0px; }

  /* Tablet: the rail is a PERSISTENT sidebar — no push-drawer. Keep the shell a
     real flex row (NOT display:contents, which detached .m-main from the row so
     it couldn't inherit height and .m-nav collapsed → blank right pane + dead
     clicks). Rail is a flex item; main flexes to fill and gets its full height
     from the row's stretch. Neutralise the drawer transform in both states. */
  .m-shell { display: flex; width: 100%; transform: none; }
  .m-app[data-drawer="open"] .m-shell { transform: none; }
  .m-scrim { display: none; }
  /* Parked approval/ask lives INSIDE the chat column (right of the rail), as a
     centered card — not a bottom sheet spanning the whole app over the sidebar. */
  .m-prompt-overlay { left: 320px; align-items: center; }
  .m-prompt { max-width: 560px; margin: 0 auto; border-radius: 22px; }
  .m-rail {
    flex: 0 0 320px;
    width: 320px;
    max-width: none;
    transform: none;
    padding: 0 3px 0 calc(var(--safe-left) + 3px);
  }
  .m-main { flex: 1 1 auto; width: auto; margin-left: 0; min-width: 0; }
  /* Align the wordmark with the content header (safe-top + 10px) and respect the
     status-bar inset in standalone PWA — without a top pad the logo crams to the
     very top of the rail while the content sits lower. */
  .m-rail-brand { padding: calc(var(--safe-top) + 14px) 0 10px 30px; }
  .m-wordmark { height: 36px; }
  .m-rail-nav { margin-top: 6px; gap: 3px; }
  .m-nav-item { padding: 11px 16px; font-size: 16px; gap: 14px; }
  .m-nav-item svg { width: 18px; height: 18px; flex-basis: 18px; }
  .m-recents { margin-top: 22px; }
  .m-recents-label { padding-left: 16px; font-size: 12px; }
  .m-recents-list { gap: 4px; }
  .m-recent { padding: 10px 16px; }
  .m-recent-title { font-size: 15px; }

  /* Loop/model chip sits beside the permission chip in Work/Code on tablet. */
  .m-pill-loopmodel { display: inline-flex; }

  /* The rail is a PERSISTENT sidebar on tablet — the drawer hamburger has
     nothing to open/close, so remove it from every header. */
  .m-chats-icon[aria-label="Open menu"] { display: none; }

  /* Roomier right panel: more breathing room on the left & right of the content
     column (messages, composer, headers, lists, home). */
  .m-sv-messages { padding-left: calc(var(--safe-left) + 48px); padding-right: 48px; }
  .m-sv-head { padding-left: calc(var(--safe-left) + 40px); padding-right: 40px; }
  .m-code-scroll { padding-left: calc(var(--safe-left) + 40px); padding-right: 40px; }
  .m-chats-head, .m-home-head { padding-left: calc(var(--safe-left) + 40px); padding-right: 40px; }
  .m-ghost { padding-left: 48px; padding-right: 48px; }

  /* Composer: match the roomier side padding and sit lower on the right panel. */
  .m-composer { padding: 6px 48px calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 48px); }

  /* The 20px body reads a touch large in the tablet's wider column — step the
     conversation type down to iOS's native body size (17px). Line-heights are
     unitless so they scale with it; inline code (0.86em) tracks automatically. */
  .m-msg { font-size: 17px; }
  .m-md { font-size: 17px; }
  .m-md-h1 { font-size: 22px; } .m-md-h2 { font-size: 20px; } .m-md-h3 { font-size: 18px; } .m-md-h4 { font-size: 17px; }
  .m-toolrow-lead { font-size: 16px; }

  /* The list + header type is phone-sized (touch targets); on a tablet it reads
     oversized. Step it down — the conversation itself is handled above. */
  .m-chats-title { font-size: 16px; }
  .m-code-name { font-size: 16px; }
  .m-desktop-name { font-size: 16px; }
  .m-desktop-status { font-size: 13px; }
  .m-code-label { font-size: 14px; }
  .m-list-note { font-size: 14px; }
  .m-code-when, .m-code-meta { font-size: 13px; }
}

/* ── Settings bottom sheet: slides up over the app, back down on close ────── */
.m-sheet-overlay { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.m-sheet-overlay[data-open="true"] { pointer-events: auto; }
.m-sheet-scrim {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  opacity: 0;
  transition: opacity 0.34s ease;
}
.m-sheet-overlay[data-open="true"] .m-sheet-scrim { opacity: 1; }
.m-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 20%;                                /* ~80% tall — not all the way up */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  overflow: hidden;                        /* clip the off-screen panel */
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
/* Shadow only while open — otherwise the parked (below-screen) sheet's upward
   shadow bleeds onto the bottom of every screen. */
.m-sheet-overlay[data-open="true"] .m-sheet { transform: translateY(0); box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.34); }

/* Horizontal track: main list ↔ a sub-screen (Profile), sliding both ways. */
.m-sheet-track { flex: 1 1 auto; min-height: 0; display: flex; width: 200%; transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1); }
.m-sheet-track[data-open="true"] { transform: translateX(-50%); }
/* Rail shortcut: jump to the sub instantly (no horizontal slide) so only the sheet's
   slide-up animates — the "slide to Connections first, then up" feel. */
.m-sheet-track[data-snap="true"] { transition: none; }
.m-sheet-panel { flex: 0 0 50%; width: 50%; min-height: 0; display: flex; flex-direction: column; }

.m-sheet-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  flex: 0 0 auto;
}
.m-sheet-title {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font: 700 21px/1 var(--font-sans);
  color: var(--text);
}
.m-sheet-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.m-sheet-btn:active { background: var(--hover); }
.m-sheet-btn svg { width: 22px; height: 22px; }

.m-sheet-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 16px calc(var(--safe-bottom) + 28px); }
.m-set-email {
  padding: 20px;
  border-radius: 16px;
  background: var(--surface);
  font: 600 21px/1.2 var(--font-sans);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 14px;
}
.m-set-section { margin-top: 24px; }
.m-set-section:first-of-type { margin-top: 10px; }
.m-set-label { font: 500 16px/1 var(--font-sans); color: var(--text-3); margin: 0 4px 10px; }
.m-set-group { background: var(--surface); border-radius: 16px; overflow: hidden; }
.m-set-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 18px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.m-set-row:active { background: var(--hover); }
.m-set-row:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 58px;              /* aligns the divider under the label, past the icon */
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--border);
}
.m-set-ico { flex: 0 0 24px; width: 24px; height: 24px; display: flex; color: var(--text-2); }
.m-set-ico svg { width: 24px; height: 24px; }
.m-set-name { flex: 1; min-width: 0; font: 500 20px/1 var(--font-sans); color: var(--text); }
.m-set-val { font: 400 18px/1 var(--font-sans); color: var(--text-faint); }
.m-set-row > svg { flex: 0 0 20px; width: 20px; height: 20px; color: var(--text-faint); }

/* ── Composer attachment menu: a frosted popover above the + ──────────────── */
.m-attach-overlay { position: fixed; inset: 0; z-index: 210; pointer-events: none; }
.m-attach-overlay[data-open="true"] { pointer-events: auto; }
.m-attach-scrim { position: absolute; inset: 0; }
.m-attach-menu {
  position: absolute;
  left: calc(var(--safe-left) + 12px);
  bottom: calc(var(--safe-bottom) + 96px);
  min-width: 258px;
  max-width: min(340px, 84vw);
  padding: 8px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  backdrop-filter: blur(26px) saturate(1.7);
  border: 1px solid var(--border);
  box-shadow: 0 14px 44px var(--overlay-bg);
  /* Slide up from below on open; slide back down on close (matches the sheets). */
  transform: translateY(100%);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.m-attach-overlay[data-open="true"] .m-attach-menu { opacity: 1; transform: translateY(0); }
.m-attach-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 15px 16px;
  border: 0;
  border-radius: 14px;
  background: none;
  cursor: pointer;
  text-align: left;
  font: 500 20px/1.25 var(--font-sans);
  color: var(--text);
}
.m-attach-row:active { background: var(--hover); }
.m-attach-row svg { flex: 0 0 24px; width: 24px; height: 24px; color: var(--text-2); }

/* ── Composer selector sheet: Loop / Models / Permission + sliding trays ──── */
.m-sel-overlay { position: fixed; inset: 0; z-index: 210; pointer-events: none; }
.m-sel-overlay[data-open="true"] { pointer-events: auto; }
.m-sel-scrim {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  opacity: 0;
  transition: opacity 0.34s ease;
}
.m-sel-overlay[data-open="true"] .m-sel-scrim { opacity: 1; }
.m-sel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 20%;                                /* ~80% tall — never higher, like Settings */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  overflow: hidden;                        /* clip the off-screen panel */
  padding-bottom: calc(var(--safe-bottom) + 16px);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
.m-sel-overlay[data-open="true"] .m-sel { transform: translateY(0); box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.34); }
/* Content-height variant (permission sheet): sizes to its rows, capped at 80%. */
.m-sel-fit { top: auto; max-height: 80%; }

/* ── Tablet: sheets become centered modal cards, not full-width bottom sheets ── */
@media (min-width: 768px) {
  .m-sheet, .m-sel {
    left: 50%; right: auto;
    top: 50%; bottom: auto;
    width: min(460px, 88vw);
    height: min(680px, 84dvh);
    max-height: 84dvh;
    border-radius: 22px;
    /* Parked well below the viewport centre; rises to centre on open. */
    transform: translate(-50%, 130vh);
  }
  .m-sel { padding-bottom: 0; }
  .m-sel-fit { height: auto; }               /* permission sheet hugs its rows */
  .m-sheet-overlay[data-open="true"] .m-sheet,
  .m-sel-overlay[data-open="true"] .m-sel {
    transform: translate(-50%, -50%);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  }
  /* The + (attachment) menu becomes a centered modal card too, matching the
     other sheets in width + position instead of floating at the composer. The
     scrim is a permanent full-screen layer (only the menu toggles), so it must
     ONLY paint when open — otherwise it veils the whole app. */
  .m-attach-scrim { transition: background 0.25s ease; }
  .m-attach-overlay[data-open="true"] .m-attach-scrim { background: var(--overlay-bg); }
  .m-attach-menu {
    left: 50%; right: auto;
    top: 50%; bottom: auto;
    width: min(460px, 88vw); min-width: 0; max-width: none;
    transform: translate(-50%, 130vh);
  }
  .m-attach-overlay[data-open="true"] .m-attach-menu {
    transform: translate(-50%, -50%);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  }
}
.m-sel-note { padding: 2px 6px 14px; font: 400 15px/1.4 var(--font-sans); color: var(--text-3); }
.m-sel-grip { flex: 0 0 auto; width: 40px; height: 5px; border-radius: 3px; background: var(--border-2); margin: 8px auto 2px; }
.m-sel-head { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 16px 14px; flex: 0 0 auto; }
.m-sel-title { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; font: 700 20px/1 var(--font-sans); color: var(--text); }
.m-sel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 16px; }
/* Horizontal track by depth: 0 = sections, 1 = a section tray, 2 = More models.
   Three equal panels of a 300%-wide track; back/forward both slide. */
.m-sel-track { flex: 1 1 auto; min-height: 0; display: flex; width: 300%; transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1); }
.m-sel-track[data-depth="0"] { transform: translateX(0); }
.m-sel-track[data-depth="1"] { transform: translateX(-33.3333%); }
.m-sel-track[data-depth="2"] { transform: translateX(-66.6666%); }
.m-sel-panel { flex: 0 0 33.3333%; width: 33.3333%; min-height: 0; display: flex; flex-direction: column; }
/* A sheet with ONE panel and no sliding track (Apps) — full width. */
.m-sel-panel.m-sel-panel-solo { flex: 1 1 100%; width: 100%; }

/* Collapsible loop-role section inside the Models tray. */
.m-role { margin-bottom: 12px; }
.m-role-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 6px 10px;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}
.m-role-name { font: 600 17px/1 var(--font-sans); color: var(--text-3); }
.m-role-val { flex: 1; min-width: 0; font: 400 16px/1 var(--font-sans); color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-role-head > svg { flex: 0 0 20px; width: 20px; height: 20px; color: var(--text-3); transition: transform 0.2s ease; }
.m-role[data-open="false"] .m-role-head > svg { transform: rotate(-90deg); }
.m-sel-group { background: var(--surface); border-radius: 16px; overflow: hidden; margin-bottom: 12px; }
.m-sel-row { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; padding: 18px; border: 0; background: none; cursor: pointer; text-align: left; }
.m-sel-row:active { background: var(--hover); }
.m-sel-row:not(:last-child)::after { content: ""; position: absolute; left: 18px; right: 0; bottom: 0; height: 1px; background: var(--border); }
.m-sel-row-label { flex: 1; font: 500 20px/1 var(--font-sans); color: var(--text); }
.m-sel-row-val { font: 400 19px/1 var(--font-sans); color: var(--text-faint); }
.m-sel-row > svg { flex: 0 0 20px; width: 20px; height: 20px; color: var(--text-faint); }
.m-sel-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; margin-bottom: 12px; border-radius: 14px; background: var(--surface); color: var(--text-faint); font: 400 18px/1 var(--font-sans); }
.m-sel-search svg { width: 20px; height: 20px; }
.m-opt { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px 18px; border: 0; background: none; cursor: pointer; text-align: left; }
.m-opt:active { background: var(--hover); }
.m-opt:not(:last-child)::after { content: ""; position: absolute; left: 18px; right: 0; bottom: 0; height: 1px; background: var(--border); }
.m-opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.m-opt-name { font: 500 21px/1.1 var(--font-sans); color: var(--text); }
.m-opt-desc { font: 400 16px/1.2 var(--font-sans); color: var(--text-3); }
.m-opt-tick { flex: 0 0 24px; display: flex; color: var(--accent); }
.m-opt-tick svg { width: 24px; height: 24px; }
.m-opt-spin { width: 18px; height: 18px; margin: 3px; border-radius: 50%; border: 2px solid var(--border-2); border-top-color: var(--text); animation: m-spin 0.7s linear infinite; }

/* ── Settings › Profile tray ─────────────────────────────────────────────── */
.m-profile-top { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 18px 0 24px; }
.m-profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grad-accent);
  color: #fff;
  font: 700 34px/1 var(--font-sans);
  margin-bottom: 6px;
}
.m-profile-name { font: 700 24px/1.1 var(--font-sans); color: var(--text); }
.m-profile-email { font: 400 17px/1 var(--font-sans); color: var(--text-faint); }
.m-profile-signout {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--danger);
  font: 600 20px/1 var(--font-sans);
  cursor: pointer;
}
.m-profile-signout:active { background: var(--hover); }

/* ── Settings info "i" + About/legal dropdown ────────────────────────────── */
.m-sheet-info svg { width: 25px; height: 25px; }   /* a tad bigger than the default */
.m-info-scrim { position: absolute; inset: 0; z-index: 5; }
.m-info-menu {
  position: absolute;
  top: 60px;
  right: 8px;
  z-index: 6;
  min-width: 268px;
  max-width: 80%;
  padding: 8px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  backdrop-filter: blur(26px) saturate(1.7);
  border: 1px solid var(--border);
  box-shadow: 0 16px 44px var(--overlay-bg);
  transform-origin: top right;
  animation: m-info-in 0.16s ease;
}
@keyframes m-info-in { from { opacity: 0; transform: scale(0.95) translateY(-8px); } to { opacity: 1; transform: none; } }
.m-info-ver { padding: 14px 16px 12px; font: 600 22px/1.25 var(--font-sans); color: var(--text); }
.m-info-sep { height: 1px; background: var(--border); margin: 2px 10px; }
.m-info-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 12px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  font: 500 20px/1.2 var(--font-sans);
}
.m-info-row:active { background: var(--hover); }
.m-info-row svg { flex: 0 0 24px; width: 24px; height: 24px; color: var(--text-2); }

/* ── Header filter dropdown (All … / Pinned) ─────────────────────────────── */
.m-filter { position: relative; display: inline-flex; }
.m-filter-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 236px;
  padding: 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  backdrop-filter: blur(24px) saturate(1.6);
  border: 1px solid var(--border);
  box-shadow: 0 14px 40px var(--overlay-bg);
  transform-origin: top right;
  animation: m-info-in 0.16s ease;
}
.m-filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px 13px 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
  text-align: left;
  font: 500 20px/1.2 var(--font-sans);
  color: var(--text);
}
.m-filter-row:active { background: var(--hover); }
.m-filter-check { flex: 0 0 26px; width: 26px; display: flex; justify-content: center; color: var(--text); }
.m-filter-check svg { width: 22px; height: 22px; }
.m-filter-row > svg { flex: 0 0 24px; width: 24px; height: 24px; color: var(--text-2); }

/* ── Session dots menu (Rename / Pin / Delete) + delete confirm ──────────── */
.m-sv-menu-wrap { position: relative; display: inline-flex; }
.m-sv-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 232px;
  padding: 8px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  backdrop-filter: blur(24px) saturate(1.6);
  border: 1px solid var(--border);
  box-shadow: 0 14px 40px var(--overlay-bg);
  transform-origin: top right;
  animation: m-info-in 0.16s ease;
}
.m-sv-menu-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: none;
  cursor: pointer;
  text-align: left;
  font: 500 20px/1.2 var(--font-sans);
  color: var(--text);
}
.m-sv-menu-row:active { background: var(--hover); }
.m-sv-menu-row svg { flex: 0 0 22px; width: 22px; height: 22px; color: var(--text-2); }
.m-sv-menu-row.m-danger, .m-sv-menu-row.m-danger svg { color: var(--danger); }
.m-sv-menu-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.m-sv-menu-t { font: 500 20px/1.2 var(--font-sans); color: var(--text); }
.m-sv-menu-s { font: 400 14px/1.2 var(--font-sans); color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-sv-menu-sep { height: 1px; background: var(--border); margin: 6px 10px; }

.m-confirm-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.m-confirm-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.m-confirm {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 22px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: m-confirm-in 0.18s ease;
}
@keyframes m-confirm-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
.m-confirm-title { font: 700 22px/1.2 var(--font-sans); color: var(--text); margin-bottom: 8px; }
.m-confirm-msg { font: 400 17px/1.45 var(--font-sans); color: var(--text-3); margin-bottom: 20px; }
.m-confirm-actions { display: flex; gap: 10px; }
.m-confirm-btn {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--border-2);          /* secondary button, per the theme */
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: 600 18px/1 var(--font-sans);
  cursor: pointer;
}
.m-confirm-btn:active { background: var(--hover); }
.m-confirm-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.m-confirm-danger:active { filter: brightness(0.92); background: var(--danger); }
.m-confirm-go { background: var(--accent); border-color: var(--accent); color: #fff; }
.m-confirm-go:active { filter: brightness(0.92); background: var(--accent); }

/* Rename modal input */
.m-rename-input {
  width: 100%;
  margin: 4px 0 16px;
  padding: 13px 14px;
  border: 1px solid var(--border-2);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: 500 18px/1.2 var(--font-sans);
  outline: none;
}
.m-rename-input:focus { border-color: var(--accent); }

/* Pin marker on a pinned list row (chat + code) */
.m-row-pin {
  display: inline-flex;
  vertical-align: -2px;
  margin-right: 6px;
  color: var(--accent);
}
.m-row-pin svg { width: 15px; height: 15px; }

/* ── Active search: focused input pinned above the keyboard ──────────────── */
.m-search-overlay { position: fixed; inset: 0; z-index: 210; pointer-events: none; }
.m-search-overlay[data-open="true"] { pointer-events: auto; }
.m-search-scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 34%, transparent);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.m-search-overlay[data-open="true"] .m-search-scrim { opacity: 1; }
.m-search-bar {
  position: absolute;
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--m-kb, 0px) + 10px);   /* tracks the keyboard's top edge */
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(160%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.m-search-overlay[data-open="true"] .m-search-bar { transform: translateY(0); }
.m-search-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 18px;
  border-radius: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 28px var(--overlay-bg);
}
.m-search-field > svg { flex: 0 0 22px; width: 22px; height: 22px; color: var(--text-faint); }
.m-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  font: 400 19px/1 var(--font-sans);
  color: var(--text);
  caret-color: var(--accent);
}
.m-search-input::placeholder { color: var(--text-faint); }
.m-search-x {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 8px 28px var(--overlay-bg);
}
.m-search-x svg { width: 22px; height: 22px; }

/* ── New-chat home header: chats-style transparent bar + centered loop/model ── */
.m-home-center { flex: 1; min-width: 0; display: flex; justify-content: center; }
.m-home-head-spacer { flex: 0 0 40px; }   /* balances the hamburger so the dropdown centers */
.m-home-loop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  cursor: pointer;
  font: 600 16px/1 var(--font-sans);
  color: var(--text);
}
.m-home-loop:active { background: var(--hover); }
.m-home-loop span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-home-loop svg { flex: 0 0 15px; width: 15px; height: 15px; color: var(--text-3); }

/* ── Login — the ONE never-themed surface (fixed brand over the muse canvas).
   The PRESENTATION is the REGULAR login's (web/src/web-login.js markup +
   styles.css `#onboarding-overlay` auth-shell rules). The mobile bundle can't
   import the desktop CSS, so every rule below replicates the source values
   verbatim and names its source class — keep them in lockstep. This surface
   never themes, so the desktop DARK-theme token values are hardcoded:
   --border #3f3f46 · --text-2 #c4c4c4 · --text-3 #a7a7a7 · --text-muted
   #828282 · --danger #f85149 · --white #fff. */
.m-login {
  position: absolute;
  inset: 0;
  z-index: 120;
  background: #0e0c14;               /* the muse canvas ground (SplashFlow paints over it) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  color: #f1f1f1;                    /* --text (dark) */
}
/* source: .auth-shell-header — the wordmark rides the top-left, not the card. */
.m-login-brand {
  position: absolute;
  top: calc(var(--safe-top) + 0.75rem);
  left: 1.5rem;
  z-index: 1;
}
/* source: .onboarding-wordmark .glyphh-logo (56px on desktop, phone-scaled). */
.m-login-logo { height: 40px; width: auto; display: block; }
/* source: .auth-shell-content — ONE centered column with the same 460px cap on
   phone AND tablet, so nothing stretches or floats loose at iPad widths. */
.m-login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  text-align: center;
}
/* source: .auth-shell-title (clamp(2.4rem,3.2vw,3.1rem) on desktop — the vw
   term is re-based so a 390px phone lands ~2rem and a tablet meets the cap). */
.m-login-title {
  font: 700 clamp(2rem, 8vw, 3.1rem)/1.08 var(--font-sans);
  letter-spacing: -0.03em;
  color: #fff;
  margin-bottom: 0.75rem;
}
/* source: .auth-shell-slogan — the web's --grad-text, verbatim. */
.m-login-tagline {
  margin: 0 0 2rem;
  font: 600 clamp(1.0625rem, 4.4vw, 1.5rem)/1.35 var(--font-sans);
  letter-spacing: -0.015em;
  background: linear-gradient(to top right, #c084fc, #f0abfc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
/* source: .auth-shell-lede (sent-state copy). */
.m-login-sub { margin: 0 0 0.25rem; font: 400 0.9375rem/1.55 var(--font-sans); color: #c4c4c4; }
/* source: .auth-shell-form. */
.m-login-form { width: 100%; display: flex; flex-direction: column; gap: 1.125rem; }
/* source: .auth-shell-field. */
.m-login-field { display: flex; flex-direction: column; gap: 0.4375rem; }
/* source: .auth-shell-label. */
.m-login-label { font: 500 0.75rem/1 var(--font-sans); letter-spacing: 0.01em; color: #c4c4c4; text-align: left; }
/* source: .auth-shell-input. Font is 1rem, NOT the source's 0.9375rem — iOS
   Safari zooms the page when focusing any input under 16px. */
.m-login-input {
  width: 100%;
  padding: 0.875rem 1rem;
  background: transparent;
  border: 1px solid #3f3f46;
  border-radius: 10px;
  color: #fff;
  font: 400 1rem/1.3 var(--font-sans);
  outline: none;
  transition: border-color 200ms ease, background 200ms ease;
}
.m-login-input::placeholder { color: #828282; }   /* --text-muted (dark) */
.m-login-input:focus { border-color: #fff; box-shadow: 0 0 0 1px #fff; background: transparent; }
/* The settings screens (help / keys / invites) reuse .m-login-primary — this
   GLOBAL rule keeps serving them unchanged; the login card scopes its own
   regular-login treatment below. */
.m-login-primary {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 15px;
  background: #fff;
  color: #111;
  cursor: pointer;
  font: 600 18px/1 var(--font-sans);
}
.m-login-primary:disabled { opacity: 0.6; }
/* source: .btn.btn-primary.btn-lg.btn-full — white resting / black text, the
   accent→pink gradient (--grad-accent) wipes in under white text on press and
   while disabled ("Sending…"), exactly like the regular login's primary. */
.m-login-card .m-login-primary {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  height: auto;
  padding: 0.875rem 1.25rem;
  border-radius: 10px;               /* source: .btn-lg */
  font: 600 0.9375rem/1.2 var(--font-sans);
  color: #000;
  transition: color 220ms ease, opacity 160ms ease;
}
.m-login-card .m-login-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(to top right, #af5fff, #ec4899);  /* --grad-accent */
  transform: translateX(-100%);
  transition: none;
}
.m-login-card .m-login-primary:active:not(:disabled)::before {
  transform: translateX(0);
  transition: transform 280ms ease;
}
.m-login-card .m-login-primary:disabled::before { transform: translateX(0); transition: none; }
.m-login-card .m-login-primary:active:not(:disabled),
.m-login-card .m-login-primary:disabled { color: #fff; }
.m-login-card .m-login-primary:disabled { opacity: 0.5; }     /* source: .btn:disabled */
/* Dev sign-in link — the primary button rendered as an anchor. */
.m-login-devlink { display: flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; }
/* source: .auth-shell-divider. */
.m-login-or {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  width: 100%;
  margin: 1.375rem 0;
  color: #a7a7a7;                    /* --text-3 (dark) */
  font: 400 0.75rem/1 var(--font-sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.m-login-or::before, .m-login-or::after { content: ""; flex: 1; height: 1px; background: #3f3f46; }
/* source: .google-btn — the real GIS button (click target) sits under our own
   face, which is overlaid pointer-events:none so taps fall through to Google's. */
.m-login-google { position: relative; width: 100%; height: 48px; }
/* source: .google-btn-gis. `color-scheme: light` is LOAD-BEARING: the page runs
   color-scheme:dark, and a cross-color-scheme iframe (Google's is light) gets
   an opaque WHITE backing — the white rectangle around the GSI button. */
.m-login-google-gis {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  overflow: hidden;
  color-scheme: light;
}
/* source: .btn.btn-lg.btn-full.btn-social.google-btn-face (bg var(--bg) → this
   login's fixed ground, covering the GIS visuals; only ours shows). */
.m-login-google-face {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  background: #0e0c14;
  color: #fff;
  border: 1px solid #3f3f46;
  border-radius: 10px;
  font: 500 0.9375rem/1 var(--font-sans);
}
/* source: .auth-shell-error. */
.m-login-err { margin-top: 0.75rem; color: #f85149; font: 400 0.8125rem/1.4 var(--font-sans); }
/* source: .auth-shell-meta a — quiet underlined link, not a button. */
.m-login-alt {
  border: 0;
  background: none;
  padding: 0;
  margin-top: 0.5rem;
  color: #f1f1f1;
  font: 400 0.8125rem/1.4 var(--font-sans);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid #a7a7a7;
}
/* source: .auth-shell-legal (net ~0.625rem under the button, snug). */
.m-login-legal { margin-top: 0.625rem; font: 400 0.75rem/1.6 var(--font-sans); color: #a7a7a7; text-align: center; }
.m-login-legal a { color: #c4c4c4; text-decoration: none; }
.m-login-legal a:active { color: #fff; }
.m-login-sent { display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* ── Settings sub-trays: profile form + billing/usage cards ──────────────── */
.m-set-loading { padding: 40px 4px; text-align: center; color: var(--text-faint); font: 400 17px/1 var(--font-sans); }
.m-saved { font: 500 13px/1 var(--font-sans); color: var(--success); text-transform: none; letter-spacing: 0; margin-left: 6px; }
.m-profile-avatar-img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; margin-bottom: 6px; }

.m-set-form { display: flex; flex-direction: column; gap: 12px; }
.m-field { display: flex; flex-direction: column; gap: 6px; }
.m-field-l { font: 500 15px/1 var(--font-sans); color: var(--text-3); padding-left: 2px; }
.m-field-in {
  height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: 400 18px/1 var(--font-sans);
  outline: none;
}
.m-field-in:focus { border-color: var(--accent); }
.m-field-btn {
  width: 100%;
  margin-top: 16px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: 600 17px/1 var(--font-sans);
  cursor: pointer;
}
.m-field-btn:active { background: var(--hover); }

.m-bill-plan { display: flex; flex-direction: column; gap: 4px; padding: 4px 2px 18px; }
.m-bill-tier { font: 700 30px/1 var(--font-sans); color: var(--text); }
.m-bill-seats { font: 400 15px/1 var(--font-sans); color: var(--text-faint); }
.m-bill-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.m-bill-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}
.m-bill-v { font: 700 22px/1 var(--font-sans); color: var(--text); font-variant-numeric: tabular-nums; }
.m-bill-l { font: 400 13px/1.2 var(--font-sans); color: var(--text-faint); }

/* ── Profile identity chips + field error ────────────────────────────────── */
.m-profile-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.m-chip {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font: 500 13px/1 var(--font-sans);
}
.m-field-err { margin-top: 12px; color: var(--danger); font: 400 15px/1.4 var(--font-sans); }
/* Native <select> should match the text inputs. */
select.m-field-in { appearance: none; -webkit-appearance: none; background-image: none; }

/* ── Connections tray ────────────────────────────────────────────────────── */
.m-conn-ico {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 17px/1 var(--font-sans);
  color: var(--text-2);
  overflow: hidden;
}
.m-conn-ico img { width: 100%; height: 100%; object-fit: contain; }
.m-opt > svg { flex: 0 0 20px; width: 20px; height: 20px; color: var(--text-faint); }
.m-conn-back {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: none; cursor: pointer;
  color: var(--text-2); font: 600 16px/1 var(--font-sans);
  padding: 2px 2px 12px;
}
.m-conn-back svg { width: 18px; height: 18px; }
.m-conn-in { flex: 1; min-width: 0; border: 0; background: none; outline: none; font: 400 18px/1 var(--font-sans); color: var(--text); }
.m-conn-in::placeholder { color: var(--text-faint); }
.m-conn-empty { padding: 32px 8px; text-align: center; color: var(--text-faint); font: 400 16px/1.5 var(--font-sans); }

/* Connect tray — in-app frame that slides in (no popup). */
.m-connect-tray {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: m-nav-in 0.28s ease;
}
.m-connect-head {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 12px 10px calc(var(--safe-left) + 12px);
  border-bottom: 1px solid var(--border);
}
.m-connect-head .m-sheet-title { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; }
.m-connect-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.m-connect-fallback {
  flex: 0 0 auto;
  text-align: center;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  color: var(--text-faint);
  font: 400 14px/1.3 var(--font-sans);
}

/* ── Connection detail (edit) tray ───────────────────────────────────────── */
.m-conn-detail-head { display: flex; align-items: center; gap: 14px; padding: 4px 2px 18px; }
.m-conn-ico-lg { flex: 0 0 52px; width: 52px; height: 52px; border-radius: 14px; font-size: 22px; }
.m-conn-detail-meta { min-width: 0; }
.m-conn-detail-name { font: 700 22px/1.2 var(--font-sans); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-conn-detail-status { font: 400 15px/1.2 var(--font-sans); color: var(--success); }
.m-conn-detail-status.bad { color: var(--danger); }
/* Toggle switch (tool allow + select-all). */
.m-switch {
  flex: 0 0 46px;
  width: 46px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-2);
  cursor: pointer;
  position: relative;
  transition: background 0.18s ease;
}
.m-switch[data-on="true"] { background: var(--accent); }
.m-switch[data-ind="true"] { background: color-mix(in srgb, var(--accent) 45%, var(--border-2)); }
.m-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s ease;
}
.m-switch[data-on="true"] .m-switch-knob { transform: translateX(18px); }
.m-switch[data-ind="true"] .m-switch-knob { transform: translateX(9px); }
.m-tool-all .m-tool-head { cursor: pointer; }
.m-tool-count { font: 400 14px/1 var(--font-sans); color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* Expandable tool row (description collapsed by default). */
.m-tool { border-bottom: 1px solid var(--border); }
.m-tool:last-child { border-bottom: 0; }
.m-tool-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; cursor: pointer; }
.m-tool-head:active { background: var(--hover); }
.m-tool-name { flex: 1; min-width: 0; font: 500 18px/1.3 var(--font-sans); color: var(--text); }
.m-tool-caret { flex: 0 0 18px; display: flex; color: var(--text-faint); transition: transform 0.2s ease; }
.m-tool-caret svg { width: 18px; height: 18px; }
.m-tool[data-open="true"] .m-tool-caret { transform: rotate(180deg); }
.m-tool-desc { padding: 0 18px 15px; font: 400 15px/1.5 var(--font-sans); color: var(--text-3); }
.m-field-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); margin-top: 22px; }

/* ── Full theme set (tokens ported from styles.css; mobile subset) ────────── */
[data-theme="purple"], [data-theme="aurora"] {
  color-scheme: dark;
  --bg:#140a1f; --surface:#221634; --surface-2:#2c1e42; --surface-3:#281a3c;
  --border:#3a2857; --border-2:#46306a;
  --text:#f1ecf8; --text-2:#c4b6da; --text-3:#9485ad; --text-faint:#544a6a;
  --white:#ffffff; --hover:#2e2046;
  --accent:#ad5df8; --accent-hover:#cda2ff; --accent-text:#c98ffb; --accent-bg:#2a1a40;
  --success:#28c840; --danger:#ff7a70; --overlay-bg:rgba(10,4,20,0.6);
}
[data-theme="prism"] {
  color-scheme: light;
  --bg:#f4f4fb; --surface:#ffffff; --surface-2:#f6f5fd; --surface-3:#eef0fb;
  --border:#e6e5f2; --border-2:#d6d5ea;
  --text:#1c1b2e; --text-2:#4a4866; --text-3:#6f6d8c; --text-faint:#9c9ab8;
  --white:#0d0c1a; --hover:#eeecfb;
  --accent:#6d5efc; --accent-hover:#8a7dff; --accent-text:#6d5efc; --accent-bg:#edeafe;
  --success:#16a34a; --danger:#e5484d; --overlay-bg:rgba(28,27,46,0.28);
  --grad-accent:linear-gradient(120deg,#6d5efc,#22d3ee 55%,#f472b6);
}
[data-theme="github"] {
  color-scheme: dark;
  --bg:#0d1117; --surface:#161b22; --surface-2:#1c2128; --surface-3:#21262d;
  --border:#30363d; --border-2:#3d444d;
  --text:#e6edf3; --text-2:#adbac7; --text-3:#7d8590; --text-faint:#636c76;
  --white:#ffffff; --hover:#21262d;
  --accent:#2f81f7; --accent-hover:#539bf5; --accent-text:#6cb6ff; --accent-bg:#12233d;
  --success:#3fb950; --danger:#f85149; --overlay-bg:rgba(1,4,9,0.7);
  --grad-accent:linear-gradient(120deg,#2f81f7,#a371f7);
}
[data-theme="highvis"] {
  color-scheme: dark;
  --bg:#000000; --surface:#0d0d0d; --surface-2:#141414; --surface-3:#1a1a1a;
  --border:#5a5a5a; --border-2:#7a7a7a;
  --text:#ffffff; --text-2:#eaeaea; --text-3:#c8c8c8; --text-faint:#909090;
  --white:#ffffff; --hover:#1f1f1f;
  --accent:#b066ff; --accent-hover:#c68cff; --accent-text:#c68cff; --accent-bg:#221133;
  --success:#00e676; --danger:#ff2b2b; --overlay-bg:rgba(0,0,0,0.8);
  --grad-accent:linear-gradient(120deg,#b066ff,#af5fff);
}
[data-theme="claude"] {
  color-scheme: light;
  --bg:#f0eee6; --surface:#ffffff; --surface-2:#f5f4ee; --surface-3:#eeece3;
  --border:#e3e1d6; --border-2:#d4d1c3;
  --text:#3d3d3a; --text-2:#605d55; --text-3:#837f74; --text-faint:#a8a496;
  --white:#1f1e1c; --hover:#eae8de;
  --accent:#d97757; --accent-hover:#c96442; --accent-text:#bd5d3a; --accent-bg:#f7e9e2;
  --success:#6a8f4e; --danger:#bf4d43; --overlay-bg:rgba(61,61,58,0.30);
  --grad-accent:linear-gradient(120deg,#d97757,#e0a06f);
}
[data-theme="chatgpt"] {
  color-scheme: dark;
  --bg:#212121; --surface:#2f2f2f; --surface-2:#343434; --surface-3:#303030;
  --border:#424242; --border-2:#4d4d4d;
  --text:#ececec; --text-2:#c5c5c5; --text-3:#9a9a9a; --text-faint:#6e6e6e;
  --white:#ffffff; --hover:#383838;
  --accent:#10a37f; --accent-hover:#1ab896; --accent-text:#2bd4ae; --accent-bg:#10261f;
  --success:#10a37f; --danger:#ef4146; --overlay-bg:rgba(0,0,0,0.6);
  --grad-accent:linear-gradient(120deg,#10a37f,#4a9eff);
}
[data-theme="gemini"] {
  color-scheme: dark;
  --bg:#131314; --surface:#1e1f20; --surface-2:#282a2c; --surface-3:#232527;
  --border:#37393b; --border-2:#444649;
  --text:#e3e3e3; --text-2:#c4c7c5; --text-3:#9aa0a6; --text-faint:#6b6f73;
  --white:#ffffff; --hover:#2d2f31;
  --accent:#8ab4f8; --accent-hover:#a6c6fa; --accent-text:#a6c6fa; --accent-bg:#1a2438;
  --success:#81c995; --danger:#f28b82; --overlay-bg:rgba(0,0,0,0.65);
  --grad-accent:linear-gradient(120deg,#4285f4,#a142f4 55%,#f76aa0);
}
[data-theme="dracula"] {
  color-scheme: dark;
  --bg:#282a36; --surface:#343746; --surface-2:#3c3f51; --surface-3:#383b4c;
  --border:#44475a; --border-2:#565a72;
  --text:#f8f8f2; --text-2:#d5d5e0; --text-3:#a5abcc; --text-faint:#6272a4;
  --white:#ffffff; --hover:#3c3f51;
  --accent:#bd93f9; --accent-hover:#cba9fb; --accent-text:#cba9fb; --accent-bg:#2f2846;
  --success:#50fa7b; --danger:#ff5555; --overlay-bg:rgba(20,21,28,0.6);
  --grad-accent:linear-gradient(120deg,#bd93f9,#ff79c6 60%,#8be9fd);
}
[data-theme="nord"] {
  color-scheme: dark;
  --bg:#2e3440; --surface:#3b4252; --surface-2:#434c5e; --surface-3:#3f485a;
  --border:#4c566a; --border-2:#5b667c;
  --text:#eceff4; --text-2:#d8dee9; --text-3:#a9b2c3; --text-faint:#6b7689;
  --white:#ffffff; --hover:#434c5e;
  --accent:#88c0d0; --accent-hover:#8fbcbb; --accent-text:#9fd3e0; --accent-bg:#2b3a44;
  --success:#a3be8c; --danger:#bf616a; --overlay-bg:rgba(20,24,31,0.6);
  --grad-accent:linear-gradient(120deg,#88c0d0,#81a1c1 55%,#b48ead);
}
[data-theme="synthwave"] {
  color-scheme: dark;
  --bg:#1a1030; --surface:#281a4a; --surface-2:#322058; --surface-3:#2c1d50;
  --border:#45307a; --border-2:#563e92;
  --text:#f5e9ff; --text-2:#d3c0ee; --text-3:#a892cf; --text-faint:#675588;
  --white:#ffffff; --hover:#32205a;
  --accent:#ff2e97; --accent-hover:#ff5cae; --accent-text:#ff77bd; --accent-bg:#3a1436;
  --success:#2bf5c8; --danger:#ff4d5e; --overlay-bg:rgba(10,5,24,0.65);
  --grad-accent:linear-gradient(120deg,#ff2e97,#b14dff 50%,#00e5ff);
}
[data-theme="matrix"] {
  color-scheme: dark;
  --bg:#020a02; --surface:#071507; --surface-2:#0b1f0b; --surface-3:#091a09;
  --border:#14371a; --border-2:#1d4d26;
  --text:#b9ffc4; --text-2:#57e06f; --text-3:#3aa64f; --text-faint:#206630;
  --white:#e6ffe9; --hover:#0c220f;
  --accent:#00ff66; --accent-hover:#4dff92; --accent-text:#4dff92; --accent-bg:#06240f;
  --success:#00ff66; --danger:#ff3b3b; --overlay-bg:rgba(0,8,0,0.75);
  --grad-accent:linear-gradient(120deg,#00ff66,#00e0c0);
}

/* Theme swatch in the Appearance picker (self-previews via its own data-theme). */
.m-theme-sw {
  flex: 0 0 34px; width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.m-theme-sw::after { content: ""; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); }

/* ── Help & Support tray ─────────────────────────────────────────────────── */
.m-help-docs { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; }
.m-help-docs svg { width: 20px; height: 20px; }
.m-field-area { height: auto; min-height: 130px; padding: 12px 16px; line-height: 1.5; resize: none; font-family: var(--font-sans); }
.m-help-submit { margin-top: 8px; }
.m-help-status {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-3);
  font: 500 12px/1 var(--font-sans);
  text-transform: capitalize;
}
.m-help-status[data-s="open"], .m-help-status[data-s="pending"] { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.m-help-status[data-s="resolved"], .m-help-status[data-s="closed"] { color: var(--text-faint); }
.m-help-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 8px; vertical-align: middle; }

.m-help-thread { display: flex; flex-direction: column; min-height: 0; }
.m-help-thread-head { display: flex; align-items: center; gap: 10px; padding: 2px 2px 14px; }
.m-help-thread-subject { flex: 1; min-width: 0; font: 700 20px/1.25 var(--font-sans); color: var(--text); }
.m-help-msgs { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.m-help-reply { display: flex; align-items: center; gap: 8px; padding-top: 10px; }
.m-help-reply .m-field-in { flex: 1; height: 48px; }
.m-help-send {
  flex: 0 0 48px; width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer;
}
.m-help-send:disabled { opacity: 0.4; }
.m-help-send svg { width: 20px; height: 20px; }

/* ── Generic sub-tray (connection catalog + detail): 80% bottom sheet, matches
   the Settings sheet. Scrim behind; slides up. ───────────────────────────── */
.m-subtray-overlay { position: fixed; inset: 0; z-index: 250; }
.m-subtray-scrim { position: absolute; inset: 0; background: var(--overlay-bg); animation: m-fade-in 0.25s ease; }
@keyframes m-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes m-sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.m-subtray {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 20%;                                /* ~80% tall — matches Settings */
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.34);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: m-sheet-up 0.34s cubic-bezier(0.32, 0.72, 0, 1);
}
.m-subtray-head {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 12px 10px calc(var(--safe-left) + 12px);
  border-bottom: 1px solid var(--border);
}
.m-subtray-head .m-sheet-title { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; }
.m-subtray-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 16px);
}

/* ── Settings batch: General / API keys / Members ────────────────────────── */
.m-field-note { margin-top: 10px; padding: 0 2px; font: 400 14px/1.45 var(--font-sans); color: var(--text-faint); }
.m-key-new {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px; margin-bottom: 18px;
  border-radius: 14px; background: var(--accent-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
}
.m-key-new-t { font: 500 15px/1.4 var(--font-sans); color: var(--accent-text); }
.m-key-token {
  font: 500 15px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text); word-break: break-all;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.m-key-revoke, .m-member-role {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  border-radius: 999px;
  padding: 7px 13px;
  font: 500 14px/1 var(--font-sans);
  cursor: pointer;
}
.m-key-revoke { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.m-member-role { appearance: none; -webkit-appearance: none; }

/* ── Settings batch 2: Models / Workspaces ───────────────────────────────── */
.m-chip-inline { margin-left: 8px; padding: 3px 8px; font-size: 12px; }
.m-key-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.m-field-inline { width: auto; margin-top: 0; flex: 0 0 auto; }

/* ── App tray: a right-slide-in surface hosting the streamed desktop app panel.
   Slides in from the RIGHT (and off to the right on dismiss), mirrors the sheet
   scrim + safe-area handling, and hosts the <video>/<canvas> the desktop casts. */
.m-apptray-overlay { position: fixed; inset: 0; z-index: 230; pointer-events: none; }
.m-apptray-overlay[data-open="true"] { pointer-events: auto; }
.m-apptray-scrim {
  position: absolute; inset: 0;
  background: var(--overlay-bg);
  opacity: 0; transition: opacity 0.34s ease;
}
.m-apptray-overlay[data-open="true"] .m-apptray-scrim { opacity: 1; }
.m-apptray {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 100%;
  display: flex; flex-direction: column;
  background: #000;
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: -12px 0 44px rgba(0, 0, 0, 0.4);
}
.m-apptray-overlay[data-open="true"] .m-apptray { transform: translateX(0); }
/* Left grab edge — swipe right here to dismiss (doesn't overlap the video body). */
.m-apptray-edge { position: absolute; top: 0; left: 0; bottom: 0; width: 18px; z-index: 2; touch-action: pan-y; }
.m-apptray-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.m-apptray-name { flex: 1; min-width: 0; font: 600 15px/1.2 var(--font-sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-apptray-sub { color: var(--text-2); font-weight: 400; }
.m-apptray-x {
  flex: 0 0 auto; width: 34px; height: 34px;
  display: grid; place-items: center;
  background: none; border: none; color: var(--text-2); cursor: pointer;
}
.m-apptray-x svg { width: 22px; height: 22px; }
.m-apptray-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.m-apptray-holder { position: absolute; inset: 0; }
.m-apptray-holder[data-hidden="true"] { visibility: hidden; }
.m-apptray-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 32px; text-align: center; color: var(--text-2);
}
.m-apptray-state svg { width: 40px; height: 40px; opacity: 0.7; }
.m-apptray-msg { font: 500 14px/1.5 var(--font-sans); max-width: 320px; }
.m-apptray-retry { padding: 9px 20px; }
.m-apptray-spin {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: m-apptray-spin 0.8s linear infinite;
}
@keyframes m-apptray-spin { to { transform: rotate(360deg); } }
/* Tablet: don't go full-bleed — a right-docked panel reads better. */
@media (min-width: 768px) {
  .m-apptray { width: min(720px, 92vw); border-radius: 18px 0 0 18px; }
}
