  /* ---------- tokens: dark (default) and light ---------- */
  :root {
    --bg: #262624; --side: #1f1e1d; --panel: #30302e; --line: #3a3936;
    --text: #f5f4ef; --dim: #a3a19a; --accent: #d97757; --user: #3a3936;
    --ok: #5fbf7f; --err: #e0645c; --warn: #e0b04b; --hunk: #8fb4ff; --hover: rgba(255,255,255,.06);
    --add-bg: rgba(95,191,127,.16); --del-bg: rgba(224,100,92,.16);
    --shadow: 0 4px 18px rgba(0,0,0,.35);
    --logo: #f5f4ef;
    color-scheme: dark;
  }
  :root[data-theme="light"] {
    --bg: #faf9f5; --side: #f0eee6; --panel: #ffffff; --line: #e3e0d6;
    --text: #2b2a27; --dim: #7a776d; --accent: #c96442; --user: #efece3;
    --ok: #2e8b57; --err: #c0392b; --warn: #b7791f; --hunk: #3b63c4; --hover: rgba(0,0,0,.05);
    --add-bg: rgba(46,139,87,.12); --del-bg: rgba(192,57,43,.10);
    --shadow: 0 4px 18px rgba(0,0,0,.10);
    --logo: #1b2a4a;
    color-scheme: light;
  }

  /* ---------- base ---------- */
  * { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
  [hidden] { display: none !important; }
  html, body { height: 100%; margin: 0; }
  body {
    background: var(--bg); color: var(--text); display: flex; flex-direction: column;
    font: 14px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  }
  code, pre { font-family: ui-monospace, Consolas, monospace; }
  button {
    font: inherit; font-size: 13px; color: var(--text); background: transparent;
    border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
  }
  button:hover:not(:disabled) { background: var(--hover); }
  button:disabled { opacity: .45; cursor: not-allowed; }
  button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
  button.ghost, button.icon { border-color: transparent; }
  button.icon { padding: 4px 8px; font-size: 15px; line-height: 1; }
  button.danger { color: var(--err); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .field {
    background: var(--panel); color: var(--text); border: 1px solid var(--line);
    border-radius: 10px; padding: 9px 12px; font: inherit; font-size: 14px;
  }
  .field:focus { outline: none; border-color: var(--accent); }
  .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
  .dot.on { background: var(--ok); }
  .dot.off { background: var(--err); }
  .grow { flex: 1; }
  .dim { color: var(--dim); font-size: 13px; }
  .brand { display: inline-flex; align-items: center; }
  /* wordmark + wave follow --logo (navy / off-white); star and gold wave are fixed in the symbol */
  .logo { display: block; height: 24px; width: auto; aspect-ratio: 260 / 74; color: var(--logo); }
  .svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
  .fp-title { font-size: 11px; font-weight: 600; color: var(--dim); letter-spacing: .6px; text-transform: uppercase; }
  .note { font-size: 12.5px; color: var(--dim); min-height: 1.2em; margin: 0; }

  /* ---------- login ---------- */
  #login { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; position: relative; }
  .corner { position: absolute; top: 12px; right: 12px; }
  #loginBox {
    width: min(380px, 100%); display: flex; flex-direction: column; gap: 6px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
  }
  #loginBox .login-title { margin-bottom: 14px; }
  #loginBox .login-title .logo { height: 46px; }
  #loginBox label { font-size: 12px; color: var(--dim); margin-top: 6px; }
  #loginBtn { margin-top: 16px; padding: 9px 14px; }
  #loginError { color: var(--err); font-size: 13px; min-height: 1.5em; }

  /* ---------- agents screen ---------- */
  #agents { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--side); }
  #agentsBody {
    flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px;
    width: 100%; max-width: 760px; margin: 0 auto;
  }
  .card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
  .card pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; font-size: 12.5px; overflow-x: auto; }
  .row { display: flex; gap: 8px; flex-wrap: wrap; }
  .row .field { flex: 1; min-width: 160px; }
  #agentList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
  .agent-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  }
  .agent-name { font-weight: 600; }
  .agent-meta { flex: 1; font-size: 12px; color: var(--dim); }
  .agent-meta .outdated { color: var(--accent); }
  a.btnlink { align-self: flex-start; background: var(--accent); color: #fff; border-radius: 8px; padding: 6px 14px; text-decoration: none; font-size: 13px; }

  /* ---------- work screen: sidebar ---------- */
  #app { flex: 1; display: flex; min-height: 0; }
  #sidebar {
    width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; min-height: 0;
  }
  /* only the session list may shrink; a long list squeezed the label above it */
  #sidebar > * { flex-shrink: 0; }
  .sb-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px 8px; }
  .agent-card {
    display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 0 8px;
    padding: 8px 10px; border-radius: 10px; background: var(--panel);
  }
  .ac-main { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .ac-sub { grid-column: 1; font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .agent-card::after { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--dim); }
  .sb-new { text-align: left; border-color: transparent; margin-top: 6px; font-weight: 500; }
  .sb-label {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--dim);
    padding: 12px 10px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #sessMsg { font-size: 12px; color: var(--dim); font-style: italic; padding: 4px 10px; }
  #sessMsg:empty { display: none; }
  #sessList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 1px; }
  #sessList li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--dim); }
  #sessList li:hover { background: var(--hover); color: var(--text); }
  #sessList li.current { background: var(--panel); color: var(--text); cursor: default; }
  #sessList .s-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #sessList .s-time { font-size: 11px; opacity: .75; white-space: nowrap; }
  #sessList .s-del { display: none; padding: 0 4px; border: none; font-size: 12px; }
  #sessList li:hover .s-del { display: inline-block; }
  .sb-more { align-self: flex-start; border-color: transparent; font-size: 12px; color: var(--dim); }
  .sb-foot {
    margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 8px 4px 0 8px;
    border-top: 1px solid var(--line); font-size: 12.5px; color: var(--dim);
  }
  #meName2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 80; }

  /* ---------- work screen: main column ---------- */
  #main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  #topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); min-height: 46px; }
  #menuBtn { display: none; }
  #topTitle { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #sessionCost { font-size: 12px; color: var(--dim); white-space: nowrap; }
  #ctxBox:not([hidden]) { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); white-space: nowrap; }
  #ctxMeter { width: 60px; height: 8px; }
  @media (max-width: 480px) { #ctxMeter { display: none; } } /* phones keep the numbers, drop the bar */
  #filesBtn { padding: 3px 10px; font-size: 12px; }
  #layout { flex: 1; display: flex; min-height: 0; }

  /* chat: one centred column, at most 760px wide */
  #chat {
    flex: 1; overflow-y: auto; min-width: 0; display: flex; flex-direction: column; gap: 12px;
    padding: 20px max(16px, calc((100% - 760px) / 2));
  }
  .msg { max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }
  .msg.md { white-space: normal; }
  .msg.md > :first-child { margin-top: 0; }
  .msg.md > :last-child { margin-bottom: 0; }
  .msg.md p, .msg.md ul, .msg.md ol, .msg.md pre, .msg.md table, .msg.md blockquote { margin: 8px 0; }
  .msg.md ul, .msg.md ol { padding-left: 22px; }
  .msg.md h1, .msg.md h2, .msg.md h3, .msg.md h4 { margin: 14px 0 6px; font-size: 1.05em; }
  .msg.md code { font-size: 13px; background: var(--panel); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
  .msg.md pre { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
  .msg.md pre code { background: none; border: none; padding: 0; }
  .msg.md table { border-collapse: collapse; display: block; overflow-x: auto; }
  .msg.md th, .msg.md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
  .msg.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--dim); }
  .msg.md a { color: var(--accent); }
  .msg.user { align-self: flex-end; max-width: 85%; background: var(--user); padding: 9px 14px; border-radius: 14px; }
  .msg.assistant { align-self: stretch; }
  .msg.thinking { align-self: flex-start; color: var(--dim); font-style: italic; font-size: 13px; }
  details.msg.thinking summary { cursor: pointer; font-style: normal; }
  details.msg.thinking > div { margin-top: 4px; }
  .msg.system { align-self: center; color: var(--dim); font-size: 12px; }
  .tool {
    align-self: stretch; max-width: 100%; color: var(--dim); font-size: 12px; font-family: ui-monospace, Consolas, monospace;
    border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  }
  .tool b { color: var(--text); font-weight: 600; }
  .tool .st { display: inline-block; width: 1.4em; }
  .tool .st.ok { color: var(--ok); }
  .tool .st.err { color: var(--err); }
  .tool .st.run, .tool .st.stop { color: var(--dim); }
  .tool details { margin: 4px 0 0 1.4em; }
  .tool summary { cursor: pointer; color: var(--dim); }
  .tool .sub { margin: 4px 0 2px 1.4em; padding-left: 10px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
  .tool .sub-count { color: var(--dim); }
  .tool pre {
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
    padding: 8px 10px; margin: 4px 0 0; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all;
  }
  .perm { align-self: stretch; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 14px; }
  .perm .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
  .perm .toolname { font-family: ui-monospace, Consolas, monospace; color: var(--accent); font-weight: 600; }
  .perm .desc { color: var(--dim); font-size: 13px; }
  .perm pre {
    background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0;
    overflow-x: auto; font-size: 12px; max-height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
  }
  .perm .actions { display: flex; gap: 8px; }
  .perm .allow { background: var(--accent); border-color: var(--accent); color: #fff; }

  /* composer */
  #composer { padding: 0 16px 14px; position: relative; }
  #composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
  #busy {
    display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim);
    padding: 0 6px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #busy .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .3; } }
  .comp-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 8px; box-shadow: var(--shadow); }
  .comp-card:focus-within { border-color: var(--accent); }
  #planBox { margin: 0 auto 6px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 13px; }
  #planBox summary { cursor: pointer; color: var(--dim); font-weight: 600; }
  #planList { list-style: none; margin: 6px 0 2px; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 30vh; overflow-y: auto; }
  #planList .pl-in_progress { font-weight: 600; }
  #planList .pl-completed { color: var(--dim); text-decoration: line-through; }
  .msg.notice { align-self: stretch; font-size: 13px; padding: 6px 10px; border-left: 3px solid var(--dim); background: var(--hover); border-radius: 6px; }
  .msg.notice.sev-warning { border-left-color: var(--warn); }
  .msg.notice.sev-error { border-left-color: var(--err); }
  details.msg.compaction { align-self: stretch; color: var(--dim); font-size: 13px; }
  details.msg.compaction summary { cursor: pointer; }
  details.msg.compaction > div { margin-top: 4px; white-space: pre-wrap; }
  #input {
    width: 100%; display: block; background: transparent; color: var(--text); border: none; outline: none;
    resize: none; font: inherit; padding: 4px 6px 8px; min-height: 28px; max-height: 200px;
  }
  #input:placeholder-shown { overflow: hidden; }
  /* the slash command at the start of the draft: a textarea cannot style part of its text, so a mirror behind it draws the background */
  .input-wrap { position: relative; }
  .input-wrap #input { position: relative; }
  #inputHl {
    position: absolute; inset: 0; padding: 4px 6px 8px; overflow: hidden; pointer-events: none;
    white-space: pre-wrap; overflow-wrap: break-word; color: transparent; font: inherit;
  }
  #inputHl mark, .msg.user mark.slash, .msg.user mark.at { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 4px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent); }
  .msg.user mark.slash, .msg.user mark.at { font-family: ui-monospace, Consolas, monospace; font-size: .95em; color: var(--accent); }
  .comp-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
  .pill {
    display: inline-flex; align-items: center; gap: 7px; max-width: 220px;
    border-color: transparent; padding: 4px 9px; font-size: 12.5px; color: var(--dim);
  }
  .pill > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pill:hover:not(:disabled), .pill.open { color: var(--text); background: var(--hover); }
  /* chevron drawn with two borders: centred, follows the text colour, flips up while the popover is open */
  .pill::after, .agent-card::after {
    content: ''; flex: none; width: 5px; height: 5px; opacity: .75;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg); transition: transform .15s ease;
  }
  .pill.open::after { transform: translateY(1px) rotate(-135deg); }
  .send {
    width: 32px; height: 32px; padding: 0; flex: none; border-radius: 10px;
    background: var(--accent); border-color: var(--accent); color: #fff; font-size: 15px; font-weight: 700;
  }
  .send:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
  .send.stop { background: var(--text); border-color: var(--text); color: var(--bg); font-size: 11px; }

  /* popover (popover.js) */
  .popover {
    position: fixed; z-index: 200; min-width: 200px; max-width: min(320px, calc(100vw - 16px)); max-height: 320px; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
    padding: 4px; display: flex; flex-direction: column;
  }
  .pop-item { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; text-align: left; border: none; border-radius: 8px; padding: 7px 10px; }
  .pop-item:focus-visible { outline: none; background: var(--hover); }
  .pop-name { font-size: 13px; }
  .pop-item.sel .pop-name { font-weight: 600; }
  .pop-desc { grid-column: 1; font-size: 11.5px; color: var(--dim); }
  .pop-check { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--accent); }

  /* ---------- changed files panel ---------- */
  #filesPanel {
    width: 280px; flex: none; border-left: 1px solid var(--line); background: var(--side);
    overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  }
  .fp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  #filesList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
  #filesList li {
    font-size: 12px; font-family: ui-monospace, Consolas, monospace; color: var(--text); word-break: break-all;
    padding: 5px 8px; border-radius: 8px; border: 1px solid transparent;
  }
  #filesList li.fp-empty { color: var(--dim); font-style: italic; }
  #filesList li.fp-dir { color: var(--dim); padding: 6px 2px 0; }
  #filesList li.fp-file { display: flex; align-items: baseline; gap: 6px; cursor: pointer; }
  #filesList li.fp-file:hover { background: var(--hover); }
  #filesList li.sel { background: var(--panel); border-color: var(--line); }
  #filesList .fp-name { flex: 1; min-width: 0; }
  #filesList .fp-badge { font-size: 10px; font-weight: 700; color: var(--dim); }
  #filesList li.ev-add .fp-badge { color: var(--ok); }
  #filesList li.ev-unlink .fp-badge { color: var(--err); }
  .fp-num, #dvStat { font-size: 11px; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; }
  .n-add { color: var(--ok); }
  .n-del { color: var(--err); }

  /* ---------- diff view ---------- */
  #diffView { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  #dvHead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); }
  #dvHead button { padding: 3px 10px; }
  #dvHead button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  #dvPos { font-size: 12px; color: var(--dim); }
  #dvPath { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }
  .dv-tools { margin-left: auto; display: flex; gap: 4px; }
  #dvHead .dv-icon { display: inline-flex; align-items: center; justify-content: center; padding: 5px 7px; }
  .dv-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
  #dvBody { flex: 1; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5; }
  .dv-msg { padding: 14px; color: var(--dim); font-style: italic; }
  .dv-msg.err { color: var(--err); font-style: normal; }
  .dv-raw { margin: 0; padding: 14px; white-space: pre-wrap; word-break: break-all; }
  .dv-table { border-collapse: collapse; min-width: 100%; }
  .dv-table.split { table-layout: fixed; width: 100%; }
  .dv-table col.c-ln { width: 4em; }
  .dv-table td { padding: 0 8px; vertical-align: top; white-space: pre; }
  .dv-table.split td.code { white-space: pre-wrap; word-break: break-all; }
  .dv-table td.ln { color: var(--dim); text-align: right; user-select: none; }
  .dv-table td.add { background: var(--add-bg); }
  .dv-table td.code.add { color: var(--ok); }
  .dv-table td.del { background: var(--del-bg); }
  .dv-table td.code.del { color: var(--err); }
  .dv-table td.none { background: var(--hover); }
  .dv-table tr.hunk td { color: var(--hunk); background: var(--side); padding: 2px 8px; white-space: pre-wrap; }
  .dv-table .noeol { color: var(--dim); font-style: italic; }

  /* ---------- folder picker modal ---------- */
  #dirModal {
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100;
    display: none; align-items: center; justify-content: center;
  }
  #dirBox {
    width: min(760px, 92vw); max-height: 84vh; display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
  }
  #dirHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .dir-title { font-weight: 600; font-size: 15px; }
  #dirGo { display: flex; gap: 8px; padding: 12px 16px 0; }
  #dirInput { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; padding: 7px 10px; background: var(--bg); }
  #dirCrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 8px 16px; font-size: 12.5px; }
  #dirCrumbs button { border-color: transparent; padding: 2px 6px; font-size: 12.5px; color: var(--accent); }
  #dirCrumbs button.cur { color: var(--text); font-weight: 600; }
  #dirCrumbs .d-sep { color: var(--dim); }
  #dirRecentBox { padding: 0 16px 8px; border-bottom: 1px solid var(--line); }
  #dirRecent { list-style: none; margin: 4px 0 0; padding: 0; max-height: 132px; overflow-y: auto; }
  #dirFilter { margin: 10px 16px 0; padding: 6px 10px; font-size: 12.5px; background: var(--bg); }
  #dirList { list-style: none; margin: 0; padding: 6px 8px; overflow-y: auto; flex: 1; min-height: 160px; }
  #dirList li, #dirRecent li { display: flex; align-items: baseline; gap: 10px; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
  #dirList li:hover, #dirRecent li:hover { background: var(--hover); }
  #dirList .d-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #dirList .d-go { color: var(--dim); }
  #dirRecent .d-name { font-weight: 600; white-space: nowrap; }
  #dirRecent .d-parent {
    color: var(--dim); font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #dirList li.dir-msg { color: var(--dim); font-style: italic; cursor: default; }
  #dirList li.dir-msg:hover { background: none; }
  #dirFoot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }

  /* ---------- desktop: the files panel hides when empty or closed ---------- */
  @media (min-width: 768px) {
    #filesPanel.shut { display: none; }
  }

  /* ---------- phone ---------- */
  @media (max-width: 767px) {
    #providerSel + .pill { display: none; }
    #sidebar {
      position: fixed; top: 0; bottom: 0; left: 0; z-index: 90; width: min(300px, 85vw);
      transform: translateX(-105%); transition: transform .2s ease;
    }
    #sidebar.open { transform: none; box-shadow: var(--shadow); }
    #menuBtn { display: inline-block; }
    #sessList .s-del { display: inline-block; }
    #topbar { padding: 6px 10px; gap: 6px; }
    #chat { padding: 14px 12px; }
    #composer { padding: 0 8px 8px; }
    .pill { max-width: 140px; }
    #filesPanel { display: none; }
    #filesPanel.open { display: flex; position: fixed; inset: 0; width: auto; z-index: 90; border-left: none; }
    #dvSplit { display: none; }
    .dv-table td.code { white-space: pre-wrap; word-break: break-all; }
    #dirBox { width: 100vw; max-height: 92vh; }
  }

  #cmdPop { position: absolute; left: 0; right: 0; bottom: 100%; max-width: 760px; margin: 0 auto 6px; z-index: 50;
    display: flex; flex-direction: column; gap: 1px; padding: 4px; max-height: 260px; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
  #cmdPop[hidden] { display: none; }
  #cmdPop .cmd { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; border: none; text-align: left; padding: 6px 10px; border-radius: 8px; }
  #cmdPop .cmd.on, #cmdPop .cmd:hover { background: var(--hover); }
  #cmdPop .cmd-name { font-family: ui-monospace, monospace; font-size: 12.5px; }
  #cmdPop .cmd-desc { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #attachRow { display: flex; gap: 6px; padding: 4px 6px 2px; flex-wrap: wrap; }
  #attachRow[hidden] { display: none; }
  #attachRow .att { position: relative; }
  #attachRow img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
  #attachRow .att-x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 18px; background: var(--panel); }
  .msg.user img.thumb { display: block; max-width: 220px; max-height: 160px; border-radius: 8px; margin-top: 6px; }
  #attachBtn { padding: 4px 8px; }
  #attachBtn::after { content: none; }
