/* Brand webfonts, self-hosted from /fonts (see scripts/sync-bridge-fonts.mjs).
   Inter Variable carries body text; Poppins carries display headings. */
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-ext-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-wght-italic.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Inter Variable";
  font-style: italic;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-ext-wght-italic.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/poppins-latin-500-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/poppins-latin-ext-500-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/poppins-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/poppins-latin-ext-600-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/poppins-latin-700-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/poppins-latin-ext-700-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}

:root {
  color-scheme: light;
  --paper: #f2f4ef;
  --paper-deep: #e6ebe2;
  --surface: #fbfcf9;
  --ink: #1c2530;
  --muted: #616b79;
  --line: rgba(16, 35, 60, 0.14);
  --accent: #0b6fd6;
  --accent-hover: #095cb4;
  --accent-soft: #dcedfd;
  --accent-contrast: #ffffff;
  --success: #157a4e;
  --warning: #8a6200;
  --danger: #b3392f;
  --shadow: 0 22px 70px rgba(14, 35, 66, 0.12);
  --font-display: "Poppins", "Inter Variable", Inter, system-ui, sans-serif;
  font-family: "Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0f1622;
    --paper-deep: #131c2b;
    --surface: #182233;
    --ink: #e9eef7;
    --muted: #a5b0c2;
    --line: rgba(255, 255, 255, 0.14);
    --accent: #1ea0ff;
    --accent-hover: #4db5ff;
    --accent-soft: #0f2f4d;
    --accent-contrast: #06233c;
    --success: #56d99a;
    --warning: #f6b516;
    --danger: #ff9b92;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  }
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.nobr { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.brand-lockup {
  display: block;
  height: 34px;
  width: auto;
}

.brand-lockup-white { display: none; }

@media (prefers-color-scheme: dark) {
  .brand-lockup-black { display: none; }
  .brand-lockup-white { display: block; }
}

/* --- Landing, sign-in, pairing, and offline gate ------------------------- */

.auth-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 28px clamp(22px, 4vw, 64px);
  overflow: hidden;
}


.auth-top { display: flex; align-items: center; justify-content: space-between; }

.auth-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 430px);
  align-items: center;
  gap: clamp(50px, 8vw, 140px);
  width: min(1160px, 100%);
  margin: auto;
}

.auth-copy { max-width: 610px; animation: rise-in 480ms cubic-bezier(.2,.8,.2,1) both; }
.eyebrow { margin: 0 0 18px; color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.auth-copy h1 { margin: 0; font-family: var(--font-display); font-size: clamp(44px, 6.5vw, 84px); line-height: 1; letter-spacing: -.035em; font-weight: 600; }
.auth-copy p:not(.eyebrow) { max-width: 470px; margin: 26px 0 0; color: var(--muted); font-size: 17px; line-height: 1.6; }

.auth-panel {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  animation: rise-in 560ms 80ms cubic-bezier(.2,.8,.2,1) both;
}
.auth-panel h2 { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.auth-panel > p { color: var(--muted); line-height: 1.55; }

.field { display: grid; gap: 8px; margin: 22px 0 0; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
}
.field input { height: 48px; padding: 0 14px; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.primary, .quiet, .rail-new-chat, .send-button, .text-button { border: 0; cursor: pointer; }
.primary {
  width: 100%;
  margin-top: 18px;
  padding: 13px 18px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  transition: transform 140ms ease, background 140ms ease;
}
.primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.primary:disabled, .send-button:disabled { opacity: .55; cursor: default; transform: none; }
.quiet { padding: 7px 10px; background: transparent; color: var(--muted); border-radius: 8px; }
.quiet:hover { color: var(--ink); background: var(--paper-deep); }
.danger { color: var(--danger); }
.form-error { margin: 14px 0 0; color: var(--danger) !important; font-size: 13px; }

.pairing-code { margin: 24px 0; font-variant-numeric: tabular-nums; font-size: 42px; font-weight: 740; letter-spacing: .18em; }
.pairing-status { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

@media (max-width: 1020px) {
}

@media (max-width: 760px) {
  .auth-shell { padding: 20px; }
  .auth-stage { grid-template-columns: 1fr; align-content: center; gap: 38px; }
  .auth-copy h1 { font-size: 52px; }
  .auth-copy p:not(.eyebrow) { font-size: 15px; }
  .auth-panel { padding: 24px; }
}

/* --- The connected app: one sidebar, four screens ------------------------
   Phone-first. One visible screen at a time. Under 860px the sidebar is the
   drawer behind ☰ in the top bar; at 860px and up it is the left column,
   expanded or collapsed to an icon rail. The screens are identical at every
   width. */

.app-shell {
  height: 100svh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  padding-top: env(safe-area-inset-top, 0px);
}

.app-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-contexts {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.context { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.context[hidden] { display: none; }
.context-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.context-column { width: min(720px, 100%); margin: 0 auto; padding: 18px 18px calc(24px + env(safe-area-inset-bottom, 0px)); }
.context-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.context-title { margin: 0; font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -.02em; outline: none; }

/* The square icon-button recipe: top-bar controls, the sidebar toggle, and
   every sidebar destination once the sidebar is collapsed. The selected
   destination gets a soft fill plus a small accent pill. */
.rail-item {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.rail-item:hover { background: var(--surface); color: var(--ink); }
.rail-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rail-item:disabled { opacity: .56; cursor: default; }
.rail-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-item[aria-current="page"] { background: var(--surface); color: var(--ink); }
.rail-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

/* --- The sidebar: the desktop column and the phone drawer, one markup ----- */

.sidebar {
  position: fixed;
  z-index: 41;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(300px, 86vw);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 10px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper-deep);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
  transform: translateX(-102%);
  /* Closed, the drawer is out of reach for the pointer and the keyboard; it
     becomes visible the instant it opens and only hides once it has left. */
  visibility: hidden;
  transition: transform 200ms cubic-bezier(.2, .8, .2, 1), visibility 0s linear 200ms;
}
.app-shell[data-drawer="open"] .sidebar {
  transform: none;
  visibility: visible;
  transition: transform 200ms cubic-bezier(.2, .8, .2, 1), visibility 0s;
}
.drawer-scrim { display: none; }
.app-shell[data-drawer="open"] .drawer-scrim { position: fixed; z-index: 40; inset: 0; display: block; background: rgba(28, 37, 48, .34); }
body.drawer-locked { overflow: hidden; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; margin-bottom: 8px; }
.sidebar-brand { display: flex; align-items: center; gap: 9px; min-width: 0; padding-left: 8px; }
.sidebar-brand img { width: 26px; height: 26px; flex: none; border-radius: 7px; }
.sidebar-brand span { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.sidebar-toggle { width: 36px; height: 36px; }
.sidebar-toggle svg { width: 19px; height: 19px; }
.glyph-expand, .glyph-close { display: none; }

.sidebar-actions { display: grid; gap: 2px; }
.sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.sidebar-item:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.sidebar-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sidebar-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.sidebar-item[aria-current="page"] { background: var(--surface); }
.sidebar-item[aria-current="page"] svg { color: var(--ink); }
.sidebar-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-chats-item { display: none; }
.sidebar-chats { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; margin: 0 -4px; padding: 0 4px; }
.sidebar-foot { flex: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.sidebar-footer-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-footer-actions .folder-picker-shell { flex: 1; min-width: 0; }
.folder-picker-shell { position: relative; }
.folder-picker {
  position: absolute;
  z-index: 70;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(300px, calc(100vw - 32px));
  max-height: min(360px, 55dvh);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.folder-picker[hidden] { display: none; }
/* Component display rules must never override the semantic hidden state. */
#desktop-presence[hidden] { display: none; }
.folder-picker-label { margin: 6px 8px 5px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.folder-picker button { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 40px; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.folder-picker button:hover, .folder-picker button:focus-visible { background: var(--paper-deep); outline: none; }
.folder-picker button[aria-current="true"] { font-weight: 650; }
.folder-picker .file-glyph { width: 18px; height: 18px; }
.folder-picker button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence { display: flex; align-items: center; gap: 8px; min-height: 32px; margin: 4px 10px 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.presence-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--muted); }
.presence[data-online="true"] { color: var(--success); }
.presence[data-online="true"] .presence-dot { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 14%, transparent); }

/* --- The phone top bar (and the desktop conversation bar) ----------------- */

.top-bar {
  flex: none;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 8px 0;
}
/* Explicit placement: the slots keep their columns even when a control is
   not shown, so the title stays centered instead of sliding left. */
.top-bar-menu { grid-column: 1; }
.top-bar-center { grid-column: 2; }
.top-bar-actions { grid-column: 3; }
.top-bar-menu .menu-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}
.top-bar-menu .menu-dot[hidden] { display: none; }
.top-bar-center { min-width: 0; justify-self: center; display: flex; align-items: center; justify-content: center; max-width: 100%; }
.top-bar-mark, .top-bar-title, .top-bar-center .conversation-title-shell { display: none; }
.app-shell[data-context="new"] .top-bar-mark { display: block; width: 28px; height: 28px; border-radius: 7px; }
.app-shell[data-context="needs"] .top-bar-title,
.app-shell[data-context="spaces"] .top-bar-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; letter-spacing: -.015em; }
.app-shell[data-context="chat"] .top-bar-center .conversation-title-shell { display: block; }
.top-bar-actions { justify-self: end; min-width: 44px; display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.app-shell[data-context="needs"] .top-bar-new-chat,
.app-shell[data-context="spaces"] .top-bar-new-chat { display: none; }

.account-settings {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.account-settings:hover, .account-settings[aria-expanded="true"] { background: var(--paper); color: var(--ink); }
.account-settings:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.account-settings svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; stroke-linejoin: round; }
.account-menu {
  position: absolute;
  z-index: 30;
  min-width: 132px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(28, 24, 20, .16);
}
.account-menu[hidden] { display: none; }
.account-menu button { width: 100%; min-height: 36px; padding: 6px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--danger); text-align: left; font-size: 12px; cursor: pointer; }
.account-menu button:hover { background: var(--paper-deep); }
.rail-account { position: relative; }
.rail-account .account-menu { right: 0; bottom: 46px; }

.text-button { display: inline-flex; align-items: center; min-height: 36px; padding: 4px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--accent); font-size: 13px; font-weight: 650; }
.text-button:hover { background: var(--accent-soft); }
.text-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.text-button[hidden] { display: none; }

/* --- The sidebar's saved-chat list, grouped by the day it last moved ------ */

.chat-list { min-width: 0; margin: 0; padding: 0; list-style: none; }
.chat-group-heading { display: block; margin: 16px 0 2px; padding: 0 10px; color: var(--muted); font-size: 11px; font-weight: 720; letter-spacing: .09em; text-transform: uppercase; }
.chat-list > li:first-child .chat-group-heading { margin-top: 16px; }
.chat-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.chat-button:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.chat-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-button.active { background: var(--surface); }
.chat-button:disabled { opacity: .56; cursor: default; }
.chat-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.chat-working { display: flex; align-items: center; gap: 6px; color: var(--accent); font-size: 11px; font-weight: 600; }
.chat-working-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); animation: work-pulse 1.4s ease-in-out infinite; }
.empty-list { padding: 10px; color: var(--muted); font-size: 13px; }

.rail-new-chat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.rail-new-chat:hover { background: var(--paper); border-color: color-mix(in srgb, var(--accent) 42%, var(--line)); transform: translateY(-1px); }
.rail-new-chat:active { transform: translateY(0) scale(.985); }
.rail-new-chat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rail-new-chat:disabled { opacity: .56; cursor: default; transform: none; }
.rail-new-chat svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- The New chat screen: one question and the composer ------------------- */

.new-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px 20px 32px; }
.new-heading {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -.02em;
  text-align: center;
  outline: none;
}

/* --- Chat: one transcript under its title, composer ----------------------- */

.conversation-title-shell { min-width: 0; width: 100%; max-width: 460px; }
.conversation-title-view {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.conversation-title-view[hidden] { display: none; }
.conversation-title-view > h1 { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; letter-spacing: -.015em; text-align: center; outline: none; }
.conversation-title-button {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.conversation-title-button svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .34; transition: opacity 120ms ease; }
.conversation-title-button:hover:not(:disabled) { background: var(--paper); color: var(--ink); }
.conversation-title-button:hover:not(:disabled) svg,
.conversation-title-button:focus-visible svg { opacity: .72; }
.conversation-title-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.conversation-title-button:disabled { cursor: default; }
.conversation-title-button:disabled svg { opacity: 0; }
.conversation-delete-button { color: var(--danger); }
.conversation-delete-button:hover:not(:disabled) { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.conversation-title-form { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 34px 34px; align-items: center; gap: 5px; }
.conversation-title-form[hidden] { display: none; }
.conversation-title-form input { min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--paper); color: var(--ink); font-size: 14px; font-weight: 620; text-align: center; }
.conversation-title-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.title-edit-action { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.title-edit-action:hover:not(:disabled) { color: var(--ink); background: var(--paper); }
.title-edit-action.save { color: var(--success); }
.title-edit-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.title-edit-action:disabled { opacity: .48; cursor: default; }
.title-edit-action svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.toolbar-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.toolbar-button:hover { color: var(--ink); background: var(--paper); }
.toolbar-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar-button.danger { color: var(--danger); }

.messages { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 20px; scroll-behavior: smooth; }
.message-stream { width: min(760px, 100%); margin: 0 auto; }
.projection-notice { margin: 0 0 18px; padding: 10px 13px; border-radius: 9px; background: var(--paper-deep); color: var(--warning); font-size: 12px; line-height: 1.45; }
.message { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 16px 0; }
.message.message-enter { animation: message-in 240ms ease both; }
.message-role { color: var(--muted); font-size: 12px; font-weight: 650; }
.message-content { min-width: 0; }
.message-body { overflow-wrap: anywhere; line-height: 1.65; user-select: text; }
.message-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.message-attachments span { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 7px; background: var(--paper-deep); color: var(--muted); font-size: 11px; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 12px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { margin: 18px 0 8px; line-height: 1.25; letter-spacing: -.02em; }
.markdown h1 { font-size: 1.35em; }
.markdown h2 { font-size: 1.22em; }
.markdown h3 { font-size: 1.1em; }
.markdown ul, .markdown ol { margin: 8px 0 12px; padding-left: 24px; }
.markdown li + li { margin-top: 4px; }
.markdown blockquote { margin: 12px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.markdown code { padding: 2px 5px; border-radius: 5px; background: var(--paper-deep); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.markdown pre { margin: 12px 0; padding: 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-deep); line-height: 1.5; }
.markdown pre code { padding: 0; background: transparent; font-size: 12px; }
.markdown a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.markdown-table-wrap { max-width: 100%; margin: 12px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
.markdown table { width: 100%; border-collapse: collapse; font-size: .92em; }
.markdown th, .markdown td { padding: 8px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.markdown th { background: var(--paper-deep); font-weight: 650; }
.markdown tr:last-child td { border-bottom: 0; }
.markdown th:last-child, .markdown td:last-child { border-right: 0; }
.working-row { display: flex; align-items: center; gap: 10px; padding: 14px 0; color: var(--muted); font-size: 13px; }
.work-event { display: flex; align-items: center; gap: 9px; width: max-content; max-width: 100%; margin: 14px 0 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--muted); font-size: 12px; }
.work-event strong { color: var(--ink); font-weight: 650; }
.work-event-mark { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 13%, transparent); }
.work-event.running .work-event-mark { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); animation: work-pulse 1.4s ease-in-out infinite; }
.work-event.failed { color: var(--danger); }
.work-event.failed .work-event-mark { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 12%, transparent); }
.banner { width: min(720px, calc(100% - 32px)); margin: 10px auto 0; padding: 10px 13px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 13px; }

/* --- The composer, at the foot of New chat and Chat ----------------------- */

.composer-wrap { flex: none; padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--surface); }
.composer { position: relative; width: min(760px, 100%); margin: 0 auto; }
.composer-context { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 7px; }
.composer-context:empty { display: none; }
.context-chip { max-width: 100%; display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 4px 5px 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--muted); font-size: 11px; }
.context-chip > span { min-width: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-chip button { width: 22px; height: 22px; border: 0; border-radius: 5px; background: transparent; color: inherit; cursor: pointer; }
.context-chip button:hover { background: var(--paper-deep); color: var(--ink); }
.composer-field {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 8px 28px rgba(28, 24, 20, 0.07);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.composer-field:focus-within {
  border-color: color-mix(in srgb, var(--accent) 72%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent), 0 10px 32px rgba(28, 24, 20, 0.09);
}
.composer textarea {
  display: block;
  min-height: 56px;
  max-height: 180px;
  resize: none;
  overflow-y: auto;
  padding: 16px 58px 15px 56px;
  border: 0;
  border-radius: 16px;
  line-height: 1.5;
  background: transparent;
  transition: height 120ms ease;
}
.composer textarea::placeholder { color: color-mix(in srgb, var(--muted) 82%, transparent); }
.attach-button {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.attach-button:hover { background: var(--paper-deep); color: var(--ink); }
.attach-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.attach-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.send-button {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 26%, transparent);
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}
.send-button:not(:disabled):hover { background: var(--accent-hover); box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 32%, transparent); transform: translateY(-1px); }
.send-button:not(:disabled):active { transform: translateY(0) scale(.96); }
.send-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.send-button:disabled { background: color-mix(in srgb, var(--muted) 26%, var(--paper-deep)); color: var(--muted); box-shadow: none; opacity: .72; }
.send-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.send-button[data-sending="true"] .send-icon { display: none; }
.send-button[data-sending="true"]::after { content: ""; width: 14px; height: 14px; border: 2px solid color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; border-radius: 50%; animation: spin .8s linear infinite; }
.send-button[hidden] { display: none; }
.stop-button { background: var(--danger); color: #fff; box-shadow: 0 5px 14px color-mix(in srgb, var(--danger) 24%, transparent); }
.stop-button:not(:disabled):hover { background: color-mix(in srgb, var(--danger) 86%, #000); box-shadow: 0 7px 18px color-mix(in srgb, var(--danger) 30%, transparent); }
.stop-button:disabled { background: color-mix(in srgb, var(--danger) 42%, var(--paper-deep)); color: #fff; opacity: .72; }
.stop-icon { width: 18px; height: 18px; fill: currentColor; }
.message.streaming .message-body::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 3px; vertical-align: -.12em; border-radius: 2px; background: var(--accent); animation: work-pulse 1s ease-in-out infinite; }
.live-reply-limit { margin-top: 8px; color: var(--muted); font-size: 11px; }
/* --- Files: the read-only Space tree as its own context ------------------- */

.workspace-pane { min-width: 0; }
.space-picker { width: 100%; max-width: 320px; height: 42px; margin: 0 0 10px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; outline: none; }
.space-picker:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.file-tree { min-width: 0; }
.request-result-links { display: flex; flex-wrap: wrap; gap: 6px; }
.request-result-links button { overflow-wrap: anywhere; text-align: left; }
.file-preview-dialog { box-sizing: border-box; width: min(900px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); }
.file-preview-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.space-web-apps { padding: 0 0 16px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.space-web-apps h3 { font-size: 13px; color: var(--muted); }
.space-web-apps button { display: block; text-align: left; overflow-wrap: anywhere; max-width: 100%; }
.browser-app-dialog { box-sizing: border-box; width: min(1100px, calc(100vw - 32px)); height: min(800px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); }
.browser-app-dialog[open] { display: flex; flex-direction: column; }
.browser-app-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.browser-app-dialog header, .browser-app-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; flex: 0 0 auto; }
.browser-app-dialog header { border-bottom: 1px solid var(--line); }
.browser-app-dialog h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.browser-app-dialog header p, .browser-app-dialog footer { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.browser-app-content { flex: 1; min-height: 0; overflow: auto; }
.browser-app-content > iframe { border: 0; width: 100%; height: 100%; display: block; }
.browser-app-actions { flex: 0 1 auto; max-height: 42%; overflow: auto; border-top: 1px solid var(--line); padding: 12px 18px; background: var(--paper); }
.browser-app-actions[hidden] { display: none; }
.browser-action-heading, .browser-app-actions li, .browser-action-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.browser-app-actions h3 { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.browser-app-actions p { margin: 8px 0; font-size: 13px; }
.browser-app-actions pre { max-height: 150px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.browser-app-actions ul { list-style: none; padding: 0; margin: 8px 0 0; }
.browser-app-actions li { padding: 5px 0; font-size: 13px; }
.browser-app-actions li span { min-width: 0; overflow-wrap: anywhere; }
.browser-app-actions button { flex-shrink: 0; }
.browser-action-controls { justify-content: flex-end; }
.browser-action-status { color: var(--muted); }
@media (max-width: 600px) { .browser-app-dialog { width: calc(100vw - 16px); height: calc(100dvh - 16px); } }
.file-preview-dialog[open] { display: flex; flex-direction: column; }
.file-preview-dialog header, .file-preview-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; flex: 0 0 auto; }
.file-preview-dialog header { border-bottom: 1px solid var(--line); }
.file-preview-dialog h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.file-preview-location, .file-preview-status, .file-preview-note { color: var(--muted); font-size: 12px; }
.file-preview-location { margin: 5px 0 0; overflow-wrap: anywhere; }
.file-preview-close { flex: 0 0 auto; border: 0; background: none; color: inherit; padding: 8px; cursor: pointer; }
.file-preview-content { overflow: auto; min-height: 80px; min-width: 0; padding: 20px; }
.file-preview-content pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.file-preview-image { display: block; max-width: 100%; height: auto; margin: auto; }
@media (max-width: 600px) { .file-preview-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); } .file-preview-dialog header, .file-preview-dialog footer, .file-preview-content { padding: 14px; } }
.file-node { min-width: 0; }
.file-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; min-height: 40px; border-radius: 8px; padding-right: 8px; }
.file-row:hover { background: var(--paper-deep); }
.file-main { min-width: 0; display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 3px 4px calc(4px + var(--depth) * 16px); border: 0; background: transparent; color: inherit; text-align: left; }
button.file-main { cursor: pointer; border-radius: 8px; }
button.file-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-caret { width: 12px; flex: none; color: var(--muted); text-align: center; font-size: 15px; }
.tree-notice { padding: 7px 8px 9px 4px; color: var(--warning); font-size: 11px; line-height: 1.4; }
.file-glyph { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.35; stroke-linejoin: round; }
.file-glyph.folder { fill: color-mix(in srgb, var(--accent) 19%, transparent); stroke: var(--accent); }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-size { padding-left: 8px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.file-empty { padding: 10px 4px; color: var(--muted); font-size: 12px; }
.file-empty.error { color: var(--danger); }

/* --- Fixture preview strip ------------------------------------------------ */

.fixture-badge {
  flex: none;
  padding: 4px 12px;
  background: var(--warning);
  color: var(--paper);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: .04em;
  text-align: center;
}

@keyframes rise-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes message-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes work-pulse { 50% { opacity: .42; transform: scale(.8); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* --- Under 860px: the screen title lives in the top bar ------------------- */

@media (max-width: 859.98px) {
  /* The sidebar is only ever the drawer here, so its header button closes it. */
  .glyph-collapse { display: none; }
  .glyph-close { display: block; }
  /* The heading stays for assistive technology and focus management; the
     visible title is the one in the top bar, so it is not said twice. */
  .context-needs .context-title, .context-spaces .context-title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .context-needs .context-head, .context-spaces .context-head { margin: 0; }
}

/* --- 860px and up: the sidebar becomes the left column -------------------- */

@media (min-width: 860px) {
  .app-shell { flex-direction: row; }
  .sidebar {
    position: static;
    flex: none;
    width: 260px;
    padding: 14px 10px 12px;
    box-shadow: none;
    transform: none;
    visibility: visible;
    transition: width 160ms ease;
  }
  .app-shell[data-drawer="open"] .drawer-scrim { display: none; }
  .top-bar { display: none; }
  /* On a chat the top bar is the conversation bar: title centered over the
     transcript, while running-state actions stay down in the composer. */
  .app-shell[data-context="chat"] .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    width: min(760px, 100%);
    margin: 0 auto;
    min-height: 58px;
    padding: 6px 12px 0;
  }
  .top-bar-menu, .top-bar-new-chat { display: none; }
  .context-column { padding: 30px 24px 32px; }
  .context-title { font-size: 28px; }
  .new-stage { flex: none; padding: 0 24px 20px; }
  .new-heading { font-size: 30px; }
  .context-new { justify-content: center; }
  .app-shell[data-context="new"] .composer textarea { padding-left: 18px; }
  .messages { padding: 22px 24px 24px; }
  .message { grid-template-columns: 78px minmax(0, 1fr); gap: 18px; padding: 21px 0; }
  .messages .work-event { margin-left: 96px; }
  .composer-wrap { padding: 12px 24px calc(18px + env(safe-area-inset-bottom, 0px)); }
  .file-row, .file-main { min-height: 34px; }
  .file-name { font-size: 12px; }

  /* The collapsed sidebar: a 60px icon rail. Expand, New chat, Chats,
     Needs you, Files, then Settings at the foot. */
  .app-shell[data-sidebar="collapsed"] .sidebar { width: 60px; padding: 14px 8px 12px; align-items: center; overflow: visible; }
  .app-shell[data-sidebar="collapsed"] .sidebar-brand,
  .app-shell[data-sidebar="collapsed"] .sidebar-label,
  .app-shell[data-sidebar="collapsed"] .sidebar-chats { display: none; }
  .app-shell[data-sidebar="collapsed"] #desktop-presence-text { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .app-shell[data-sidebar="collapsed"] .presence { position: relative; width: 44px; height: 24px; justify-content: center; }
  .app-shell[data-sidebar="collapsed"] .sidebar-head { justify-content: center; margin-bottom: 10px; }
  .app-shell[data-sidebar="collapsed"] .sidebar-toggle { width: 44px; height: 44px; }
  .app-shell[data-sidebar="collapsed"] .sidebar-toggle svg { width: 21px; height: 21px; }
  .app-shell[data-sidebar="collapsed"] .glyph-collapse { display: none; }
  .app-shell[data-sidebar="collapsed"] .glyph-expand { display: block; }
  /* The groups dissolve so every item is one column of 44px targets. */
  .app-shell[data-sidebar="collapsed"] .sidebar-actions,
  .app-shell[data-sidebar="collapsed"] .sidebar-foot,
  .app-shell[data-sidebar="collapsed"] .sidebar-footer-actions,
  .app-shell[data-sidebar="collapsed"] .folder-picker-shell { display: contents; }
  .app-shell[data-sidebar="collapsed"] .folder-picker { display: block; left: 54px; bottom: 8px; }
  .app-shell[data-sidebar="collapsed"] .folder-picker[hidden] { display: none; }
  .app-shell[data-sidebar="collapsed"] .sidebar-chats-item { display: flex; }
  .app-shell[data-sidebar="collapsed"] .sidebar-item,
  .app-shell[data-sidebar="collapsed"] .rail-new-chat {
    width: 44px;
    height: 44px;
    min-height: 44px;
    margin: 2px 0 0;
    padding: 0;
    justify-content: center;
    border-radius: 11px;
  }
  .app-shell[data-sidebar="collapsed"] .rail-new-chat { border-color: var(--line); }
  .app-shell[data-sidebar="collapsed"] .sidebar-item svg,
  .app-shell[data-sidebar="collapsed"] .rail-new-chat svg { width: 22px; height: 22px; }
  .app-shell[data-sidebar="collapsed"] .rail-new-chat svg { width: 20px; height: 20px; }
  .app-shell[data-sidebar="collapsed"] .sidebar-item[aria-current="page"]::before,
  .app-shell[data-sidebar="collapsed"] .rail-new-chat[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 14px;
    bottom: 14px;
    width: 3px;
    border-radius: 3px;
    background: var(--accent);
  }
  .rail-account .account-settings { width: 36px; height: 36px; }
  .app-shell[data-sidebar="collapsed"] .rail-account .account-settings { width: 44px; height: 44px; }
  .app-shell[data-sidebar="collapsed"] .presence { margin: 4px 0 0; }
  .app-shell[data-sidebar="collapsed"] .rail-account .account-menu { left: 46px; right: auto; bottom: 0; }

  /* Names ride tooltips only while the rail hides them. */
  .app-shell[data-sidebar="collapsed"] .sidebar [data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    z-index: 60;
    transform: translateY(-50%);
    padding: 5px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: 0 8px 22px rgba(28, 24, 20, .16);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
  }
  .app-shell[data-sidebar="collapsed"] .sidebar [data-tip]:focus-visible::after { opacity: 1; }
  .app-shell[data-sidebar="collapsed"] .sidebar [data-tip][aria-expanded="true"]::after { opacity: 0; }
}

@media (min-width: 860px) and (hover: hover) {
  .app-shell[data-sidebar="collapsed"] .sidebar [data-tip]:hover::after { opacity: 1; }
  .app-shell[data-sidebar="collapsed"] .sidebar [data-tip][aria-expanded="true"]:hover::after { opacity: 0; }
}

/* --- Behavioral affordances: boot splash, jump-to-latest, pending sends,
   nav badges, banner dismissal, and touch ergonomics. ---------------------- */

/* Paints while the client boots; the first real render replaces it. */
.boot-splash { min-height: 100svh; display: grid; place-items: center; }

/* Inner scrollers own their overscroll, so a drag past the top of a
   transcript can't trigger the browser's pull-to-refresh and drop state. */
body { overscroll-behavior-y: none; }
.context-scroll, .messages { overscroll-behavior-y: contain; }

/* Keyboard users can focus and scroll the transcript directly. */
.messages:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Floating return-to-newest control; visible only after scrolling up. */
.jump-latest {
  position: sticky;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 10px 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}
.jump-latest[hidden] { display: none; }
.jump-latest svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.jump-latest:hover { background: var(--paper); }
.jump-latest:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A sent-but-not-yet-recorded message renders provisionally. */
.message.pending { opacity: 0.62; }

/* Needs-you count on the Needs you destination, from every screen. */
.rail-item, .sidebar-item { position: relative; }
.nav-badge {
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 10px;
  font-weight: 750;
  line-height: 1;
}
.nav-badge[hidden] { display: none; }
@media (min-width: 860px) {
  .app-shell[data-sidebar="collapsed"] .nav-badge {
    position: absolute;
    top: 3px;
    right: 5px;
    min-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0 4px;
    box-shadow: 0 0 0 2px var(--paper-deep);
  }
}

/* Error banners carry their own dismissal. */
.banner { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.banner-dismiss {
  flex: none;
  margin: -4px -7px -4px 0;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}
.banner-dismiss:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.banner-dismiss:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The auth screens respect the notch in standalone display. */
.auth-shell, .landing-shell { padding-top: max(28px, env(safe-area-inset-top, 0px)); }

@media (pointer: coarse) {
  /* iOS zooms the page into any sub-16px field and the zoom sticks. */
  .conversation-title-form input, .space-picker { font-size: 16px; }
  /* Thumb-sized targets for the controls tapped most. */
  .attach-button, .send-button { width: 44px; height: 44px; }
  .sidebar-toggle, .rail-account .account-settings { width: 44px; height: 44px; }
  .conversation-title-button, .title-edit-action { min-width: 42px; min-height: 42px; }
  .context-chip button { min-width: 30px; min-height: 30px; }
}

/* Folders: a picker, then one folder with browsable files and apps. */
.workspace-pane[hidden], .space-files[hidden], .space-apps[hidden], .space-directory[hidden], .file-preview-inline[hidden] { display: none; }
.space-workspace { height: 100%; min-height: 0; display: flex; flex-direction: column; padding: 24px 32px; gap: 20px; overflow-y: auto; }
.space-workspace-header { flex: none; }
.space-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.space-title-row h1 { min-width: 0; margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.025em; overflow-wrap: anywhere; outline: none; }
.space-workspace-header > p { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
#spaces-back { margin-bottom: 12px; }
.space-refresh { display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 550; white-space: nowrap; cursor: pointer; }
.space-refresh:hover { background: var(--paper-deep); color: var(--ink); }
.space-refresh:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.space-refresh[hidden] { display: none; }
.space-refresh svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.space-directory { width: min(760px, 100%); }
.space-directory-row { display: flex; align-items: center; gap: 16px; width: 100%; padding: 20px 8px; background: none; border: none; border-bottom: 1px solid var(--line); border-radius: 0; color: var(--ink); text-align: left; transition: background 120ms ease; }
.space-directory-row:hover { background: var(--paper-deep); }
.space-directory-row > .file-glyph { width: 26px; height: 26px; }
.space-directory-row > span:first-of-type { flex: 1; font-size: 16px; font-weight: 550; }
.workspace-pane { display: flex; flex-direction: column; flex: 1; min-height: 280px; }
.space-views { display: flex; flex: none; gap: 22px; border-bottom: 1px solid var(--line); }
.space-views button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 2px; color: var(--muted); font-size: 13px; }
.space-views button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.space-files { display: grid; grid-template-columns: minmax(190px, 30%) minmax(0, 1fr); min-height: 0; flex: 1; }
.space-files > .file-tree { min-height: 0; overflow: auto; padding: 16px 12px 16px 0; border-right: 1px solid var(--line); }
.space-preview { min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#space-preview-empty { margin: auto; padding: 24px; color: var(--muted); text-align: center; font-size: 13px; }
.file-preview-inline { display: flex; flex-direction: column; height: 100%; min-height: 240px; }
.file-preview-inline header { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.file-preview-inline h2 { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.file-preview-inline .file-preview-location { margin: 4px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.file-preview-inline .file-preview-content { padding: 20px; flex: 1; min-height: 100px; overflow: auto; font-size: 14px; }
.file-preview-inline footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 12px; }
.file-preview-inline footer > span { margin-right: auto; color: var(--muted); }
.space-apps { overflow: auto; padding: 16px 0; }
.space-app-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 18px 8px; border: none; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; background: none; color: var(--ink); }
.space-app-row small, .chat-waiting { font-size: 12px; color: var(--accent); }
.chat-waiting { display: block; padding-top: 3px; }
.chat-button:has(.chat-waiting) { grid-template-columns: minmax(0, 1fr); gap: 2px; }
.chat-button .chat-waiting { padding: 0; font-size: 11px; }
@media (max-width: 1050px) { .space-workspace { padding: 20px; } }
@media (max-width: 650px) {
  .space-workspace { padding: 16px; gap: 16px; }
  .space-title-row { gap: 12px; }
  .space-title-row h1 { font-size: 23px; }
  .workspace-pane { flex: none; }
  .space-files { display: flex; flex-direction: column; }
  .space-files > .file-tree { max-height: 38dvh; border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; }
  .file-preview-inline { height: auto; max-height: 70dvh; }
  .file-preview-inline header, .file-preview-inline .file-preview-content, .file-preview-inline footer { padding: 14px 4px; }
  .file-preview-inline footer { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { .space-directory-row { transition: none; } }

@media (pointer: coarse) { .space-refresh { min-height: 44px; } }
.space-app-row:hover { background: var(--paper-deep); }
