/* Dobby web frontend.
   Sidebar spans the full height. The main chrome holds the view segment
   control, connection status, and account actions over the work surface. */

:root {
  --canvas: #f2f0ec;
  --surface: #ffffff;
  --rail: #fbfaf8;
  --sunk: #f1eee9;
  --ink: #1b1a18;
  --ink-2: #45413b;
  --muted: #64605a;
  --line: #e3dfd8;
  --line-2: #cbc6bd;
  --accent: #8f4527;
  --accent-ink: #8b4227;
  --accent-soft: #f6e9e3;
  --ok: #2f6a45;
  --warn: #7a5615;
  --bad: #9b3323;
  --focus: #8f4527;
  --shadow: 0 1px 2px rgba(40, 30, 22, .07);
  --diff-add-bg: #dcefe1;
  --diff-add-ink: #1d6538;
  --diff-delete-bg: #f7dcd7;
  --diff-delete-ink: #972f25;
  --diff-hunk-bg: #e5e0d8;

  --gutter: 86px;
  --measure: 940px;
  --radius: 8px;
  --radius-sm: 6px;
  --rail-width: 268px;
  --settings-rail-width: 0px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light dark;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

::selection {
  color: #fff;
  background: var(--accent);
}
::-moz-selection {
  color: #fff;
  background: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #131211;
    --surface: #1c1a18;
    --rail: #171614;
    --sunk: #232120;
    --ink: #ede8e1;
    --ink-2: #c9c1b7;
    --muted: #a09a90;
    --line: #2c2926;
    --line-2: #423d38;
    --accent: #d98a63;
    --accent-ink: #e79c76;
    --accent-soft: #2e211a;
    --ok: #85b58d;
    --warn: #d0a75f;
    --bad: #e08a78;
    --focus: #e0956e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --diff-add-bg: #183923;
    --diff-add-ink: #9ee0ad;
    --diff-delete-bg: #48231f;
    --diff-delete-ink: #ffb2a4;
    --diff-hunk-bg: #302b27;
  }
}

/* Persistent e-ink mode: monochrome, hairline structure, no fills. */
:root[data-theme="eink"] {
  --canvas: #ffffff;
  --surface: #ffffff;
  --rail: #ffffff;
  --sunk: #ffffff;
  --ink: #000000;
  --ink-2: #000000;
  --muted: #333333;
  --line: #000000;
  --line-2: #000000;
  --accent: #000000;
  --accent-ink: #000000;
  --accent-soft: #ffffff;
  --ok: #000000;
  --warn: #000000;
  --bad: #000000;
  --focus: #000000;
  --shadow: none;
  --diff-add-bg: #ffffff;
  --diff-add-ink: #000000;
  --diff-delete-bg: #ffffff;
  --diff-delete-ink: #000000;
  --diff-hunk-bg: #ffffff;
  color-scheme: light;
  -webkit-font-smoothing: auto;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  position: fixed;
  top: var(--app-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  min-width: 320px;
  background: var(--canvas);
}

h1, h2, h3 { margin: 0; font-weight: 640; line-height: 1.25; letter-spacing: -.012em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { margin: 0; border: 0; background: none; cursor: pointer; }
input, textarea, select { margin: 0; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

.kicker {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
}

/* ---------- Controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost:hover:not(:disabled), .btn-quiet:hover:not(:disabled) { background: var(--sunk); }
.btn-quiet { border-color: var(--line-2); background: var(--surface); }
.btn-primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-block { width: 100%; min-height: 42px; }

.input, .select {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
  font-size: 13.5px;
}
.input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.select { padding-right: 26px; }
.select:disabled { color: var(--muted); background: var(--sunk); cursor: not-allowed; }
.input:focus-visible, .select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
}
.field-label {
  display: block;
  margin: 0 0 6px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 550;
}

/* ---------- Login & gate ---------- */

.login,
.gate {
  height: 100%;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 24px max(20px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}
.login-card,
.gate-card {
  width: min(100%, 380px);
  padding: 30px 28px 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-card h1,
.gate-card h1 { margin: 8px 0 0; font-size: 24px; }
.login-note,
.gate-note { margin: 8px 0 20px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.login-card .input { width: 100%; min-height: 42px; }
#passcodeStep:not([hidden]) {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
#passcodeStep .field-label {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.passcode-boxes {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.passcode-digit {
  box-sizing: border-box;
  width: 40px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--sunk);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  caret-color: var(--accent);
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.passcode-digit:hover:not(:disabled) {
  border-color: var(--line-2);
  background: var(--surface);
}
.passcode-digit:focus {
  outline: none;
  border-color: var(--focus);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.passcode-digit:disabled {
  opacity: 0.55;
}
#identifyStep:not([hidden]) {
  display: block;
  margin-bottom: 16px;
}
.identify-chat {
  display: grid;
  gap: 12px;
  width: 100%;
}
.identify-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 96px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunk);
}
.identify-bubble {
  max-width: 92%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.identify-bubble[data-role="user"] {
  align-self: flex-end;
  color: #fff;
  background: var(--accent);
  border-bottom-right-radius: 4px;
}
.identify-bubble[data-role="assistant"] {
  align-self: flex-start;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.identify-bubble[data-role="status"] {
  align-self: center;
  max-width: 100%;
  padding: 4px 8px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-style: italic;
}
.identify-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.identify-input {
  min-height: 40px;
}
.identify-send {
  min-height: 40px;
  padding-inline: 14px;
}
.login-card[data-stage="identify"] {
  width: min(100%, 420px);
}
.login-card[data-stage="identify"] .login-note {
  margin-bottom: 12px;
}
.login-card .form-error {
  margin: 0 0 14px;
  min-height: 0;
}
.login-card .form-error[data-empty="true"] {
  display: none;
  margin: 0;
}
.form-error {
  min-height: 20px;
  margin: 8px 0 14px;
  color: var(--bad);
  font-size: 13px;
}
.gate-card .form-error { color: var(--muted); }

/* ---------- Shell ---------- */

.frame {
  position: relative;
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  padding:
    env(safe-area-inset-top) env(safe-area-inset-right)
    0 env(safe-area-inset-left);
}
.frame-surface { min-height: 0; overflow: hidden; }
.frame-status {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 6;
  display: flex;
  align-items: center;
  pointer-events: none;
}
.frame-status:empty {
  display: none;
}
.frame[data-session="authenticated"] .frame-status {
  display: none;
}

.app {
  height: 100%;
  max-height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

/* Segment stays natural-width and centers in the leftover gap between
   leading and actions (not the full bar), so unequal side chrome cannot
   push it into a collision. */
.appbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 46px;
  padding: 0 12px 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  container-type: inline-size;
  container-name: appbar;
}
.appbar-leading {
  flex: none;
  display: flex;
  align-items: center;
  z-index: 1;
}
.appbar .modes {
  flex: none;
  margin-inline: auto;
  z-index: 1;
}
.appbar-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  z-index: 1;
}
.reload-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line));
  color: var(--ink);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  font-size: 13px;
}
.reload-banner[hidden] { display: none; }
.reload-banner p { min-width: 0; }
body:has(#reloadBanner:not([hidden])) .frame {
  padding-top: 42px;
}
.runtime {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 12.5px;
  pointer-events: auto;
}
.runtime-dot {
  flex: none;
  width: 7px; height: 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: currentColor;
}
.runtime[data-state="online"],
.runtime[data-state="ok"] { color: var(--ok); }
.runtime[data-state="degraded"],
.runtime[data-state="maintenance"],
.runtime[data-state="connecting"],
.runtime[data-state="unknown"] { color: var(--warn); }
.runtime[data-state="offline"],
.runtime[data-state="no-connection"],
.runtime[data-state="down"] { color: var(--bad); }
.runtime[data-state="offline"] .runtime-dot,
.runtime[data-state="no-connection"] .runtime-dot,
.runtime[data-state="down"] .runtime-dot,
.runtime[data-state="connecting"] .runtime-dot { background: none; }
.runtime[data-state="connecting"] .runtime-dot { animation: pulse 1.4s ease-in-out infinite; }
.appbar-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
}
.appbar-icon:hover { border-color: var(--line-2); color: var(--ink); background: var(--sunk); }
.appbar-icon:disabled {
  opacity: 0.38;
  pointer-events: none;
}
.appbar-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}
.appbar-workbench .wb-tool-icon { display: none; }
.appbar-workbench [data-action="erase"] .wb-tool-erase,
.appbar-workbench [data-action="draw"] .wb-tool-draw,
.appbar-workbench [data-action="preview"] .wb-tool-preview,
.appbar-workbench [data-action="edit"] .wb-tool-edit,
.appbar-workbench [data-action="source"] .wb-tool-edit {
  display: block;
}
.appbar-actions .settings-toggle[aria-expanded="true"],
.appbar-workbench .wb-save:not(:disabled),
.appbar-workbench .wb-draw-tool[aria-pressed="true"],
.appbar-workbench .wb-preview-tool[aria-pressed="true"] {
  color: var(--ink);
}
.appbar-workbench .wb-save {
  position: relative;
}
.appbar-workbench .wb-save-dot {
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}
.appbar-workbench .wb-save[data-dirty="true"] .wb-save-dot {
  opacity: 1;
}
/* Keep workbench / settings actions flat like the left sidebar toggle. */
.appbar-actions .btn {
  min-height: 32px;
  padding: 5px 10px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}
.appbar-actions .btn:hover:not(:disabled) {
  border-color: var(--line-2);
  color: var(--ink);
  background: var(--sunk);
  filter: none;
}

.shell {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-width) 10px minmax(0, 1fr) var(--settings-rail-width);
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
.shell > .rail {
  grid-column: 1;
  grid-row: 1 / -1;
}
.shell > .rail-resizer {
  grid-column: 2;
  grid-row: 1 / -1;
}
.shell > .appbar {
  grid-column: 3;
  grid-row: 1;
}
.shell > .work {
  grid-column: 3;
  grid-row: 2;
}
.shell > .settings-rail {
  grid-column: 4;
  grid-row: 1 / -1;
}

/* ---------- Navigation rail ---------- */

.rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--rail);
  border-right: 1px solid var(--line);
}
.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
}
.rail-brand .run-state {
  min-width: 0;
  max-width: none;
  flex: 1 1 auto;
  color: var(--muted);
}
.rail-brand[data-state="busy"] { color: var(--warn); }
.rail-brand[data-state="error"] { color: var(--bad); }
.rail-brand[data-state="busy"] .run-state,
.rail-brand[data-state="error"] .run-state { color: currentColor; }
.sock-mark {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}
.rail-brand[data-state="busy"] .sock-mark,
.appbar-dobby[data-state="busy"] .sock-mark,
.shell[data-run="busy"] .sock-mark {
  animation: sock-flash 1.1s ease-in-out infinite;
}
@keyframes sock-flash {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .28; transform: scale(.92); }
}
.appbar-dobby {
  display: none;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--accent);
}
.appbar-dobby .sock-mark { width: 20px; height: 20px; }
.appbar-dobby[data-state="busy"] { color: var(--warn); }
.appbar-dobby[data-state="error"] { color: var(--bad); }
.shell[data-sidebar="collapsed"] .appbar-dobby { display: grid; }
.rail-resizer {
  position: relative;
  z-index: 3;
  display: grid;
  place-items: center;
  min-width: 0;
  cursor: col-resize;
  touch-action: none;
}
.rail-resizer::before {
  content: "";
  position: absolute;
  inset: 0 4px;
  background: transparent;
  transition: background .12s ease;
}
.rail-handle {
  position: relative;
  z-index: 1;
  width: 4px;
  height: 44px;
  border-radius: 999px;
  background: var(--line-2);
  box-shadow: inset 0 0 0 1px transparent;
  transition: background .12s ease, height .12s ease, width .12s ease;
  pointer-events: none;
}
.rail-resizer:hover::before,
.rail-resizer:focus-visible::before,
body[data-resizing-rail="true"] .rail-resizer::before {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.rail-resizer:hover .rail-handle,
.rail-resizer:focus-visible .rail-handle,
body[data-resizing-rail="true"] .rail-resizer .rail-handle {
  background: var(--accent);
}
body[data-resizing-rail="true"] {
  cursor: col-resize;
  user-select: none;
}

@media (min-width: 720px) {
  .shell[data-sidebar="collapsed"] {
    grid-template-columns: 0 0 minmax(0, 1fr) var(--settings-rail-width);
  }
  .shell[data-sidebar="collapsed"] .rail {
    visibility: hidden;
    pointer-events: none;
    border-right: 0;
  }
  .shell[data-sidebar="collapsed"] .rail-resizer {
    display: none;
  }
  .shell[data-settings="collapsed"] .settings-rail {
    visibility: hidden;
    pointer-events: none;
    border-left: 0;
  }
}
.rail-block { min-height: 0; display: flex; flex-direction: column; }
.rail-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 8px;
}
.rail-actions { display: flex; align-items: center; gap: 8px; }
.rail-head h2 {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.rail-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.rail-context {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px 10px;
  scrollbar-width: thin;
}
.list-item {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: left;
}
.list-item:hover { background: var(--sunk); }
.list-item[aria-current="true"] {
  border-color: var(--line-2);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.conversation-item { display: grid; gap: 5px; }
.rail-conversations .conversation-list { flex: 1; }
.conversation-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.conversation-status {
  display: none;
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}
.conversation-status[data-working="true"] { display: inline-block; }
.conversation-working-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.conversation-title {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-meta {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow-x: auto;
  color: var(--muted);
  font-size: 11.5px;
  scrollbar-width: none;
}
.conversation-meta::-webkit-scrollbar { display: none; width: 0; height: 0; }
.conversation-meta > * {
  flex: none;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  line-height: 1.35;
  white-space: nowrap;
}
.conversation-meta time { font-variant-numeric: tabular-nums; }

.list-empty {
  margin: 4px 9px;
  padding: 14px 12px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
}

.rail-foot {
  flex: none;
  display: grid;
  gap: 8px;
  padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  border-top: 1px solid var(--line);
}
.rail-foot-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 12px;
}
.conversation-filters {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.filter-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  padding: 0 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filter-row::-webkit-scrollbar { display: none; width: 0; height: 0; }
.filter-chip {
  flex: none;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--ink-2);
  background: var(--surface);
  font-size: 12px;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
}
.filter-chip:hover { background: var(--sunk); }
.filter-chip[data-active="true"],
.filter-chip[aria-checked="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2));
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}
.appbar-workbench {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
}
.appbar-workbench .appbar-icon[hidden] { display: none !important; }
.rail-foot-label[data-state="modified"],
.rail-foot-label[data-state="saving"],
.rail-foot-label[data-state="loading"] { color: var(--warn); }
.rail-foot-label[data-state="saved"] { color: var(--ok); }
.rail-foot-label[data-state="error"] { color: var(--bad); }
/* ---------- Settings rail (right sidebar) ---------- */

.settings-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
}
.settings-close:hover { color: var(--ink); background: var(--sunk); }
.settings-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}
.notification-toggle { position: relative; }
.notification-badge {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  color: var(--surface);
  background: var(--danger, #b42318);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.settings-rail {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--rail);
  border-left: 1px solid var(--line);
}
.settings-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 46px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line);
}
.settings-rail-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.settings-rail-body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.settings-section { padding: 16px 14px; border-bottom: 1px solid var(--line); }
.settings-section:last-child { border-bottom: 0; }
.settings-section h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 42px;
}
.settings-row + .settings-row { margin-top: 8px; }
.settings-row > span { min-width: 0; }
.settings-row strong { display: block; font-size: 13.5px; font-weight: 600; }
.settings-lede {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}
.settings-row-stack {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.settings-select {
  width: 100%;
  min-height: 34px;
}
.settings-range {
  width: 100%;
  accent-color: var(--ink);
}
.settings-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--sunk);
}
.settings-segment-option {
  min-height: 32px;
  padding: 6px 8px;
  border: 0;
  border-right: 1px solid var(--line-2);
  color: var(--ink-2);
  background: transparent;
  font-size: 12px;
  font-weight: 550;
  line-height: 1.2;
}
.settings-segment-option:last-child { border-right: 0; }
.settings-segment-option:hover { color: var(--ink); background: var(--surface); }
.notification-pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.notification-pane-head .settings-lede { margin-bottom: 6px; }
.notification-list {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.notification-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.notification-item[data-severity="error"] { border-left-color: var(--danger, #b42318); }
.notification-item[data-severity="warning"] { border-left-color: #b7791f; }
.notification-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10.5px;
}
.notification-item strong {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.35;
}
.notification-item details { margin-top: 7px; color: var(--ink-2); font-size: 11.5px; }
.notification-item pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  line-height: 1.4;
}
.voice-inline-preview {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 var(--accent);
}
.settings-segment-option[aria-checked="true"] {
  color: var(--accent-ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, var(--line-2));
}
.settings-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.switch {
  flex: none;
  width: 42px;
  height: 24px;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings-status {
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Work surface ---------- */

.work {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  background: var(--surface);
}
.rail-edge-handle {
  display: none;
  position: absolute;
  top: 50%;
  left: 0;
  z-index: 4;
  place-items: center;
  width: 28px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 0 14px 14px 0;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 88%, var(--rail));
  box-shadow: 1px 0 0 var(--line), 0 1px 2px rgba(40, 30, 22, .06);
  transform: translateY(-50%);
  touch-action: manipulation;
}
.rail-edge-handle .rail-handle {
  width: 5px;
  height: 36px;
  background: var(--line-2);
}
.rail-edge-handle:hover,
.rail-edge-handle:focus-visible {
  color: var(--ink);
  background: var(--surface);
}
.rail-edge-handle:hover .rail-handle,
.rail-edge-handle:focus-visible .rail-handle {
  background: var(--accent);
}
.run-state {
  flex: none;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.run-state[data-state="busy"] { color: var(--warn); }
.run-state[data-state="error"] { color: var(--bad); }
/* Status pulse lives on .sock-mark — no separate circle beside the sock. */

.modes {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--sunk);
}
.mode {
  flex: none;
  min-height: 28px;
  padding: 3px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.mode[aria-selected="true"] {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Connectivity mark sits at the upper-right of the Status label. */
.mode-status {
  position: relative;
}
.mode-conn {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 7px;
  height: 7px;
  box-sizing: border-box;
  pointer-events: none;
}
.mode-status[data-connectivity="online"] .mode-conn,
.mode-status[data-connectivity="ok"] .mode-conn {
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: currentColor;
}
.mode-status[data-connectivity="connecting"] .mode-conn,
.mode-status[data-connectivity="unknown"] .mode-conn {
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: transparent;
  animation: pulse 1.4s ease-in-out infinite;
}
.mode-status[data-connectivity="degraded"] .mode-conn,
.mode-status[data-connectivity="maintenance"] .mode-conn {
  border: 1.5px solid currentColor;
  border-radius: 1px;
  background: transparent;
  transform: rotate(45deg);
}
.mode-status[data-connectivity="offline"] .mode-conn,
.mode-status[data-connectivity="no-connection"] .mode-conn,
.mode-status[data-connectivity="down"] .mode-conn {
  border: 0;
  background: transparent;
}
.mode-status[data-connectivity="offline"] .mode-conn::before,
.mode-status[data-connectivity="offline"] .mode-conn::after,
.mode-status[data-connectivity="no-connection"] .mode-conn::before,
.mode-status[data-connectivity="no-connection"] .mode-conn::after,
.mode-status[data-connectivity="down"] .mode-conn::before,
.mode-status[data-connectivity="down"] .mode-conn::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  width: 1.5px;
  margin-left: -0.75px;
  background: currentColor;
}
.mode-status[data-connectivity="offline"] .mode-conn::before,
.mode-status[data-connectivity="no-connection"] .mode-conn::before,
.mode-status[data-connectivity="down"] .mode-conn::before {
  transform: rotate(45deg);
}
.mode-status[data-connectivity="offline"] .mode-conn::after,
.mode-status[data-connectivity="no-connection"] .mode-conn::after,
.mode-status[data-connectivity="down"] .mode-conn::after {
  transform: rotate(-45deg);
}

/* When the main chrome is tight, give the segment leftover space and
   keep Save / Preview / settings as flat trailing controls.
   Do not replace the sidebar toggle with the sock here — a dragged-wide
   rail also squeezes the appbar, and the toggle must stay available. */
@container appbar (max-width: 560px) {
  .appbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
  }
  .appbar-leading {
    display: flex;
    align-items: center;
  }
  .appbar .modes {
    flex: 1 1 auto;
    min-width: max-content;
    margin-inline: 0;
    justify-content: center;
  }
  .appbar .mode {
    flex: none;
    min-height: 30px;
  }
  .appbar-actions {
    flex: none;
    align-self: stretch;
    display: flex;
    align-items: center;
    gap: 2px;
  }
  .appbar-actions .settings-toggle {
    width: 34px;
    height: 34px;
  }
}

.panel { min-width: 0; min-height: 0; overflow: hidden; }
.panel:focus { outline: none; }
.transcript {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

/* ---------- Transcript ---------- */

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 4px 20px var(--float-composer-pad, 148px);
  scrollbar-width: thin;
}
.messages:focus-visible { outline-offset: -2px; }
.messages > * { max-width: var(--measure); margin-inline: auto; }

.msg {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  gap: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.msg:first-child { border-top: 0; }
.msg-aside {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}
.msg-role {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .07em;
  text-align: right;
  text-transform: uppercase;
}
.msg-time {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  text-align: right;
  line-height: 1.3;
}
.msg-main { min-width: 0; }
.msg-body {
  min-width: 0;
  max-width: 100%;
  font-size: 14.5px;
  line-height: 1.62;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.msg-user .msg-body {
  padding: 10px 14px;
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
}
.turn-context {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 0 0 6px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.turn-context-label {
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.turn-context-path {
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}
.turn-context-selection {
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
button.turn-context-path {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.turn-context-path:hover,
button.turn-context-path:focus-visible {
  color: var(--accent);
}
.msg-body.is-error { color: var(--bad); }
.msg-body.is-waiting { color: var(--muted); }

.msg-body pre {
  margin: 12px 0;
  padding: 12px 14px;
  max-width: 100%;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunk);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-body pre, .msg-body code,
.markdown-preview pre, .markdown-preview code {
  font-family: var(--mono);
  font-size: 12.75px;
  line-height: 1.55;
}
.msg-body pre[data-lang]::before,
.markdown-preview pre[data-lang]::before {
  content: attr(data-lang);
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
}

/* Stacked unified diffs. The fixed gutters keep old/new line numbers aligned
   while the code column expands and scrolls as one surface. */
.diff-view {
  max-width: 100%;
  margin: 12px 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.diff-grid {
  width: max-content;
  min-width: 100%;
  font-family: var(--mono);
  font-size: 12.75px;
  line-height: 1.55;
}
.diff-row {
  display: grid;
  grid-template-columns: 5ch 5ch 2.25ch minmax(max-content, 1fr);
  min-height: 1.55em;
  border-left: 3px solid transparent;
}
.diff-row + .diff-row { border-top: 1px solid color-mix(in srgb, var(--line) 45%, transparent); }
.diff-row-added + .diff-row-added,
.diff-row-deleted + .diff-row-deleted { border-top-color: transparent; }
.diff-line-number {
  padding: 0 .65ch;
  border-right: 1px solid var(--line);
  color: var(--muted);
  text-align: right;
  user-select: none;
}
.diff-marker {
  color: var(--muted);
  text-align: center;
  user-select: none;
}
.diff-code {
  padding: 0 12px 0 2px;
  color: var(--ink);
  white-space: pre;
}
.diff-row-added {
  border-left-color: var(--diff-add-ink);
  color: var(--diff-add-ink);
  background: var(--diff-add-bg);
}
.diff-row-added .diff-marker,
.diff-row-added .diff-code { color: var(--diff-add-ink); }
.diff-row-deleted {
  border-left-color: var(--diff-delete-ink);
  color: var(--diff-delete-ink);
  background: var(--diff-delete-bg);
}
.diff-row-deleted .diff-marker,
.diff-row-deleted .diff-code { color: var(--diff-delete-ink); }
.diff-row-added .diff-marker,
.diff-row-deleted .diff-marker { font-weight: 750; }
.diff-row-hunk {
  margin-top: -1px;
  border-top: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  background: var(--diff-hunk-bg);
}
.diff-row-hunk .diff-line-number,
.diff-row-hunk .diff-marker { color: transparent; }
.diff-row-hunk .diff-code { color: var(--muted); }
.diff-row-note .diff-code {
  color: var(--muted);
  font-style: italic;
}

/* Safe Markdown shared by transcript messages and the workbench preview. */
.markdown { white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: .65em 0; overflow-wrap: anywhere; word-break: break-word; }
.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 {
  margin: 1.25em 0 .5em;
  color: var(--ink);
  line-height: 1.25;
  letter-spacing: -.012em;
}
.markdown h1 { font-size: 1.55em; }
.markdown h2 { padding-bottom: .25em; border-bottom: 1px solid var(--line); font-size: 1.3em; }
.markdown h3 { font-size: 1.12em; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 1em; }
.markdown ul, .markdown ol { margin: .65em 0; padding-left: 1.65em; }
.markdown ul { list-style: disc; }
.markdown ol { list-style: decimal; }
.markdown li { margin: .22em 0; }
.markdown li > input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0 7px 0 -1.35em;
  vertical-align: -.12em;
}
.markdown blockquote {
  margin: .8em 0;
  padding: .1em 0 .1em 14px;
  border-left: 3px solid var(--line-2);
  color: var(--ink-2);
}
.markdown blockquote > :first-child { margin-top: 0; }
.markdown blockquote > :last-child { margin-bottom: 0; }
.markdown hr { margin: 1.2em 0; border: 0; border-top: 1px solid var(--line); }
.markdown strong { font-weight: 650; }
.markdown-link {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.markdown-link:hover { background: var(--accent-soft); }
.math-display {
  max-width: 100%;
  margin: 1em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: .15em 0;
  overscroll-behavior-x: contain;
}
.math-inline {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  vertical-align: -.15em;
  overscroll-behavior-x: contain;
}
.math-display[data-math-fallback="true"],
.math-inline[data-math-fallback="true"] {
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: .9em;
  white-space: pre-wrap;
}
.markdown-table { max-width: 100%; margin: .9em 0; overflow-x: auto; }
.markdown table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: .92em; }
.markdown th, .markdown td {
  padding: 7px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.markdown th { background: var(--sunk); font-weight: 650; }
.code-inline {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--sunk);
  font-family: var(--mono);
  font-size: 12.75px;
}
.path-link {
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--accent-ink);
  font-family: var(--mono);
  font-size: 12.75px;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.path-link:hover { background: var(--accent-soft); }

.thinking,
.turn-context-block {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12.5px;
}
.thinking[data-active="true"] { animation: pulse 1.6s ease-in-out infinite; }
.thinking > summary,
.turn-context-block > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 12.5px;
}
.thinking > summary::-webkit-details-marker,
.turn-context-block > summary::-webkit-details-marker { display: none; }
.thinking > summary::before,
.turn-context-block > summary::before { content: "▸"; color: var(--line-2); font-size: 11px; }
.thinking[open] > summary::before,
.turn-context-block[open] > summary::before { content: "▾"; }
.thinking-body,
.turn-context-body {
  margin: 6px 0 4px;
  padding: 8px 10px;
  max-width: 100%;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunk);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}

.turn-stream {
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}
.turn-stream > * {
  min-width: 0;
  max-width: 100%;
}
.turn-stream > .msg-body { margin: 0; }

.tools { margin-bottom: 10px; }
.tools summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 12.5px;
  list-style: none;
  cursor: pointer;
}
.tools summary::-webkit-details-marker { display: none; }
.tools summary::before { content: "▸"; color: var(--line-2); font-size: 11px; }
.tools[open] summary::before { content: "▾"; }
.tool-rows {
  margin: 4px 0 0;
  border-left: 1px solid var(--line);
  padding: 2px 0 2px 12px;
}
.turn-stream > .tool-row,
.tool-rows .tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 3px 0;
  font-size: 12.5px;
}
.turn-stream > .tool-row {
  margin: 0;
  padding: 4px 0 4px 12px;
  border-left: 1px solid var(--line);
}
.tool-state {
  flex: none;
  min-width: 56px;
  padding-right: 6px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.tool-row[data-status="running"] .tool-state { color: var(--warn); }
.tool-row[data-status="completed"] .tool-state { color: var(--ok); }
.tool-row[data-status="error"] .tool-state { color: var(--bad); }
.tool-name { font-weight: 570; }
.tool-detail {
  min-width: 0;
  flex: 1 1 220px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-detail.path-link { flex: 0 1 auto; color: var(--accent-ink); white-space: nowrap; }

.turn-meta { margin-top: 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Context introduction — the first item of every conversation. */
.msg-context .msg-body { padding: 0; background: none; white-space: normal; }
.context-summary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  text-align: left;
  font-size: 13.5px;
}
.context-summary:hover { background: var(--sunk); }
.context-summary-main {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.context-summary-meta {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.context-summary[aria-expanded="true"] {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.context-details {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.context-details[hidden] { display: none; }
.context-lede { padding: 10px 12px 0; color: var(--ink-2); font-size: 13.5px; line-height: 1.55; }
.context-note { padding: 0 12px 10px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.context-list { list-style: none; margin: 0; padding: 0; }
.context-list li + li { border-top: 1px solid var(--line); }
.context-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(0, 1.4fr) auto;
  gap: 6px 14px;
  align-items: baseline;
  padding: 9px 12px;
  text-align: left;
}
.context-row:hover { background: var(--sunk); }
.context-name { font-size: 13.5px; font-weight: 550; }
.context-src {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.context-size { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.placeholder {
  padding: 26px 0 8px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}
.placeholder strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 15px; font-weight: 600; }
.placeholder.is-error { color: var(--bad); }

@keyframes pulse { 50% { opacity: .45; } }

/* ---------- Composer ---------- */

.composer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 3;
  min-width: 0;
  padding: 0;
  background: transparent;
  pointer-events: none;
}
.composer-box {
  pointer-events: auto;
  position: relative;
  max-width: var(--measure);
  margin-inline: auto;
  display: grid;
  gap: 8px;
  padding: 14px 14px 12px;
  border: 1px solid var(--line-2);
  border-radius: calc(var(--radius) + 4px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.composer-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.composer-toolbar::-webkit-scrollbar { display: none; width: 0; height: 0; }
.composer-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}
.composer-attachments[hidden] {
  display: none !important;
}
.composer-attachment {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--sunk);
  flex: none;
}
.composer-attachment img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.composer-attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.composer-attachment-remove:hover {
  background: var(--surface);
}
.composer-box.is-drop-target {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2));
  box-shadow:
    var(--shadow),
    0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
.composer-input {
  position: relative;
  min-width: 0;
  min-height: 40px;
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0;
  color: var(--ink);
  background: transparent;
  /* 16px avoids iOS focus zoom that knocks the composer out of view. */
  font: inherit;
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
}
.composer-input[data-empty="true"]::before {
  /* Absolutely positioned so an empty contenteditable caret stays at the
     start instead of sitting after the placeholder text. */
  content: attr(data-placeholder);
  position: absolute;
  inset: 8px 0 auto 0;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.composer-input:focus,
.composer-input:focus-visible {
  outline: none;
}
.composer-box:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line-2));
}
@property --recording-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.composer-box.is-recording,
.wb-composer-box.is-recording,
.wb-doc.is-recording {
  /* Keep the normal translucent fill; the orbit lives on a masked ring only.
     --recording-* vars are driven live from mic amplitude. */
  --recording-level: 0;
  --recording-glow: 12px;
  --recording-glow-alpha: 0.16;
  --recording-ring: 2px;
  --recording-hot: 0.35;
  border-color: color-mix(
    in srgb,
    var(--accent) calc(28% + var(--recording-level) * 45%),
    var(--line-2)
  );
  box-shadow:
    var(--shadow),
    0 0 var(--recording-glow) color-mix(
      in srgb,
      var(--accent) calc(var(--recording-glow-alpha) * 100%),
      transparent
    );
}
.wb-doc.is-recording {
  border: 1px solid color-mix(
    in srgb,
    var(--accent) calc(28% + var(--recording-level) * 45%),
    var(--line-2)
  );
  border-radius: var(--radius-sm);
}
.composer-box.is-recording::before,
.wb-composer-box.is-recording::before,
.wb-doc.is-recording::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--recording-ring));
  z-index: 0;
  border-radius: inherit;
  padding: var(--recording-ring);
  background: conic-gradient(
    from var(--recording-angle),
    color-mix(in srgb, var(--accent) calc(6% + var(--recording-level) * 10%), transparent) 0deg,
    color-mix(in srgb, var(--accent) calc(55% + var(--recording-level) * 45%), transparent) 42deg,
    color-mix(
      in srgb,
      var(--accent-ink) calc(70% + var(--recording-hot) * 30%),
      var(--accent)
    ) 88deg,
    color-mix(in srgb, var(--accent) calc(12% + var(--recording-level) * 18%), transparent) 150deg,
    transparent calc(200deg + var(--recording-level) * 20deg),
    color-mix(in srgb, var(--accent) calc(6% + var(--recording-level) * 10%), transparent) 360deg
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  pointer-events: none;
  animation: composer-recording-orbit 1.5s linear infinite;
  filter: saturate(calc(0.9 + var(--recording-level) * 0.7));
  opacity: calc(0.72 + var(--recording-level) * 0.28);
}
.wb-doc.is-recording::before {
  inset: 0;
  z-index: 4;
  border-radius: inherit;
}
.composer-box.is-recording > *,
.wb-composer-box.is-recording > * {
  z-index: 1;
}
.composer-box.is-recording > .composer-input,
.composer-box.is-recording > .composer-toolbar,
.composer-box.is-recording > .composer-attachments,
.wb-composer-box.is-recording > .wb-composer-row,
.wb-composer-box.is-recording > .wb-chat {
  position: relative;
}
.composer-box.is-transcribing,
.wb-composer-box.is-transcribing,
.wb-doc.is-transcribing {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2));
  box-shadow:
    var(--shadow),
    0 0 16px color-mix(in srgb, var(--accent) 22%, transparent);
  animation: composer-transcribing 1.4s ease-in-out infinite;
}
.wb-doc.is-transcribing {
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line-2));
  border-radius: var(--radius-sm);
}
@keyframes composer-recording-orbit {
  to { --recording-angle: 360deg; }
}
@keyframes composer-transcribing {
  0%, 100% {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--line-2));
    box-shadow:
      var(--shadow),
      0 0 10px color-mix(in srgb, var(--accent) 14%, transparent);
  }
  50% {
    border-color: color-mix(in srgb, var(--accent) 80%, var(--line-2));
    box-shadow:
      var(--shadow),
      0 0 20px color-mix(in srgb, var(--accent) 30%, transparent);
  }
}
.send,
.mic,
.keyboard,
.attach,
.include-sel {
  display: grid;
  place-items: center;
  flex: none;
  align-self: end;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.mic {
  touch-action: none;
}
.mic[aria-pressed="true"],
.keyboard[aria-pressed="true"],
.include-sel[data-has-selection="true"] {
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2));
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}
.mic-icon,
.keyboard-icon,
.attach-icon,
.include-sel-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.send-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.send-icon-new,
.send-icon-stop { display: none; }
.send[data-mode="new"] .send-icon-send { display: none; }
.send[data-mode="new"] .send-icon-new { display: block; }
.send[data-mode="stop"] {
  border-color: var(--line-2);
  color: var(--ink);
  background: var(--sunk);
}
.send[data-mode="stop"] .send-icon-send,
.send[data-mode="stop"] .send-icon-new { display: none; }
.send[data-mode="stop"] .send-icon-stop { display: block; }
.wb-composer .send[data-mode="new"] {
  border-color: var(--line-2);
  color: var(--ink);
  background: var(--sunk);
}
.model {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.model::-webkit-scrollbar { display: none; width: 0; height: 0; }
.model-label { color: var(--muted); font-size: 12.5px; }
.model .select { min-height: 28px; padding: 2px 24px 2px 8px; font-size: 12.5px; }
.provider-action { min-height: 28px; padding: 2px 8px; font-size: 12px; white-space: nowrap; }
.model-fixed {
  padding: 2px 8px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(52vw, 28rem);
}

/* ---------- Workbench ---------- */

.workbench {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}
.file-list {
  max-height: min(28vh, 220px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 8px 8px;
  scrollbar-width: thin;
}
.rail-files .file-list {
  flex: 1;
  max-height: none;
  overflow-x: auto;
  padding: 0 8px 10px;
}
.file-tree, .file-branch { list-style: none; }
.file-branch {
  width: max-content;
  min-width: calc(100% - 18px);
  margin: 0 0 0 11px;
  padding: 0 0 0 7px;
  border-left: 1px solid var(--line);
}
.file-directory > summary {
  list-style: none;
}
.file-directory > summary::-webkit-details-marker { display: none; }
.directory-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 29px;
  padding: 4px 7px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 12.5px;
  cursor: pointer;
}
.directory-row:hover { background: var(--sunk); }
.directory-caret {
  flex: none;
  width: 10px;
  color: var(--muted);
}
.directory-caret::before { content: "›"; }
.file-directory[open] > .directory-row .directory-caret::before { content: "⌄"; }
.directory-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 570;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-row {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-row:hover { background: var(--sunk); }
.file-row[aria-current="true"] { color: var(--ink); background: var(--sunk); font-weight: 600; }
.file-note { padding: 6px 10px 10px; color: var(--muted); font-size: 12.5px; }

.wb-doc {
  /* Image tools keep a protected inset. Text surfaces put the same space
     inside their scroller so content can move beneath the floating chat. */
  position: relative;
  min-height: 0;
  display: grid;
  overflow: hidden;
  background: var(--surface);
  padding-bottom: var(--float-composer-pad, 100px);
}
.wb-doc[data-media="text"] { padding-bottom: 0; }
.wb-doc > .wb-editor-scroll,
.wb-doc > .wb-canvas,
.wb-doc > .wb-selection-ink,
.wb-doc > .wb-image-preview,
.wb-doc > .markdown-preview,
.wb-doc > .html-preview {
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 0;
}
.wb-editor-scroll {
  /* Shared scroller for the textarea and its decoration layers — overlays
     move with the content natively (no JS scroll mirroring). */
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
}
.wb-editor-scroll[hidden] { display: none !important; }
.wb-editor-stack {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}
.wb-editor-stack > .wb-gitdiff-layer,
.wb-editor-stack > .wb-selmatch-layer,
.wb-editor-stack > .wb-search-layer,
.wb-editor-stack > .wb-wish-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
.wb-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
  color: #111;
}
.wb-canvas[hidden] { display: none !important; }
.wb-selection-ink {
  z-index: 5;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
  background: transparent;
}
.wb-selection-ink[hidden] { display: none !important; }
.wb-image-preview {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: color-mix(in srgb, var(--sunk) 70%, var(--surface));
  overflow: hidden;
}
.wb-image-preview[hidden] { display: none !important; }
.wb-image-viewport {
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.wb-image-viewport:active { cursor: grabbing; }
.wb-image-bounds {
  position: relative;
  display: inline-block;
  max-width: none;
  line-height: 0;
  background: #fff;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--ink) 35%, transparent),
    0 0 0 6px color-mix(in srgb, var(--accent-soft, var(--sunk)) 80%, transparent);
  transform-origin: center center;
}
.wb-image-img {
  display: block;
  max-width: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}
.wb-image-size {
  position: absolute;
  left: 0;
  bottom: 100%;
  margin-bottom: 6px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}
.wb-image-hint {
  margin: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.wb-doc[data-media="image"] .wb-editor-scroll,
.wb-doc[data-media="image"] .markdown-preview {
  display: none !important;
}
.wb-doc[data-image-mode="edit"] .wb-image-preview {
  display: none !important;
  pointer-events: none !important;
}
.wb-dialog {
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 48px color-mix(in srgb, var(--ink) 18%, transparent);
  max-width: min(440px, calc(100vw - 32px));
  width: 100%;
}
.wb-dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 28%, transparent);
}
.wb-dialog-form {
  display: grid;
  gap: 12px;
  padding: 18px 18px 16px;
}
.wb-dialog-form h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.wb-dialog-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.wb-dialog-input {
  width: 100%;
  box-sizing: border-box;
}
.wb-dialog-error {
  margin: 0;
  color: var(--danger, #b00020);
  font-size: 12.5px;
}
.wb-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
:root[data-theme="eink"] .wb-canvas {
  background: #fff;
}
.editor {
  position: relative;
  z-index: 3;
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 100%;
  height: auto;
  resize: none;
  /* Parent `.wb-editor-scroll` owns scrolling; keep the field content-sized. */
  overflow: hidden;
  padding: 16px 18px var(--float-composer-pad, 100px);
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 13.25px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.editor[data-pen-input="true"] {
  /* Draw/select only: block pen→scroll/caret conversion while the pen is armed.
     Touch mode never sets this attribute so finger scrolling stays native. */
  touch-action: none;
}
:root[data-editor-wrap="off"] .editor {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  width: max-content;
  min-width: 100%;
}
.editor:focus-visible { outline: none; }
.editor[readonly] { background: color-mix(in srgb, var(--sunk) 70%, transparent); }
.wb-doc[data-wish-select="on"] .editor {
  caret-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.wb-doc[data-wish-select="marks"] .wb-wish-layer {
  background: transparent;
  outline: none;
  pointer-events: none;
  cursor: default;
}
.wb-doc[data-wish-select="marks"] .wb-wish-mirror {
  color: transparent;
}
.wb-doc[data-wish-select="marks"] .wb-wish-hint {
  display: none;
}
.wb-wish-layer {
  z-index: 4;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
  cursor: crosshair;
}
.wb-wish-layer[hidden] { display: none !important; }
.wb-wish-mirror {
  position: relative;
  z-index: 0;
  margin: 0;
  min-height: 100%;
  padding: 16px 18px;
  border: 0;
  color: inherit;
  background: transparent;
  font-size: 13.25px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: none;
  -webkit-user-select: none;
}
:root[data-editor-wrap="off"] .wb-wish-mirror {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  width: max-content;
  min-width: 100%;
}
.wb-wish-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.wb-wish-mark {
  position: absolute;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 34%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
    0 0 18px color-mix(in srgb, var(--accent) 22%, transparent);
  mix-blend-mode: multiply;
  animation: wish-glow 1.1s ease-in-out infinite alternate;
}
.wb-wish-hint {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 0;
  z-index: 1;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0 12px;
  padding: 7px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line-2));
  border-radius: 999px;
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--surface) 88%, var(--accent-soft));
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0.96;
  transition: opacity .18s ease, transform .18s ease;
}
.wb-wish-layer[data-stroking="true"] .wb-wish-hint {
  opacity: 0;
  transform: translateY(6px);
}
@keyframes wish-glow {
  from { filter: saturate(1); }
  to { filter: saturate(1.25) brightness(1.05); }
}
@media (prefers-color-scheme: dark) {
  .wb-wish-mark { mix-blend-mode: screen; }
}
.wb-search-layer {
  /* Same stacking idea as wish-select marks: overlay the editor, never steal input. */
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
}
.wb-search-layer[hidden] { display: none !important; }
.wb-selmatch-layer {
  /* Below search highlights; above the textarea ink for occurrence reflection. */
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
}
.wb-selmatch-layer[hidden] { display: none !important; }
.wb-search-mirror {
  position: relative;
  z-index: 0;
  margin: 0;
  min-height: 100%;
  padding: 16px 18px;
  border: 0;
  color: transparent;
  background: transparent;
  font-size: 13.25px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
:root[data-editor-wrap="off"] .wb-search-mirror {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  width: max-content;
  min-width: 100%;
}
.wb-selmatch-mirror {
  position: relative;
  z-index: 0;
  margin: 0;
  min-height: 100%;
  padding: 16px 18px;
  border: 0;
  color: transparent;
  background: transparent;
  font-size: 13.25px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
:root[data-editor-wrap="off"] .wb-selmatch-mirror {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  width: max-content;
  min-width: 100%;
}
.wb-search-marks {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
}
.wb-selmatch-marks {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
}
.wb-search-mark {
  position: absolute;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 34%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
    0 0 18px color-mix(in srgb, var(--accent) 22%, transparent);
  mix-blend-mode: multiply;
}
.wb-search-mark.is-current {
  background: color-mix(in srgb, var(--accent) 52%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 14px color-mix(in srgb, var(--accent) 28%, transparent);
}
/* Quieter than find-in-file: same idea as VS Code selectionHighlight. */
.wb-selmatch-mark {
  position: absolute;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 12%, transparent);
  mix-blend-mode: multiply;
}
@media (prefers-color-scheme: dark) {
  .wb-search-mark { mix-blend-mode: screen; }
  .wb-selmatch-mark {
    mix-blend-mode: screen;
    background: color-mix(in srgb, var(--ink) 22%, transparent);
  }
}
.markdown-preview mark.wb-search-hit {
  color: inherit;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.markdown-preview mark.wb-search-hit.is-current {
  background: color-mix(in srgb, var(--accent) 42%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}
.wb-gitdiff-layer {
  /* Under find/selection overlays; never steal editor input.
     Lives inside the shared editor scroller, so marks track text natively. */
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
}
.wb-gitdiff-layer[hidden] { display: none !important; }
.wb-gitdiff-mirror {
  position: relative;
  z-index: 0;
  box-sizing: border-box;
  margin: 0;
  width: 100%;
  min-height: 100%;
  padding: 16px 18px;
  border: 0;
  color: transparent;
  background: transparent;
  font-size: 13.25px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
:root[data-editor-wrap="off"] .wb-gitdiff-mirror {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  width: max-content;
  min-width: 100%;
}
.wb-gitdiff-marks {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
}
.wb-gitdiff-mark {
  position: absolute;
  box-sizing: border-box;
  border-left: 4px solid transparent;
  pointer-events: none;
}
.wb-gitdiff-mark.is-added {
  border-left-color: var(--diff-add-ink);
  background: color-mix(in srgb, var(--diff-add-bg) 92%, transparent);
}
.wb-gitdiff-mark.is-deleted {
  border-left-color: var(--diff-delete-ink);
  width: 10px;
  padding: 0;
  color: transparent;
  background: repeating-linear-gradient(
    -45deg,
    var(--diff-delete-ink) 0 2px,
    var(--diff-delete-bg) 2px 4px
  );
  box-shadow: inset -1px 0 var(--diff-delete-ink);
  font-size: 0;
}
:root[data-editor-wrap="off"] .wb-gitdiff-mark.is-deleted {
  width: 10px;
}
.markdown-preview {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px clamp(16px, 4vw, 42px) var(--float-composer-pad, 100px);
  color: var(--ink);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.65;
}
.markdown-preview:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.html-preview {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}
.html-preview[hidden] { display: none !important; }
.html-preview:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.markdown-preview pre {
  margin: 12px 0;
  padding: 12px 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunk);
  white-space: pre;
}
.wb-composer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 3;
  pointer-events: none;
}
.wb-composer-box {
  position: relative;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: calc(var(--radius) + 4px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow: visible;
}
.wb-composer-knob {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 18px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
  touch-action: none;
}
.wb-composer-knob::before {
  content: "";
  position: absolute;
  inset: 2px 6px;
  border-radius: 999px;
  background: transparent;
  transition: background .12s ease;
}
.wb-composer-handle {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-2);
  box-shadow: inset 0 0 0 1px transparent;
  transition: background .12s ease, width .12s ease, height .12s ease;
  pointer-events: none;
}
.wb-composer-knob:hover::before,
.wb-composer-knob:focus-visible::before,
body[data-resizing-wb-chat="true"] .wb-composer-knob::before {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.wb-composer-knob:hover .wb-composer-handle,
.wb-composer-knob:focus-visible .wb-composer-handle,
body[data-resizing-wb-chat="true"] .wb-composer-handle {
  background: var(--accent);
}
body[data-resizing-wb-chat="true"] {
  cursor: ns-resize;
  user-select: none;
}
.wb-chat {
  min-height: 0;
  flex: 0 1 auto;
  max-height: var(--wb-chat-max, 220px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px) calc(var(--radius) + 4px) 0 0;
  display: grid;
  align-content: start;
  gap: 12px;
  scrollbar-width: thin;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}
.wb-composer-box[data-expanded="false"] .wb-chat {
  display: none;
}
.wb-chat .msg {
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
}
.wb-chat .msg:first-child { border-top: 0; }
.wb-chat .msg-role {
  font-size: 10.5px;
}
.wb-chat .msg-time {
  font-size: 10px;
}
.wb-chat .msg-body {
  font-size: 13.5px;
  line-height: 1.5;
}
.wb-chat .msg-user .msg-body {
  padding: 8px 12px;
}
.wb-chat .turn-context {
  margin-bottom: 4px;
  font-size: 11px;
}
.wb-chat .tool-row,
.wb-chat .thinking-row {
  font-size: 12px;
}
.wb-chat-picker {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  justify-items: stretch;
}
.wb-chat-picker-item {
  display: grid;
  gap: 1px;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.wb-chat-picker-item:hover,
.wb-chat-picker-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: none;
}
.wb-chat-picker-item[aria-current="true"] {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.wb-chat-picker-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wb-chat-picker-meta {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wb-chat-picker-item[data-working="true"] .wb-chat-picker-meta {
  color: var(--accent);
}
.wb-chat-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
  width: 100%;
  padding: 4px 0;
}
.wb-chat-settings[hidden] {
  display: none !important;
}
.wb-chat-settings .select {
  min-height: 32px;
  padding: 2px 24px 2px 8px;
  font-size: 13px;
  max-width: 100%;
}
.wb-composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto auto;
  align-items: end;
  gap: 8px;
  flex: none;
  padding: 10px 10px 10px 14px;
}
.wb-composer-box[data-picker="true"] .wb-composer-row {
  align-items: center;
}
.wb-composer-box[data-picker="true"] .wb-composer-input,
.wb-composer-box[data-picker="true"] .wb-search-meta {
  display: none !important;
}
.wb-composer-box[data-search="true"] .wb-composer-row {
  /* input + meta + search + keyboard + clear + prev + next */
  grid-template-columns: minmax(0, 1fr) auto auto auto auto auto auto;
  align-items: center;
}
.wb-composer-box[data-search="true"] .wb-chat-settings {
  display: none !important;
}
.wb-composer-input {
  position: relative;
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
}
.wb-composer-input[data-empty="true"]::before {
  /* Keep empty-caret at the start; see .composer-input placeholder. */
  content: attr(data-placeholder);
  position: absolute;
  inset: 8px 0 auto 0;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wb-composer-input:focus,
.wb-composer-input:focus-visible {
  outline: none;
}
.wb-search,
.wb-search-clear,
.wb-search-nav,
.wb-include-sel {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
  align-self: end;
  touch-action: manipulation;
}
.wb-composer-box[data-search="true"] .wb-search,
.wb-composer-box[data-search="true"] .wb-search-clear,
.wb-composer-box[data-search="true"] .wb-search-nav,
.wb-composer-box[data-search="true"] .keyboard {
  align-self: center;
}
.wb-search[aria-pressed="true"],
.wb-include-sel[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2));
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.wb-search-icon,
.wb-search-nav-icon,
.wb-include-sel-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.wb-search-meta {
  display: none;
  margin: 0;
  min-width: 4.5em;
  max-width: 9em;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
  user-select: none;
}
.wb-composer-box[data-search="true"] .wb-search-meta {
  display: block;
}
.wb-composer-box[data-search="true"] .wb-include-sel,
.wb-composer-box[data-search="true"] .mic,
.wb-composer-box[data-search="true"] .send {
  display: none;
}
.wb-composer-box:not([data-search="true"]) .wb-search-clear,
.wb-composer-box:not([data-search="true"]) .wb-search-nav,
.wb-composer-box:not([data-search="true"]) .wb-search-meta {
  display: none;
}
.wb-composer-box[data-search="true"] .wb-chat,
.wb-composer-box[data-search="true"] .wb-composer-knob {
  display: none;
}
.wb-composer-box[data-search="true"] .wb-composer-input {
  /* Single-line find field; Enter advances matches. */
  max-height: 2.8em;
  overflow: hidden;
}
.wb-sel-chip,
.composer-sel-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.28em;
  max-width: min(100%, 22em);
  height: auto;
  margin: 0 0.12em;
  padding: 0.12em 0.45em 0.12em 0.32em;
  vertical-align: text-bottom;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  cursor: pointer;
  user-select: none;
  font-size: 0.86em;
  line-height: 1.25;
}
.wb-sel-chip:focus-visible,
.composer-sel-chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.wb-sel-chip svg,
.composer-sel-chip svg {
  flex: none;
  width: 0.95em;
  height: 0.95em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.wb-sel-chip-text,
.composer-sel-chip .wb-sel-chip-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wb-composer-box:focus-within {
  border-color: var(--focus);
}
.wb-composer .mic,
.wb-composer .keyboard {
  position: static;
  top: auto;
  right: auto;
  z-index: auto;
  flex: none;
  align-self: end;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
}
.wb-composer .send {
  position: static;
  top: auto;
  right: auto;
  z-index: auto;
  flex: none;
  align-self: end;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
}

/* ---------- Status ---------- */

.status { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.status-body {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 18px 20px 28px;
  display: grid;
  gap: 18px;
}
.status-section {
  display: grid;
  gap: 8px;
}
.status-section h3 {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.status-card {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.status-row {
  display: grid;
  grid-template-columns: minmax(96px, 140px) minmax(0, 1fr);
  gap: 8px 14px;
  align-items: baseline;
  font-size: 13.5px;
}
.status-row dt, .status-term { color: var(--muted); }
.status-row dd, .status-value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.status-row .mono, .status-change .mono { font-family: var(--mono); font-size: 12.5px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: 12.5px;
}
.status-pill[data-tone="ok"] { color: var(--ok); }
.status-pill[data-tone="warn"] { color: var(--warn); }
.status-pill[data-tone="bad"] { color: var(--bad); }
.status-changes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: min(42vh, 360px);
  overflow: auto;
}
.status-change {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.status-change:first-child { border-top: 0; }
.status-change-code {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
.status-rail-list .list-item { cursor: default; }
.status-rail-list .list-item:hover { background: transparent; }
.status-rail-meta {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

/* ---------- Graph explorer ---------- */

.rail-graph {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.graph-search {
  width: 100%;
  font-size: 13px;
}
.graph-kind-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.graph-kind-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  cursor: pointer;
}
.graph-kind-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.graph-kind-chip .count {
  color: var(--muted);
  margin-left: 4px;
  font-family: var(--mono);
  font-size: 11px;
}
.rail-subhead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.graph-hit-list,
.graph-recent-list {
  min-height: 0;
  overflow: auto;
  flex: 1;
}
.graph-hit-list .list-item,
.graph-recent-list .list-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
}
.graph-hit-id {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}
.graph-hit-meta {
  color: var(--muted);
  font-size: 11px;
}

.panel.graph {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--rail);
  flex-wrap: wrap;
}
.graph-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  min-width: 0;
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
}
.graph-crumb {
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.graph-crumb[aria-current="page"] {
  color: var(--ink);
  cursor: default;
  font-weight: 600;
}
.graph-crumb-sep {
  color: var(--muted);
}
.graph-toolbar-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}
.graph-split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(240px, 0.9fr);
  min-height: 0;
  flex: 1;
}
.graph-map-wrap {
  position: relative;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--canvas);
  overflow: auto;
}
.graph-tree {
  min-height: 280px;
  padding: 14px 16px 28px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}
.graph-tree-row {
  display: flex;
  align-items: baseline;
  gap: 0;
  min-width: 0;
  white-space: nowrap;
}
.graph-tree-indent {
  flex: 0 0 auto;
  color: var(--line-2);
  white-space: pre;
  user-select: none;
}
.graph-tree-line {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 1px 4px;
  margin: 0;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.graph-tree-line:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.graph-tree-line[data-focus="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: default;
}
.graph-tree-line[data-kind="folder"] {
  color: var(--accent-ink);
  font-weight: 600;
}
.graph-tree-line[data-kind="folder"]::before {
  content: "▸ ";
  color: var(--muted);
  font-weight: 400;
}
.graph-tree-line[data-kind="folder"][data-open="true"]::before {
  content: "▾ ";
}
.graph-tree-edge {
  color: var(--muted);
}
.graph-tree-target {
  color: inherit;
}
.graph-tree-seen {
  color: var(--muted);
  font-weight: 400;
}
.graph-tree-prop {
  color: var(--muted);
  padding: 1px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.graph-tree-more {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 1px 4px;
  margin: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.graph-tree-more:hover {
  color: var(--accent-ink);
  text-decoration: underline;
}
.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.graph-map-wrap[data-has-focus="true"] .graph-empty { display: none; }
.graph-inspector {
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 24px;
  background: var(--surface);
}
.graph-inspector-empty {
  margin: 0;
  color: var(--muted);
}
.graph-inspector-body h3 {
  margin: 0 0 6px;
  font-size: 14px;
}
.graph-inspector-id {
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
  margin: 0 0 12px;
}
.graph-inspector-section {
  margin-top: 16px;
}
.graph-inspector-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.graph-prop,
.graph-assertion {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}
.graph-prop:first-of-type,
.graph-assertion:first-of-type { border-top: 0; }
.graph-prop-key,
.graph-assertion-rel {
  font-family: var(--mono);
  font-size: 12px;
}
.graph-prop-meta,
.graph-assertion-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.graph-prop-value {
  margin: 6px 0 0;
  padding: 8px;
  background: var(--sunk);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}
.graph-linkish {
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  text-align: left;
}

@media (max-width: 900px) {
  .graph-split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 45%) minmax(0, 1fr);
  }
  .graph-map-wrap { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  :root { --gutter: 62px; }
  .msg { gap: 16px; }
}

/* Single pane below the tablet threshold: rail, work, and settings swap. */
@media (max-width: 719px) {
  :root { --gutter: 0px; }
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .shell > .appbar {
    grid-column: 1;
    grid-row: 1;
  }
  .shell > .rail,
  .shell > .work,
  .shell > .settings-rail {
    grid-column: 1;
    grid-row: 2;
  }
  .rail-resizer { display: none; }
  .rail { border-right: 0; }
  .settings-rail { border-left: 0; }
  .shell[data-pane="nav"] .work,
  .shell[data-pane="nav"] .settings-rail { display: none; }
  .shell[data-pane="work"] .rail,
  .shell[data-pane="work"] .settings-rail { display: none; }
  .shell[data-pane="settings"] .rail,
  .shell[data-pane="settings"] .work { display: none; }
  .shell[data-pane="work"] .rail-edge-handle { display: grid; }
  .appbar {
    gap: 8px;
    padding: 0 8px 0 8px;
  }
  .appbar-leading {
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .appbar-leading .appbar-icon { display: none; }
  .shell[data-pane="work"] .appbar-dobby,
  .shell[data-pane="nav"] .appbar-dobby,
  .shell[data-pane="settings"] .appbar-dobby { display: grid; }
  .appbar-icon { width: 34px; height: 34px; }
  .messages { padding: 2px 14px var(--float-composer-pad, 132px); }
  .msg { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 14px 0; }
  .msg-aside {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
  }
  .msg-role { text-align: left; }
  .msg-time { text-align: left; }
  .context-row { grid-template-columns: minmax(0, 1fr) auto; }
  .context-src { grid-column: 1 / -1; }
  .composer { left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .composer-box { padding: 12px 12px 10px; }
  .composer-input { min-height: 40px; }
  .rail-files .file-list { padding-inline: 6px; }
  .file-branch {
    min-width: calc(100% - 14px);
    margin-left: 8px;
    padding-left: 5px;
  }
  .directory-row, .file-row { min-height: 42px; }
  .wb-composer { left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .editor { padding: 12px; }
  .wb-wish-mirror,
  .wb-selmatch-mirror,
  .wb-search-mirror { padding: 12px; }
  .markdown-preview { padding: 14px 14px var(--float-composer-pad, 100px); }
}

@media (pointer: coarse) {
  .btn, .mode { min-height: 40px; }
  .list-item, .file-row, .directory-row { min-height: 44px; padding: 10px; }
  .context-row { padding: 12px; }
  .rail-handle {
    width: 6px;
    height: 56px;
  }
  .rail-edge-handle {
    width: 34px;
    height: 88px;
    border-radius: 0 18px 18px 0;
  }
  .rail-edge-handle .rail-handle {
    width: 6px;
    height: 44px;
  }
}

@media (pointer: coarse) and (min-width: 720px) {
  .shell {
    grid-template-columns: var(--rail-width) 18px minmax(0, 1fr) var(--settings-rail-width);
  }
  .shell[data-sidebar="collapsed"] {
    grid-template-columns: 0 0 minmax(0, 1fr) var(--settings-rail-width);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- E-ink overrides ---------- */

:root[data-theme="eink"] .wb-sel-chip {
  border-color: #000;
  color: #000;
  background: #fff;
  font-weight: 700;
}
:root[data-theme="eink"] .wb-wish-layer {
  background: #fff;
  outline: 2px solid #000;
  outline-offset: -2px;
}
/* Marks-only overlay stays see-through so the selection does not hide the editor. */
:root[data-theme="eink"] .wb-doc[data-wish-select="marks"] .wb-wish-layer {
  background: transparent;
  outline: none;
}
:root[data-theme="eink"] .wb-doc[data-wish-select="marks"] .wb-wish-mirror {
  color: transparent;
}
:root[data-theme="eink"] .wb-doc[data-wish-select="marks"] .wb-wish-hint {
  display: none;
}
:root[data-theme="eink"] .wb-doc[data-wish-select="marks"] .wb-wish-mark {
  /* The textarea already paints its native selection. Avoid a white
     difference-blend rectangle floating above it in high-contrast mode. */
  display: none;
}
:root[data-theme="eink"] .wb-wish-mark,
:root[data-theme="eink"] .wb-search-mark,
:root[data-theme="eink"] .wb-selmatch-mark {
  /* Match ::selection (white on black) via difference over black ink. */
  background: #fff;
  opacity: 1;
  border-radius: 0;
  box-shadow: none;
  mix-blend-mode: difference;
  animation: none;
  filter: none;
}
:root[data-theme="eink"] .wb-selmatch-mark {
  /* Softer than find hits: outline-only reflection of other occurrences. */
  background: transparent;
  opacity: 1;
  box-shadow: inset 0 0 0 2px #000;
  mix-blend-mode: normal;
}
:root[data-theme="eink"] .wb-search-mark.is-current {
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-theme="eink"] .markdown-preview mark.wb-search-hit {
  color: #fff;
  background: #000;
  border-radius: 0;
  box-shadow: none;
}
:root[data-theme="eink"] .markdown-preview mark.wb-search-hit.is-current {
  color: #fff;
  background: #000;
  box-shadow: inset 0 0 0 2px #fff;
  outline: 2px solid #000;
  outline-offset: 1px;
}
:root[data-theme="eink"] .wb-wish-hint {
  border-color: #000;
  color: #000;
  background: #fff;
}
:root[data-theme="eink"] .wb-search,
:root[data-theme="eink"] .wb-search-clear,
:root[data-theme="eink"] .wb-search-nav,
:root[data-theme="eink"] .wb-include-sel {
  border-color: #000;
}
:root[data-theme="eink"] .wb-search[aria-pressed="true"],
:root[data-theme="eink"] .wb-include-sel[aria-pressed="true"] {
  border-color: #000;
  color: #000;
  background: #fff;
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-theme="eink"] .wb-search-meta {
  color: #000;
}
:root[data-theme="eink"] .turn-context-selection {
  color: #000;
  font-weight: 700;
}
:root[data-theme="eink"] ::selection,
:root[data-theme="eink"] .editor::selection,
:root[data-theme="eink"] .markdown-preview::selection,
:root[data-theme="eink"] textarea::selection {
  color: #fff;
  background: #000;
}
:root[data-theme="eink"] ::-moz-selection,
:root[data-theme="eink"] .editor::-moz-selection,
:root[data-theme="eink"] .markdown-preview::-moz-selection,
:root[data-theme="eink"] textarea::-moz-selection {
  color: #fff;
  background: #000;
}
:root[data-theme="eink"] .btn-quiet,
:root[data-theme="eink"] .input,
:root[data-theme="eink"] .select,
:root[data-theme="eink"] .composer-box,
:root[data-theme="eink"] .modes,
:root[data-theme="eink"] .model-fixed { border-color: #000; }
:root[data-theme="eink"] .composer-input { border: 0; }
:root[data-theme="eink"] .composer-box:focus-within { border-color: #000; }
:root[data-theme="eink"] .composer-box.is-recording,
:root[data-theme="eink"] .composer-box.is-transcribing,
:root[data-theme="eink"] .wb-composer-box.is-recording,
:root[data-theme="eink"] .wb-composer-box.is-transcribing,
:root[data-theme="eink"] .wb-doc.is-recording,
:root[data-theme="eink"] .wb-doc.is-transcribing {
  border-width: 2px;
  border-color: #000;
  animation: none;
  box-shadow: none;
}
:root[data-theme="eink"] .composer-box.is-recording::before,
:root[data-theme="eink"] .wb-composer-box.is-recording::before,
:root[data-theme="eink"] .wb-doc.is-recording::before {
  display: none;
}
:root[data-theme="eink"] .btn-primary { border-color: #000; color: #fff; background: #000; }
:root[data-theme="eink"] .btn-ghost { border-color: #000; }
:root[data-theme="eink"] .settings-rail,
:root[data-theme="eink"] .rail-edge-handle { border-color: #000; box-shadow: none; }
:root[data-theme="eink"] .appbar-icon,
:root[data-theme="eink"] .settings-close,
:root[data-theme="eink"] .appbar-actions .btn { color: #000; }
:root[data-theme="eink"] .rail-handle { background: #000; }
:root[data-theme="eink"] .appbar-actions .settings-toggle[aria-expanded="true"],
:root[data-theme="eink"] .appbar-workbench .wb-save:not(:disabled),
:root[data-theme="eink"] .appbar-workbench .wb-draw-tool[aria-pressed="true"],
:root[data-theme="eink"] .appbar-workbench .wb-preview-tool[aria-pressed="true"] {
  color: #000;
}
:root[data-theme="eink"] .btn-ghost:hover, :root[data-theme="eink"] .btn-quiet:hover,
:root[data-theme="eink"] .filter-chip:hover,
:root[data-theme="eink"] .list-item:hover, :root[data-theme="eink"] .context-row:hover,
:root[data-theme="eink"] .context-summary:hover,
:root[data-theme="eink"] .file-row:hover,
:root[data-theme="eink"] .directory-row:hover { background: #eee; }
:root[data-theme="eink"] .filter-chip { border-color: #000; }
:root[data-theme="eink"] .filter-chip[data-active="true"],
:root[data-theme="eink"] .filter-chip[aria-checked="true"] {
  border-color: #000;
  color: #fff;
  background: #000;
}
:root[data-theme="eink"] .settings-segment,
:root[data-theme="eink"] .settings-segment-option {
  border-color: #000;
}
:root[data-theme="eink"] .settings-segment-option[aria-checked="true"] {
  color: #000;
  background: #eee;
  box-shadow: inset 0 0 0 2px #000;
}
:root[data-theme="eink"] .sock-mark { color: #000; }
:root[data-theme="eink"] .mode-conn { color: #000; }
:root[data-theme="eink"] .list-item[aria-current="true"],
:root[data-theme="eink"] .file-row[aria-current="true"] { border-color: #000; color: #fff; background: #000; }
:root[data-theme="eink"] .list-item[aria-current="true"] .conversation-meta {
  color: #fff;
  border-color: #fff;
}
:root[data-theme="eink"] .list-item[aria-current="true"] .conversation-status[data-working="true"],
:root[data-theme="eink"] .conversation-status[data-working="true"] {
  background: currentColor;
}
:root[data-theme="eink"] .mode[aria-selected="true"] { color: #fff; background: #000; }
:root[data-theme="eink"] .msg-user .msg-body { border-left-width: 3px; background: #fff; }
:root[data-theme="eink"] .code-inline,
:root[data-theme="eink"] .msg-body pre,
:root[data-theme="eink"] .markdown-preview pre,
:root[data-theme="eink"] .editor[readonly] { border: 1px solid #000; background: #fff; }
:root[data-theme="eink"] .diff-view { border-color: #000; background: #fff; }
:root[data-theme="eink"] .diff-row { background: #fff; }
:root[data-theme="eink"] .diff-row-added { border-left-style: solid; border-left-color: #000; }
:root[data-theme="eink"] .diff-row-deleted { border-left-style: dashed; border-left-color: #000; }
:root[data-theme="eink"] .diff-row-added .diff-marker,
:root[data-theme="eink"] .diff-row-deleted .diff-marker { color: #000; font-weight: 800; }
:root[data-theme="eink"] .diff-row-hunk { border-color: #000; }
:root[data-theme="eink"] .diff-line-number { border-right-color: #000; }
:root[data-theme="eink"] .path-link,
:root[data-theme="eink"] .markdown-link { color: #000; text-decoration-thickness: 2px; }
:root[data-theme="eink"] .path-link:hover { background: #eee; }
:root[data-theme="eink"] .tool-state,
:root[data-theme="eink"] .run-state,
:root[data-theme="eink"] .wb-state { font-weight: 700; }
:root[data-theme="eink"] .msg { border-top-color: #000; }
:root[data-theme="eink"] .list-empty { border-style: solid; }
:root[data-theme="eink"] .select:disabled { color: #000; background: #fff; }
