  :root {
    --bg: #f7f7f5; --surface: #fff; --line: rgba(0,0,0,.08); --text: #1c1c1a; --muted: #77756f;
    --accent: #1c1c1a; --bubble-user: #1c1c1a; --bubble-user-text: #fff; --bubble-user-bg: color-mix(in srgb, #1c1c1a 7%, transparent); --danger: #b4342a;
    --radius: 12px; --radius-sm: 8px;
  }
  @media (prefers-color-scheme: dark) {
    :root { --bg: #131312; --surface: #1c1c1b; --line: rgba(255,255,255,.1); --text: #f0efe9; --muted: #9a9890;
      --accent: #f0efe9; --bubble-user: #f0efe9; --bubble-user-text: #131312; --bubble-user-bg: color-mix(in srgb, #f0efe9 9%, transparent); --danger: #ef8b80; }
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  /* Phones must not autosize text or zoom the page on a double tap. */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body {
    margin: 0; background: var(--bg); color: var(--text); touch-action: manipulation;
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased; text-wrap: pretty;
  }
  button, input, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; border: none; background: none; }
  .screen { display: none; height: 100%; }
  .screen.on { display: flex; }

  /* login */
  #login { align-items: center; justify-content: center; padding: 24px; }
  .card {
    width: 100%; max-width: 360px; background: var(--surface); border-radius: var(--radius);
    padding: 24px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 40px rgba(0,0,0,.06);
  }
  .card h1 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.01em; }
  .card p.hint { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
  label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
  input[type=text], input[type=password] {
    width: 100%; padding: 11px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--bg); transition: border-color .15s, box-shadow .15s;
  }
  input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(127,127,127,.12); }
  .primary {
    width: 100%; margin-top: 18px; padding: 12px; border-radius: var(--radius-sm);
    background: var(--bubble-user); color: var(--bubble-user-text); font-weight: 600;
    transition: transform .12s ease, opacity .15s;
  }
  .primary:active { transform: scale(.96); }
  .primary[disabled] { opacity: .5; cursor: default; }
  .warn { margin-top: 16px; font-size: 12px; color: var(--muted); line-height: 1.5; }
  .login-updates { margin: 10px 0 0; }
  .link { font-size: 12.5px; color: var(--text); text-decoration: underline; text-underline-offset: 2px; padding: 0; }
  .error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

  /* app shell */
  #app { flex-direction: column; height: 100%; }
  header {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
  }
  header .who {
    font-size: 13px; color: var(--muted); min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  header .spacer { flex: 1; }
  .icon-btn {
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm);
    transition: background .15s, transform .12s ease;
  }
  .icon-btn:hover { background: var(--line); }
  .icon-btn:active { transform: scale(.96); }
  .icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; }

  #layout { flex: 1; display: flex; min-height: 0; }
  #sidebar {
    width: 240px; border-right: 1px solid var(--line); display: flex; flex-direction: column;
    background: var(--surface); min-height: 0;
  }
  #sidebar .new {
    margin: 10px; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
    font-size: 13px; font-weight: 600; text-align: center; transition: background .15s;
  }
  #sidebar .new:hover { background: var(--bg); }
  #sessions { overflow-y: auto; flex: 1; padding: 0 6px 10px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .session {
    display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: background .15s;
  }
  .session:hover { background: var(--bg); }
  .session.active { background: var(--bg); font-weight: 600; }
  .usage { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

  #main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  #messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
  /* The transcript is the scroll box plus the "back to the bottom" pill floating over its lower edge. */
  .transcript { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
  #to-bottom {
    position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 8px);
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--line); color: var(--text);
    font-size: 12.5px; font-weight: 500; white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.12);
    opacity: 0; pointer-events: none; z-index: 4;
    transition: opacity .16s ease, transform .16s ease;
  }
  #to-bottom.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
  #to-bottom:active { transform: translate(-50%, 0) scale(.95); }
  #to-bottom .tb-dot { width: 6px; height: 6px; border-radius: 50%; background: #d9534f; flex: none; }
  #to-bottom svg { width: 14px; height: 14px; flex: none; opacity: .8; }
  .msg.user { max-width: 720px; margin: 0 auto 18px; display: flex; justify-content: flex-end; }
  .msg.user .bubble {
    max-width: 86%; padding: 9px 13px; border-radius: var(--radius); white-space: pre-wrap;
    overflow-wrap: anywhere; background: var(--bubble-user-bg);
  }
  /* The reply is plain text on the page background: no card, no bubble, no border. */
  .reply { max-width: 720px; margin: 0 auto 20px; }
  .reply-head {
    font-size: 12px; font-weight: 600; letter-spacing: .01em; color: var(--muted);
    margin: 0 0 7px; opacity: .75;
  }
  .reply-body { font-size: 15px; line-height: 1.72; color: color-mix(in srgb, var(--text) 92%, transparent); overflow-wrap: anywhere; }
  .reply-body > *:first-child { margin-top: 0; }
  .reply-body > *:last-child { margin-bottom: 0; }
  .reply-body.streaming::after {
    content: ''; display: inline-block; width: 7px; height: 15px; margin-left: 2px; background: currentColor;
    opacity: .4; vertical-align: -2px; animation: caret 1s steps(2) infinite;
  }
  @keyframes caret { 50% { opacity: 0; } }
  .reply-meta {
    margin-top: 7px; font-size: 11.5px; color: var(--muted); opacity: .62;
    display: flex; flex-wrap: wrap; gap: 8px; font-variant-numeric: tabular-nums;
  }
  .reply-note { color: var(--danger); opacity: .9; }

  /* process timeline: one hairline rail, one faint summary line */
  .timeline { margin: 0 0 10px; }
  .timeline-head {
    display: flex; align-items: center; gap: 7px; width: 100%; max-width: 100%;
    padding: 3px 6px 3px 2px; margin-left: -2px; border-radius: 7px; text-align: left;
    color: var(--muted); transition: color .15s, background .15s;
  }
  .timeline-head:hover { color: color-mix(in srgb, var(--text) 76%, transparent); background: color-mix(in srgb, var(--text) 4%, transparent); }
  .timeline-icon { width: 15px; height: 15px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; opacity: .85; }
  .timeline-live {
    width: 6px; height: 6px; flex: none; margin: 0 4.5px; border-radius: 50%;
    background: #d69b2d; animation: pulse 1.1s ease-in-out infinite;
  }
  .timeline-summary {
    font-size: 13px; font-weight: 600; letter-spacing: .005em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .timeline-chevron {
    width: 13px; height: 13px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9;
    opacity: .3; transition: transform .18s ease, opacity .15s;
  }
  .timeline.open .timeline-chevron { transform: rotate(90deg); }
  .timeline-head:hover .timeline-chevron { opacity: .7; }
  .timeline-rail {
    display: flex; flex-direction: column; gap: 2px;
    border-left: 1px solid var(--line); margin: 5px 0 0 7px; padding: 2px 0 2px 13px;
  }
  .act { font-size: 12.5px; color: var(--muted); }
  .act > summary {
    display: flex; align-items: baseline; gap: 7px; padding: 3px 4px 3px 0;
    cursor: pointer; list-style: none; transition: color .15s;
  }
  .act > summary::-webkit-details-marker { display: none; }
  .act > summary:hover { color: color-mix(in srgb, var(--text) 78%, transparent); }
  .act-name { flex: none; font-weight: 500; color: color-mix(in srgb, var(--text) 70%, transparent); }
  .act-cmd {
    min-width: 0; flex: 0 1 auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .act > summary::marker { content: ''; }
  .act-time { flex: none; font-variant-numeric: tabular-nums; opacity: .65; font-size: 11.5px; }
  .act-body, .act > pre {
    margin: 3px 0 7px; white-space: pre-wrap; overflow-wrap: anywhere;
    font-size: 12.5px; line-height: 1.62; color: var(--muted);
  }
  .act > pre {
    background: color-mix(in srgb, var(--text) 4%, transparent); border-radius: 7px;
    padding: 8px 10px; overflow-x: auto; max-height: 280px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  }
  .act-label { font-size: 11px; color: var(--muted); opacity: .8; margin: 6px 0 2px; }
  .act-label.err, .act.failed .act-name, .act.failed > summary { color: var(--danger); }
  .act.notice { padding: 4px 0; font-size: 12px; opacity: .8; }
  .dot { width: 5px; height: 5px; border-radius: 50%; background: #d69b2d; flex: none; animation: pulse 1.1s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .25; } }
  .waiting { color: var(--muted); }

  /* markdown body shared by the reply text and the user bubble */
  .md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: color-mix(in srgb, var(--text) 8%, transparent); border-radius: 4px; padding: .12em .34em; }
  .md pre {
    background: color-mix(in srgb, var(--text) 4%, transparent); border-radius: var(--radius-sm);
    padding: 10px 12px; overflow-x: auto; margin: 10px 0 2px; font-size: 12.5px; line-height: 1.6;
  }
  .md pre code { background: none; padding: 0; font-size: 12.5px; }
  .md h3 { font-size: 15px; margin: 14px 0 6px; }
  .md p { margin: 6px 0; }
  .table-wrap { overflow-x: auto; margin: 10px 0 2px; }
  .md table { border-collapse: collapse; font-size: 13px; min-width: 60%; }
  .md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
  .md th { background: color-mix(in srgb, var(--text) 4%, transparent); font-weight: 600; }

  #composer { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); position: relative; }
  #composer.drag { background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }
  #composer.drag .composer-inner { border-color: var(--accent); border-style: dashed; }
  .attach-wrap { position: relative; flex: none; }
  #attach {
    width: 34px; height: 34px; border-radius: var(--radius-sm); display: grid; place-items: center;
    color: var(--muted); transition: background .15s, color .15s;
  }
  #attach:hover { background: var(--line); color: var(--text); }
  #attach svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; }
  #file-menu {
    position: absolute; bottom: 44px; left: 0; width: 280px; max-height: 300px; overflow-y: auto; z-index: 30;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,.16); padding: 6px; display: none;
  }
  #file-menu.open { display: block; }
  #file-menu button {
    display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm);
    font-size: 13px; transition: background .15s;
  }
  #file-menu button:hover { background: var(--bg); }
  #file-menu .menu-label {
    font-size: 11px; color: var(--muted); padding: 8px 10px 4px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
  }
  /* The scope switch sits in the label row: "本对话" is the default, "全部" is opt-in. */
  #file-menu .menu-label .scope {
    width: auto; padding: 0 6px; height: 20px; font-size: 11px; color: var(--muted);
    border: 1px solid var(--line); border-radius: 999px;
  }
  #file-menu .menu-label .scope:hover { background: var(--bg); color: var(--text); }
  #file-menu .menu-label.sub { padding: 6px 10px 2px; }
  #file-menu .recent { display: flex; align-items: center; gap: 8px; }
  #file-menu .recent span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #file-menu .recent em { font-style: normal; color: var(--muted); font-size: 11px; }
  #file-menu .empty { padding: 8px 10px; font-size: 12px; color: var(--muted); }
  .attachments { max-width: 720px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
  .attachments:empty { display: none; }
  .attach-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
    background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px;
  }
  .attach-chip .name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .attach-chip .size { color: var(--muted); font-variant-numeric: tabular-nums; }
  .attach-chip .x {
    width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: var(--muted);
    font-size: 13px; line-height: 1; transition: background .15s, color .15s;
  }
  .attach-chip .x:hover { background: var(--line); color: var(--text); }
  .attach-chip.uploading { opacity: .6; }
  .file-note { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
  .attach-chip .kind { color: var(--muted); font-size: 11px; }
  #file-menu .row { display: flex; align-items: center; gap: 4px; }
  #file-menu .row .recent { flex: 1; }
  #file-menu .del {
    flex: none; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center;
    color: var(--muted); font-size: 14px; line-height: 1; transition: background .15s, color .15s;
  }
  #file-menu .del:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
  #file-menu .del.confirm { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); padding: 0 8px; width: auto; font-size: 11px; }
  #file-menu .confirm-row { padding: 4px 6px; }
  #file-menu .confirm-row .del { width: auto; min-width: 44px; padding: 0 8px; height: 26px; font-size: 11px; white-space: nowrap; }
  #file-menu .confirm-row .ask { flex: 1; font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .composer-inner {
    max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 8px 12px;
    transition: border-color .15s, box-shadow .15s;
  }
  .composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(127,127,127,.1); }
  #input { flex: 1; border: none; background: none; resize: none; max-height: 160px; padding: 4px 0; line-height: 1.5; }
  #input:focus { outline: none; box-shadow: none; }
  #send {
    width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--bubble-user); color: var(--bubble-user-text);
    display: grid; place-items: center; flex: none; transition: transform .12s ease, opacity .15s;
  }
  #send:active { transform: scale(.96); }
  #send[disabled] { opacity: .4; }
  /* the status line shares its row with the model chip: the chip stays put, the text takes the rest */
  .composer-foot { max-width: 720px; margin: 6px auto 0; display: flex; align-items: center; gap: 8px; }
  .composer-foot .status { margin: 0; flex: 1; min-width: 0; }
  .status { max-width: 720px; margin: 6px auto 0; font-size: 12px; color: var(--muted); min-height: 16px; }
  .model-picker { position: relative; flex: none; }
  #model-btn {
    display: inline-flex; align-items: center; gap: 4px; max-width: 170px; height: 22px; padding: 0 9px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 11.5px;
  }
  #model-btn .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #model-btn .caret { font-size: 9px; line-height: 1; opacity: .8; }
  #model-btn:hover:not([disabled]) { color: var(--text); border-color: var(--muted); }
  #model-btn[disabled] { opacity: .55; }
  #model-btn[aria-expanded="true"] { color: var(--text); border-color: var(--accent); }
  #model-menu {
    position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 30; width: 232px; max-height: 46vh; overflow-y: auto;
    padding: 5px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0,0,0,.16);
  }
  #model-menu .m-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; padding: 6px 8px; border-radius: var(--radius-sm); text-align: left; }
  #model-menu .m-item:hover { background: var(--bg); }
  #model-menu .m-label { font-size: 13px; }
  #model-menu .m-note { font-size: 11.5px; color: var(--muted); }
  #model-menu .m-item.current .m-label { color: var(--accent); font-weight: 600; }
  .empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; text-align: center; padding: 24px; }

  /* tooltips */
  .tip { position: relative; }
  .tip::after {
    content: attr(data-tip);
    position: absolute; top: calc(100% + 7px); left: 50%; transform: translateX(-50%) translateY(-2px);
    background: var(--text); color: var(--bg); font-size: 11.5px; line-height: 1.3; font-weight: 500;
    padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
    opacity: 0; transition: opacity .14s ease, transform .14s ease; z-index: 60;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
  }
  .tip:hover::after, .tip:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
  /* icons near the right edge align their tooltip to the right to stay on screen */
  .tip-end::after { left: auto; right: 0; transform: translateY(-2px); }
  .tip-end:hover::after, .tip-end:focus-visible::after { transform: translateY(0); }
  .tip-start::after { left: 0; transform: translateY(-2px); }
  .tip-start:hover::after, .tip-start:focus-visible::after { transform: translateY(0); }
  /* the attachment menu is anchored bottom-left, so its tooltips point up */
  .tip-up::after { top: auto; bottom: calc(100% + 7px); }

  /* changelog */
  .dot-new { position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: #d9534f; box-shadow: 0 0 0 2px var(--bg); }
  .modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.34); }
  .modal[hidden] { display: none; }
  .modal-card { width: 100%; max-width: 560px; max-height: 78vh; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: 0 12px 48px rgba(0,0,0,.24); overflow: hidden; }
  .modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
  .modal-body { overflow-y: auto; padding: 14px; }
  .cl-entry + .cl-entry { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
  .cl-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .cl-title { font-size: 14px; font-weight: 600; margin: 2px 0 10px; }
  .cl-item { margin-bottom: 12px; }
  .cl-item:last-child { margin-bottom: 0; }
  .cl-item h4 { margin: 0 0 3px; font-size: 13.5px; font-weight: 600; }
  .cl-item p { margin: 0; font-size: 13px; line-height: 1.65; color: var(--muted); }

  /* artifacts panel */
  #artifacts-panel { border-bottom: 1px solid var(--line); background: var(--surface); max-height: 46vh; display: flex; flex-direction: column; overflow: hidden; }
  #artifacts-panel[hidden] { display: none; }
  .ap-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13px; }
  .ap-head .spacer { flex: 1; }
  .ap-head .ap-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
  /* flex + min-height:0 is what makes a long listing or a long document scroll INSIDE the panel instead of
     spilling over the conversation below it. */
  #artifacts-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 8px 8px; }
  .artifact { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; }
  .artifact:hover { background: var(--bg); }
  .artifact .icon { flex: none; opacity: .7; }
  .artifact .info { flex: 1; min-width: 0; }
  .artifact .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
  .artifact .sub { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
  .artifact a.dl { flex: none; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; text-decoration: none; color: var(--text); transition: background .15s; }
  .artifact a.dl:hover { background: var(--line); }
  .ap-empty { padding: 12px 14px 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }
  /* a preview needs more room than the list, and it scrolls on its own */
  #artifacts-panel.previewing { max-height: 82vh; }
  .ap-head, .ws-tabs, .ws-crumbs, .ws-hint, .ap-foot-note, .ap-status { flex: none; }
  .artifact { cursor: pointer; }
  .artifact .open { flex: 1; min-width: 0; padding: 0; background: none; text-align: left; }
  .artifact .pv {
    flex: none; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
    font-size: 12px; color: var(--muted);
  }
  .artifact:hover .pv { color: var(--text); border-color: color-mix(in srgb, var(--text) 25%, transparent); }
  .ws-hint { padding: 0 14px 6px; color: var(--muted); font-size: 11px; }
  .ap-preview-foot { display: flex; flex-wrap: wrap; gap: 12px; }
  .artifact:hover .name { text-decoration: underline; text-underline-offset: 2px; }
  .ap-back { flex: none; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; transition: background .15s; }
  .ap-back:hover { background: var(--line); }
  .ap-title {
    min-width: 0; max-width: 46%; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .ap-toggle { flex: none; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; transition: background .15s; }
  .ap-toggle:hover { background: var(--line); }
  .ap-head a.dl { flex: none; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; text-decoration: none; color: var(--text); transition: background .15s; }
  .ap-head a.dl:hover { background: var(--line); }
  #artifact-preview { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 14px; }
  .ap-preview-meta {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 0 8px;
    color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums;
  }
  .ap-cut { padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--text) 7%, transparent); }
  .ap-md { padding-bottom: 4px; }
  .ap-source {
    margin: 0; padding: 10px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--text) 4%, transparent);
    font: 12px/1.55 ui-monospace, Menlo, monospace; white-space: pre; overflow-x: auto; tab-size: 2;
  }
  .ap-image { display: block; max-width: 100%; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); }
  /* workspace: mount tabs, breadcrumbs, in-place delete */
  .ws-tabs { display: flex; flex: none; gap: 4px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; }
  .ws-tabs::-webkit-scrollbar { display: none; }
  .ws-tab {
    display: inline-flex; align-items: center; gap: 5px; flex: none; padding: 4px 10px; border-radius: 999px;
    border: 1px solid transparent; font-size: 12px; color: var(--muted); white-space: nowrap; transition: background .15s;
  }
  .ws-tab:hover { background: var(--bg); color: var(--text); }
  .ws-tab.on { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); font-weight: 600; }
  .ws-tab.dim { opacity: .45; }
  .ws-ro {
    padding: 0 5px; border-radius: 999px; background: color-mix(in srgb, var(--text) 8%, transparent);
    font-size: 10px; font-weight: 400; color: var(--muted);
  }
  .ws-crumbs { display: flex; flex: none; align-items: center; gap: 4px; padding: 0 12px 6px; font-size: 12px; overflow-x: auto; }
  .ws-crumb { padding: 2px 6px; border-radius: 6px; color: var(--muted); }
  .ws-crumb:hover { background: var(--bg); color: var(--text); }
  .ws-crumb-wrap { display: inline-flex; align-items: center; gap: 4px; }
  .ws-sep { color: var(--muted); opacity: .6; }
  .ws-new {
    margin-left: 6px; padding: 0 5px; border-radius: 999px;
    background: color-mix(in srgb, var(--text) 10%, transparent); font-size: 10px; font-style: normal;
  }
  .artifact.confirm { background: var(--bg); gap: 6px; }
  .artifact.confirm .ask { font-size: 12.5px; }
  .artifact .del { flex: none; width: 24px; height: 24px; border-radius: 999px; color: var(--muted); font-size: 15px; line-height: 1; }
  .artifact .del:hover { background: var(--line); color: var(--danger); }
  .ap-toggle.on { background: color-mix(in srgb, var(--text) 8%, transparent); }
  .ap-toggle.danger { color: var(--danger); }
  .ap-status { padding: 6px 14px 10px; color: var(--danger); font-size: 12px; }
  .ap-foot-note { padding: 2px 14px 10px; color: var(--muted); font-size: 11px; line-height: 1.5; }
  #file-preview { overflow-y: auto; }
  .ap-preview-foot { padding: 10px 0 2px; }
  .ap-plain-link { font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
  #artifacts-badge { position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 10px; line-height: 15px; text-align: center; }
  #artifacts-btn { position: relative; }

  .bubble-files { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
  .file-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px;
    background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--muted);
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; line-height: 1.4; font-weight: 600; }
  .md h3 { font-size: 15.5px; }
  .md h4 { font-size: 15px; }
  .md h5, .md h6 { font-size: 14px; }
  .md ul, .md ol { margin: 6px 0; padding-left: 18px; }
  .md li { margin: 3px 0; }
  .md blockquote { margin: 8px 0; padding: 2px 0 2px 10px; border-left: 2px solid var(--line); color: var(--muted); }
  .md hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
  .md a { color: inherit; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, var(--text) 35%, transparent); }
  .md a:hover { text-decoration-color: currentColor; }
  .md strong { font-weight: 600; }

  @media (max-width: 760px) {
    /* iOS and Android zoom the whole page when a field smaller than 16px gets focus: keep fields at 16px. */
    input[type=text], input[type=password], textarea { font-size: 16px; }
    #input { font-size: 16px; line-height: 1.45; }

    header {
      gap: 2px; padding: 8px 8px;
      padding-top: calc(8px + env(safe-area-inset-top));
      padding-left: calc(8px + env(safe-area-inset-left));
      padding-right: calc(8px + env(safe-area-inset-right));
    }
    header .who { font-size: 12.5px; }
    .icon-btn { width: 40px; height: 40px; }
    .icon-btn svg { width: 19px; height: 19px; }

    /* The drawer is a thumb target, not a 240px sliver, and respects the notch and home indicator. */
    #sidebar {
      position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(84vw, 320px);
      transform: translateX(-100%); transition: transform .22s cubic-bezier(.2,0,0,1);
      box-shadow: 0 0 40px rgba(0,0,0,.18); padding-top: env(safe-area-inset-top);
    }
    #sidebar.open { transform: none; }
    #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 15; }
    #scrim.open { opacity: 1; pointer-events: auto; }
    #sidebar .new { padding: 12px; font-size: 14px; }
    .session { padding: 12px 10px; font-size: 14px; }
    .usage { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

    #messages { padding: 14px 14px 6px; }
    #to-bottom { bottom: 10px; padding: 9px 15px; font-size: 13px; }
    #to-bottom svg { width: 15px; height: 15px; }
    .msg.user { margin-bottom: 16px; }
    .msg.user .bubble { max-width: 92%; padding: 10px 14px; }
    .reply { margin-bottom: 18px; }
    .reply-body { font-size: 15.5px; line-height: 1.7; }

    /* Composer: the field is the lowest element so it sits under the thumb, the one-line status moves above it,
       and the paperclip/send buttons grow into 40px tap targets. */
    #composer {
      display: flex; flex-direction: column;
      padding: 6px calc(12px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    }
    #composer .composer-foot { order: 0; margin: 0 4px 6px; gap: 6px; }
    #composer .status { order: 0; margin: 0; min-height: 0; font-size: 11.5px; line-height: 1.4; }
    #composer .attachments { order: 1; margin-bottom: 8px; }
    #composer .composer-inner { order: 2; width: 100%; gap: 4px; padding: 6px 6px 6px 8px; border-radius: 14px; }
    #attach { width: 40px; height: 40px; }
    #send { width: 40px; height: 40px; border-radius: 10px; }
    #input { padding: 8px 0; max-height: 120px; }
    #file-menu { bottom: 50px; width: min(300px, calc(100vw - 40px)); max-height: min(320px, 55vh); }
    #file-menu button { padding: 12px 10px; font-size: 14px; }
    #file-menu .del { width: 34px; height: 34px; }
    .attach-chip { font-size: 12.5px; }

    #login { padding: 16px; }
    .card { padding: 20px; }
    input[type=text], input[type=password] { padding: 12px; }

    .modal { padding: 12px; }
    .modal-card { max-height: 84vh; max-height: 84dvh; }
    .cl-item p { font-size: 13.5px; }

    #artifacts-panel { max-height: 52vh; }
    #artifacts-panel.previewing { max-height: 90vh; }
    .artifact .del { width: 32px; height: 32px; }
    .ws-tabs { padding-bottom: 10px; }
    .ap-title { max-width: 38%; }
    .ap-source { font-size: 12.5px; }
    .ap-head { padding: 10px 12px; }
    .artifact { padding: 10px; }
    .artifact a.dl { padding: 7px 12px; }
  }

  /* React root fills the viewport; the screens inside keep their own height rules. */
  #root { height: 100%; }
  /* 100dvh follows the collapsing browser chrome; --app-height is set from visualViewport while a keyboard is open. */
  @supports (height: 100dvh) {
    #root { height: var(--app-height, 100dvh); }
  }
  #boot { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; }
