/* ==========================================================================
   claude web: fonts, design tokens, base, layout and shell components.
   Values follow docs/DESIGN.md. Dark values are declared three times on purpose: for the system preference (unless the
   user picked light), and for an explicit dark choice. Other stylesheets read these tokens; they keep their names.
   ========================================================================== */

/* ---- Fonts: Atkinson Hyperlegible Next and Mono, vendored variable fonts (OFL-1.1, see public/fonts) ------------- */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  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: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  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: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-wght-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
  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: "Atkinson Hyperlegible Mono";
  src: url("/fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  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: "Atkinson Hyperlegible Mono";
  src: url("/fonts/atkinson-hyperlegible-mono-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  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;
}

/* ---- Tokens: light ------------------------------------------------------ */
:root {
  color-scheme: light;
  --bg: #fbfbfa;
  --bg-sunken: #f3f4f2;
  --bg-elev: #ffffff;
  --bg-hover: #eceeea;
  --bg-active: #e2e5df;
  --hover-overlay: rgba(23, 25, 28, 0.05);
  --scrim: rgba(17, 18, 22, 0.32);
  --fg: #17191c;
  --fg-muted: #5a6068;
  --fg-subtle: #666c74;
  --border: #e2e4e0;
  --border-strong: #c9cdc7;
  --accent: #3949c7;
  --accent-fg: #ffffff;
  --accent-soft: #eceefb;
  --attention: #b45309;
  --attention-soft: #fdf3e4;
  --warning: var(--attention);
  --warning-soft: var(--attention-soft);
  --success: #1f7a3e;
  --success-soft: #e3f3e7;
  --danger: #b42318;
  --danger-fg: #ffffff;
  --danger-soft: #fbe7e6;
  --info: var(--accent);
  --info-soft: var(--accent-soft);
  --diff-add-bg: #e3f3e7;
  --diff-del-bg: #fbe7e6;
  --focus-ring: var(--accent);
  --shadow-sm: 0 1px 2px rgba(15, 17, 20, 0.06);
  --shadow-md: 0 8px 24px -8px rgba(15, 17, 20, 0.18);
  --shadow-lg: 0 24px 64px -16px rgba(15, 17, 20, 0.28);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --font-sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "PingFang SC",
    monospace;
  /* Text size. Settings sets html[data-font-size], which sets --fs-scale; every size token and its line height scale
     with it, so the sidebar, header, panels and prose all follow the choice. */
  --fs-scale: 1;
  --fs-xs: calc(12px * var(--fs-scale));
  --fs-sm: calc(13px * var(--fs-scale));
  --fs-md: calc(15px * var(--fs-scale));
  --fs-prose: calc(16px * var(--fs-scale));
  --fs-lg: calc(17px * var(--fs-scale));
  --fs-xl: calc(22px * var(--fs-scale));
  --lh-xs: calc(16px * var(--fs-scale));
  --lh-sm: calc(18px * var(--fs-scale));
  --lh-md: calc(22px * var(--fs-scale));
  --lh-prose: calc(26px * var(--fs-scale));
  --lh-lg: calc(24px * var(--fs-scale));
  --lh-xl: calc(28px * var(--fs-scale));
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --header-h: 52px;
  --control-h: 40px;
  --sidebar-w: 280px;
  --content-max: 760px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur: 140ms;
  --dur-panel: 200ms;
}

/* ---- Tokens: dark (system preference unless the user chose light) ------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121316;
    --bg-sunken: #0d0e10;
    --bg-elev: #1a1c20;
    --bg-hover: #22252a;
    --bg-active: #2b2f36;
    --hover-overlay: rgba(232, 234, 237, 0.06);
    --scrim: rgba(0, 0, 0, 0.55);
    --fg: #e8eaed;
    --fg-muted: #a2a9b2;
    --fg-subtle: #858c95;
    --border: #2a2d33;
    --border-strong: #3a3e46;
    --accent: #8d99ff;
    --accent-fg: #0d0e10;
    --accent-soft: #23284a;
    --attention: #f2b24c;
    --attention-soft: #3a2a12;
    --success: #5bd48a;
    --success-soft: rgba(91, 212, 138, 0.14);
    --danger: #ff7b72;
    --danger-fg: #0d0e10;
    --danger-soft: rgba(255, 123, 114, 0.14);
    --diff-add-bg: rgba(63, 185, 80, 0.16);
    --diff-del-bg: rgba(248, 81, 73, 0.16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
  }
}

/* ---- Tokens: dark (explicit choice) ------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121316;
  --bg-sunken: #0d0e10;
  --bg-elev: #1a1c20;
  --bg-hover: #22252a;
  --bg-active: #2b2f36;
  --hover-overlay: rgba(232, 234, 237, 0.06);
  --scrim: rgba(0, 0, 0, 0.55);
  --fg: #e8eaed;
  --fg-muted: #a2a9b2;
  --fg-subtle: #858c95;
  --border: #2a2d33;
  --border-strong: #3a3e46;
  --accent: #8d99ff;
  --accent-fg: #0d0e10;
  --accent-soft: #23284a;
  --attention: #f2b24c;
  --attention-soft: #3a2a12;
  --success: #5bd48a;
  --success-soft: rgba(91, 212, 138, 0.14);
  --danger: #ff7b72;
  --danger-fg: #0d0e10;
  --danger-soft: rgba(255, 123, 114, 0.14);
  --diff-add-bg: rgba(63, 185, 80, 0.16);
  --diff-del-bg: rgba(248, 81, 73, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
}

/* ---- Base --------------------------------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

/* The text-size setting changes the scale the --fs-* tokens multiply; the root font size stays the browser's. */
html[data-font-size="sm"] {
  --fs-scale: 0.93;
}

html[data-font-size="lg"] {
  --fs-scale: 1.13;
}

html.is-locked {
  overflow: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
dd,
figure {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--accent-soft);
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.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;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--fg-subtle);
  background-clip: content-box;
}

/* ---- Icons: masks drawn from /img/icons, colored by currentColor -------- */
.icon {
  display: inline-block;
  flex: none;
  width: 1em;
  height: 1em;
  vertical-align: middle;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

.icon-send { --icon: url(/img/icons/send.svg); }
.icon-stop { --icon: url(/img/icons/stop.svg); }
.icon-plus { --icon: url(/img/icons/plus.svg); }
.icon-menu { --icon: url(/img/icons/menu.svg); }
.icon-close { --icon: url(/img/icons/close.svg); }
.icon-chevron-right { --icon: url(/img/icons/chevron-right.svg); }
.icon-chevron-down { --icon: url(/img/icons/chevron-down.svg); }
.icon-search { --icon: url(/img/icons/search.svg); }
.icon-folder { --icon: url(/img/icons/folder.svg); }
.icon-file { --icon: url(/img/icons/file.svg); }
.icon-terminal { --icon: url(/img/icons/terminal.svg); }
.icon-settings { --icon: url(/img/icons/settings.svg); }
.icon-sun { --icon: url(/img/icons/sun.svg); }
.icon-moon { --icon: url(/img/icons/moon.svg); }
.icon-monitor { --icon: url(/img/icons/monitor.svg); }
.icon-copy { --icon: url(/img/icons/copy.svg); }
.icon-check { --icon: url(/img/icons/check.svg); }
.icon-x { --icon: url(/img/icons/x.svg); }
.icon-alert { --icon: url(/img/icons/alert.svg); }
.icon-info { --icon: url(/img/icons/info.svg); }
.icon-edit { --icon: url(/img/icons/edit.svg); }
.icon-trash { --icon: url(/img/icons/trash.svg); }
.icon-fork { --icon: url(/img/icons/fork.svg); }
.icon-rewind { --icon: url(/img/icons/rewind.svg); }
.icon-refresh { --icon: url(/img/icons/refresh.svg); }
.icon-plug { --icon: url(/img/icons/plug.svg); }
.icon-cpu { --icon: url(/img/icons/cpu.svg); }
.icon-shield { --icon: url(/img/icons/shield.svg); }
.icon-gauge { --icon: url(/img/icons/gauge.svg); }
.icon-clock { --icon: url(/img/icons/clock.svg); }
.icon-user { --icon: url(/img/icons/user.svg); }
.icon-bot { --icon: url(/img/icons/bot.svg); }
.icon-tool { --icon: url(/img/icons/tool.svg); }
.icon-image { --icon: url(/img/icons/image.svg); }
.icon-paperclip { --icon: url(/img/icons/paperclip.svg); }
.icon-external { --icon: url(/img/icons/external.svg); }
.icon-more { --icon: url(/img/icons/more.svg); }
.icon-logout { --icon: url(/img/icons/logout.svg); }
.icon-globe { --icon: url(/img/icons/globe.svg); }
.icon-list { --icon: url(/img/icons/list.svg); }
.icon-spark { --icon: url(/img/icons/spark.svg); }
.icon-layers { --icon: url(/img/icons/layers.svg); }
.icon-play { --icon: url(/img/icons/play.svg); }
.icon-lock { --icon: url(/img/icons/lock.svg); }
.icon-unlock { --icon: url(/img/icons/unlock.svg); }
.icon-brain { --icon: url(/img/icons/brain.svg); }
.icon-download { --icon: url(/img/icons/download.svg); }
.icon-command { --icon: url(/img/icons/command.svg); }
.icon-at { --icon: url(/img/icons/at.svg); }
.icon-archive { --icon: url(/img/icons/archive.svg); }
.icon-restore { --icon: url(/img/icons/restore.svg); }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  --btn-h: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-h);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.btn > .icon {
  width: 16px;
  height: 16px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: inset 0 0 0 999px var(--hover-overlay);
}

.btn-secondary {
  background: var(--bg-elev);
  border-color: var(--border-strong);
  color: var(--fg);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-ghost {
  color: var(--fg-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--fg);
}

.btn-danger {
  background: var(--danger);
  color: var(--danger-fg);
}

.btn-danger:hover:not(:disabled) {
  box-shadow: inset 0 0 0 999px var(--hover-overlay);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  --btn-h: 30px;
  padding: 0 var(--space-2);
  font-size: var(--fs-xs);
}

.btn-sm > .icon {
  width: 14px;
  height: 14px;
}

.btn-lg {
  --btn-h: 44px;
  padding: 0 var(--space-5);
  font-size: var(--fs-md);
}

.btn-lg > .icon {
  width: 18px;
  height: 18px;
}

.btn-icon {
  width: var(--btn-h);
  padding: 0;
}

.btn-icon > .icon {
  width: 18px;
  height: 18px;
}

.btn-icon.btn-sm {
  width: 30px;
}

.btn-icon.btn-sm > .icon {
  width: 15px;
  height: 15px;
}

.btn-icon.btn-lg {
  width: 44px;
}

/* ---- Form controls ------------------------------------------------------ */
/* Every text field, select and multi-line text shares one border, radius, surface and type. Bare elements are matched
   with :where() (zero specificity), so a feature's own class always takes precedence over these defaults. */
.input,
.select,
.textarea,
.sidebar-search-input,
:where(input:not([type]), input[type="text"], input[type="search"], input[type="url"], input[type="email"],
  input[type="password"], input[type="number"], input[type="date"], select) {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-sm);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

/* Single-line controls are exactly --control-h tall (44 px on coarse pointers) with identical horizontal padding. */
.input,
.select,
.sidebar-search-input,
:where(input:not([type]), input[type="text"], input[type="search"], input[type="url"], input[type="email"],
  input[type="password"], input[type="number"], input[type="date"], select) {
  height: var(--control-h);
  padding: 0 12px;
  line-height: 1.25;
}

.input,
.select,
.textarea,
.sidebar-search-input {
  display: block;
  width: 100%;
}

.input::placeholder,
.textarea::placeholder,
.sidebar-search-input::placeholder {
  color: var(--fg-subtle);
  opacity: 1;
}

.input:focus,
.select:focus,
.textarea:focus,
.sidebar-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.select,
:where(select) {
  padding-right: 32px;
  cursor: pointer;
}

.textarea {
  min-height: 80px;
  padding: 8px 12px;
  line-height: 1.45;
  resize: vertical;
}

.field {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-muted);
}

.field-hint {
  font-size: var(--fs-xs);
  color: var(--fg-muted);
}

.form-stack {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.form-error {
  font-size: var(--fs-sm);
  color: var(--danger);
}

.chip,
.badge,
kbd {
  font-variant-numeric: tabular-nums;
}

/* ---- Badges, chips, keys, spinners, skeletons --------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-attention {
  background: var(--warning-soft);
  color: var(--warning);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: 1.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-accent {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-success {
  border-color: transparent;
  background: var(--success-soft);
  color: var(--success);
}

.chip-danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-warning {
  border-color: transparent;
  background: var(--warning-soft);
  color: var(--warning);
}

.chip-muted {
  border-color: transparent;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

.spinner {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.85;
  animation: spin 0.8s linear infinite;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 3px;
  color: var(--accent);
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--bg-elev), transparent);
  opacity: 0.55;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-row {
  height: 30px;
  margin: 6px 12px;
}

.skeleton-block {
  height: 64px;
}

.skeleton-stack {
  display: grid;
  gap: var(--space-3);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 var(--accent-soft);
  }
  70% {
    box-shadow: 0 0 0 6px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes sheet-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---- Layout ------------------------------------------------------------- */
.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}

.app-sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
}

.app-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* Focus rests on the main region only when nothing else can take it (a sheet closed on the welcome page). */
.app-main:focus {
  outline: none;
}

.app-header-slot {
  position: relative;
  z-index: 2;
  flex: none;
  padding-top: env(safe-area-inset-top);
}

.app-banners:empty {
  display: none;
}

.app-banners {
  flex: none;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4) 0;
  max-width: calc(var(--content-max) + 2 * var(--space-4));
  width: 100%;
  margin: 0 auto;
}

.app-timeline-slot {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
}

.app-timeline {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.app-timeline > * {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.app-terminal-slot {
  flex: none;
  min-width: 0;
  min-height: 0;
}

.app-terminal-slot:has(> *) {
  display: flex;
  flex-direction: column;
  height: min(42vh, 440px);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}

.app-terminal-slot > * {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.app-composer-slot {
  position: relative;
  z-index: 1;
  flex: none;
  padding-bottom: env(safe-area-inset-bottom);
}

/* A zero-height anchor after the banner stack: the toast host hangs from its top, so toasts open below every banner. */
.app-toast-anchor {
  position: relative;
  flex: none;
  height: 0;
}

.app-toasts {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 60;
  pointer-events: none;
}

.app-scrim {
  display: none;
}

.app-reopen {
  display: none;
  position: absolute;
  top: calc(var(--space-2) + env(safe-area-inset-top));
  left: calc(var(--space-3) + env(safe-area-inset-left));
  z-index: 6;
  box-shadow: var(--shadow-sm);
}

.app-main > .app-header-slot {
  transition: padding-left var(--dur) var(--ease);
}

@media (min-width: 768px) {
  .app[data-sidebar="closed"] {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .app[data-sidebar="closed"] .app-sidebar {
    visibility: hidden;
    border-right-color: transparent;
  }

  .app[data-sidebar="closed"] .app-reopen {
    display: inline-flex;
  }

  .app[data-sidebar="closed"] .app-main > .app-header-slot {
    padding-left: 52px;
  }

  .sidebar-close {
    display: none;
  }
}

@media (max-width: 767.98px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(86vw, 320px);
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    box-shadow: var(--shadow-md);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform 220ms var(--ease), visibility 220ms;
  }

  .app[data-sidebar="open"] .app-sidebar {
    transform: none;
    visibility: visible;
  }

  .app-scrim {
    position: fixed;
    inset: 0;
    z-index: 39;
    display: block;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ease);
  }

  .app[data-sidebar="open"] .app-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-collapse {
    display: none;
  }

  .app-banners {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

/* ---- Welcome and boot / fatal pages ------------------------------------ */
.welcome {
  display: grid;
  flex: 1 1 auto;
  align-content: center;
  justify-items: center;
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.welcome-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
}

.welcome-title {
  margin-top: var(--space-2);
  font-size: var(--fs-xl);
  line-height: var(--lh-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.welcome-text {
  max-width: 42ch;
  color: var(--fg-muted);
  font-size: var(--fs-md);
  line-height: var(--lh-md);
}

.welcome > .btn {
  margin-top: var(--space-2);
}

.welcome-projects {
  display: grid;
  gap: var(--space-2);
  width: min(360px, 100%);
  margin-top: var(--space-4);
  text-align: left;
}

.welcome-heading {
  padding: 0 var(--space-2);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.welcome-project-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.welcome-project {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "icon name"
    "icon path";
  align-items: center;
  column-gap: var(--space-3);
  width: 100%;
  min-height: 48px;
  padding: 6px var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.welcome-project:hover {
  background: var(--bg-hover);
}

.welcome-project > .icon {
  grid-area: icon;
  width: 16px;
  height: 16px;
  color: var(--fg-muted);
}

.welcome-project-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.welcome-project-path {
  grid-area: path;
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.welcome-keys {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: var(--space-5) 0 0;
  color: var(--fg-muted);
  font-size: var(--fs-sm);
}

.welcome-keys dt {
  justify-self: end;
}

.welcome-keys dd {
  margin: 0;
}

.boot-page,
.fatal-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-5);
  background: var(--bg);
}

.fatal-card {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  width: min(420px, 100%);
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}

.fatal-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
}

.fatal-title {
  margin-top: var(--space-2);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.fatal-text {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

/* ---- Login -------------------------------------------------------------- */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-5) var(--space-4);
  padding-top: calc(var(--space-5) + env(safe-area-inset-top));
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  background: radial-gradient(60rem 30rem at 50% -12%, var(--accent-soft), transparent 70%), var(--bg);
}

.login-card {
  display: grid;
  gap: var(--space-4);
  width: min(400px, 100%);
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.login-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
}

.login-app {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-title {
  margin-top: var(--space-2);
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin-top: calc(var(--space-2) * -1);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
}

.login-form {
  display: grid;
  gap: var(--space-3);
}

.login-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-sm);
}

.login-footnote {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.login-footnote > .icon {
  width: 14px;
  height: 14px;
  margin-top: 2px;
}

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-height: var(--header-h);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
}

/* ---- Brand logo ----------------------------------------------------------
   dom.js brandLogo puts the ink tile (for light themes) and the paper tile (for dark ones) in the page; the theme picks
   one of them, so a theme change needs no script. The explicit choice overrides the system preference. */
.brand-logo-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo-light {
    display: none;
  }

  :root:not([data-theme="light"]) .brand-logo-dark {
    display: inline-block;
  }
}

:root[data-theme="dark"] .brand-logo-light {
  display: none;
}

:root[data-theme="dark"] .brand-logo-dark {
  display: inline-block;
}

.sidebar-logo {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
}

.sidebar-app {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-top {
  display: grid;
  gap: var(--space-2);
  flex: none;
  padding: var(--space-1) var(--space-3) var(--space-3);
}

/* Quiet by design: the accent is the icon, not the button. */
.sidebar-new {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding: 0 var(--space-3);
  border-color: var(--border);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  background: var(--bg-elev);
  color: var(--fg);
  font-weight: 500;
}

.sidebar-new > .icon {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.sidebar-new-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* "New session" and its chevron share one row; the chevron opens the new-session dialog for another folder. */
.sidebar-new-row {
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.sidebar-new-folder {
  flex: none;
  width: var(--control-h);
  min-height: var(--control-h);
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-color: var(--border);
  background: var(--bg-elev);
  color: var(--fg-muted);
}

.sidebar-new-folder > .icon {
  width: 14px;
  height: 14px;
}

.sidebar-search {
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar-search > .icon {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--fg-subtle);
  pointer-events: none;
}

/* The field's clear button sits at the end of the text, left of the quick switcher button (66 px wide, 6 px in). */
.sidebar-search-input {
  padding-left: 34px;
  padding-right: 80px;
}

/* The ⌘K hint opens the quick switcher; it is a mouse target, the key is the shortcut. */
.sidebar-switch {
  position: absolute;
  top: 50%;
  right: 6px;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  transform: translateY(-50%);
  cursor: pointer;
}

.sidebar-switch:hover {
  background: var(--bg-hover);
}

.sidebar-switch > .kbd {
  pointer-events: none;
}

.sidebar-list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-2) var(--space-3);
}

/* minmax(0, 1fr): a long title truncates inside its row instead of pushing the time and the count off the edge. */
.session-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}

.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 30px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

/* A project heading folds its group; the "+" beside it starts a session in that folder. The "+" shows on hover and focus,
   and always where there is no hover (touch). */
.group-head-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.group-head-row > .group-head {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.group-new {
  flex: none;
  opacity: 0;
}

.group-head-row:hover .group-new,
.group-head-row:focus-within .group-new,
.group-new:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .group-new {
    opacity: 1;
  }
}

.group-head:hover {
  background: var(--bg-hover);
  color: var(--fg-muted);
}

.group-head > .icon {
  width: 13px;
  height: 13px;
}

.group-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-count {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.group-items {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  list-style: none;
  padding: 0;
}

.session-row {
  position: relative;
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-md);
}

.session-row:hover {
  background: var(--bg-hover);
}

/* The selected session: the hover tint and a 2 px accent bar on the left (docs/DESIGN.md). */
.session-row.is-active {
  background: var(--bg-hover);
}

.session-row.is-active::before {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 0;
  width: 2px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.session-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  min-height: 36px;
  padding: 6px 6px 6px 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.session-line {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: var(--lh-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-row.is-active .session-title {
  font-weight: 600;
}

.session-meta {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  max-width: 50%;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
}

.session-meta .chip {
  max-width: 96px;
}

.chip-tag {
  overflow: hidden;
  background: var(--bg-hover);
  color: var(--fg-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.session-pending {
  flex: none;
  min-width: 20px;
  justify-content: center;
}

.session-more {
  align-self: center;
  margin-right: 4px;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.session-row:hover .session-more,
.session-row:focus-within .session-more,
.session-row.is-active .session-more {
  opacity: 1;
}

@media (hover: none) {
  .session-more {
    opacity: 1;
  }
}

/* State glyphs: one shape per state, the same in the sidebar, the header and the composer. A glyph is 12 px; idle
   sessions keep an empty 12 px slot so the titles stay on one edge. */
.state-glyph {
  position: relative;
  display: inline-block;
  flex: none;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
}

.state-glyph.state-empty {
  visibility: hidden;
}

.state-glyph.state-running,
.state-glyph.state-starting {
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.state-glyph.state-attention {
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--attention);
}

.state-glyph.state-attention::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--attention);
}

.state-glyph.state-error {
  border-radius: 50%;
  background: var(--danger);
  color: var(--danger-fg);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 12px;
  text-align: center;
}

.state-glyph.state-error::before {
  content: "!";
}

.sidebar-more {
  margin-top: var(--space-2);
}

/* The page sentinel is watched for the end of the list; it takes no room. */
.sidebar-paging {
  display: grid;
}

.sidebar-sentinel {
  height: 1px;
}

/* The Archived entry closes the session list; its count is how many sessions the archive holds. */
.sidebar-archived-entry {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 36px;
  margin-top: var(--space-2);
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg-muted);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.sidebar-archived-entry:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.sidebar-archived-entry > .icon {
  flex: none;
  width: 16px;
  height: 16px;
}

.sidebar-archived-entry > .icon-chevron-right {
  margin-left: auto;
}

.sidebar-archived-label {
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-archived-count {
  flex: none;
  color: var(--fg-subtle);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* The Archived list replaces the session list while it is open: a head with Back, then its rows. */
.archived-panel {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  min-width: 0;
}

.archived-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 0 var(--space-1);
}

.archived-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archived-count {
  flex: none;
  color: var(--fg-subtle);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* Back points left: the chevron is turned around. */
.sidebar-back > .icon {
  transform: rotate(180deg);
}

.archived-status {
  margin: 0;
  padding: 0 var(--space-2);
}

.archived-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.archived-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 2px;
  border-radius: var(--radius-md);
}

.archived-row:hover {
  background: var(--bg-hover);
}

.archived-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.archived-line {
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archived-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.archived-meta > .mono {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archived-restore {
  flex: none;
}

.archived-delete {
  flex: none;
}

.sidebar-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  color: var(--fg-muted);
  text-align: center;
}

.sidebar-empty > .icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.sidebar-empty-title {
  color: var(--fg);
  font-weight: 600;
}

.sidebar-empty-text {
  font-size: var(--fs-sm);
}

.sidebar-skeleton {
  display: grid;
  gap: 6px;
  padding-top: var(--space-2);
}

/* Search: the Titles section matches at once; In conversations follows once the server answers. Each section has a
   heading, its rows, and the lines that describe it (status, indexing, scope). */
.search-section {
  display: grid;
  gap: 2px;
}

.search-section + .search-section {
  margin-top: var(--space-2);
}

.search-section-title {
  margin: 0;
  padding: 0 var(--space-2);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: var(--lh-xs);
}

.search-status,
.search-indexing,
.search-note {
  margin: 0;
  padding: 0 var(--space-2);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
}

.search-indexing {
  font-style: italic;
}

.search-archived {
  flex: none;
}

.search-results {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.search-result {
  margin: 0;
  padding: 0;
}

.search-result-main {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.search-result-main:hover {
  background: var(--bg-hover);
}

.search-result-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.search-result-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-head .session-time {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.search-result-project {
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-snippet {
  display: -webkit-box;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  flex: none;
  gap: 4px;
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.sidebar-connection {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.conn-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-subtle);
}

.sidebar-connection[data-state="open"] .conn-dot {
  background: var(--success);
}

.sidebar-connection[data-state="connecting"] .conn-dot {
  background: var(--warning);
  animation: pulse 1.6s ease-out infinite;
}

.conn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Banners and toasts ------------------------------------------------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  color: var(--fg);
  font-size: var(--fs-sm);
}

.banner > .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.banner-text {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.banner-action {
  flex: none;
  align-self: center;
}

.banner-info {
  border-color: transparent;
  background: var(--info-soft);
}

.banner-info > .icon {
  color: var(--info);
}

.banner-warning {
  border-color: transparent;
  background: var(--warning-soft);
}

.banner-warning > .icon {
  color: var(--warning);
}

.banner-danger {
  border-color: transparent;
  background: var(--danger-soft);
}

.banner-danger > .icon {
  color: var(--danger);
}

/* Toasts open 12 px below the banner stack (the anchor sits under the header and any banners), so no banner's action
   is covered. */
.toast-region {
  position: absolute;
  top: var(--space-3);
  right: var(--space-4);
  bottom: auto;
  display: grid;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: toast-in 200ms var(--ease);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
}

.toast > .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.toast-info > .icon {
  color: var(--info);
}

.toast-success > .icon {
  color: var(--success);
}

.toast-warning > .icon {
  color: var(--warning);
}

.toast-error > .icon {
  color: var(--danger);
}

.toast-error {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.toast-message {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.toast-close {
  flex: none;
  margin: -4px -4px 0 0;
}

/* A toast action (Undo) sits after the message, before the close button. */
.toast-action {
  flex: none;
  margin-top: -3px;
}

/* The side safe-area insets are already the padding of .app, which the toast host sits inside. */
@media (max-width: 767.98px) {
  .toast-region {
    left: var(--space-4);
    right: var(--space-4);
    width: auto;
  }
}

/* ---- Dialogs ------------------------------------------------------------ */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--scrim);
  animation: fade-in var(--dur-panel) var(--ease);
}

/* Some dialogs (the quick switcher) sit near the top, like a command palette. */
.dialog-backdrop.is-top {
  align-items: start;
  padding-top: min(12dvh, 96px);
  padding-inline: var(--space-4);
}

.dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(86dvh, 760px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg);
  outline: none;
  animation: dialog-in var(--dur-panel) var(--ease);
}

.dialog-sm {
  width: min(400px, 100%);
}

.dialog-lg {
  width: min(680px, 100%);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) 0 var(--space-5);
}

.dialog-title {
  flex: 1;
  min-width: 0;
  padding-top: 5px;
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: var(--lh-lg);
  letter-spacing: -0.01em;
}

.dialog-close {
  margin: -2px -6px 0 0;
}

.dialog-body {
  display: grid;
  gap: var(--space-3);
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--space-3) var(--space-5) var(--space-4);
}

.dialog-text {
  margin: 0;
  color: var(--fg-muted);
}

.dialog-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--border);
}

/* The quick switcher: a search field, then a list. Its title is for assistive technology only, and its close button
   sits in the corner so the field keeps the full width. */
.dialog.switcher {
  width: min(560px, 100%);
  max-height: min(70dvh, 560px);
  overflow: hidden;
}

.dialog.switcher > .dialog-header {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  padding: 6px 6px 0 0;
}

.dialog.switcher > .dialog-header > .dialog-close {
  margin: 0;
}

/* ---- Side sheets -------------------------------------------------------- */
.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  pointer-events: auto;
  animation: fade-in 160ms var(--ease);
}

.sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  padding-top: env(safe-area-inset-top);
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  outline: none;
  animation: sheet-in 200ms var(--ease);
}

.sheet-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--header-h);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.sheet-title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 600;
}

/* Rows take the height of their content, and the body scrolls. Auto rows would grow into the free height of the sheet
   and clip a tall section under the one after it (the memory editor's footer covered its text). */
.sheet-body {
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  flex: 1;
  gap: var(--space-5);
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--space-5) var(--space-6);
}

.sheet-section {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.sheet-section-title {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.sheet-note {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
}

.sheet-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.sheet-actions {
  display: grid;
  gap: var(--space-2);
}

.sheet-action {
  justify-content: flex-start;
}

.sheet-error {
  display: grid;
  justify-items: start;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.sheet .kv-row {
  display: grid;
  grid-template-columns: minmax(calc(7.5 * var(--fs-md)), auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-label {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.kv-value {
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kv-list {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.kv-list > .kv-row {
  padding-left: 12px;
  padding-right: 8px;
}

.item-list {
  display: grid;
  gap: var(--space-2);
  list-style: none;
  padding: 0;
}

.item {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.item-compact {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 6px 10px;
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.item-name {
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-desc {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.item-hint {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.item-error {
  color: var(--danger);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.context {
  display: grid;
  gap: var(--space-4);
}

/* The live figures above the breakdown: they update with every API call and compaction. */
.context-live {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.context-live:empty {
  display: none;
}

.context-last {
  display: grid;
  gap: 4px;
}

.context-last-time {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.context-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.context-figure {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.context-number {
  font-size: var(--fs-xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.context-of,
.context-percent {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-hover);
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 300ms var(--ease);
}

.progress.is-attention .progress-bar {
  background: var(--attention);
}

.progress.is-danger .progress-bar {
  background: var(--danger);
}

.bar-list {
  display: grid;
  gap: var(--space-3);
  list-style: none;
  padding: 0;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--fs-sm);
}

.bar-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-hover);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-row.is-muted .bar-head {
  color: var(--fg-muted);
}

.bar-row.is-muted .bar-fill {
  background: var(--fg-subtle);
  opacity: 0.5;
}

.tasks {
  display: grid;
  gap: var(--space-3);
}

.caps {
  display: grid;
  gap: var(--space-5);
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.settings-label {
  font-size: var(--fs-sm);
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  min-height: var(--control-h);
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-hover);
}

.seg-btn {
  min-height: calc(var(--control-h) - 8px);
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
}

.seg-btn:hover {
  color: var(--fg);
}

/* The pressed segment is a raised tint with a border, not a shadow (docs/DESIGN.md: depth is for floating layers). */
.seg-btn[aria-pressed="true"] {
  border-color: var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg);
  font-weight: 600;
}

.switch {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-hover);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-elev);
  transition: transform var(--dur) var(--ease);
}

.switch[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent);
}

.switch[aria-checked="true"] .switch-thumb {
  transform: translateX(18px);
  background: var(--accent-fg);
}

.switch:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.newsession {
  display: grid;
  gap: var(--space-4);
}

/* Folder trust notice in the new-session dialog (gateway: GET/POST /api/fs/trust). */
.trust-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--warning-soft);
  color: var(--fg);
  font-size: var(--fs-sm);
}

.trust-notice > .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: var(--warning);
}

.trust-notice-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.trust-notice-title,
.trust-notice-text {
  margin: 0;
  line-height: 1.45;
}

.trust-notice-title {
  font-weight: 600;
}

.trust-notice-text {
  color: var(--fg-muted);
}

.trust-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--control-h);
  cursor: pointer;
}

.trust-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

@media (pointer: coarse) {
  .trust-check input[type="checkbox"] {
    width: 22px;
    height: 22px;
  }
}

.newsession-grid {
  display: grid;
  align-items: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.dir-browser {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.dir-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.dir-path {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-up > .icon {
  transform: rotate(180deg);
}

.dir-new-row {
  display: flex;
  gap: var(--space-2);
}

.dir-new-row .input {
  flex: 1;
}

.dir-list {
  display: grid;
  align-content: start;
  gap: 1px;
  min-height: 120px;
  max-height: 240px;
  overflow: auto;
  overscroll-behavior: contain;
  list-style: none;
  padding: 0;
}

.dir-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.dir-row:hover,
.dir-row:focus-visible {
  background: var(--bg-hover);
  outline: none;
}

.dir-row > .icon:first-child {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.dir-row > .icon:last-child {
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--fg-subtle);
}

.dir-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-empty {
  padding: var(--space-4);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  text-align: center;
}

.form-error:empty {
  display: none;
}

/* ---- Popover menus ------------------------------------------------------ */
.menu {
  position: fixed;
  z-index: 70;
  min-width: 200px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(70dvh, 480px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
  outline: none;
  animation: menu-in 120ms var(--ease);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg);
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--bg-hover);
  outline: none;
}

.menu-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.menu-item.is-danger {
  color: var(--danger);
}

.menu-item > .icon {
  width: 16px;
  height: 16px;
  color: var(--fg-muted);
}

.menu-item.is-danger > .icon {
  color: var(--danger);
}

.menu-item > .icon.icon-check {
  color: var(--accent);
}

.menu-icon-slot {
  flex: none;
  width: 16px;
}

.menu-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-separator {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

/* ---- Responsive refinements -------------------------------------------- */
@media (max-width: 767.98px) {
  /* iOS zooms the page when a field under 16px is focused, so fields never go below 16px; Large still grows them. */
  .input,
  .select,
  .textarea,
  .sidebar-search-input,
  input,
  select,
  textarea {
    font-size: max(16px, calc(16px * var(--fs-scale)));
  }

  .btn {
    --btn-h: 44px;
  }

  .btn-sm {
    --btn-h: 44px;
    font-size: var(--fs-sm);
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  .btn-icon.btn-sm {
    width: 44px;
  }

  .btn-icon.btn-sm > .icon {
    width: 18px;
    height: 18px;
  }

  .group-head {
    min-height: 40px;
  }

  .session-main {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .session-more {
    width: 44px;
    height: 44px;
  }

  .sidebar-new,
  .sidebar-new-folder,
  .group-new,
  .archived-main,
  .archived-restore,
  .archived-delete,
  .sidebar-archived-entry {
    min-height: 44px;
  }

  .sidebar-new-folder,
  .group-new,
  .archived-delete {
    width: 44px;
  }

  .menu-item {
    min-height: 44px;
  }

  .dir-row {
    min-height: 44px;
  }

  .newsession-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dialog-backdrop {
    align-items: end;
    padding: 0;
  }

  .dialog {
    width: 100%;
    max-height: 90dvh;
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: sheet-up 220ms var(--ease);
  }

  /* The quick switcher keeps its gutter and all four corners on a phone: it is a palette, not a bottom sheet. */
  .dialog.switcher {
    border-radius: var(--radius-lg);
    animation: dialog-in var(--dur-panel) var(--ease);
  }

  .dialog-footer .btn {
    flex: 1 1 auto;
  }

  /* On phones a side panel becomes a full-height sheet (docs/DESIGN.md, "Layout and components"). */
  .sheet {
    left: 0;
    width: 100%;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    border-left: 0;
    border-radius: 0;
    animation: sheet-up 220ms var(--ease);
  }

  .sheet-header {
    padding-top: var(--space-2);
  }
}

/* ---- Utilities and keys ------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keys in running text and in the shortcut hints: a small raised cap in the mono face. */
.kbd {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

mark {
  padding: 0 1px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--fg);
}

/* ---- Runtime panel: tabs, tables, memory and settings sources ---------- */
/* Every tab stays in view: the strip wraps onto a second line instead of scrolling sideways. */
.runtime-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-4);
  margin: 0 calc(-1 * var(--space-2));
  border-bottom: 1px solid var(--border);
}

.runtime-tab {
  flex: none;
  min-height: 40px;
  padding: 10px var(--space-2) 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--fg-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.runtime-tab:hover {
  color: var(--fg);
}

.runtime-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--fg);
  font-weight: 600;
}

.runtime-stage {
  min-height: 120px;
  padding-top: var(--space-4);
}

.runtime-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.runtime-updated {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.runtime-body {
  display: grid;
  gap: var(--space-4);
}

.runtime-restart {
  margin-top: var(--space-2);
}

.runtime-unavailable {
  margin: 0;
}

.runtime-error {
  margin-top: var(--space-2);
}

.runtime-body .table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.runtime-body .table th {
  padding: 0 var(--space-2) var(--space-2) 0;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: left;
}

.runtime-body .table td {
  padding: 9px var(--space-2) 9px 0;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.table-desc {
  margin: 0;
  color: var(--fg-muted);
  line-height: var(--lh-sm);
}

.table-rule {
  color: var(--fg);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.table-source {
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.sandbox-rule {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.sandbox-rule > .kv-label {
  min-width: 0;
}

.settings-source {
  display: grid;
  gap: 6px;
}

.settings-source > .field-label {
  margin: 0;
}

.memory-file {
  display: grid;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.memory-file:first-child {
  padding-top: 0;
  border-top: 0;
}

.memory-file > .item-head {
  align-items: baseline;
}

.memory-file .field {
  gap: 6px;
}

.runtime-memory {
  min-height: 160px;
  resize: vertical;
  font-size: calc(12.5px * var(--fs-scale));
  line-height: 1.55;
}

.hook-command {
  display: block;
  margin-top: 4px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.item.is-muted > .item-head > .item-name,
.item.is-muted > .item-name {
  color: var(--fg-subtle);
}

/* ---- Developer console: raw views and the bounded event log ------------- */
.devtools-view {
  display: grid;
  gap: var(--space-2);
}

.devtools-json {
  max-height: 320px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  color: var(--fg);
  font-size: calc(12.5px * var(--fs-scale));
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.evt-list {
  display: grid;
  max-height: 52dvh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  font-size: var(--fs-sm);
}

.evt {
  min-width: 0;
  padding: 7px 10px;
  border-top: 1px solid var(--border);
}

.evt:first-child {
  border-top: 0;
}

.evt-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.evt-time {
  flex: none;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.evt-type {
  flex: none;
  color: var(--fg);
  font-weight: 500;
}

.evt-sub {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evt-size {
  flex: none;
  margin-left: auto;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.evt-note {
  margin: 4px 0 0;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.evt-empty {
  padding: var(--space-4);
  color: var(--fg-muted);
  text-align: center;
}

.evt-details {
  margin-top: 6px;
}

.evt-details > summary {
  width: fit-content;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  cursor: pointer;
}

.evt-details[open] > summary {
  color: var(--fg);
}

.evt-details > .devtools-json {
  margin-top: 6px;
}

/* ---- Quick switcher ----------------------------------------------------- */
.switcher-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.switcher-input {
  flex: none;
  height: 52px;
  padding: 0 var(--space-5) 0 var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: none;
  font-size: var(--fs-md);
}

.switcher-input:focus {
  box-shadow: none;
}

.switcher-status {
  flex: none;
  margin: 0;
  padding: 6px var(--space-4) 0;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
}

.switcher-status:empty {
  display: none;
}

.switcher-note {
  flex: none;
  margin: 0;
  padding: 4px var(--space-4) 10px;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
}

.switcher-list {
  display: grid;
  flex: 1 1 auto;
  gap: 1px;
  min-height: 0;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.switcher-group {
  padding: 10px 10px 4px;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}

.switcher-option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--space-3);
  min-height: 40px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  color: var(--fg);
  cursor: pointer;
}

.switcher-option.is-active {
  background: var(--accent-soft);
}

.switcher-search-icon {
  display: inline-flex;
  flex: none;
  color: var(--fg-subtle);
}

.switcher-search-icon > .icon {
  width: 16px;
  height: 16px;
}

.switcher-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switcher-detail {
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switcher-hint {
  flex: none;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.switcher-result-head {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.switcher-result-head > .switcher-label {
  flex: 0 1 auto;
  max-width: 60%;
}

.switcher-result-head > .switcher-detail {
  flex: 1 1 auto;
}

.switcher-snippet {
  display: -webkit-box;
  flex: 1 1 100%;
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* ---- Account: the runtime's own sign-in steps --------------------------- */
.account {
  display: grid;
  gap: var(--space-4);
}

.account-flow {
  display: grid;
  gap: var(--space-3);
}

.account-steps {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.account-step {
  display: grid;
  gap: var(--space-2);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border);
}

.account-step-title {
  margin: 0;
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.account-link {
  justify-self: start;
}

.account-code {
  font-size: var(--fs-sm);
}

.account-reopen {
  color: var(--success);
}

/* ---- Panels: sessions, tasks, MCP servers ------------------------------- */
.session-settings {
  display: grid;
  gap: var(--space-4);
}

.task-output {
  min-height: 200px;
  max-height: 60dvh;
  margin: 0;
  padding: 12px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  color: var(--fg);
  font-size: calc(12.5px * var(--fs-scale));
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.held-reload {
  display: grid;
  gap: var(--space-2);
  padding-left: var(--space-3);
  border-left: 2px solid var(--attention);
}

.mcp-auth {
  display: grid;
  gap: var(--space-3);
  padding-top: var(--space-1);
}

.mcp-override {
  display: grid;
  gap: 6px;
  margin-top: var(--space-2);
}

.dir-item {
  margin: 0;
  padding: 0;
}

/* ---- New session: the folder chips and the advanced options ------------- */
.dir-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dir-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 2px 2px 2px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  font-size: var(--fs-xs);
}

.dir-chip-name {
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-chip-remove {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
}

.dir-chip-remove:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.dir-chip-remove > .icon {
  width: 12px;
  height: 12px;
}

.dir-browser-extra {
  margin-top: var(--space-2);
}

.dir-browser-toggle {
  margin-top: var(--space-1);
}

.newsession-advanced {
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.newsession-advanced-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.newsession-advanced-toggle::-webkit-details-marker {
  display: none;
}

.newsession-advanced-toggle::before {
  flex: none;
  width: 6px;
  height: 6px;
  margin-left: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  transform: rotate(-45deg);
  transition: transform var(--dur) var(--ease);
}

.newsession-advanced[open] > .newsession-advanced-toggle::before {
  transform: rotate(45deg);
}

.newsession-advanced > .newsession-grid {
  margin-top: var(--space-3);
}

/* ---- Sign-in ----------------------------------------------------------- */
.login-token {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* ---- Touch targets: 44 px on coarse pointers (docs/DESIGN.md, Keys) ----------------------------------------------
   These rules come after the base rules they refine. Earlier in this file, the base rules of .runtime-tab and
   .switcher-option would win over a touch rule of the same specificity. Small controls keep their look and get a
   larger ::before hit area instead. */
@media (pointer: coarse) {
  :root {
    --control-h: 44px;
  }

  .group-head {
    min-height: var(--control-h);
  }

  .runtime-tab,
  .switcher-option,
  .menu-item {
    min-height: var(--control-h);
  }

  .sidebar-switch {
    min-width: var(--control-h);
    min-height: var(--control-h);
  }

  .seg {
    padding: 0;
    border-width: 0;
  }

  .seg-btn {
    min-height: var(--control-h);
  }

  /* The switch is 42 x 24 px: its hit area adds 10 px above and below, and 1 px beside the border. */
  .switch::before {
    content: "";
    position: absolute;
    inset: -11px -2px;
  }

  /* The header title is about 23 px tall: its hit area adds 11 px above and below. */
  .hdr-title {
    position: relative;
  }

  .hdr-title::before {
    content: "";
    position: absolute;
    inset: -11px 0;
  }
}

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

  /* The running glyph is the one ambient motion in the product. Reduced motion keeps it as a static partial ring. */
  .state-glyph.state-running,
  .state-glyph.state-starting,
  .sidebar-connection[data-state="connecting"] .conn-dot {
    animation: none !important;
  }

  .spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }
}
