:root {
  color-scheme: light;
  --paper: #ffffff;
  --field: #f5f6f8;
  --ink: #101114;
  --muted: #656b75;
  --line: #d9dde4;
  --line-strong: #aeb6c3;
  --blue: #002fa7;
  --blue-soft: #edf2ff;
  --danger: #c8172b;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--field); color: var(--ink); touch-action: pan-x pan-y; }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.hidden { display: none !important; }

.app-shell { height: 100dvh; min-height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: var(--field); }
.topbar {
  min-height: calc(62px + env(safe-area-inset-top, 0px));
  padding: calc(9px + env(safe-area-inset-top, 0px)) 14px 9px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-block { grid-column: 2; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.12; }
.brand-block span { color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.brand-block strong { max-width: min(62vw, 420px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; letter-spacing: -.03em; }
.icon-button { width: 48px; height: 48px; padding: 11px; border: 0; background: transparent; color: var(--ink); }
.icon-button:active, .icon-button:focus-visible { background: var(--blue-soft); outline: 0; }
.icon-button.is-refreshing { color: var(--blue); background: var(--blue-soft); }
.icon-button.is-refreshing svg { animation: refresh-spin .7s linear infinite; }
.icon-button svg, .send-button svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#back-button { grid-column: 1; grid-row: 1; }
#refresh-button { grid-column: 3; grid-row: 1; }

.controller-bar {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  color: #fff;
  background: var(--blue);
  border-bottom: 1px solid var(--blue);
}
.controller-bar.readonly { color: var(--ink); background: var(--paper); border-color: var(--line); border-left: 4px solid var(--line-strong); padding-left: 14px; }
.controller-bar span { display: block; font-size: 14px; font-weight: 700; }
.controller-bar p { margin: 3px 0 0; font-size: 12px; line-height: 1.35; color: inherit; opacity: .78; }
.bar-button { min-height: 42px; border: 1px solid currentColor; background: transparent; color: inherit; padding: 9px 12px; font-weight: 700; white-space: nowrap; }
.bar-button:active, .bar-button:focus-visible { background: rgb(255 255 255 / .16); outline: 0; }

.main-stage { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
.thread-list-view, .conversation-view { width: min(100%, 760px); margin: 0 auto; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 22px 18px 16px; border-bottom: 1px solid var(--line); background: var(--field); }
.section-heading h1 { margin: 0; font-size: clamp(32px, 10vw, 48px); line-height: .9; letter-spacing: -.06em; }
.folio { margin: 0 0 8px; color: var(--blue); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count { color: var(--blue); font-size: 24px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }

.search-field { display: grid; grid-template-columns: 56px 1fr; align-items: center; min-height: 50px; margin: 12px 12px 10px; border: 1px solid var(--line-strong); background: var(--paper); }
.search-field span { padding-left: 13px; color: var(--muted); font-size: 12px; font-weight: 700; }
.search-field input { width: 100%; height: 48px; border: 0; outline: 0; padding: 0 13px 0 0; background: transparent; color: var(--ink); font-size: 16px; }
.search-field:focus-within { border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }

.thread-list { padding: 0 12px 24px; }
.thread-row {
  width: 100%; min-height: 82px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px;
  margin: 0 0 8px; padding: 15px 14px; text-align: left;
  border: 1px solid var(--line); border-left: 4px solid transparent;
  background: var(--paper); color: var(--ink); cursor: pointer;
  appearance: none; -webkit-appearance: none; transition: background-color .12s ease, border-color .12s ease, opacity .12s ease;
}
.thread-row:active, .thread-row:focus-visible { background: var(--blue-soft); border-color: var(--blue); border-left-color: var(--blue); outline: 0; }
.thread-row:disabled { cursor: wait; }
.thread-row.thread-row-unavailable:disabled { cursor: default; opacity: .58; }
.thread-row.thread-row-unavailable .thread-row-arrow { opacity: .28; }
.thread-row.is-loading { background: var(--blue-soft); border-color: var(--blue); border-left-color: var(--blue); opacity: .74; }
.thread-row-main { min-width: 0; }
.thread-row h2 { margin: 0 0 7px; font-size: 17px; line-height: 1.2; letter-spacing: -.025em; overflow-wrap: anywhere; }
.thread-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-row-aside { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; align-items: center; justify-items: end; gap: 7px 9px; min-width: 66px; }
.thread-row time { grid-column: 1 / -1; color: var(--muted); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.thread-status { color: var(--muted); font-size: 11px; white-space: nowrap; }
.thread-status.active { color: var(--blue); font-weight: 700; }
.thread-row .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.thread-row .status-dot.active { background: var(--blue); }
.thread-row-arrow { width: 9px; height: 9px; border-top: 2px solid currentColor; border-right: 2px solid currentColor; color: var(--blue); transform: rotate(45deg); }
.thread-row.is-loading .thread-row-arrow { animation: row-wait .8s linear infinite; }
@keyframes row-wait { from { transform: rotate(45deg); } to { transform: rotate(405deg); } }
.empty-state { margin: 0; padding: 44px 18px; color: var(--muted); border: 1px solid var(--line); background: var(--paper); }

.conversation-view { min-height: 100%; padding-bottom: 0; }
.conversation-heading { padding: 20px 18px 18px; border-bottom: 1px solid var(--line); background: var(--paper); }
.conversation-heading h1 { margin: 5px 0 8px; font-size: clamp(26px, 8vw, 38px); line-height: 1; letter-spacing: -.055em; overflow-wrap: anywhere; }
.thread-project { margin: 0; color: var(--blue); font-size: 12px; font-weight: 700; }
.thread-path { margin: 0; color: var(--muted); font-size: 11px; word-break: break-all; }
.conversation-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 17px; }
.help-text { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.primary-button, .secondary-button { min-height: 48px; border: 1px solid var(--blue); padding: 11px 14px; font-weight: 700; cursor: pointer; }
.primary-button { background: var(--blue); color: #fff; }
.secondary-button { background: var(--paper); color: var(--blue); }
.primary-button:active, .secondary-button:active { background: var(--blue-soft); color: var(--blue); }
.danger-button { background: var(--danger); border-color: var(--danger); color: #fff; }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .45; }

.message-list { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.history-controls { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 4px 0 8px; color: var(--muted); font-size: 11px; }
.history-button { min-height: 42px; border: 1px solid var(--line-strong); background: var(--paper); color: var(--blue); padding: 9px 13px; font-weight: 700; cursor: pointer; }
.history-button:active, .history-button:focus-visible { border-color: var(--blue); background: var(--blue-soft); outline: 0; }
.history-button:disabled { cursor: wait; opacity: .55; }
.message { padding: 15px; border: 1px solid var(--line); background: var(--paper); }
.conversation-loading { display: flex; align-items: center; gap: 10px; color: var(--blue); min-height: 60px; font-weight: 700; }
.conversation-loading::before { content: ""; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: row-wait .8s linear infinite; }
.message .message-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.message-identity { display: flex; align-items: center; gap: 8px; min-width: 0; }
.message-identity > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-button {
  flex: 0 0 auto;
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: color .16s ease, background-color .16s ease, border-color .16s ease, transform .12s ease;
}
.copy-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.copy-button:hover, .copy-button:focus-visible { color: var(--blue); border-color: #dbe3ff; background: var(--blue-soft); outline: 0; }
.copy-button:active { transform: scale(.94); }
.copy-button:disabled { cursor: not-allowed; opacity: .35; }
.copy-button.is-copied { color: #14652f; border-color: #cce8d2; background: #e8f6ec; }
.message .message-body { margin: 0; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; min-width: 0; }
.message.user { background: var(--paper); border-left: 4px solid var(--line-strong); padding-left: 12px; }
.message.agent { border-left: 4px solid var(--blue); padding-left: 12px; }
.message.command .message-body, .message.reasoning .message-body { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.message details summary { color: var(--blue); font-size: 13px; font-weight: 700; cursor: pointer; }

/* The app-server sends agentMessage.text as Markdown. Keep the renderer
   deliberately small and safe, while giving the result the same visual
   hierarchy users expect from the Desktop conversation view. */
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 12px; white-space: pre-wrap; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 { margin: 18px 0 8px; line-height: 1.2; letter-spacing: -.025em; }
.markdown-body h1 { font-size: 26px; }
.markdown-body h2 { font-size: 22px; }
.markdown-body h3 { font-size: 19px; }
.markdown-body h4 { font-size: 17px; }
.markdown-body h5, .markdown-body h6 { font-size: 15px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 12px; padding-left: 24px; }
.markdown-body li { margin: 4px 0; padding-left: 2px; }
.markdown-body blockquote { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--line-strong); color: var(--muted); background: var(--field); }
.markdown-body hr { margin: 16px 0; border: 0; border-top: 1px solid var(--line); }
.markdown-body a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.markdown-code { max-width: 100%; margin: 0 0 12px; padding: 12px; overflow-x: auto; border: 1px solid var(--line); background: #f1f3f6; color: #1c2430; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; tab-size: 2; white-space: pre; -webkit-overflow-scrolling: touch; }
.inline-code { padding: 2px 5px; border: 1px solid var(--line); background: #f1f3f6; color: #1c2430; font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; }
.markdown-table { display: block; max-width: 100%; margin: 0 0 12px; overflow-x: auto; border-collapse: collapse; -webkit-overflow-scrolling: touch; }
.markdown-table th, .markdown-table td { min-width: 96px; padding: 7px 9px; border: 1px solid var(--line); text-align: left; vertical-align: top; white-space: pre-wrap; }
.markdown-table th { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.markdown-image { color: var(--muted); font-size: .9em; font-style: italic; }
.message-rich-content { min-width: 0; }
.message-rich-content > .message-image-figure { margin-top: 10px; }
.message-rich-content > .message-video-figure { margin-top: 10px; }
.message-image-figure { max-width: 100%; margin: 0; }
.message-video-figure { max-width: 100%; margin: 0; }
.image-preview-trigger {
  position: relative;
  display: inline-flex;
  width: min(100%, 560px);
  height: clamp(180px, 56vw, 320px);
  align-items: center;
  justify-content: center;
  max-width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--field);
  color: var(--muted);
  cursor: zoom-in;
  overflow: hidden;
  text-align: left;
}
.image-preview-trigger:focus-visible { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.image-preview-trigger.is-loading { cursor: wait; }
.image-preview-trigger.is-error { cursor: default; }
.image-preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.image-preview-loading::before {
  content: "";
  width: 15px;
  height: 15px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: row-wait .8s linear infinite;
}
.image-preview-trigger:not(.is-loading) .image-preview-loading { display: none; }
.message-image { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-preview-fallback { display: block; padding: 20px 24px; font-size: 12px; }
.video-preview-shell {
  position: relative;
  display: inline-flex;
  vertical-align: top;
  width: min(100%, 560px);
  height: clamp(180px, 56vw, 320px);
  align-items: center;
  justify-content: center;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #101114;
  color: var(--muted);
  overflow: hidden;
}
.video-preview-shell.is-loading { cursor: wait; }
.video-preview-shell.is-error { cursor: default; background: var(--field); }
.video-preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: rgb(255 255 255 / .78);
  font-size: 12px;
  pointer-events: none;
}
.video-preview-loading::before {
  content: "";
  width: 15px;
  height: 15px;
  border: 2px solid rgb(255 255 255 / .38);
  border-top-color: #fff;
  border-radius: 50%;
  animation: row-wait .8s linear infinite;
}
.video-preview-shell:not(.is-loading) .video-preview-loading { display: none; }
.message-video { display: block; width: 100%; height: 100%; background: #101114; object-fit: contain; }
.video-preview-fallback { display: block; padding: 20px 24px; color: var(--muted); font-size: 12px; }
.message-attachment-label { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.message.file, .message.tool { border-left: 4px solid var(--line-strong); padding-left: 12px; }
.message.tool { background: #fbfcfe; }
.message.file details, .message.tool details, .message.command details, .message.reasoning details { min-width: 0; }
.message.file details > summary, .message.tool details > summary { list-style-position: outside; }
.diff-file-list { display: grid; gap: 8px; margin-top: 12px; min-width: 0; }
.diff-file { min-width: 0; border: 1px solid var(--line); background: var(--paper); }
.diff-file > summary { padding: 9px 10px; color: var(--ink); font-size: 12px; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.diff-file > summary::marker { color: var(--blue); }
.diff-block { display: block; max-width: 100%; margin: 10px 0 0; padding: 9px 0; overflow-x: auto; border: 1px solid var(--line); background: #f7f8fa; color: #26313d; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; tab-size: 2; white-space: pre; -webkit-overflow-scrolling: touch; }
.diff-line { display: block; min-width: max-content; padding: 0 10px; }
.diff-line.add { background: #e8f6ec; color: #14652f; }
.diff-line.remove { background: #fdebec; color: #9f1d2d; }
.diff-line.header { background: #eaf0ff; color: #244a9b; font-weight: 700; }
.diff-line.context { color: #39424e; }
.diff-empty { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.live-diff { border-left-color: var(--blue); }

.request-stack { margin: 12px; border: 1px solid var(--blue); background: var(--blue-soft); }
.request-card { padding: 16px; border-bottom: 1px solid var(--blue); }
.request-card:last-child { border-bottom: 0; }
.request-card.is-submitting { opacity: .72; }
.request-card h2 { margin: 0 0 8px; font-size: 17px; }
.request-card p, .request-card pre { margin: 0 0 12px; font-size: 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.request-card .request-header, .question-header { color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.request-card .request-error { color: var(--danger); }
.request-card .request-submitting { margin: 10px 0 0; color: var(--blue); font-weight: 700; }
.request-card .request-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.request-card .decline { color: var(--danger); border-color: var(--danger); }
.request-plan-details { margin: 12px 0; border: 1px solid var(--line); background: var(--paper); }
.request-plan-details > summary { padding: 11px 12px; color: var(--blue); font-size: 12px; font-weight: 700; cursor: pointer; }
.request-plan { padding: 12px; border-top: 1px solid var(--line); max-height: min(48dvh, 420px); overflow: auto; }
.request-feedback { width: 100%; min-height: 76px; margin: 4px 0 12px; resize: vertical; border: 1px solid var(--line-strong); border-radius: 0; padding: 10px; background: var(--paper); font-size: 15px; line-height: 1.4; }
.request-feedback:focus { outline: 0; border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.question-block { margin: 12px 0; }
.question-block label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
.question-block select, .question-block input { width: 100%; min-height: 48px; border: 1px solid var(--line-strong); border-radius: 0; background: var(--paper); padding: 8px; }

.composer { position: fixed; z-index: 15; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: minmax(0, 1fr) 52px 52px; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom)); background: rgb(255 255 255 / .96); border-top: 1px solid var(--line-strong); }
.composer label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.composer textarea { width: 100%; max-height: 132px; resize: none; border: 1px solid var(--line-strong); border-radius: 0; padding: 12px; outline: 0; font-size: 16px; line-height: 1.35; }
.composer textarea:focus { border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.send-button { width: 52px; height: 52px; border: 0; background: var(--blue); color: #fff; padding: 13px; cursor: pointer; }
.voice-button { width: 52px; height: 52px; border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); padding: 13px; cursor: pointer; }
.voice-button svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.voice-button:focus-visible { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.voice-button.is-listening { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); animation: voice-pulse 1.35s ease-in-out infinite; }
.voice-button:disabled { cursor: not-allowed; opacity: .5; }
.voice-status { grid-column: 1 / -1; min-height: 0; color: var(--muted); font-size: 10px; line-height: 1.25; }
.voice-status:empty { display: none; }
.voice-undo { grid-column: 1 / -1; justify-self: start; border: 0; padding: 0; background: transparent; color: var(--blue); font-size: 11px; cursor: pointer; }
.voice-undo:hover { text-decoration: underline; }
.voice-undo.hidden { display: none; }

.toast { position: fixed; z-index: 50; left: 12px; right: 12px; bottom: calc(82px + var(--safe-bottom)); max-width: 640px; margin: auto; padding: 14px 15px; border-left: 4px solid var(--blue); background: var(--ink); color: #fff; font-size: 13px; line-height: 1.4; }
dialog { width: min(calc(100% - 32px), 420px); border: 1px solid var(--ink); border-radius: 0; padding: 22px; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h2 { margin: 0 0 10px; font-size: 24px; letter-spacing: -.04em; }
dialog p { margin: 0; color: var(--muted); line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.login-view { min-height: 100dvh; display: grid; align-items: center; padding: 24px 18px calc(30px + var(--safe-bottom)); background: var(--blue); }
.login-panel { width: min(100%, 460px); margin: auto; background: var(--paper); border: 1px solid var(--ink); padding: 26px 22px; box-shadow: 8px 8px 0 rgb(0 0 0 / .18); }
.login-panel h1 { margin: 0 0 12px; font-size: 38px; line-height: .95; letter-spacing: -.06em; }
.login-panel > p:not(.folio):not(.error-text) { color: var(--muted); line-height: 1.5; }
.login-panel form { display: grid; gap: 10px; margin-top: 24px; }
.login-panel label { font-size: 12px; font-weight: 700; }
.login-panel input { min-height: 50px; border: 1px solid var(--line-strong); border-radius: 0; padding: 10px; font-size: 16px; }
.login-panel input:focus { outline: 0; border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.error-text { min-height: 18px; color: var(--danger); font-size: 12px; }

@media (min-width: 760px) {
  .main-stage { display: grid; grid-template-columns: minmax(320px, 38%) 1fr; }
  .thread-list-view { width: 100%; border-right: 1px solid var(--line); }
  .conversation-view { width: 100%; margin: 0; }
  .thread-list-view.hidden + .conversation-view { grid-column: 1 / -1; }
  .thread-list-view.hidden + .conversation-view .composer { left: 0; }
  #back-button { visibility: hidden; }
  .composer { left: 38%; }
}

/* Codex-inspired visual pass: quiet surfaces, compact navigation, and a
   conversation-first hierarchy. Interaction and responsive behavior above
   remain unchanged. */
:root {
  --paper: #ffffff;
  --field: #f7f7f5;
  --ink: #242424;
  --muted: #777774;
  --line: #e8e8e4;
  --line-strong: #d2d2cd;
  --blue: #3159d9;
  --blue-soft: #edf2ff;
  --danger: #b42318;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

html, body { background: var(--field); color: var(--ink); }
.topbar { min-height: calc(56px + env(safe-area-inset-top, 0px)); padding-top: calc(6px + env(safe-area-inset-top, 0px)); padding-bottom: 6px; background: rgb(255 255 255 / .94); border-bottom-color: var(--line); }
.brand-block span { color: var(--muted); font-size: 10px; letter-spacing: .05em; }
.brand-block strong { font-size: 15px; letter-spacing: -.02em; }
.icon-button { width: 44px; height: 44px; color: var(--muted); border-radius: 10px; }
.icon-button:active, .icon-button:focus-visible { color: var(--ink); background: #eeeeeb; }

.controller-bar { min-height: 54px; padding: 9px 18px; color: var(--ink); background: var(--paper); border-bottom-color: var(--line); }
.controller-bar:not(.readonly) { background: #f2f5ff; border-bottom-color: #dbe3ff; }
.controller-bar.readonly { color: var(--muted); background: var(--paper); border-left: 0; padding-left: 18px; }
.controller-bar span { font-size: 12px; }
.controller-bar p { font-size: 11px; }
.bar-button { min-height: 36px; padding: 7px 11px; border-color: var(--line-strong); border-radius: 8px; color: var(--ink); background: var(--paper); font-size: 12px; }

.section-heading { align-items: center; padding: 17px 18px 10px; border-bottom: 0; background: transparent; }
.section-heading h1 { font-size: 24px; line-height: 1.1; letter-spacing: -.04em; }
.section-heading .folio { display: none; }
.count { min-width: 25px; padding: 4px 7px; border-radius: 999px; background: #ecece9; color: var(--muted); font-size: 11px; text-align: center; }
.search-field { min-height: 40px; margin: 4px 12px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.search-field span { display: none; }
.search-field input { height: 38px; padding: 0 12px; color: var(--ink); font-size: 14px; }
.search-field:focus-within { border-color: #bdc8ec; box-shadow: 0 0 0 3px #edf2ff; }

.thread-list { padding: 0 8px 20px; }
.thread-row { min-height: 70px; gap: 10px; margin: 3px 0; padding: 12px 11px; border: 0; border-left: 0; border-radius: 10px; background: transparent; }
.thread-row:active, .thread-row:focus-visible, .thread-row.is-loading { background: #ecece9; border: 0; border-left: 0; outline: 0; }
.thread-row h2 { margin-bottom: 5px; font-size: 14px; font-weight: 650; }
.thread-row p { font-size: 11px; }
.thread-row-aside { min-width: 58px; gap: 5px 7px; }
.thread-row time, .thread-status { font-size: 10px; }
.thread-row-arrow { width: 7px; height: 7px; border-width: 1.5px; color: var(--muted); }
.thread-row .status-dot { width: 6px; height: 6px; }
.thread-row .status-dot.active { position: relative; animation: active-dot 1.35s ease-in-out infinite; }
.thread-row .status-dot.active::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid rgb(49 89 217 / .42);
  border-radius: 50%;
  animation: active-ring 1.35s ease-out infinite;
}

.conversation-view { background: var(--paper); }
.conversation-heading { padding: 17px 20px 14px; border-bottom: 1px solid var(--line); background: var(--paper); }
.conversation-heading h1 { margin: 4px 0 6px; font-size: 24px; line-height: 1.12; letter-spacing: -.04em; }
.thread-project { color: var(--muted); font-size: 10px; letter-spacing: .03em; text-transform: uppercase; }
.thread-path { color: var(--muted); font-size: 10px; }
.conversation-actions { gap: 7px; margin-top: 13px; }
.primary-button, .secondary-button { min-height: 42px; border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.primary-button { background: var(--ink); border-color: var(--ink); }
.secondary-button { color: var(--ink); border-color: var(--line-strong); }
.primary-button:active, .secondary-button:active { color: var(--ink); background: #eeeeeb; }
.help-text { margin-top: 8px; font-size: 11px; }

.message-list { max-width: 800px; margin: 0 auto; gap: 3px; padding: 16px 18px calc(110px + var(--safe-bottom)); background: var(--paper); }
.message { margin: 0; padding: 12px 8px; border: 0; border-radius: 12px; background: transparent; }
.message .message-meta { margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 600; }
.message .message-body { font-size: 15px; line-height: 1.58; }
.message.user { max-width: 88%; margin-left: auto; padding: 11px 14px; border: 0; border-radius: 14px; background: #ecece9; }
.message.user .message-meta { margin-bottom: 4px; color: #62625f; }
.message.agent { padding: 14px 8px; border: 0; }
.message.agent .message-meta span:first-child { color: var(--ink); }
.message.command, .message.reasoning, .message.file, .message.tool { margin: 5px 0; padding: 11px 13px; border: 1px solid var(--line); border-left: 0; border-radius: 11px; background: #fbfbfa; }
.message.command .message-body, .message.reasoning .message-body { font-size: 12px; }
.message details summary { color: var(--ink); font-size: 12px; font-weight: 600; list-style: none; }
.message details summary::-webkit-details-marker { display: none; }
.message details summary::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 8px 2px 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .16s ease;
}
.message details[open] > summary::before { transform: rotate(45deg); }

/* Agent operations stay quiet in the transcript until the user opens one.
   The summary is the useful bit of information on a small screen: it names
   the current action and stays on one line when a command or path is long. */
.message.operation {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 5px;
  margin: 3px 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: 10px;
  background: #fbfbfa;
}
.message.operation.is-active {
  border-color: #dbe3ff;
  border-left-color: var(--blue);
  background: #f7f9ff;
}
.message.operation details { min-width: 0; }
.message.operation > .copy-button { grid-column: 2; grid-row: 1; margin-top: 0; }
.message.operation > details > summary {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 28px;
  margin: -2px 0;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.message.operation.is-active > details > summary { color: var(--blue); }
.message.operation > details > summary::before { flex: 0 0 auto; }
.operation-summary-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message.operation > details[open] > summary {
  margin-bottom: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}
.message.operation .message-body {
  min-width: 0;
  max-height: 360px;
  overflow: auto;
}
.message.operation .message-body:not(.markdown-body) {
  padding: 2px 0 1px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.operation .diff-file-list { margin-top: 0; }
.image-operation-body { min-width: 0; }
.operation-image-figure { margin: 0; }
.operation-image {
  display: block;
  width: min(100%, 560px);
  max-height: 440px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f3f1;
  object-fit: contain;
}
.operation-image-caption {
  margin-top: 7px;
  color: var(--muted);
  font: 10px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-dialog {
  width: min(calc(100vw - 20px), 960px);
  max-width: calc(100vw - 20px);
  height: min(calc(100dvh - 20px), 900px);
  max-height: calc(100dvh - 20px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: rgb(16 17 20 / .96);
  color: #fff;
  overflow: hidden;
}
.image-dialog::backdrop { background: rgb(0 0 0 / .72); }
.image-dialog-form { position: relative; display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; padding: 28px 12px 42px; }
.image-dialog-image { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.image-dialog-close { position: absolute; z-index: 1; top: 8px; right: 8px; width: 42px; height: 42px; border: 1px solid rgb(255 255 255 / .38); border-radius: 999px; background: rgb(0 0 0 / .42); color: #fff; font-size: 27px; line-height: 1; cursor: pointer; }
.image-dialog-close:focus-visible { outline: 0; border-color: #fff; box-shadow: 0 0 0 3px rgb(255 255 255 / .25); }
.image-dialog-caption { position: absolute; right: 56px; bottom: 11px; left: 12px; margin: 0; overflow: hidden; color: rgb(255 255 255 / .75); font-size: 11px; line-height: 1.35; text-align: center; text-overflow: ellipsis; white-space: nowrap; }

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { letter-spacing: -.03em; }
.markdown-code { margin: 10px 0 12px; border: 1px solid #deded9; border-radius: 9px; background: #f3f3f1; color: #2d2d2a; }
.inline-code { border: 0; border-radius: 4px; background: #eeeeeb; color: #2d2d2a; }
.markdown-table th { background: #f0f0ed; color: var(--ink); }
.markdown-table th, .markdown-table td { border-color: var(--line); }

.request-stack { margin: 10px 18px calc(110px + var(--safe-bottom)); border: 1px solid #dbe3ff; border-radius: 11px; background: #f7f9ff; overflow: hidden; }
.request-stack:empty { display: none; }
.request-card { padding: 13px; border-bottom-color: #dbe3ff; }
.request-card h2 { font-size: 15px; }
.request-card p, .request-card pre { font-size: 11px; }
.request-card .request-actions { gap: 6px; }

.diff-file-list { gap: 6px; margin-top: 10px; }
.diff-file { border-color: var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
.diff-file > summary { padding: 8px 10px; font-size: 11px; }
.diff-block { margin: 8px 0 0; border: 1px solid var(--line); border-radius: 8px; background: #f5f5f3; font-size: 11px; }
.diff-line.add { background: #eaf6ec; color: #23633a; }
.diff-line.remove { background: #fbeded; color: #963b43; }
.diff-line.header { background: #eef2fb; color: #40588f; }
.diff-empty { margin-top: 8px; font-size: 11px; }

.composer { padding: 8px 12px calc(8px + var(--safe-bottom)); background: rgb(247 247 245 / .95); border-top-color: var(--line); }
.running-indicator {
  grid-column: 1 / -1;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border: 1px solid #dbe3ff;
  border-radius: 11px;
  background: #f2f5ff;
  color: var(--ink);
}
.activity-bars { height: 18px; display: flex; align-items: center; justify-content: center; gap: 3px; }
.activity-bars i { width: 3px; height: 7px; border-radius: 999px; background: var(--blue); animation: activity-wave .9s ease-in-out infinite; }
.activity-bars i:nth-child(2) { animation-delay: .14s; }
.activity-bars i:nth-child(3) { animation-delay: .28s; }
.running-copy { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.running-copy strong { font-size: 12px; line-height: 1.25; }
.running-copy small { overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.live-label { color: var(--blue); font-size: 9px; font-weight: 750; letter-spacing: .08em; }
.conversation-view.is-running .message-list { padding-bottom: calc(162px + var(--safe-bottom)); }
.composer textarea { min-height: 44px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--paper); padding: 11px 12px; font-size: 15px; }
.composer textarea:focus { border-color: #9eade0; box-shadow: 0 0 0 3px #edf2ff; }
.voice-button { width: 44px; height: 44px; border-radius: 11px; padding: 11px; }
.send-button { width: 44px; height: 44px; border-radius: 11px; background: var(--ink); }
.toast { bottom: calc(72px + var(--safe-bottom)); border-left: 0; border-radius: 10px; background: #242424; font-size: 12px; }

@keyframes active-dot {
  0%, 100% { opacity: .72; transform: scale(.88); }
  50% { opacity: 1; transform: scale(1.18); }
}
@keyframes active-ring {
  0% { opacity: .8; transform: scale(.5); }
  75%, 100% { opacity: 0; transform: scale(1.3); }
}
@keyframes activity-wave {
  0%, 100% { height: 6px; opacity: .45; }
  50% { height: 17px; opacity: 1; }
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgb(49 89 217 / .18); }
  50% { box-shadow: 0 0 0 5px rgb(49 89 217 / .08); }
}
@keyframes refresh-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .thread-row .status-dot.active,
  .thread-row .status-dot.active::after,
  .activity-bars i { animation: none; }
  .voice-button.is-listening { animation: none; }
  .icon-button.is-refreshing svg { animation: none; }
  .thread-row .status-dot.active::after { opacity: .45; transform: scale(.72); }
  .activity-bars i { height: 10px; opacity: .8; }
}

@media (min-width: 760px) {
  .main-stage { grid-template-columns: 280px minmax(0, 1fr); background: var(--field); }
  .thread-list-view { width: 100%; min-height: calc(100dvh - 110px); border-right: 1px solid var(--line); background: #f3f3f1; }
  .conversation-view { width: 100%; min-height: 100%; }
  .conversation-heading { padding-left: 34px; padding-right: 34px; }
  .message-list { padding-left: 34px; padding-right: 34px; }
  .request-stack { margin: 10px 34px 82px; }
  .composer { left: 280px; }
}
