:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #172033;
  --ink: #172033;
  --muted: #677080;
  --line: #dce1dc;
  --paper: #ffffff;
  --wash: #f8f9f7;
  --accent: #0d675d;
  --accent-soft: #def0eb;
  --warn: #9a3412;
  --danger: #b42318;
  --code: #f2f4f1;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: #f4f6f3; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.offscreen { position: fixed; left: -9999px; top: 0; }

.app { display: flex; flex-direction: column; height: 100dvh; max-width: 48rem; margin: 0 auto; background: var(--wash); }
.bar { display: flex; align-items: center; gap: .5rem; padding: max(.6rem, env(safe-area-inset-top)) .75rem .6rem;
  border-bottom: 1px solid var(--line); background: var(--paper); }
.bar-title { flex: 1; min-width: 0; }
.bar-title h1 { margin: 0; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { margin: 0; color: var(--accent); font-size: .65rem; font-weight: 800; letter-spacing: .14em; }
.bar-link, .bar-button { color: var(--accent); font-size: .85rem; font-weight: 700; text-decoration: none; padding: .6rem .3rem;
  border: 0; background: transparent; min-height: 2.75rem; }
.bar-button:disabled { opacity: .5; }
.icon { min-width: 2.75rem; min-height: 2.75rem; border: 0; background: transparent; font-size: 1.8rem; color: var(--accent); }
.live { font-size: .7rem; font-weight: 700; padding: .15rem .45rem; border-radius: 1rem; white-space: nowrap; }
.live.up { color: var(--accent); background: var(--accent-soft); }
.live.down { color: var(--warn); background: #fff4ed; }

.center { display: grid; place-content: center; gap: .8rem; flex: 1; padding: 1.5rem; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; text-align: center; }
.primary, .secondary, .danger { min-height: 2.75rem; padding: .55rem 1.1rem; border-radius: .8rem; font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.primary { border: 0; color: #fff; background: var(--accent); }
.secondary { border: 1px solid var(--line); color: var(--ink); background: var(--paper); }
.danger { border: 1px solid #f3b8b2; color: var(--danger); background: #fff5f4; }
.primary:disabled, .secondary:disabled, .danger:disabled { opacity: .55; }
.wide { width: 100%; }
.link-button { border: 0; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 600; padding: .35rem .4rem;
  min-height: 2rem; }

.list { flex: 1; overflow-y: auto; padding: 1rem; }
.sessions { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .6rem; }
.session { width: 100%; display: grid; gap: .3rem; padding: .85rem 1rem; text-align: left; border: 1px solid var(--line);
  border-radius: .9rem; background: var(--paper); color: var(--ink); }
.session-head { display: flex; align-items: center; gap: .5rem; }
.session-title { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.session-meta { color: var(--muted); font-size: .78rem; }
.badge { flex: none; font-size: .7rem; font-weight: 700; padding: .1rem .45rem; border-radius: 1rem; }
.badge.run { color: var(--accent); background: var(--accent-soft); }
.badge.wait { color: var(--warn); background: #fff4ed; }

.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: .75rem .75rem 1rem; }
.older { display: flex; margin: 0 auto .75rem; font-size: .85rem; min-height: 2.5rem; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.msg { max-width: 92%; padding: .6rem .85rem .3rem; border-radius: 1rem; overflow-wrap: anywhere; line-height: 1.55; }
.msg.user { align-self: flex-end; color: #fff; background: var(--accent); border-bottom-right-radius: .3rem; }
.msg.user .link-button { color: #d5ece7; }
.msg.user.pending { opacity: .7; }
.msg.assistant { align-self: stretch; max-width: 100%; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: .3rem; }
.msg.assistant.streaming .md > :last-child::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg.error { align-self: stretch; max-width: none; color: var(--warn); background: #fff4ed; border: 1px solid #fed7aa; padding-bottom: .6rem;
  white-space: pre-wrap; }
.msg.tool, .msg.reasoning, .msg.context { align-self: stretch; max-width: 100%; padding: 0; background: transparent; }
.msg details { border-radius: .7rem; }
.msg summary { cursor: pointer; padding: .35rem .5rem; color: var(--muted); font-size: .8rem; list-style: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg summary::-webkit-details-marker { display: none; }
.msg summary::before { content: "▸"; display: inline-block; width: 1rem; color: var(--accent); }
.msg details[open] summary::before { content: "▾"; }
.msg.tool summary { color: #4b5563; }
.msg details[open] { background: var(--paper); border: 1px solid var(--line); }
.msg details[open] summary { white-space: normal; border-bottom: 1px solid var(--line); }
.plain { white-space: pre-wrap; }
.muted { color: var(--muted); font-size: .82rem; padding: .5rem .6rem; max-height: 50vh; overflow-y: auto; }
.msg-actions { display: flex; justify-content: flex-end; gap: .25rem; margin-top: .1rem; }
.msg-meta { font-size: .72rem; opacity: .8; padding: .2rem 0 .3rem; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.chip { font-size: .75rem; padding: .1rem .5rem; border-radius: 1rem; background: rgba(255, 255, 255, .2); }

.md { font-size: .95rem; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .45rem 0; }
.md h3, .md h4, .md h5, .md h6 { margin: .8rem 0 .4rem; line-height: 1.3; }
.md h3 { font-size: 1.1rem; }
.md h4 { font-size: 1rem; }
.md h5, .md h6 { font-size: .92rem; }
.md ul, .md ol { margin: .4rem 0; padding-left: 1.4rem; }
.md li { margin: .15rem 0; }
.md li > p { margin: .15rem 0; }
.md li.task { list-style: none; margin-left: -1.2rem; display: flex; gap: .4rem; align-items: baseline; }
.md .check { flex: none; color: var(--accent); }
.md .task-body { min-width: 0; }
.md .task-body > p:first-child { margin-top: 0; }
.md blockquote { margin: .5rem 0; padding: .1rem .75rem; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: .8rem 0; }
.md a { color: var(--accent); }
.inline-code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .85em; padding: .05rem .3rem;
  border-radius: .3rem; background: var(--code); }
.code-block { margin: .55rem 0; border: 1px solid var(--line); border-radius: .6rem; overflow: hidden; background: var(--code); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .3rem 0 .65rem;
  border-bottom: 1px solid var(--line); font-size: .72rem; color: var(--muted); }
.code-block pre { margin: 0; padding: .6rem .7rem; overflow-x: auto; font-size: .8rem; line-height: 1.45; }
.code-block code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; white-space: pre; }
.table-wrap { margin: .55rem 0; overflow-x: auto; }
.md table { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: left; vertical-align: top; }
.md th { background: var(--code); }
.md .align-center { text-align: center; }
.md .align-right { text-align: right; }

.notice { margin: 0 .75rem .4rem; padding: .5rem .75rem; border-radius: .7rem; font-size: .85rem; color: var(--warn);
  background: #fff4ed; border: 1px solid #fed7aa; }
.tasks { margin: 0 .75rem .4rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--paper); font-size: .85rem; }
.tasks summary { cursor: pointer; padding: .5rem .75rem; font-weight: 700; }
.task-list { list-style: none; margin: 0; padding: 0 .75rem .5rem; display: grid; gap: .25rem; max-height: 30dvh; overflow-y: auto; }
.task-item { display: flex; gap: .45rem; align-items: baseline; }
.task-item.completed { color: var(--muted); text-decoration: line-through; }
.task-item.in_progress { font-weight: 700; }
.task-mark { flex: none; width: 1rem; color: var(--accent); }
.activity { margin: 0 .75rem .35rem; font-size: .8rem; color: var(--accent); }
.activity::before { content: ""; display: inline-block; width: .5rem; height: .5rem; margin-right: .4rem; border-radius: 50%;
  background: var(--accent); animation: blink 1.2s steps(2) infinite; }

.interaction { max-height: 55dvh; overflow-y: auto; margin: 0 .75rem .5rem; padding: .85rem; border: 1px solid var(--accent);
  border-radius: 1rem; background: var(--accent-soft); display: grid; gap: .55rem; }
.card-title { margin: 0; font-weight: 800; overflow-wrap: anywhere; }
.card-meta { margin: 0; font-size: .8rem; color: var(--muted); display: flex; gap: .5rem; align-items: center; }
.card-meta:empty { display: none; }
.card-label { margin: 0; font-size: .75rem; font-weight: 700; color: var(--muted); }
.risk { font-weight: 700; padding: .05rem .45rem; border-radius: 1rem; background: var(--paper); }
.risk-high, .risk-critical { color: var(--danger); }
.interaction pre, .detail { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; color: var(--ink); }
.interaction pre.preview { padding: .5rem .6rem; border-radius: .5rem; background: var(--paper);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .78rem; max-height: 30dvh; overflow-y: auto; }
.question { margin: 0; padding: 0; border: 0; display: grid; gap: .45rem; }
.question legend { font-weight: 800; margin-bottom: .3rem; }
.option { display: flex; gap: .55rem; align-items: flex-start; min-height: 2.75rem; padding: .5rem .6rem; border-radius: .7rem;
  background: var(--paper); }
.option input { margin-top: .25rem; width: 1.1rem; height: 1.1rem; flex: none; }
.option-text { display: grid; gap: .1rem; }
.option-description { font-size: .8rem; color: var(--muted); }
.question input[type="text"] { min-height: 2.75rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .7rem; }
.actions { display: flex; gap: .6rem; }
.actions button { flex: 1; }

.composer { display: flex; gap: .5rem; align-items: flex-end; padding: .6rem .75rem max(.6rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--paper); }
.composer textarea { flex: 1; min-width: 0; min-height: 2.75rem; max-height: 9rem; padding: .6rem .8rem; resize: none;
  border: 1px solid var(--line); border-radius: .9rem; field-sizing: content; }
.composer-actions { display: flex; gap: .4rem; }
.composer-actions button { padding: .55rem .8rem; }

/* Phase 2: session list tools, row menus, action sheet, model picker, slash commands. */
.md ul { list-style: disc; }
.md ul ul { list-style: circle; }
.menu { font-size: 1.5rem; line-height: 1; }
.list-tools { display: grid; gap: .6rem; margin-top: .9rem; }
.search { width: 100%; min-height: 2.75rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: .8rem;
  background: var(--paper); }
.tabs { display: flex; gap: .4rem; }
.tab { flex: 1; min-height: 2.5rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--paper);
  color: var(--muted); font-weight: 700; }
.tab[aria-selected="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.session-row { display: flex; align-items: stretch; gap: .35rem; }
.session-row .session { flex: 1; min-width: 0; }
.more { flex: none; border: 1px solid var(--line); border-radius: .9rem; background: var(--paper); font-size: 1.3rem; color: var(--muted); }
.notice.info { color: var(--accent); background: var(--accent-soft); border-color: #b9ddd4; white-space: pre-wrap; }

.sheet { width: min(100%, 48rem); max-width: 100%; max-height: 85dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 1.1rem 1.1rem 0 0; background: var(--paper); color: var(--ink); overflow: hidden; }
.sheet::backdrop { background: rgba(23, 32, 51, .45); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; padding: .4rem .5rem .4rem 1rem; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { display: grid; gap: .5rem; padding: .75rem 1rem max(1rem, env(safe-area-inset-bottom)); overflow-y: auto; }
.sheet-action { min-height: 2.9rem; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--paper);
  color: var(--ink); text-align: left; font-weight: 600; }
.danger-text { color: var(--danger); }
.sheet-label { margin: .3rem 0 0; font-size: .75rem; font-weight: 800; color: var(--muted); letter-spacing: .05em; }
.sheet-text { margin: 0; font-size: .88rem; color: var(--muted); }
.sheet-error { margin: 0; font-size: .85rem; color: var(--danger); }
.sheet-form { display: flex; gap: .5rem; }
.sheet-form input { flex: 1; min-width: 0; min-height: 2.75rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: .8rem; }
.model-box { display: grid; gap: .45rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.choice-list { display: grid; gap: .4rem; }
.choice { display: grid; gap: .15rem; min-height: 2.9rem; padding: .55rem .85rem; text-align: left; border: 1px solid var(--line);
  border-radius: .8rem; background: var(--paper); color: var(--ink); }
.choice.active, .effort.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.choice-description { font-size: .78rem; color: var(--muted); }
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.effort { min-height: 2.5rem; padding: .35rem .9rem; border: 1px solid var(--line); border-radius: 2rem; background: var(--paper);
  color: var(--ink); font-weight: 600; }

.commands { list-style: none; margin: 0 .75rem .4rem; padding: .3rem; border: 1px solid var(--line); border-radius: .8rem;
  background: var(--paper); max-height: 35dvh; overflow-y: auto; display: grid; gap: .15rem; }
.command { width: 100%; display: grid; gap: .1rem; padding: .5rem .6rem; text-align: left; border: 0; border-radius: .6rem;
  background: transparent; color: var(--ink); min-height: 2.75rem; }
.command:hover, .command:focus-visible { background: var(--accent-soft); }
.command-description { font-size: .78rem; color: var(--muted); }

/* Phase 3: attachments, thumbnails, file chips and the Files view. */
.attach { flex: none; width: 2.75rem; height: 2.75rem; border: 1px solid var(--line); border-radius: 50%; background: var(--paper);
  color: var(--accent); font-size: 1.5rem; line-height: 1; }
.attach:disabled { opacity: .5; }
.pending-attachments { list-style: none; margin: 0 .75rem .4rem; padding: 0; display: flex; gap: .45rem; overflow-x: auto; }
.pending-attachment { position: relative; flex: none; display: flex; align-items: center; gap: .35rem; height: 3.6rem; max-width: 12rem;
  padding: .25rem 1.6rem .25rem .3rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--paper); }
.pending-attachment img { width: 3rem; height: 3rem; object-fit: cover; border-radius: .45rem; }
.pending-attachment .file-name { font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-attachment .remove { position: absolute; top: .1rem; right: .1rem; width: 1.5rem; height: 1.5rem; border: 0; border-radius: 50%;
  background: rgba(23, 32, 51, .08); color: var(--ink); font-size: 1rem; line-height: 1; }
.attachments { display: flex; flex-wrap: wrap; gap: .4rem; margin: .35rem 0 .1rem; }
.thumb { padding: 0; border: 0; border-radius: .6rem; overflow: hidden; background: rgba(255, 255, 255, .25); width: 6.5rem; height: 6.5rem; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.broken { width: auto; height: auto; padding: .4rem .6rem; font-size: .75rem; color: inherit; }
.file-chip { display: flex; align-items: center; gap: .45rem; max-width: 100%; min-height: 2.75rem; padding: .35rem .6rem; border: 0;
  border-radius: .6rem; background: rgba(255, 255, 255, .92); color: var(--ink); text-align: left; }
.file-chip .file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.file-chip .file-size { flex: none; font-size: .72rem; color: var(--muted); }
.file-badge { flex: none; display: inline-grid; place-items: center; min-width: 2.4rem; height: 1.6rem; padding: 0 .3rem; border-radius: .4rem;
  background: var(--accent-soft); color: var(--accent); font-size: .65rem; font-weight: 800; }
.file-badge.folder { background: #fef3c7; color: #92400e; }
.preview-image { width: 100%; max-height: 65dvh; object-fit: contain; border-radius: .6rem; background: var(--code); }

.files { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: .2rem; align-items: center; }
.crumb { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: .35rem .3rem; min-height: 2.25rem; }
.crumb + .crumb::before { content: "/"; color: var(--muted); margin-right: .4rem; font-weight: 400; }
.crumb[aria-current="page"] { color: var(--ink); }
.files-tools { display: flex; gap: .5rem; }
.files-tools button { flex: 1; }
.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.entry { width: 100%; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: .6rem; align-items: center;
  min-height: 3rem; padding: .5rem .7rem; text-align: left; border: 1px solid var(--line); border-radius: .75rem; background: var(--paper); color: var(--ink); }
.entry .file-badge { grid-row: 1 / span 2; }
.entry-name { overflow-wrap: anywhere; font-weight: 600; font-size: .9rem; }
.entry-meta { color: var(--muted); font-size: .72rem; }
.entry-meta:empty { display: none; }
.entry.selected { border-color: var(--accent); background: var(--accent-soft); }

/* Storage quota line in the Files view. */
.files-quota { margin: 4px 0 8px; }
.files-quota.full { color: var(--danger, #b42318); font-weight: 600; }
