/* Port Studio styles: calm, system fonts, light and dark themes from CSS variables. */
:root {
  --bg: #eaecf0; --surface: #ffffff; --text: #1d2330; --muted: #5d6677; --border: #d7dbe3;
  --accent: #2b59d9; --accent-text: #ffffff; --accent-soft: #e6edff; --ok: #187a41; --bad: #c8372d; --warn: #8a5200;
  --warn-bg: #fff4dd; --code-bg: #eef0f4; --focus: #7aa2ff; --rail-w: 220px; --next: #c2560c; --next-text: #ffffff;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300; --series-other: var(--muted);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --surface: #1d222b; --text: #e6e9ef; --muted: #98a1b2; --border: #323946;
    --accent: #6c93ff; --accent-text: #0b1020; --accent-soft: #22305c; --ok: #4cc27f; --bad: #ff7a70; --warn: #f0b34a;
    --warn-bg: #3a2f17; --code-bg: #272d38; --focus: #8fb0ff; --next: #ff9a4a; --next-text: #1a0f05;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
.topbar, .tabs, .view { max-width: 1000px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.view { padding-bottom: 48px; }
.view-title { margin-top: 18px; }
h1 { font-size: 1.25rem; margin: 0; }
/* Card titles and section headings stay larger than the 15px body text. */
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 20px 0 8px; }
h4 { font-size: .85rem; margin: 14px 0 6px; color: var(--muted); }
p { margin: 6px 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre { background: var(--code-bg); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.warn { background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 6px; }
.error-text { color: var(--bad); }
.apk-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.banner { background: var(--code-bg); padding: 10px 12px; border-radius: 6px; font-weight: 600; }
/* The questions-first warning before a Port direct run: warning colours, a thick edge and an icon. */
.ask-notice { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: start; margin: 12px 0; padding: 12px 14px; border: 1px solid var(--warn); border-left-width: 5px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 1rem; line-height: 1.4; }
.ask-notice::before { content: "?"; grid-row: span 2; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--warn); color: var(--warn-bg); font-weight: 700; font-size: 1.1rem; }
.ask-notice .ask-title { display: block; font-size: 1.05rem; text-transform: uppercase; letter-spacing: .03em; }
.ask-notice.live { animation: ask-pulse 1.2s ease-in-out 3; }
@keyframes ask-pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--warn) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .ask-notice.live { animation: none; } }
[hidden] { display: none !important; }

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

/* Scrollbars: a thin rounded thumb on a clear track, coloured from the theme so both modes match. */
:root { --scroll-thumb: color-mix(in srgb, var(--muted) 40%, transparent); --scroll-thumb-hover: color-mix(in srgb, var(--muted) 70%, transparent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
/* The transparent border insets the thumb from the edge without a wider bar. */
::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); background-clip: padding-box; border: 3px solid transparent; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}

/* rail */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.shell.rail-collapsed { --rail-w: 56px; }
.content { min-width: 0; min-height: 0; overflow-y: auto; }
.content:has(#projectView:not([hidden])) { display: flex; flex-direction: column; overflow: hidden; }
#projectView:not([hidden]) { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rail {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; padding: 10px 8px;
  background: var(--surface); border-right: 1px solid var(--border); overflow-x: hidden; overflow-y: auto; min-width: 0;
}
.rail-toggle, .rail-btn, .rail-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none; border-radius: 8px; min-height: 40px; padding: 4px 10px;
}
.rail-toggle { font-weight: 700; }
.rail-btn:hover:not(:disabled), .rail-item:hover { background: var(--code-bg); border-color: transparent; }
.rail-btn[aria-current=page], .rail-item[aria-current=page] { background: var(--code-bg); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.rail-icon { flex: none; width: 20px; text-align: center; }
.rail-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rail-heading { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 10px 2px; }
.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-entry { display: flex; align-items: center; gap: 2px; }
.rail-item { flex: 1; min-width: 0; cursor: pointer; font: inherit; color: var(--text); }
.rail-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rail-engine { font-size: .75rem; color: var(--muted); }
.rail-short { display: none; font-size: .8rem; font-weight: 600; }
.rail-close { flex: none; min-height: 32px; width: 32px; padding: 0; border: 0; background: none; color: var(--muted); }
.rail-divider { border: 0; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
.rail-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 6px 10px; }
.rail .badge { margin-left: 0; flex: none; background: var(--warn); }
.dot.run { background: var(--accent); }
.dot.wait { background: var(--warn); }
.dot.done { background: var(--ok); }
.dot.term { background: none; border: 2px solid var(--accent); }
.dot.queue { background: none; border: 2px dashed var(--next); }
.shell.rail-collapsed .rail-label, .shell.rail-collapsed .rail-heading, .shell.rail-collapsed .rail-name,
.shell.rail-collapsed .rail-close, .shell.rail-collapsed .rail-engine, .shell.rail-collapsed .rail-footer .ghost { display: none; }
.shell.rail-collapsed .rail-short { display: inline; }
.shell.rail-collapsed .rail-item { justify-content: center; padding: 4px; gap: 4px; }
.shell.rail-collapsed .rail-item .badge { display: none; }
.shell.rail-collapsed .rail-footer { align-items: center; padding: 6px 0; }
@media (max-width: 760px) {
  :root { --rail-w: 56px; }
  .rail-label, .rail-heading, .rail-name, .rail-close, .rail-footer .ghost { display: none; }
  .rail-short { display: inline; }
  .rail-item { justify-content: center; padding: 4px; gap: 4px; }
  .rail-item .badge { display: none; }
  .rail-footer { align-items: center; padding: 6px 0; }
  .rail-toggle { display: none; }
}

/* header */
.topbar { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-top: 14px; padding-bottom: 8px; }
.topbar-main { flex: 1 1 200px; min-width: 0; }
.topbar-main p { margin: 0; overflow-wrap: anywhere; }
.topbar-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.conn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.dots { display: inline-flex; gap: 4px; margin-right: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.unknown { background: var(--muted); opacity: .6; }
.popover {
  position: absolute; z-index: 20; top: 100%; left: 16px; right: 16px; max-width: 520px; margin-left: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.popover ul { list-style: none; margin: 0 0 10px; padding: 0; }
.popover li { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.popover li .dot { margin-top: 6px; }
.fix { display: block; color: var(--warn); font-size: .85rem; }

/* sub-tabs (the key form's Paste / All fields switch) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; padding-top: 4px; padding-bottom: 0; }
.tabs [role=tab] {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted);
  min-height: 44px; padding: 0 14px; font-weight: 600; cursor: pointer; flex: none;
}
.tabs [role=tab][aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; margin-left: 4px; }

/* controls */
button, select, input[type=text], input[type=password], input[type=number], textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; min-height: 40px; padding: 6px 12px; max-width: 100%;
}
button { cursor: pointer; }
a.button { display: inline-flex; align-items: center; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 8px; min-height: 40px; background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled, select:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.ghost { background: none; }
button.small { min-height: 40px; padding: 4px 10px; font-size: .85rem; }
button.big { width: 100%; min-height: 48px; font-size: 1.05rem; }
textarea { width: 100%; resize: vertical; }
input[type=text], input[type=password] { width: 100%; }
input[type=number] { width: 8em; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; font-size: .85rem; padding: 0; }
.help { margin: -6px 0 10px; font-size: .85rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: 20px; height: 20px; flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: 0 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin: 14px 0; }
.chip { display: inline-block; background: var(--code-bg); border-radius: 10px; padding: 0 8px; font-size: .75rem; margin-right: 4px; }
.pill { display: inline-block; border-radius: 10px; padding: 0 9px; font-size: .78rem; font-weight: 600; background: var(--code-bg); }
.pill.running, .pill.st-in-progress { background: #dbe7ff; color: #1b3f9e; }
.pill.idle, .pill.st-pending { background: var(--code-bg); }
.pill.ended, .pill.completed, .pill.st-done { background: #d6f2e1; color: #176b3a; }
.pill.starting { background: #dbe7ff; color: #1b3f9e; }
.pill.error { background: #fbdcd9; color: #9b2a21; }
.pill.st-needs-sync, .pill.st-check-pending { background: var(--warn-bg); color: var(--warn); }
.pill.st-skipped, .pill.st-optional, .pill.terminal { background: var(--code-bg); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .pill.running, .pill.st-in-progress { background: #22305c; color: #b6caff; }
  .pill.ended, .pill.completed, .pill.st-done { background: #1b3a29; color: #8fe0b0; }
  .pill.starting { background: #22305c; color: #b6caff; }
  .pill.error { background: #4a2420; color: #ffb4ad; }
}

/* start */
.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 16px; text-align: center; }
.dropzone.over { border-color: var(--accent); background: var(--code-bg); }
.dropzone .actions { justify-content: center; }
.drop-list { display: flex; flex-direction: column; gap: 10px; }
/* A drop is a tinted well, so its file buttons are the only bordered boxes inside the card. */
.drop { background: var(--code-bg); border-radius: 8px; padding: 10px; }
.drop-title { overflow-wrap: anywhere; margin-bottom: 4px; }
.pick {
  display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left; margin-top: 4px; overflow-wrap: anywhere;
  font-family: ui-monospace, Menlo, monospace; font-size: .85rem;
}
.pick:disabled { opacity: 0.55; cursor: not-allowed; }
/* Only selectable picks get a radio mark; picks that copy a drop have no aria-pressed. */
.pick[aria-pressed]::before {
  content: ""; flex: none; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--muted);
}
.pick.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); font-weight: 600; }
.pick.selected::before { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
.preview { white-space: pre-wrap; overflow-wrap: anywhere; }

/* sync */
.chip.newer { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
#syncRef .table-wrap { margin-top: 8px; }

/* project picker and new project */
.project-list li { display: block; padding: 2px 0; }
.project-item { display: block; width: 100%; text-align: left; overflow-wrap: anywhere; }
.project-item[aria-current=true] { border-color: var(--accent); }
.project-item .muted { display: block; font-size: .8rem; }
.summary { margin: 10px 0; overflow-wrap: anywhere; }
.field > label { font-weight: 600; font-size: .85rem; }
.inline-row { display: flex; gap: 8px; align-items: stretch; }
.inline-row input { flex: 1; min-width: 0; }
.inline-row button { flex: none; }
.np-default { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 6px; font-size: .85rem; }
.np-default .muted { flex: 1 1 100%; overflow-wrap: anywhere; }

.np-gitlab-list { max-height: 240px; overflow-y: auto; margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
/* Cards keep their full height; the list scrolls instead of squeezing them. */
.np-gitlab-list > * { flex: none; }
.np-gitlab-list .project-item { padding: 8px 12px; line-height: 1.35; }
.np-gitlab-list .project-item strong { display: block; }
.np-gitlab-list .project-item[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.np-gitlab-error { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 6px; }
.np-gitlab-error p { flex: 1 1 200px; margin: 0; overflow-wrap: anywhere; }
.summary button.danger { margin-top: 6px; }
body[data-mode="simple"] .np-source { order: -1; }

/* folder browser */
.folder-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text); padding: 14px; }
.folder-dialog::backdrop { background: rgb(0 0 0 / .45); }
.fb-bar { display: flex; gap: 8px; align-items: center; margin: 10px 0; min-width: 0; }
.fb-bar code { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.folder-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.folder-list li { border-bottom: 1px solid var(--border); }
.folder-list li:last-child { border-bottom: 0; }
.folder-list li.muted { padding: 10px; }
.folder-item { display: block; width: 100%; min-height: 40px; text-align: left; border: 0; border-radius: 0; background: none; overflow-wrap: anywhere; }
.folder-item::before { content: "📁 "; }
.folder-item:hover { background: var(--code-bg); }
.summary ul { margin: 6px 0; padding-left: 20px; }
.summary p { margin: 4px 0; }

/* run */
.wslog { display: block; }
.statusline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.statusline .session { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.statusline .elapsed { color: var(--muted); }
/* The blue left bar marks only cards that wait for the user's answer. */
.request { border-left: 4px solid var(--accent); }
.request header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.request header h3 { margin: 0; }
.request.sent { opacity: .7; }
.question { border: 1px solid var(--border); border-radius: 8px; margin: 10px 0; padding: 8px 10px; min-width: 0; }
.question legend { font-weight: 600; padding: 0 4px; }
.question input.other, .question input.notes { margin-top: 6px; }
.option { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; min-height: 40px; cursor: pointer; }
.option input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.option-label { display: block; font-weight: 600; }
.option-desc { display: block; color: var(--muted); font-size: .85rem; }
.plan-view { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px; margin: 8px 0; }
.plan-edit { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.edit-mode { display: none; }
.request.editing .edit-mode { display: block; }
.request.editing .view-mode { display: none; }
.md h3, .md h4, .md h5, .md h6 { margin: 12px 0 4px; }
.md ul, .md ol { padding-left: 22px; margin: 6px 0; }
.log-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.log-head h2 { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { border-radius: 20px; }
.chip-btn[aria-pressed=true] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.log {
  height: 380px; overflow: auto; margin: 10px 0; padding: 8px; background: var(--code-bg); border-radius: 8px;
  font-family: ui-monospace, Menlo, monospace; font-size: .8rem;
}
.logline { display: flex; gap: 8px; padding: 1px 0; }
.logline .ts { color: var(--muted); flex: none; }
.logline .txt { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.logline.tool .txt { color: var(--muted); }
.logline.agent .txt { color: var(--accent); }
.logline.error .txt { color: var(--bad); }
.logline.result .txt { color: var(--ok); }
.logline.user .txt { font-weight: 700; }
.logline.system .txt { font-style: italic; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td code { font-size: .75rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 0; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.2rem; font-weight: 600; }

/* Run Stats wheels: a donut with the sum in its centre and a legend beside it. */
.wheel-block { margin-top: 14px; }
.wheel-block > h4 { margin: 0 0 8px; }
.wheel { display: flex; align-items: center; gap: 14px; }
.wheel-chart { position: relative; flex: none; width: 96px; height: 96px; }
.wheel-ring { display: block; width: 100%; height: 100%; }
.wheel-ring circle { fill: none; stroke-width: 6; }
.wheel-track { stroke: var(--code-bg); }
.wheel-slice { cursor: default; transition: opacity .15s; }
.wheel.hot .wheel-slice:not(.on) { opacity: .35; }
.wheel-sum { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: .9rem; pointer-events: none; }
.wheel-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wheel-key {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 28px;
  padding: 2px 6px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; font-size: .8rem; text-align: left;
}
.wheel-key:hover, .wheel-key:focus-visible { background: var(--code-bg); }
.wheel-swatch { width: 10px; height: 10px; border-radius: 3px; }
.wheel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wheel-val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.usage-tip {
  position: fixed; z-index: 60; max-width: 260px; padding: 8px 10px; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18); font-size: .8rem; line-height: 1.4;
}
.tip-value { display: block; font-size: 1rem; }
.tip-name { overflow-wrap: anywhere; }
.tip-kinds { display: grid; grid-template-columns: auto auto; gap: 0 12px; margin: 6px 0 0; }
.tip-kinds div { display: contents; }
.tip-kinds dt { color: var(--muted); }
.tip-kinds dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .wheel-slice { transition: none; } }

/* history */
/* Status sits in a fixed first column so failed runs line up down the list. */
.history-row summary { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 4px 12px; align-items: start; cursor: pointer; min-height: 40px; }
.history-row summary > .pill { justify-self: start; white-space: nowrap; margin-top: 2px; }
.history-row .h-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-row .h-line { display: flex; flex-wrap: wrap; gap: 0 12px; }
.history-row .h-project { font-weight: 600; }
.history-row .h-main code { align-self: flex-start; overflow-wrap: anywhere; }
.history-row .h-meta { font-size: .85rem; }
@media (max-width: 480px) {
  .history-row summary { grid-template-columns: minmax(0, 1fr); }
}
.history-detail { margin-top: 10px; }

/* toasts */
.toasts { position: fixed; z-index: 50; left: 16px; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; max-width: 560px; padding: 10px 14px; border-radius: 8px; background: var(--bad); color: #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
.toast.ok { background: var(--ok); }

@media (max-width: 480px) {
  .log { height: 300px; }
  .request .actions button { flex: 1 1 100%; }
}

/* ---------- orchestrator view ---------- */
.copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.copy-row code { flex: 1 1 260px; min-width: 0; white-space: pre-wrap; padding: 6px 8px; }
.orch-details summary { cursor: pointer; margin-top: 10px; }
.orch-list { margin: 6px 0; padding-left: 18px; }
.orch-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 40px; }
.orch-toggle input { width: 20px; height: 20px; flex: none; }
.orch-addr { margin-top: 10px; }
.orch-label { display: block; margin: 12px 0 4px; }

/* sdk */
.sdk-group { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.sdk-group:first-child { border-top: 0; margin-top: 0; }
.sdk-group h3 { margin: 0 0 4px; }
/* Short fields sit two to a row on wide screens; optional ones fold into .sdk-more. */
.sdk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(max(260px, calc(50% - 8px)), 1fr)); gap: 0 16px; }
.sdk-more > summary { cursor: pointer; min-height: 32px; display: list-item; color: var(--muted); font-size: .85rem; font-weight: 600; }
/* A box: a title row on top, its fields under a rule inside the same border. */
.sdk-boxes { display: flex; flex-direction: column; gap: 8px; }
.sdk-box { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.sdk-box-head { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; background: var(--code-bg); }
label.sdk-box-head { cursor: pointer; background: none; }
/* Blue marks only a provider that is switched on; settings boxes keep the grey head. */
.sdk-box:has(> .sdk-box-head input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sdk-box:has(> .sdk-box-head input:checked) > .sdk-box-head { background: var(--accent-soft); }
.sdk-box > .sdk-fields { border-top: 1px solid var(--border); padding: 2px 12px 8px; }
.sdk-group h4 { margin: 8px 0 4px; font-size: .9rem; }
/* Where a value comes from, and a soft warning when it has the wrong shape; both show in every view. */
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.check .hint { display: inline; margin: 0 0 0 6px; }
.check-warn { display: block; color: var(--warn); font-size: .8rem; margin-top: 2px; }
.check-warn[hidden] { display: none; }
/* A field Claude just filled from pasted text, until the form is redrawn. */
.filled input { border-color: var(--accent); background: var(--accent-soft); }
.sub-tabs { margin-bottom: 8px; }
.sub-tabs [role=tab] { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.sdk-paste textarea { width: 100%; }
.ok-line { color: var(--ok); font-weight: 600; }
.field input[type=file] { font: inherit; max-width: 100%; }
/* On the Convert tab the whole form hangs under the "Add ads and analytics" switch. */
#sdkFormStart { margin: 4px 0 0 10px; padding-left: 16px; border-left: 2px solid var(--border); }
.secret-row { display: flex; gap: 8px; }
.secret-row input { flex: 1; min-width: 0; }
.sdk-steps { list-style: none; margin: 8px 0 0; padding: 0; }
.sdk-steps li { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; overflow-wrap: anywhere; }
.mark { flex: none; width: 1.2em; text-align: center; font-weight: 700; }
.mark.ok { color: var(--ok); } .mark.bad { color: var(--bad); } .mark.unknown { color: var(--warn); }
.check input.switch {
  appearance: none; -webkit-appearance: none; position: relative; width: 40px; height: 22px; flex: none;
  border-radius: 11px; background: var(--border); border: 0; cursor: pointer; transition: background .15s;
}
.check input.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); transition: transform .15s;
}
.check input.switch:checked { background: var(--accent); }
.check input.switch:checked::after { transform: translateX(18px); }
.check input.switch:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- language toggle and glossary ---------- */
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.lang-btn { min-height: 32px; padding: 2px 10px; border: 0; border-radius: 0; background: none; font-size: .8rem; font-weight: 600; color: var(--muted); }
.lang-btn[aria-pressed=true] { background: var(--accent); color: var(--accent-text); }
.rail-link { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; padding: 4px 0; min-height: 32px; color: var(--muted); }
.rail-link .rail-label { white-space: normal; }
.shell.rail-collapsed .lang-btn { padding: 2px 4px; font-size: .7rem; }
@media (max-width: 760px) {
  .lang-btn { padding: 2px 4px; font-size: .7rem; }
}
.glossary-dialog { width: min(640px, calc(100vw - 32px)); overflow-y: auto; }
.glossary { margin: 8px 0; }
.glossary dt { font-weight: 700; margin-top: 10px; }
.glossary dd { margin: 2px 0 0; color: var(--muted); }

/* ---------- guided Convert form ---------- */
.step-num {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-right: 8px;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: .8rem; vertical-align: 1px;
}
.step-help { margin: -4px 0 10px; font-size: .85rem; }
.help-after { margin: 6px 0 0; font-size: .85rem; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 32px; text-decoration: underline; }
.link-text { color: var(--accent); text-decoration: underline; }
.selected-drop { font-weight: 600; overflow-wrap: anywhere; margin: 10px 0 0; }
.selected-drop.none { font-weight: 400; color: var(--muted); }
.dropzone.compact { padding: 10px; }
.dropzone.compact p { margin: 0 0 4px; }

.choices { display: grid; gap: 8px; }
.choices.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choice {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; background: var(--surface);
}
.choice:hover { border-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--code-bg); }
.choice:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.choice input { width: 18px; height: 18px; margin-top: 3px; flex: none; }
.choice-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice-title { font-weight: 600; }
.choice-desc { color: var(--muted); font-size: .85rem; }
.choice code { font-size: .75rem; align-self: flex-start; }
.chip.recommended { background: var(--accent); color: var(--accent-text); font-weight: 600; margin-left: 6px; }

details.parts > summary, details.panel-details > summary { cursor: pointer; min-height: 32px; display: list-item; }
details.parts > summary { font-weight: 600; }
details.panel-details > summary { font-weight: 600; }
details.panel-details[open] > summary { margin-bottom: 8px; }
.parts-list { flex-direction: column; gap: 0; }
.parts-list .check { align-items: flex-start; padding: 2px 0; }
.parts-list .check input { margin-top: 3px; }
.part-name { font-weight: 600; }
.part-desc { display: block; color: var(--muted); font-size: .8rem; }
.parts-list code { font-size: .75rem; margin-left: 6px; }
.sdk-block { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 6px; }

.continue-banner {
  background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: 12px 14px; margin: 14px 0;
}
.continue-banner p:first-child { font-weight: 600; margin-top: 0; }

.start-bar {
  position: sticky; bottom: 0; z-index: 5; margin: 14px 0 0; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
}
.start-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.start-text { flex: 1 1 260px; min-width: 0; }
.start-text p { margin: 2px 0; overflow-wrap: anywhere; }
.start-summary { font-weight: 600; }
.start-btn { min-height: 48px; min-width: 140px; font-size: 1.05rem; }
@media (max-width: 480px) {
  .start-btn { flex: 1 1 100%; }
}

/* ---------- new project ---------- */
.field-label { font-weight: 600; font-size: .85rem; }
.np-html { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; font-weight: 600; overflow-wrap: anywhere; }
.np-html span { flex: 1 1 200px; min-width: 0; }
#npResult details { margin-top: 8px; }

/* ---------- Convert wizard ---------- */
.stepper {
  display: flex; gap: 4px; list-style: none; margin: 14px 0 0; padding: 0 0 4px; overflow-x: auto;
  counter-reset: none;
}
.stepper li { flex: 1 0 auto; display: flex; }
.step-btn {
  flex: 1; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 10px; border-radius: 8px;
  background: var(--surface); color: var(--muted); font-size: .85rem; white-space: nowrap; text-align: left;
}
.step-dot {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex: none;
  border-radius: 50%; border: 2px solid var(--border); font-size: .75rem; font-weight: 700;
}
.step-btn.done { color: var(--text); }
.step-btn.done .step-dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step-btn[aria-current=step] { color: var(--text); font-weight: 700; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.step-btn[aria-current=step] .step-dot { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.step-btn.skipped { opacity: .45; text-decoration: line-through; }
.step-btn.skipped .step-dot { border-style: dashed; }
.step-btn:disabled { cursor: not-allowed; }
.step-nav .start-row { flex-wrap: nowrap; }
.step-nav .start-text { margin: 0; text-align: center; }
@media (max-width: 600px) {
  .step-label { display: none; }
  .step-btn[aria-current=step] .step-label { display: inline; }
  .step-nav .start-row { flex-wrap: wrap; }
  .step-nav .start-text { flex-basis: 100%; order: -1; }
}
.review-list { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr) auto; gap: 6px 14px; margin: 4px 0 12px; align-items: baseline; }
.review-list dt { font-weight: 600; color: var(--muted); font-size: .85rem; }
.review-list dd { margin: 0; overflow-wrap: anywhere; }
.review-list .link-btn { min-height: 28px; padding: 0; }
@media (max-width: 480px) {
  .review-list { grid-template-columns: minmax(0, 1fr) auto; }
  .review-list dt { grid-column: 1 / -1; margin-top: 6px; }
}
.preview-details { margin: 8px 0; }
.preview-details > summary { cursor: pointer; color: var(--muted); font-size: .85rem; min-height: 32px; display: list-item; }
#reviewCard .start-row { margin-top: 12px; }

/* ---------- collapsible cards ---------- */
/* The heading keeps its place; a .card-head button inside it toggles the card. */
.card-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 0; min-height: 32px; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer; border-radius: 6px;
}
/* The caret sits before the title, so it reads as part of it and not of buttons on the right. */
.card-head::before { content: "▾"; font-size: 1.1em; line-height: 1; transition: transform .15s; flex: none; }
.card.collapsed .card-head::before { transform: rotate(-90deg); }
.log-head > h2:has(> .card-head), .request header > h3:has(> .card-head) { flex: 1 1 auto; min-width: 0; }
.request header > h3 .card-head { width: auto; }
/* Folded: only the heading row stays. */
.card.collapsed > :not(:has(.card-head)) { display: none !important; }
.card.request.collapsed > header ~ * { display: none !important; }
.card.collapsed > h2:has(> .card-head) { margin-bottom: 0; }

/* ---------- banners ---------- */
.server-stale { width: calc(100% - 32px); max-width: 968px; margin: 10px auto 0; }

/* ---------- dialogs keep the page still ---------- */
html:has(dialog[open]) { overflow: hidden; }
.folder-dialog { overscroll-behavior: contain; }

/* ---------- other devices ---------- */
.rail-device { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: .85rem; }
.rail-device-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.rail-device-actions button { min-height: 32px; padding: 2px 8px; }
.rail-owner { flex: none; max-width: 7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 0; }
.shell.rail-collapsed .rail-owner { display: none; }
@media (max-width: 760px) {
  .rail-owner { display: none; }
}
.history-device { max-width: 260px; }
/* The loading mark shown until the page knows whether to show the app or Join. */
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.boot-mark { color: var(--muted); font-size: 1.1rem; font-weight: 600; letter-spacing: .02em; animation: boot-pulse 1.5s ease-in-out infinite; }
@keyframes boot-pulse { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .boot-mark { animation: none; } }
.join { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.join-card { width: min(420px, 100%); }
/* ---------- Sign in with M1 button (from the M1 integration guide) ---------- */
.m1-signin {
  --m1-h: 44px;
  display: inline-flex; align-items: center; gap: 10px;
  height: var(--m1-h); padding: 0 18px 0 12px;
  border-radius: 10px; border: 1px solid transparent;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .13s ease, border-color .13s ease;
}
.m1-signin svg { width: calc(var(--m1-h) * .5); height: calc(var(--m1-h) * .5);
                 flex: none; display: block; }
.m1-signin:active        { transform: translateY(1px); }
.m1-signin:focus-visible { outline: 3px solid #6E7CFF; outline-offset: 2px; }
.m1-signin.dark        { background: #12151F; color: #FFF; border-color: #12151F; }
.m1-signin.dark:hover  { background: #1D2233; }
.m1-signin.light       { background: #FFF; color: #12151F; border-color: #D5DAE5; }
.m1-signin.light:hover { background: #F4F6FA; border-color: #B9C1D2; }
@media (prefers-reduced-motion: reduce) { .m1-signin { transition: none; } }
.clip-helper { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------- simple mode ---------- */
/* Help text and code tokens are for developers; the simple view leaves them out. */
body[data-mode="simple"] .verbose,
body[data-mode="simple"] .drawer .step-help,
body[data-mode="simple"] .drawer .help,
body[data-mode="simple"] .drawer .help-after,
body[data-mode="simple"] .working-row { display: none !important; }
/* In the simple view the primary button is the next step, so it is orange. */
body[data-mode="simple"] button.primary,
body[data-mode="simple"] a.button { background: var(--next); border-color: var(--next); color: var(--next-text); }
body[data-mode="simple"] button.primary:hover:not(:disabled) { border-color: var(--text); }

/* ---------- progress ---------- */
/* Waiting questions in other projects, shown above every screen. */
.ask-alert { position: sticky; top: 0; z-index: 40; width: calc(100% - 32px); max-width: 1000px; margin: 8px auto; box-sizing: border-box; }
.ask-alert-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.chips .small { border-radius: 20px; }

/* ---------- new project ---------- */
.np-form { display: flex; flex-direction: column; }
body[data-mode="simple"] .np-htmlfield { order: -3; }
body[data-mode="simple"] .np-engine { order: -2; }
body[data-mode="simple"] .np-godot { order: -1; }

/* local mode */
.local-claude { border-color: var(--accent); background: var(--accent-soft); }
.local-claude .copy-row { margin: 4px 0 8px; }
.local-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.local-tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 14px; font-weight: 600; }
.local-tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.local-stages { display: flex; flex-direction: column; gap: 10px; }
.local-stage { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.local-stage h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 1rem; }
.local-stage-mark { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); font-size: .8rem; flex: none; }
.local-stage.current { border-color: var(--accent); }
.local-stage.current .local-stage-mark { border-color: var(--accent); color: var(--accent); }
.local-stage.done .local-stage-mark { border-color: var(--ok); color: var(--ok); }
.local-stage.failed .local-stage-mark { border-color: var(--bad); color: var(--bad); }
.local-stage.locked { opacity: .6; }
.local-stage.locked h3, .local-stage.done h3 { margin-bottom: 2px; }
.local-ok { color: var(--ok); font-weight: 600; }
.local-steps { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.local-step { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); }
.local-step.running { color: var(--text); font-weight: 600; }
.local-step.done, .local-step.skipped { color: var(--ok); }
.local-step.failed { color: var(--bad); }
.local-mark { flex: none; width: 20px; text-align: center; }
.local-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 400; }
.local-bar progress, .local-brief progress { width: 160px; max-width: 100%; }
.local-brief { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .8rem; }
.local-run { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: 8px 0; }
.local-run .copy-row { align-self: stretch; }
a.button[aria-disabled=true] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.chip.ok { background: var(--accent-soft); color: var(--ok); font-weight: 600; }
.chip.bad { background: var(--warn-bg); color: var(--bad); font-weight: 600; }
.local-group h4 { margin: 12px 0 4px; }
.local-check.soft { color: var(--warn); }
.local-check.failed .fix { color: var(--bad); }
.local-detail { display: block; }
.local-folded { margin: 8px 0; }
.local-folded summary { cursor: pointer; font-weight: 600; }
.rail-upstream { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; }
.shell.rail-collapsed .rail-upstream { display: none; }

/* ---------- chat shell ---------- */
#projectView > .topbar { max-width: none; width: 100%; margin: 0; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
#projectView > .topbar h1 { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; }
.topbar-main p { font-size: .85rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; padding: 0; flex: none; }
#projectView > .server-stale { margin: 8px 20px 0; width: auto; max-width: none; }
.workarea { flex: 1; min-height: 0; display: flex; }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.chat.over::after { content: ""; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--accent) 8%, transparent); pointer-events: none; }
.thread-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; }
.thread-inner { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; min-height: 100%; }
.thread { display: flex; flex-direction: column; gap: 14px; }
.hero { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.hero h2 { margin: 0; font-size: 1.75rem; font-weight: 650; }
.hero p { margin: 0; }
.hero-drop { width: 100%; padding: 28px; background: var(--surface); border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); }
.hero-drop p { color: var(--text); font-weight: 600; }
.hero-drop .muted { font-weight: 400; }
.hero-chips { justify-content: center; gap: 8px; }
.chip-pill { border-radius: 999px; }

/* ---------- thread entries ---------- */
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 90%; min-width: 0; }
.msg-who { font-size: .8rem; color: var(--muted); font-weight: 600; }
.msg .md > :first-child { margin-top: 0; }
.msg .md p { margin: 0 0 8px; overflow-wrap: anywhere; }
.msg .md pre { max-width: 100%; }
.msg.you { align-self: flex-end; align-items: flex-end; max-width: 80%; }
.you-bubble { background: var(--accent-soft); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.att-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.att { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px 6px 8px; position: relative; max-width: 100%; }
.att-thumb { width: 44px; height: 44px; border-radius: 6px; background: var(--code-bg); display: grid; place-items: center; color: var(--muted); overflow: hidden; flex: none; font-size: 1.2rem; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.att-text strong { font-size: .875rem; overflow-wrap: anywhere; }
.att-text span { font-size: .75rem; color: var(--muted); overflow-wrap: anywhere; }
.att.bad { border-color: var(--bad); }
.att-remove { position: absolute; top: 2px; right: 2px; min-height: 24px; width: 24px; padding: 0; border: 0; background: none; color: var(--muted); }
.att.removable { padding-right: 30px; }
.sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; text-align: center; }
.sep::before, .sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.sep.ok { color: var(--ok); font-weight: 600; }
.sep.bad { color: var(--bad); font-weight: 600; }
.run-end { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.run-end .apk-box { justify-content: center; margin: 0; }
.thread-note { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.thread-note.bad { color: var(--bad); }
.working-row { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; background: none; border-style: dashed; color: var(--muted); font-size: .875rem; }
.working-row[aria-expanded=true] { border-style: solid; }
.working-caret { display: inline-block; transition: transform .15s; }
.working-row[aria-expanded=true] .working-caret { transform: rotate(90deg); }
.working-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: ask-pulse 1.2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .working-dot { animation: none; } }
.working-box { align-self: flex-start; max-width: 100%; display: flex; flex-direction: column; gap: 6px; }
.working-lines { align-self: stretch; max-height: 260px; overflow: auto; background: var(--code-bg); border-radius: 8px; padding: 8px; font-family: ui-monospace, Menlo, monospace; font-size: .8rem; }
.thinking { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); }
.thread .request { border-color: var(--warn); border-left-width: 5px; border-radius: 12px; margin: 0; padding: 16px 18px; }
.thread .request .option:has(input:checked) { background: var(--accent-soft); border-radius: 8px; }
.action-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.action-card.used { opacity: .75; }
.action-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.action-head h3 { margin: 0; font-size: 1.05rem; flex: 1; }
.action-rows { margin: 0; display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); gap: 6px 16px; }
.action-rows dt { color: var(--muted); font-size: .85rem; padding-top: 1px; }
.action-rows dd { margin: 0; overflow-wrap: anywhere; }
.action-quote { margin: 0; padding: 8px 12px; border-left: 3px solid var(--border); color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.action-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.action-foot .muted { font-size: .85rem; }
button.next, body[data-mode="simple"] button.next { background: var(--next); color: var(--next-text); border-color: var(--next); font-weight: 600; }

/* ---------- composer ---------- */
.composer-wrap { padding: 0 20px 14px; }
.composer, .composer-hint { max-width: 760px; margin-left: auto; margin-right: auto; }
.composer { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.composer.over, .composer:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; resize: none; background: transparent; padding: 4px 2px; min-height: 0; max-height: 220px; outline: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer-bar .spacer { flex: 1; }
.composer-bar button { min-height: 36px; }
.composer-bar .icon-btn { width: 36px; }
.composer-bar .round { width: 36px; border-radius: 50%; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.composer-bar .model-chip { color: var(--muted); font-size: .8rem; border-color: transparent; }
.composer-bar .pill-run { font-size: .8rem; padding: 4px 10px; }
.composer-bar #modeBtn { display: inline-flex; align-items: center; gap: 6px; }
.composer-bar #modeBtn.set { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: .875rem; color: var(--muted); }
.composer-hint { font-size: .85rem; margin-top: 6px; margin-bottom: 0; min-height: 1.4em; }
.menu-anchor { position: relative; display: inline-flex; }
.menu { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 30; width: 290px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.menu.menu-up-right { left: auto; right: 0; width: 220px; }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; min-height: 40px; padding: 4px 10px; }
.menu button:hover:not(:disabled) { background: var(--code-bg); }
.menu button[aria-checked=true] { background: var(--accent-soft); font-weight: 600; }
.menu button[aria-checked=true]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.menu-text { display: flex; flex-direction: column; text-align: left; }
.menu-sub { font-size: .75rem; color: var(--muted); font-weight: 400; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-row .att { background: none; }
.att-progress { font-size: .75rem; color: var(--muted); }

/* ---------- side bar ---------- */
.sidebar { flex: 0 0 340px; width: 340px; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); min-height: 0; }
.sidebar.folded { flex-basis: 56px; width: 56px; }
.side-head { display: flex; align-items: center; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); }
.side-head strong { flex: 1; }
.side-body { flex: 1; min-height: 0; overflow-y: auto; }
.side-sec.card { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; margin: 0; padding: 14px 16px; }
.side-sec.card[hidden] { display: none; }
.side-sec > h2 { margin: 0 0 8px; font-size: .75rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.side-sec .log-head { margin-bottom: 8px; }
.side-sec .log-head h2 { font-size: .75rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); flex: 1; }
.side-sec.card.collapsed > h2 { margin-bottom: 0; }
.side-sec .log { height: 260px; }
.side-sec .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.side-sec .stats dd { font-size: 1rem; }
.side-sec .apk-box { margin-top: 8px; }
.side-sec .request { margin: 8px 0; }
.side-sec.accent { background: var(--accent-soft); }
.side-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0; }
.side-line > span:first-child, .side-line > strong { min-width: 0; overflow-wrap: anywhere; }
.html-row .html-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.html-row .html-date { font-size: .75rem; white-space: nowrap; }
.side-note { font-size: .8rem; color: var(--muted); margin: 6px 0; }
.plan-progress { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); margin: 4px 0 8px; }
.plan-progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--code-bg); overflow: hidden; }
.plan-progress .bar > span { display: block; height: 100%; background: var(--ok); }
.plan-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: .875rem; }
.plan-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 3px 6px; border-radius: 6px; }
.plan-row.current { background: var(--accent-soft); font-weight: 600; }
.plan-name { min-width: 0; overflow-wrap: anywhere; }
.plan-name .muted { font-size: .75rem; font-weight: 400; }
.plan-row .pill { flex: none; }
.side-sec .continue-banner { margin: 10px 0 0; padding: 10px 12px; }
.side-sec .continue-banner .actions { margin-top: 8px; }
.sidebar .pill.idle, .thread .pill.idle { background: var(--warn-bg); color: var(--warn); }
.sheet-bar { display: none; }
.side-strip { display: none; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0; }
.sidebar.folded .side-head, .sidebar.folded .side-body { display: none; }
.sidebar.folded .side-strip { display: flex; }
.strip-btn { position: relative; width: 40px; min-height: 40px; padding: 0; border-color: transparent; background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.strip-dot { position: absolute; right: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.strip-dot.ok { background: var(--ok); } .strip-dot.warn { background: var(--warn); } .strip-dot.run { background: var(--accent); }
.strip-rule { border: 0; border-top: 1px solid var(--border); width: 32px; margin: 4px 0; }

/* ---------- drawers ---------- */
.drawer-layer { position: fixed; top: 0; bottom: 0; left: var(--rail-w); right: 0; z-index: 35; display: flex; justify-content: flex-end; }
.drawer-scrim { position: absolute; inset: 0; background: rgb(20 23 29 / .38); }
.drawer { position: relative; width: 540px; max-width: 100%; height: 100%; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -12px 0 32px rgba(0, 0, 0, .18); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { flex: 1; margin: 0; }
.drawer-close { font-size: 1.4rem; line-height: 1; }
.drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 20px; overscroll-behavior: contain; }
body.drawer-open .chat, body.drawer-open .sidebar { pointer-events: none; }

/* ---------- phone: the side bar is a bottom sheet ---------- */
@media (max-width: 760px) {
  .thread-scroll { padding: 14px 12px; }
  .composer-wrap { padding: 0 10px 10px; }
  .chat { padding-bottom: 76px; }
  .sidebar, .sidebar.folded { position: fixed; left: var(--rail-w); right: 0; bottom: 0; width: auto; flex: none; max-height: 70vh; z-index: 25; border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 24px rgba(0, 0, 0, .12); }
  .sheet-bar { display: flex; flex-direction: column; gap: 6px; padding: 4px 16px 10px; }
  .sheet-handle { align-self: center; min-height: 24px; padding: 4px 20px; border-color: transparent; }
  .sheet-grab { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); }
  .sheet-line { display: flex; align-items: center; gap: 8px; }
  .sheet-line strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-head, .sidebar.folded .side-strip, .side-strip { display: none; }
  .sidebar .side-body, .sidebar.folded .side-body { display: none; }
  .sidebar.sheet-open .side-body { display: block; overflow-y: auto; max-height: calc(70vh - 90px); }
  .drawer-layer { left: 0; }
  .drawer { width: 100%; }
  .msg, .msg.you { max-width: 100%; }
}
