/* deepon chat page. No external assets. Light and dark follow the system setting. */

:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #dcdcd6;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --user-bg: #e6edf4;
  --code-bg: #f0f0ec;
  --error: #a3261b;
  --error-bg: #fbeae8;
  --ok: #2e7d4f;
  --run: #2f5d8a;
  --warn: #9a6a00;
  --press: #ecece7;
  --add-bg: #e6f4ea;
  --add-text: #1e5c34;
  --del-bg: #fbeae8;
  --del-text: #8a2219;
  --hunk: #5b5b9a;
  --notice-bg: #e8f1e9;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716;
    --surface: #21211f;
    --text: #e8e8e3;
    --muted: #9a9a93;
    --border: #383835;
    --accent: #6f9fcf;
    --accent-text: #0f1a25;
    --user-bg: #263342;
    --code-bg: #2a2a27;
    --error: #f19a90;
    --error-bg: #3a1f1c;
    --ok: #6cc28f;
    --run: #6f9fcf;
    --warn: #e0b44f;
    --press: #2c2c29;
    --add-bg: #1d3325;
    --add-text: #a6dcb6;
    --del-bg: #3a1f1c;
    --del-text: #f1b0a8;
    --hunk: #a9a9e0;
    --notice-bg: #1f3324;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

.app {
  height: 100vh;   /* fallback */
  height: 100dvh;  /* follows the on-screen keyboard where supported */
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
}

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

button { cursor: pointer; }

button:disabled { cursor: default; opacity: 0.55; }

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

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.link {
  background: none;
  border: 0;
  padding: 0.35rem 0.4rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.boot, .empty {
  color: var(--muted);
  text-align: center;
  margin: auto;
  padding: 1rem;
}

.error {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--error-bg);
  color: var(--error);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- login */

.login {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.title { margin: 0 0 0.5rem; font-size: 1.5rem; font-weight: 600; text-align: center; }

.login-form label { font-size: 0.9rem; color: var(--muted); }

.login-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------------------------------------------------------------- chat */

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.mode {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-btn {
  background: var(--surface);
  border: 0;
  padding: 0.3rem 0.75rem;
  font-size: 0.9rem;
}

.mode-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.model-name {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 45%;
}

.spacer { flex: 1; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 100%;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  max-width: 88%;
  background: var(--user-bg);
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg.thinking { color: var(--muted); font-style: italic; }

.msg p { margin: 0 0 0.6rem; }
.msg p:last-child { margin-bottom: 0; }

.msg code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

.code-block {
  margin: 0 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
}

.code-block:last-child { margin-bottom: 0; }

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.15rem 0.3rem 0.15rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.code-block pre {
  margin: 0;
  padding: 0.6rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
}

.code-block pre code { background: none; padding: 0; font-size: inherit; }

.composer {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
}

.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }

.chat-form textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  field-sizing: content;
  min-height: 2.6rem;
  max-height: 40vh;
  max-height: 40dvh;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  line-height: 1.4;
}

.status-line {
  margin: 0.35rem 0 0;
  min-height: 1.1em;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------- tabs */

.tabs {
  order: 10;  /* phones: a bottom bar */
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  background: none;
  border: 0;
  padding: 0.65rem 0.5rem;
  font-weight: 600;
  color: var(--muted);
  border-top: 2px solid transparent;
}

.tab[aria-selected="true"] { color: var(--accent); border-top-color: var(--accent); }

@media (min-width: 700px) {
  .tabs {
    order: -1;  /* wide screens: on top */
    border-top: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
  }
  .tab { flex: 0 0 auto; padding: 0.55rem 1.25rem; border-top: 0; border-bottom: 2px solid transparent; }
  .tab[aria-selected="true"] { border-bottom-color: var(--accent); }
}

/* With the tab bar at the bottom, the chat composer does not need the safe-area padding twice. */
.tabs:not([hidden]) ~ .chat .composer { padding-bottom: 0.6rem; }

/* ---------------------------------------------------------------- work views */

.work {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.bar-title { margin: 0; font-size: 1rem; font-weight: 600; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
}

.job-form { display: flex; flex-direction: column; gap: 0.5rem; }

.job-form textarea {
  width: 100%;
  resize: none;
  field-sizing: content;
  min-height: 4.5rem;
  max-height: 40vh;
  max-height: 40dvh;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  line-height: 1.4;
}

.row { display: flex; align-items: center; gap: 0.5rem; }
.row.wrap { flex-wrap: wrap; }

.select {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  color: inherit;
}

.toggle { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; }
.toggle input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.work-status { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); min-height: 1.3em; }

.notice {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--notice-bg);
  color: var(--ok);
  font-size: 0.9rem;
}

.scroll > .error { margin-top: 0.5rem; }

.section-title { font-size: 0.95rem; margin: 1rem 0 0.4rem; font-weight: 600; }

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }

.card-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  min-height: 3rem;
}

.card-btn:active, .file-btn:active { background: var(--press); }

.card-top { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.card-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.card-status { flex: 0 0 auto; }
.card-meta { overflow-wrap: anywhere; }
.pr-num { flex: 0 0 auto; font-variant-numeric: tabular-nums; }

.badge {
  flex: 0 0 auto;
  font-size: 0.72rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.empty-small { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0; }

/* status dots */
.dot {
  flex: 0 0 auto;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.dot-queued { background: transparent; border: 2px solid var(--muted); }
.dot-running { background: var(--run); animation: pulse 1.4s ease-in-out infinite; }
.dot-done { background: var(--ok); }
.dot-failed, .dot-stalled { background: var(--error); }
.dot-stopped { background: var(--warn); }

@keyframes pulse { 50% { opacity: 0.35; } }

/* buttons: immediate feedback */
button:active:not(:disabled) { transform: translateY(1px); }
.primary:active:not(:disabled) { filter: brightness(0.92); }
.is-busy { opacity: 0.75; cursor: progress; }

.secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
}

.danger {
  background: var(--surface);
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
}

.primary.armed { background: var(--warn); color: #1d1d1b; }
.danger.armed { background: var(--error); color: var(--surface); }

/* ---------------------------------------------------------------- detail */

.status-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.links { margin: 0.5rem 0; font-size: 0.9rem; }
.links:empty { display: none; }
.ext { color: var(--accent); }

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.88rem;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.steps { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.step { display: flex; gap: 0.45rem; align-items: baseline; }
.step-mark { flex: 0 0 1.1rem; text-align: center; color: var(--muted); }
.step-done .step-mark { color: var(--ok); }
.step-failed .step-mark { color: var(--error); }
.step-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.step-commit { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }

.error-box, .task-text {
  margin: 0.5rem 0;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 0.8rem;
  max-height: 40vh;
  overflow-y: auto;
}
.error-box { background: var(--error-bg); color: var(--error); }
.task-text { background: var(--code-bg); }

.task-box { margin: 0.5rem 0; }
.task-box summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; }

.log-head { display: flex; align-items: center; gap: 0.5rem; }
.log-head .section-title { margin: 0.75rem 0 0.4rem; }

.log {
  margin: 0;
  height: 50vh;
  height: 50dvh;
  min-height: 12rem;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre;
}
.log-phase { color: var(--accent); font-weight: 600; }
.log-note { color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- pull request view */

#pr-actions { margin: 0.5rem 0; }

.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }

.file-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}
.file-name { flex: 1; min-width: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.file-counts { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.add { color: var(--add-text); }
.del { color: var(--del-text); }

.diff {
  margin: 0.25rem 0 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre;
}
.diff > span { display: block; padding: 0 0.6rem; min-width: max-content; }
.diff-add { background: var(--add-bg); color: var(--add-text); }
.diff-del { background: var(--del-bg); color: var(--del-text); }
.diff-hunk { color: var(--hunk); background: var(--code-bg); }
.diff-note { color: var(--muted); font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  button:active:not(:disabled) { transform: none; }
}

/* ---------------------------------------------------------------- safe merge */

.version-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; min-height: 1.9rem; font-size: 0.85rem; }
.version-text { color: var(--muted); overflow-wrap: anywhere; }
.version-text:empty { display: none; }
.undo-link { color: var(--error); margin-left: auto; }
.undo-link.armed { font-weight: 600; }
.merge-box { margin: 0.5rem 0; }
.stage {
  margin: 0.5rem 0;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  min-height: 2.3rem;
}
.stage-checking, .stage-merging, .stage-deploying { border-color: var(--run); }
.stage-merged, .stage-live { border-color: var(--ok); background: var(--notice-bg); }
.stage-check_failed, .stage-failed, .stage-reverted, .stage-revert_failed { border-color: var(--error); background: var(--error-bg); color: var(--error); }
.merge-box .danger { margin-top: 0.25rem; }

/* ---------------------------------------------------------------- agentic chat (chat.js, md.js) */

.chat { flex-direction: row; position: relative; }
.chat-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.tabs:not([hidden]) ~ .chat .chat-main .composer { padding-bottom: 0.6rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.25rem; min-height: 2.25rem; padding: 0.25rem;
  background: none; border: 0; border-radius: 8px; color: var(--text);
}
.icon-btn:active:not(:disabled) { background: var(--press); }

/* The drawer: slides over on phones, a permanent sidebar from 900 px. */
.drawer {
  position: fixed; z-index: 30; top: 0; bottom: 0; left: 0;
  width: min(85vw, 320px);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 0.6rem; padding-top: max(0.6rem, env(safe-area-inset-top));
  transform: translateX(-102%); transition: transform 0.2s ease; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.35); }
.drawer-head { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.new-chat { padding: 0.45rem 0.9rem; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; gap: 2px; border-radius: 8px; }
.conv.current { background: var(--user-bg); }
.conv-btn {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start;
  background: none; border: 0; text-align: left; padding: 0.4rem 0.5rem; border-radius: 8px;
}
.conv-btn:active { background: var(--press); }
.conv-title { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.conv-time { font-size: 0.72rem; color: var(--muted); }
.conv-act { font-size: 0.72rem; color: var(--muted); min-width: 0; padding: 0.25rem 0.35rem; }
.conv-del.armed { color: var(--error); font-weight: 600; }
.conv-rename { flex: 1; min-width: 0; padding: 0.35rem 0.5rem; border: 1px solid var(--accent); border-radius: 8px; background: var(--bg); }
.conv-empty { padding: 0.5rem; }

@media (min-width: 900px) {
  .app { max-width: 1180px; }
  .work { width: 100%; max-width: 820px; margin: 0 auto; }
  .drawer {
    position: static; transform: none; visibility: visible; transition: none;
    width: 270px; flex: 0 0 270px; padding-top: 0.6rem; background: var(--bg);
  }
  .scrim, .drawer-open, .drawer-close { display: none !important; }
}

.chat .bar { flex-wrap: nowrap; }
.chat .bar-title { flex: 1; font-size: 0.98rem; }

/* Messages */
.messages { overflow-anchor: auto; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; max-width: 30rem; }
.empty p { margin: 0; }
.empty-title { font-size: 1.05rem; color: var(--text); }

.msg.user { white-space: normal; display: flex; flex-direction: column; align-items: flex-end; gap: 0.15rem; background: none; padding: 0; }
.user-text { background: var(--user-bg); padding: 0.55rem 0.8rem; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.user-actions { display: flex; gap: 0.25rem; }
.small-link { font-size: 0.78rem; padding: 0.1rem 0.35rem; color: var(--muted); }
.small-link:hover { color: var(--accent); }

.group { display: flex; flex-direction: column; gap: 0.4rem; }
.group-body { display: flex; flex-direction: column; gap: 0.45rem; min-width: 0; }
.seg { min-width: 0; }
.seg.live { overflow-anchor: none; }
.seg:empty { display: none; }
.group.streaming .seg.live:empty { display: block; min-height: 1.5em; }
.group.streaming .seg.live:empty::before { content: ""; }
.group-foot { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; margin: 0.1rem -0.35rem -0.2rem; min-height: 1.6rem; }
.group-cost { margin-left: auto; padding-right: 0.35rem; font-variant-numeric: tabular-nums; }
.group-error { margin: 0; }

.caret {
  display: inline-block; width: 0.5em; height: 1.05em; margin-left: 1px; vertical-align: text-bottom;
  background: var(--accent); border-radius: 1px; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.reasoning { font-size: 0.85rem; color: var(--muted); }
.reasoning summary { cursor: pointer; }
.reasoning-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14rem; overflow-y: auto; padding: 0.3rem 0 0 0.6rem; border-left: 2px solid var(--border); margin-top: 0.3rem; }

/* Markdown */
.md-h { margin: 0.6rem 0 0.35rem; line-height: 1.3; }
.md-h1 { font-size: 1.12rem; }
.md-h2 { font-size: 1.04rem; }
.md-h3 { font-size: 0.98rem; }
.seg > :first-child { margin-top: 0; }
.seg > :last-child { margin-bottom: 0; }
.md-list { margin: 0 0 0.6rem; padding-left: 1.4rem; }
.md-list .md-list { margin: 0.15rem 0 0.2rem; }
.md-list li + li { margin-top: 0.15rem; }
.md-quote { margin: 0 0 0.6rem; padding: 0.1rem 0 0.1rem 0.75rem; border-left: 3px solid var(--border); color: var(--muted); }
.md-hr { border: 0; border-top: 1px solid var(--border); margin: 0.75rem 0; }
.md-link { color: var(--accent); overflow-wrap: anywhere; }
.md-host { color: var(--muted); font-size: 0.85em; }
.table-wrap { overflow-x: auto; margin: 0 0 0.6rem; max-width: 100%; }
.md-table { border-collapse: collapse; font-size: 0.88rem; min-width: max-content; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 0.3rem 0.55rem; text-align: left; vertical-align: top; }
.md-table th { background: var(--code-bg); font-weight: 600; }
.md-table .al-right { text-align: right; }
.md-table .al-center { text-align: center; }
.copy-btn { font-size: 0.75rem; padding: 0.1rem 0.4rem; }

.fileref {
  display: inline; padding: 0 0.15rem; margin: 0; border: 0; border-radius: 4px;
  background: none; color: var(--accent); font: inherit; text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 2px; cursor: pointer; overflow-wrap: anywhere;
}
.fileref-code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); text-decoration: none; padding: 0.05rem 0.3rem; }
.fileref:active { background: var(--press); }

/* Tool lines */
.tool { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); min-width: 0; }
.tool-line {
  width: 100%; display: flex; align-items: center; gap: 0.45rem;
  background: none; border: 0; padding: 0.3rem 0.55rem; text-align: left; font-size: 0.84rem; color: var(--muted);
  min-height: 2rem;
}
.tool-line:active { background: var(--press); }
.tool-sum { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-icon { flex: 0 0 0.95rem; height: 0.95rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; }
.tool-running .tool-icon { border: 2px solid var(--border); border-top-color: var(--run); animation: spin 0.8s linear infinite; }
.tool-ok .tool-icon::before { content: "\2713"; color: var(--ok); font-weight: 700; }
.tool-fail .tool-icon::before { content: "\2715"; color: var(--error); font-weight: 700; }
.tool-fail .tool-sum { color: var(--error); }
.tool-chev::before { content: "\203A"; display: inline-block; transition: transform 0.15s ease; }
.tool-line[aria-expanded="true"] .tool-chev::before { transform: rotate(90deg); }
.tool-detail { border-top: 1px solid var(--border); padding: 0.4rem 0.55rem 0.55rem; }
.tool-label { font-size: 0.72rem; color: var(--muted); margin: 0.2rem 0; }
.tool-pre {
  margin: 0; padding: 0.45rem 0.55rem; background: var(--code-bg); border-radius: 6px;
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 16rem; overflow: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Job proposals */
.proposal { border: 1px solid var(--accent); border-radius: var(--radius); padding: 0.6rem; display: flex; flex-direction: column; gap: 0.45rem; background: var(--surface); }
.proposal-dismissed { border-color: var(--border); padding: 0.35rem 0.6rem; }
.proposal-dismissed p { margin: 0; }
.proposal-started { border-color: var(--border); }
.prop-head { font-size: 0.9rem; overflow-wrap: anywhere; }
.prop-task {
  width: 100%; resize: vertical; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 0.9rem; line-height: 1.4;
}
.prop-task-done { margin: 0; overflow-wrap: anywhere; }
.chip {
  display: inline-flex; align-items: center; gap: 0.45rem; align-self: flex-start; max-width: 100%;
  border: 1px solid var(--border); border-radius: 999px; padding: 0.3rem 0.75rem; background: var(--bg); font-size: 0.85rem;
}
.chip .dot { flex: 0 0 auto; }
.chip-open { color: var(--accent); white-space: nowrap; }

/* Composer */
.jump {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 8.4rem; z-index: 5;
  border: 1px solid var(--border); background: var(--surface); color: var(--accent);
  border-radius: 999px; padding: 0.3rem 0.85rem; font-size: 0.82rem; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.composer-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; min-width: 0; }
.repo-select { max-width: 45%; padding: 0.25rem 0.4rem; font-size: 0.82rem; }
.send { min-width: 4.6rem; }
.send.stop { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.edit-note { margin: 0 0 0.4rem; font-size: 0.8rem; color: var(--muted); }

/* Sheets (file viewer, settings): bottom sheet on phones, a centred panel on wide screens */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 100%; max-height: 88vh; max-height: 88dvh;
  border-radius: 14px 14px 0 0; background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; overflow: hidden;
}
.sheet:not([open]) { display: none; }
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
@media (min-width: 700px) {
  .sheet { margin: auto; width: min(860px, 92vw); border-radius: 14px; }
  .settings-sheet { width: min(560px, 92vw); }
}
.sheet-head { display: flex; align-items: center; gap: 0.4rem; padding: 0.55rem 0.6rem 0.55rem 0.9rem; border-bottom: 1px solid var(--border); }
.sheet-title { margin: 0; font-size: 0.98rem; font-weight: 600; }
.fv-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fv-title .sheet-title { font-family: var(--mono); font-size: 0.86rem; }
.file-sheet > .error { margin: 0.5rem 0.75rem 0; }
.fv-body { overflow: auto; flex: 1; min-height: 8rem; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5; padding: 0.3rem 0; }
.fv-loading { padding: 0.5rem 0.9rem; font-family: var(--sans); }
.fl { display: flex; min-width: max-content; }
.ln { flex: 0 0 auto; min-width: var(--ln-width, 4ch); padding: 0 0.6rem 0 0.4rem; text-align: right; color: var(--muted); user-select: none; }
.lt { white-space: pre; padding-right: 0.9rem; }
.fl-target { background: var(--user-bg); }
.fl-target .ln { color: var(--accent); font-weight: 700; }

.set-form { display: flex; flex-direction: column; gap: 0.55rem; padding: 0 0 0.9rem; overflow-y: auto; }
.set-form > :not(.sheet-head) { margin-left: 0.9rem; margin-right: 0.9rem; }
.set-form .sheet-head { padding-right: 0.9rem; }
.set-label { font-size: 0.86rem; color: var(--muted); }
.set-form textarea {
  width: auto; resize: vertical; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 0.9rem; line-height: 1.4; min-height: 6rem;
}
.set-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 0.75rem; align-items: center; }
.set-grid .select { width: 100%; }
.set-auto { font-size: 0.92rem; }
.set-form p { margin-top: 0; margin-bottom: 0; }
