/* MajesticMesh — the node's web chat.
   One gold node (self), blue peers — the brand logic from the app
   icon. Tokens first: dark is the default (:root); the light values
   apply through prefers-color-scheme unless [data-theme='dark'] pins
   dark, and through [data-theme='light'] on any system setting. The
   light list exists twice only because a media query cannot share a
   selector list with a plain rule. Components use tokens only. */

/* ── tokens: scale (theme-independent) ─────────────────────────── */
:root {
  /* spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  /* radius */
  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;
  /* type: size / line-height pairs */
  --t-xs: 12px;
  --lh-xs: 1.4;
  --t-sm: 13px;
  --lh-sm: 1.5;
  --t-md: 16px;
  --lh-md: 1.65;
  --t-lg: 20px;
  --lh-lg: 1.3;
  --t-xl: 28px;
  --lh-xl: 1.2;
  --w-regular: 400;
  --w-medium: 500;
  --w-semi: 600;
  --w-hero: 700;
  --sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI',
    Roboto, 'Helvetica Neue', sans-serif;
  --mono: 'SF Mono', ui-monospace, Menlo, monospace;
  /* controls, icons, layout */
  --ctl-sm: 28px;
  --ctl-md: 36px;
  --icon: 14px;
  --bar-h: 56px;
  --side-w: 264px;
  --col: 40rem;
  --ease: 140ms ease;
}

/* ── tokens: colour, dark (default) ────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #14121a;
  --surface-1: #1a1722;
  --surface-2: #211d2c;
  --surface-3: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: rgba(255, 255, 255, 0.95);
  --text-2: rgba(255, 255, 255, 0.68);
  --text-3: rgba(255, 255, 255, 0.5);
  --primary: rgb(255, 200, 130);
  --primary-hover: rgb(255, 214, 162);
  --on-primary: #16130c;
  --accent: rgb(255, 200, 130);
  --accent-soft: rgba(255, 200, 130, 0.14);
  --accent-line: rgba(255, 200, 130, 0.45);
  --link: rgb(140, 180, 255);
  --link-soft: rgba(140, 180, 255, 0.13);
  --ok: rgb(140, 220, 160);
  --ok-soft: rgba(140, 220, 160, 0.12);
  --warn: rgb(250, 204, 110);
  --warn-soft: rgba(250, 204, 110, 0.12);
  --danger: rgb(255, 140, 140);
  --danger-soft: rgba(255, 140, 140, 0.12);
  --danger-solid: rgb(200, 60, 60);
  --on-solid: #ffffff;
  --scrim: rgba(0, 0, 0, 0.55);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --side-bg:
    radial-gradient(130% 36% at 0% 0%, rgba(255, 200, 130, 0.12), transparent 70%),
    radial-gradient(130% 40% at 100% 34%, rgba(232, 121, 249, 0.09), transparent 70%),
    radial-gradient(150% 46% at 50% 100%, rgba(140, 180, 255, 0.12), transparent 72%),
    #0f0d15;
  /* the mesh texture behind the empty state */
  --mesh-dot: rgba(255, 255, 255, 0.09);
}

/* ── tokens: colour, light ─────────────────────────────────────── */
:root[data-theme='light'] {
  color-scheme: light;
  --bg: #fdfcff;
  --surface-1: #f7f5fb;
  --surface-2: #ffffff;
  --surface-3: rgba(25, 19, 49, 0.05);
  --border: rgba(25, 19, 49, 0.12);
  --border-strong: rgba(25, 19, 49, 0.24);
  --text: #191331;
  --text-2: rgba(25, 19, 49, 0.74);
  --text-3: rgba(25, 19, 49, 0.62);
  --primary: #191331;
  --primary-hover: #2e2652;
  --on-primary: #ffffff;
  --accent: #8f5c14;
  --accent-soft: rgba(143, 92, 20, 0.12);
  --accent-line: rgba(143, 92, 20, 0.4);
  --link: rgb(52, 92, 196);
  --link-soft: rgba(52, 92, 196, 0.1);
  --ok: rgb(24, 118, 60);
  --ok-soft: rgba(24, 118, 60, 0.1);
  --warn: #855400;
  --warn-soft: rgba(185, 122, 36, 0.12);
  --danger: rgb(180, 40, 40);
  --danger-soft: rgba(180, 40, 40, 0.09);
  --danger-solid: rgb(180, 40, 40);
  --scrim: rgba(25, 19, 49, 0.32);
  --shadow: 0 8px 24px rgba(25, 19, 49, 0.1), 0 1px 2px rgba(25, 19, 49, 0.06);
  --side-bg:
    radial-gradient(130% 36% at 0% 0%, rgba(255, 201, 143, 0.38), transparent 70%),
    radial-gradient(130% 40% at 100% 34%, rgba(236, 160, 245, 0.22), transparent 70%),
    radial-gradient(150% 46% at 50% 100%, rgba(169, 199, 255, 0.32), transparent 72%),
    #fbfaff;
  --mesh-dot: rgba(25, 19, 49, 0.11);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    color-scheme: light;
    --bg: #fdfcff;
    --surface-1: #f7f5fb;
    --surface-2: #ffffff;
    --surface-3: rgba(25, 19, 49, 0.05);
    --border: rgba(25, 19, 49, 0.12);
    --border-strong: rgba(25, 19, 49, 0.24);
    --text: #191331;
    --text-2: rgba(25, 19, 49, 0.74);
    --text-3: rgba(25, 19, 49, 0.62);
    --primary: #191331;
    --primary-hover: #2e2652;
    --on-primary: #ffffff;
    --accent: #8f5c14;
    --accent-soft: rgba(143, 92, 20, 0.12);
    --accent-line: rgba(143, 92, 20, 0.4);
    --link: rgb(52, 92, 196);
    --link-soft: rgba(52, 92, 196, 0.1);
    --ok: rgb(24, 118, 60);
    --ok-soft: rgba(24, 118, 60, 0.1);
    --warn: #855400;
    --warn-soft: rgba(185, 122, 36, 0.12);
    --danger: rgb(180, 40, 40);
    --danger-soft: rgba(180, 40, 40, 0.09);
    --danger-solid: rgb(180, 40, 40);
    --scrim: rgba(25, 19, 49, 0.32);
    --shadow: 0 8px 24px rgba(25, 19, 49, 0.1), 0 1px 2px rgba(25, 19, 49, 0.06);
    --side-bg:
      radial-gradient(130% 36% at 0% 0%, rgba(255, 201, 143, 0.38), transparent 70%),
      radial-gradient(130% 40% at 100% 34%, rgba(236, 160, 245, 0.22), transparent 70%),
      radial-gradient(150% 46% at 50% 100%, rgba(169, 199, 255, 0.32), transparent 72%),
      #fbfaff;
    --mesh-dot: rgba(25, 19, 49, 0.11);
  }
}

/* ── base ──────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('assets/fonts/plus-jakarta-sans-var.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--t-md);
  line-height: var(--lh-md);
  -webkit-font-smoothing: antialiased;
}
/* hidden must win over every display rule below */
[hidden] {
  display: none !important;
}
a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
code,
pre {
  font-family: var(--mono);
}
code {
  font-size: 0.875em;
  background: var(--surface-3);
  padding: 2px var(--s1);
  border-radius: var(--r-xs);
}
pre {
  font-size: var(--t-sm);
  line-height: var(--lh-md);
  background: var(--surface-1);
  padding: var(--s4);
  overflow-x: auto;
}
pre code {
  font-size: inherit;
  background: none;
  padding: 0;
}
svg {
  flex: none;
}

/* one focus ring for the whole surface (WCAG 2.4.7) */
.chat-body :focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* ── buttons: one system ───────────────────────────────────────── */
/* .btn is the base; one variant sets the colours:
   primary (filled), accent (gold state), ghost (bordered),
   quiet (borderless), danger (bordered, destructive).
   .btn-md is the 36px size, .btn-icon makes it square. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: var(--ctl-sm);
  padding: 0 var(--s3);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-family: var(--sans);
  font-size: var(--t-sm);
  font-weight: var(--w-semi);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--ease), border-color var(--ease), color var(--ease),
    opacity var(--ease);
}
.btn:hover {
  text-decoration: none;
}
.btn > svg {
  width: var(--icon);
  height: var(--icon);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.btn-md {
  height: var(--ctl-md);
  padding: 0 var(--s4);
}
.btn-icon {
  width: var(--ctl-sm);
  padding: 0;
}
.btn-icon.btn-md {
  width: var(--ctl-md);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-accent,
.tb-seg .btn.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.btn-accent:hover {
  border-color: var(--accent);
}
.btn-ghost {
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn-ghost:hover {
  border-color: var(--text-3);
  background: var(--surface-3);
  color: var(--text);
}
.btn-quiet:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-soft);
}

/* ── chips: tool activity, picked agents, model capabilities ───── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  max-width: 100%;
  min-width: 0;
  height: var(--ctl-sm);
  padding: 0 var(--s3);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--link-soft);
  color: var(--link);
  font-size: var(--t-xs);
  font-weight: var(--w-medium);
  line-height: 1;
  white-space: nowrap;
}
.chip > svg {
  width: var(--icon);
  height: var(--icon);
}
.chip > span:not(.mm-av) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.chip-err {
  background: var(--danger-soft);
  color: var(--danger);
}
.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip-agent {
  padding-left: var(--s1);
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.chip-neutral {
  background: none;
  border-color: var(--border);
  color: var(--text-2);
}

/* ── layout ────────────────────────────────────────────────────── */
.chat-body {
  height: 100dvh;
  overflow: hidden;
}
.chat-app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  height: 100dvh;
}

/* ── sidebar ───────────────────────────────────────────────────── */
.cs {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--side-bg);
  border-right: 1px solid var(--border);
}
/* same height and rule as .cm-top: one continuous header line */
.cs-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--bar-h);
  padding: 0 var(--s2) 0 var(--s4);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: var(--text);
}
.brand:hover {
  text-decoration: none;
}
/* pixel logo + wordmark: inline SVG in currentColor, crisp at their
   grid multiples (13px, 10px) */
.brand svg {
  display: block;
}
.new-chat {
  flex: none;
  justify-content: flex-start;
  margin: var(--s3);
}
.cs .session-search {
  flex: none;
  height: var(--ctl-sm);
  margin: 0 var(--s3) var(--s2);
  font-size: var(--t-sm);
}
.session-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--s2);
}
.session-group {
  padding: var(--s3) var(--s3) var(--s1);
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  font-weight: var(--w-semi);
  color: var(--text-3);
}
.session-group:first-child {
  padding-top: var(--s1);
}
.session-empty {
  padding: var(--s2) var(--s3);
  font-size: var(--t-sm);
  color: var(--text-3);
}
.cs .session-rename {
  flex: 1;
  min-width: 0;
  height: var(--ctl-md);
  font-size: var(--t-sm);
}
.session-row.renaming {
  padding-right: 0;
}
.session-row {
  display: flex;
  align-items: center;
  gap: var(--s1);
  padding-right: var(--s1);
  border-radius: var(--r-sm);
  transition: background-color var(--ease);
}
.session-row:hover,
.session-row:focus-within {
  background: var(--surface-3);
}
.session-row.active {
  background: var(--surface-3);
  box-shadow: inset 2px 0 0 var(--accent);
}
.session-btn {
  flex: 1;
  min-width: 0;
  height: var(--ctl-md);
  padding: 0 var(--s3);
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--t-sm);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.session-row.active .session-btn {
  color: var(--text);
  font-weight: var(--w-medium);
}
.session-kebab {
  opacity: 0;
}
.session-row:hover .session-kebab,
.session-row:focus-within .session-kebab {
  opacity: 1;
}
@media (hover: none) {
  .session-kebab {
    opacity: 1;
  }
}
.cs-links {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  font-size: var(--t-sm);
}
.cs-links a {
  color: var(--text-2);
}
.cs-links a:hover {
  color: var(--text);
  text-decoration: none;
}
.cs-account {
  padding: var(--s2);
  border-top: 1px solid var(--border);
}
.acct-menu-btn {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  padding: var(--s2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--t-sm);
  cursor: pointer;
  transition: background-color var(--ease), border-color var(--ease);
}
.acct-menu-btn:hover {
  background: var(--surface-3);
  border-color: var(--border);
}
.acct-dot {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--ctl-sm);
  height: var(--ctl-sm);
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--on-primary);
  font-size: var(--t-xs);
  font-weight: var(--w-semi);
}
.acct-meta {
  flex: 1;
  min-width: 0;
  text-align: left;
  line-height: var(--lh-xs);
}
.acct-id {
  display: block;
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acct-menu-btn .chev {
  flex: none;
  color: var(--text-3);
}

/* ── main column + header ──────────────────────────────────────── */
.cm {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.cm-top {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
  height: var(--bar-h);
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--border);
}
.lang-switch {
  margin-left: auto;
}
.hide-desktop {
  display: none;
}

/* model picker: the native <select> (keyboard, screen readers, mobile
   pickers) dressed as a control; the chevron is a mask in currentColor */
.picker {
  position: relative;
  display: inline-flex;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--text-2);
}
.picker::after {
  content: '';
  position: absolute;
  top: 50%;
  right: var(--s3);
  width: var(--icon);
  height: var(--icon);
  margin-top: calc(var(--icon) / -2);
  background: currentColor;
  pointer-events: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
}
.picker:hover {
  color: var(--text);
}
.model-picker {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: var(--ctl-md);
  padding: 0 calc(var(--s6)) 0 var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: var(--w-semi);
  text-overflow: ellipsis;
  cursor: pointer;
  transition: border-color var(--ease);
}
.model-picker:hover {
  border-color: var(--text-3);
}
.model-picker optgroup,
.model-picker option {
  background: var(--surface-2);
  color: var(--text);
  font-weight: var(--w-regular);
}
.model-hint {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  overflow: hidden;
  font-size: var(--t-xs);
  color: var(--text-2);
  white-space: nowrap;
}
.model-hint .chip {
  height: 24px;
  cursor: default;
}
.cap-text {
  overflow: hidden;
  text-overflow: ellipsis;
}
.cap-warn {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  color: var(--warn);
  cursor: default;
}
.cap-warn > svg {
  width: var(--icon);
  height: var(--icon);
}

/* ── chat area ─────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s6) var(--s4) var(--s2);
  scroll-padding-bottom: var(--s5);
}
/* ── empty state: your crew ─────────────────────────────────────── */
/* no messages yet: the crew and the composer sit together in the
   middle; with the first message the composer returns to the bottom */
.chat-main.is-empty {
  justify-content: center;
  padding-bottom: 6vh;
}
.chat-main.is-empty .messages-wrap,
.chat-main.is-empty .messages {
  flex: none;
}
.chat-main.is-empty .messages {
  overflow: visible;
  /* the mesh texture reaches past the column; on phones it would
     widen the page */
  overflow-x: clip;
  padding-top: 0;
}
.crew-empty {
  position: relative;
  isolation: isolate;
  width: 100%;
  max-width: var(--col);
  margin: 0 auto;
  padding: var(--s6) 0 var(--s5);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s3);
}
/* the mesh: a faint dot grid that fades out towards the edges */
.crew-empty::before {
  content: '';
  position: absolute;
  inset: calc(var(--s7) * -1) calc(var(--s7) * -2);
  z-index: -1;
  background-image: radial-gradient(circle, var(--mesh-dot) 1px, transparent 1.5px);
  background-size: 24px 24px;
  background-position: center;
  -webkit-mask-image: radial-gradient(closest-side, #000 25%, transparent);
  mask-image: radial-gradient(closest-side, #000 25%, transparent);
  pointer-events: none;
}
.crew-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.crew-empty h1 {
  margin: 0;
  font-size: var(--t-xl);
  line-height: var(--lh-xl);
  font-weight: var(--w-hero);
  letter-spacing: -0.02em;
  color: var(--text);
  text-wrap: balance;
}
.crew-note {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  font-size: var(--t-sm);
  line-height: var(--lh-sm);
  color: var(--text-2);
}
.crew-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: var(--s2) 0 0 calc(var(--s2) * -1);
}
/* eight agents and the "+n" fit one row of the column */
.crew-pick {
  width: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s1);
  border: 0;
  border-radius: var(--r-md);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}
.crew-pick:hover {
  background: var(--surface-3);
  color: var(--text);
}
.crew-pick .mm-av {
  transition: box-shadow var(--ease);
}
/* gold: an agent of this node; blue: of another node */
.crew-pick.own:hover .mm-av,
.crew-pick.own[aria-pressed='true'] .mm-av {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}
.crew-pick.peer:hover .mm-av,
.crew-pick.peer[aria-pressed='true'] .mm-av {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--link);
}
.crew-pick.own[aria-pressed='true'] {
  color: var(--accent);
}
.crew-pick.peer[aria-pressed='true'] {
  color: var(--link);
}
.crew-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crew-more-box {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px dashed var(--border-strong);
  border-radius: 28%;
  font-size: var(--t-sm);
  font-weight: var(--w-semi);
}
.crew-asks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
  margin-left: calc(var(--s3) * -1);
}
.crew-empty.leaving {
  opacity: 0;
  transform: translateY(calc(var(--s3) * -1));
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}

/* messages */
.msg {
  width: 100%;
  max-width: var(--col);
  margin: 0 auto;
  font-size: var(--t-md);
  line-height: var(--lh-md);
}
/* air before a question, tight coupling between an answer and its byline */
.msg.user {
  width: fit-content;
  max-width: min(var(--col), 85%);
  margin-top: var(--s3);
  margin-right: calc((100% - min(var(--col), 100%)) / 2);
  margin-left: auto;
  padding: var(--s2) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-3);
  white-space: pre-wrap;
  word-break: break-word;
}
.messages > .msg-head + .msg.assistant {
  margin-top: calc(var(--s1) * -1);
}
.msg.assistant {
  color: var(--text);
}
.msg.assistant.streaming::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.msg.assistant p {
  margin: 0 0 var(--s3);
}
.msg.assistant h3 {
  margin: var(--s4) 0 var(--s2);
  font-size: var(--t-lg);
  line-height: var(--lh-lg);
  font-weight: var(--w-semi);
}
.msg.assistant h4,
.msg.assistant h5,
.msg.assistant h6 {
  margin: var(--s3) 0 var(--s1);
  font-size: var(--t-md);
  font-weight: var(--w-semi);
}
.msg.assistant ul,
.msg.assistant ol {
  margin: 0 0 var(--s3);
  padding-left: var(--s5);
}
.msg.assistant li {
  margin: 2px 0;
}
.msg.assistant li > ul,
.msg.assistant li > ol {
  margin: 2px 0 var(--s1);
}
.msg.assistant li.task {
  list-style: none;
  margin-left: -20px;
}
.msg.assistant li.task > input[type='checkbox'] {
  margin: 0 6px 0 0;
  vertical-align: -1px;
}
.msg.assistant blockquote {
  margin: 0 0 var(--s3);
  padding: 2px 0 2px var(--s3);
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}
.msg.assistant blockquote p:last-child {
  margin-bottom: 0;
}
.msg.assistant hr {
  margin: var(--s4) 0;
  border: 0;
  border-top: 1px solid var(--border);
}
/* wide tables scroll inside the answer, never the page */
.table-wrap {
  overflow-x: auto;
  margin: var(--s1) 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.msg.assistant table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  line-height: var(--lh-sm);
}
.msg.assistant th,
.msg.assistant td {
  padding: var(--s2) var(--s3);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.msg.assistant th {
  background: var(--surface-1);
  font-weight: var(--w-semi);
  white-space: nowrap;
}
.msg.assistant tbody tr:last-child td {
  border-bottom: 0;
}

/* code blocks: long lines scroll sideways; height follows the code —
   no scroll area nested inside the scrolling conversation */
.codeblock {
  margin: var(--s1) 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.codebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  min-height: var(--ctl-md);
  padding: var(--s1) var(--s1) var(--s1) var(--s3);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--text-3);
}
.codeblock pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  overflow-x: auto;
}

/* media made by agents */
.msg img.mm-image {
  display: block;
  max-width: min(100%, 512px);
  max-height: 512px;
  min-height: 64px;
  margin: var(--s2) 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-3);
  cursor: zoom-in;
}
.msg .mm-image-gone {
  display: inline-block;
  margin: var(--s1) 0;
  font-size: var(--t-xs);
  color: var(--text-3);
}
.msg video.mm-media {
  display: block;
  width: 100%;
  max-width: 640px;
  max-height: 480px;
  margin: var(--s2) 0;
  border-radius: var(--r-md);
  background: var(--scrim);
}
.msg audio.mm-media {
  display: block;
  width: 100%;
  max-width: 480px;
  margin: var(--s2) 0;
}
/* a job still being made: becomes the result when done */
.msg .mm-job {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  margin: var(--s2) 0;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  font-size: var(--t-sm);
  font-variant-numeric: tabular-nums;
}
.msg .mm-job-failed {
  color: var(--danger);
}
.msg .mm-job-spin {
  width: var(--icon);
  height: var(--icon);
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--r-full);
  opacity: 0.6;
  animation: mm-job-spin 0.9s linear infinite;
}
@keyframes mm-job-spin {
  to {
    transform: rotate(360deg);
  }
}

/* thinking indicator: a mesh tool call can take 10–30s. Three gold
   pixels, stepping like the logo's grid. */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: 22px;
}
.thinking i {
  display: block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  opacity: 0.55;
}
@media (prefers-reduced-motion: no-preference) {
  .thinking i {
    animation: think 0.9s steps(3) infinite;
  }
  .thinking i:nth-child(2) {
    animation-delay: 0.3s;
  }
  .thinking i:nth-child(3) {
    animation-delay: 0.6s;
  }
  @keyframes think {
    from {
      opacity: 1;
    }
    to {
      opacity: 0.2;
    }
  }
}

/* ── byline: who wrote an answer ───────────────────────────────── */
.msg-head {
  width: 100%;
  max-width: var(--col);
  margin: var(--s2) auto 0;
}
.msg-by {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  min-height: var(--ctl-sm);
  font-size: var(--t-sm);
  line-height: var(--lh-sm);
  color: var(--text-2);
}
.by-avs {
  flex: none;
  display: inline-flex;
}
.by-av {
  box-shadow: 0 0 0 2px var(--bg);
}
.by-av + .by-av {
  margin-left: -6px;
}
.by-av.is-err {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--danger);
  filter: grayscale(1);
}
.by-av.is-idle {
  opacity: 0.5;
}
@media (prefers-reduced-motion: no-preference) {
  .by-av.is-run {
    animation: by-run 1.2s ease-in-out infinite;
  }
  @keyframes by-run {
    50% {
      opacity: 0.4;
    }
  }
}
.by-logo {
  flex: none;
  color: var(--accent);
}
.by-names {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
}
.by-name {
  font-weight: var(--w-semi);
  color: var(--text);
}
.by-name.is-err {
  color: var(--danger);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: help;
}
.by-act {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--text-3);
}
.by-status {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--t-xs);
  color: var(--text-3);
}
.by-toggle {
  margin-left: auto;
  color: var(--text-3);
}
.by-toggle.open {
  background: var(--surface-3);
  color: var(--text);
}
/* the node an agent ran on: gold this node, blue another node */
.node-tag {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 var(--s2);
  border-radius: var(--r-xs);
  font-size: var(--t-xs);
  font-weight: var(--w-medium);
  line-height: 1;
  white-space: nowrap;
}
.node-tag.own {
  background: var(--accent-soft);
  color: var(--accent);
}
.node-tag.peer {
  background: var(--link-soft);
  color: var(--link);
  font-family: var(--mono);
}
.by-note {
  display: flex;
  align-items: flex-start;
  gap: var(--s1);
  margin-top: 2px;
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  color: var(--text-2);
}
.by-note > svg {
  width: var(--icon);
  height: var(--icon);
  margin-top: 1px;
  color: var(--text-3);
}
.by-note.warn > svg {
  color: var(--warn);
}
.by-note.err > svg {
  color: var(--danger);
}

/* under an answer: copy */
.msg-meta {
  width: 100%;
  max-width: var(--col);
  min-height: var(--ctl-sm);
  margin: calc(var(--s2) * -1) auto var(--s1);
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.msg-stopped {
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  color: var(--text-3);
}
.msg-act {
  opacity: 0;
}
.msg-meta:hover .msg-act,
.msg-act:focus-visible {
  opacity: 1;
}
@media (hover: none) {
  .msg-act {
    opacity: 1;
  }
}
/* origin panel: opens under the byline */
.prov-panel {
  margin: var(--s2) 0 var(--s1);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
}
.prov-panel dl {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: var(--s1) var(--s4);
  margin: 0;
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
}
.prov-panel dt {
  color: var(--text-3);
}
.prov-panel dd {
  margin: 0;
  color: var(--text-2);
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

/* scroll to latest */
.to-bottom {
  position: absolute;
  left: 50%;
  bottom: var(--s3);
  z-index: 5;
  transform: translateX(-50%);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.to-bottom:hover {
  background: var(--surface-2);
}

/* ── notices: one form for errors, warnings and confirmations ──── */
.notice,
.tb-warn {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--ctl-md);
  padding: var(--s1) var(--s1) var(--s1) var(--s3);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--t-sm);
  line-height: var(--lh-sm);
}
.notice > svg,
.tb-warn > svg {
  width: var(--icon);
  height: var(--icon);
  color: var(--warn);
}
.notice > span,
.tb-warn > span {
  flex: 1;
  min-width: 0;
  padding: var(--s1) 0;
}
.notice a {
  color: inherit;
  text-decoration: underline;
}
.notice.ok {
  background: var(--ok-soft);
}
.notice.ok > svg {
  color: var(--ok);
}
.notice.error {
  background: var(--danger-soft);
}
.notice.error > svg {
  color: var(--danger);
}
.notice {
  width: calc(100% - 2 * var(--s4));
  max-width: var(--col);
  margin: 0 auto var(--s2);
}
.tb-warn {
  flex: 1 1 100%;
  flex-wrap: wrap;
  min-width: 0;
}
/* narrow: the switch drops under the sentence instead of squeezing it */
.tb-warn > span {
  flex: 1 1 14rem;
}

/* ── composer ──────────────────────────────────────────────────── */
.composer-wrap {
  position: relative;
  padding: var(--s2) var(--s4) var(--s3);
}
.tb-bar {
  max-width: var(--col);
  margin: 0 auto var(--s2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}
/* Auto | Manual: both visible, the active one in gold */
.tb-seg {
  display: inline-flex;
  gap: 2px;
  height: var(--ctl-sm);
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
}
.tb-seg .btn {
  height: 100%;
}
#tb-chips {
  display: contents;
}
.tb-chip.own {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.tb-chip.peer {
  background: var(--link-soft);
  border-color: var(--link-soft);
}
.tb-chip.missing {
  border-color: var(--danger);
  color: var(--danger);
  text-decoration: line-through;
}
.tb-chip-label {
  min-width: 0;
  max-width: 14rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.tb-chip-label:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.tb-plus .kbd {
  margin-right: calc(var(--s1) * -1);
}
.tb-chip .btn-icon {
  width: 20px;
  height: 20px;
  margin-right: -6px;
}
.mention-pop {
  position: absolute;
  bottom: calc(100% - 2px);
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  width: min(20rem, calc(100% - 2 * var(--s4)));
  display: flex;
  flex-direction: column;
  padding: var(--s1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.mention-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  height: var(--ctl-md);
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--t-sm);
  text-align: left;
  cursor: pointer;
}
.mention-item:hover,
.mention-item.active {
  background: var(--surface-3);
  color: var(--accent);
}
.mention-name {
  min-width: 0;
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--sans);
  font-size: var(--t-xs);
  color: var(--text-3);
}
.composer {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  /* one line: centred; once the textarea grows the button pins itself
     to the bottom */
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s2) var(--s2) var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.composer:focus-within {
  border-color: var(--text-3);
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 220px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
  line-height: var(--lh-sm);
  resize: none;
  outline: none;
}
.composer textarea::placeholder {
  color: var(--text-3);
}
.composer textarea:focus-visible {
  outline: none;
}
.send-btn {
  align-self: flex-end;
}
.send-btn > svg {
  width: 18px;
  height: 18px;
}
.send-btn.stop,
.send-btn.stop:hover {
  background: var(--danger-solid);
  color: var(--on-solid);
}
.send-btn.stop > svg {
  width: var(--icon);
  height: var(--icon);
}
.composer-foot,
.conn-status {
  max-width: var(--col);
  margin: var(--s2) auto 0;
  text-align: center;
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  color: var(--text-3);
}
.conn-status {
  margin-top: 2px;
  cursor: default;
}
.conn-status svg {
  width: 12px;
  height: 12px;
  margin-right: var(--s1);
  vertical-align: -1px;
}
.composer-hint::after {
  content: ' ·';
}
.composer-foot a {
  color: inherit;
  text-decoration: underline;
}
.composer-foot a:hover {
  color: var(--text-2);
}

/* ── agent palette (and the token / name dialogs in auth.js) ──── */
.pal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--s4) var(--s4);
  background: var(--scrim);
}
.pal {
  width: min(34rem, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.pal-head {
  display: flex;
  align-items: center;
  padding-right: var(--s2);
  border-bottom: 1px solid var(--border);
}
.pal-head input[type='search'] {
  flex: 1;
  min-width: 0;
  padding: var(--s3) var(--s4);
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
  outline: none;
}
.pal-head input[type='search']::placeholder {
  color: var(--text-3);
}
.pal-body {
  min-height: 8rem;
  overflow-y: auto;
  padding: var(--s1) var(--s2) var(--s2);
}
.pal-section {
  padding: var(--s3) var(--s2) var(--s1);
  font-size: var(--t-xs);
  font-weight: var(--w-semi);
  color: var(--text-3);
}
.pal-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2);
  border-radius: var(--r-md);
  transition: background-color var(--ease);
}
.pal-row:hover {
  background: var(--surface-3);
}
.pal-row.own:hover {
  box-shadow: inset 2px 0 0 var(--accent);
}
.pal-row.peer:hover {
  box-shadow: inset 2px 0 0 var(--link);
}
.pal-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: var(--s1);
}
.pal-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.pal-name {
  min-width: 0;
  font-size: var(--t-sm);
  font-weight: var(--w-medium);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* two lines of description beat a mid-word ellipsis */
.pal-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  color: var(--text-3);
}
.note-input {
  height: var(--ctl-sm);
  margin-top: 2px;
  padding: 0 var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--text-2);
  font: inherit;
  font-size: var(--t-xs);
  outline: none;
}
.note-input:focus {
  border-color: var(--accent);
  color: var(--text);
}
.pal-empty {
  padding: var(--s3) var(--s2);
  font-size: var(--t-sm);
  color: var(--text-3);
}
.pal-explore {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: var(--s3) var(--s2) var(--s1);
  font-size: var(--t-sm);
  color: var(--text-2);
}
.pal-explore > svg {
  width: var(--icon);
  height: var(--icon);
}
.pal-explore:hover {
  color: var(--text);
}
.pal-stack-save {
  margin: 2px var(--s2) var(--s2);
  border-style: dashed;
}
.pal-foot {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  font-size: var(--t-xs);
  line-height: var(--lh-xs);
  color: var(--text-3);
}
.pal-foot > span {
  flex: 1;
  min-width: 0;
}
@media (min-width: 641px) {
  .pal-close {
    display: none;
  }
}
/* opening: the scrim fades in, the panel settles */
@media (prefers-reduced-motion: no-preference) {
  .pal-overlay {
    animation: pal-fade 160ms ease-out;
  }
  .pal-overlay .pal {
    animation: pal-in 160ms ease-out;
  }
  @keyframes pal-fade {
    from {
      opacity: 0;
    }
  }
  @keyframes pal-in {
    from {
      opacity: 0;
      transform: scale(0.98);
    }
  }
}

/* dialogs built in auth.js reuse .pal */
.field {
  height: var(--ctl-md);
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
}
.field:focus {
  border-color: var(--text-3);
}
.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--t-sm);
  text-decoration: underline;
  cursor: pointer;
}
.linkish:hover {
  color: var(--text);
}

/* ── popup menu (session actions, account) ─────────────────────── */
.menu {
  position: fixed;
  z-index: 60;
  min-width: 172px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.menu [role^='menuitem'] {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  height: var(--ctl-md);
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--t-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--ease);
}
.menu [role^='menuitem']:hover {
  background: var(--surface-3);
}
.menu [role^='menuitem'].danger {
  color: var(--danger);
}
.menu [role^='menuitem'] svg {
  color: var(--text-2);
}
.menu [role^='menuitem'].danger svg {
  color: inherit;
}
.menu-sep {
  height: 1px;
  margin: var(--s1) 2px;
  background: var(--border);
}
.menu-label {
  padding: var(--s1) var(--s3);
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--text-3);
}
/* a pick's note: the menu box holding a small form */
.note-pop {
  width: min(20rem, calc(100vw - 2 * var(--s2)));
  gap: var(--s2);
  padding: var(--s2);
}
.note-pop .menu-label {
  padding: 0 var(--s1);
}
.note-pop-text {
  height: auto;
  min-height: 5rem;
  padding: var(--s2);
  font-size: var(--t-sm);
  line-height: var(--lh-sm);
  resize: vertical;
}
.note-pop .btn {
  align-self: flex-end;
}

/* a key to press, set small: ⌘K on the agents button */
.kbd {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-family: var(--mono);
  font-size: var(--t-xs);
  font-weight: var(--w-regular);
  color: var(--text-3);
}
/* a picture opened full size */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: var(--s7) var(--s4);
  background: var(--scrim);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: calc(100dvh - 2 * var(--s7));
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.lightbox-close {
  position: absolute;
  top: var(--s3);
  right: var(--s3);
  background: var(--surface-2);
}
.lightbox-close:hover {
  background: var(--surface-2);
}
/* the drawer's scrim: only on small screens, see below */
.cs-scrim {
  display: none;
}

/* ── chrome outside the chat ───────────────────────────────────── */
/* over plain HTTP from another machine: loud, above everything */
.insecure-band {
  position: sticky;
  top: 0;
  z-index: 200;
  padding: var(--s2) var(--s4);
  background: var(--danger-solid);
  color: var(--on-solid);
  font-size: var(--t-sm);
  font-weight: var(--w-semi);
  text-align: center;
}
/* agent avatar (avatar.js): gradient with a white icon or the letter;
   sizes are set inline */
.mm-av {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 28%;
  color: var(--on-solid);
  font-family: var(--sans);
  font-weight: var(--w-semi);
  font-style: normal;
  line-height: 1;
  user-select: none;
}
/* Font Awesome 7 paths reach slightly past their viewBox */
.mm-av svg {
  overflow: visible;
}

/* ── small screens ─────────────────────────────────────────────── */
/* ── central chat (chat.majesticmesh.com, central.js) ──────────── */
/* The gate before the chat: join, sign in, pick an account. */
.gate {
  gap: var(--s3);
  padding: var(--s5);
}
.gate-title {
  margin: 0;
  font-size: var(--t-lg);
}
.gate-text {
  margin: 0;
  color: var(--text-2);
}
.gate-form {
  display: grid;
  gap: var(--s3);
}
.gate-label {
  font-weight: 600;
}
.gate-err {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
}
/* Which node answers, in the top bar. */
.served-chip {
  min-width: 0;
  margin-left: auto;
  overflow: hidden;
  font-size: var(--t-xs);
  color: var(--text-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.served-chip:not([hidden]) + .lang-switch {
  margin-left: var(--s2);
}
.served-toast {
  position: fixed;
  top: calc(var(--bar-h) + var(--s2));
  left: 50%;
  z-index: 70;
  max-width: min(32rem, calc(100% - 2 * var(--s4)));
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: var(--t-sm);
  transform: translateX(-50%);
}

@media (max-width: 760px) {
  .chat-app {
    grid-template-columns: 1fr;
  }
  .cs {
    position: fixed;
    inset: 0 84px 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }
  .cs.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  .cs-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 29;
    background: var(--scrim);
  }
  /* 16px inputs: iOS zooms into anything smaller */
  .cs .session-search,
  .cs .session-rename,
  .note-pop-text {
    font-size: var(--t-md);
  }
  .hide-desktop {
    display: inline-flex;
  }
  .cm-top {
    padding: 0 var(--s2);
  }
  .msg.user {
    max-width: 92%;
    margin-right: 0;
  }
  /* several agents: the names get their own line rather than an ellipsis */
  .msg-by {
    flex-wrap: wrap;
    row-gap: 2px;
  }
}
/* keyboard hints only where there is a keyboard */
@media (hover: none), (max-width: 760px) {
  .tb-plus .kbd,
  .composer-hint {
    display: none;
  }
}
/* secondary info — never let it crowd the header */
@media (max-width: 720px) {
  .model-hint {
    display: none;
  }
}
/* the palette becomes a full-screen sheet on phones: no "tap outside",
   so the close button shows; 16px search so iOS never zooms */
@media (max-width: 640px) {
  .pal-overlay {
    align-items: stretch;
    padding: 0;
  }
  .pal {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    padding-bottom: env(safe-area-inset-bottom);
    border: 0;
    border-radius: 0;
  }
  .pal-head input[type='search'] {
    padding: var(--s4);
  }
  .pal-row {
    flex-flow: row wrap;
    padding: var(--s3) var(--s2);
  }
  .pal-main {
    flex: 1 0 calc(100% - 48px);
  }
  .pal-name {
    white-space: normal;
  }
  .pal-row .btn {
    height: var(--ctl-md);
  }
  .pal-foot {
    padding-bottom: var(--s4);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .msg .mm-job-spin {
    animation: none;
  }
}
