:root {
    color-scheme: light;
    --text: #242329;
    --muted: #66636e;
    --line: #e6e3eb;
    --surface: #fff;
    --accent: #5341ac;
    --sidebar: #f8f7fa;
    --selected: #eeeaf7;
    font: 16px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    background: #faf9fb;
}

* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1000px; margin: 0 auto; padding: 3rem 1.5rem; }
.app-shell { min-height: 100dvh; }
.app-shell:has(.chat-main) {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .7rem;
    margin: 0;
    padding: .68rem 1.2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand {
    color: var(--text);
    font-size: .97rem;
    font-weight: 750;
    letter-spacing: -.025em;
    text-decoration: none;
    justify-self: start;
}
.topbar nav { display: flex; align-items: center; gap: .2rem; }
.topbar nav a {
    display: block;
    padding: .47rem .8rem;
    border-radius: 8px;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.topbar nav a:hover { color: var(--accent); background: var(--sidebar); }
.topbar nav a[aria-current="page"] {
    color: var(--accent);
    background: var(--selected);
}
.logout { justify-self: end; }
.logout button { color: var(--muted); font-size: .82rem; }
.app-content {
    min-width: 0;
    width: 100%;
    max-width: 76rem;
    padding: clamp(1.5rem, 4vw, 3rem) clamp(1.2rem, 4vw, 3.3rem);
}
header, .panel-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
header { margin-bottom: 1.3rem; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.5rem); letter-spacing: -.04em; }
h2 { font-size: 1.13rem; }
h3 { font-size: .94rem; }
h2 span, .panel-title > span, small { color: var(--muted); font-size: .8rem; font-weight: 400; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 1.25rem; }
.panel-title { padding: 1rem 1.2rem; }
.panel-note { padding: 0 1.2rem 1rem; color: var(--muted); }
.panel-note:first-child { padding-top: 1rem; }
.panel-subtitle { border-top: 1px solid var(--line); padding: .85rem 1.2rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; text-align: left; }
th, td { padding: .7rem 1.2rem; border-top: 1px solid var(--line); }
thead th { font-size: .82rem; color: var(--muted); white-space: nowrap; }
td, tbody th { font-size: .92rem; }
tbody th, td { overflow-wrap: anywhere; }
.mobile-label { display: none; }
code { font-size: .85rem; }
small { display: block; }
.state { font-size: .84rem; font-weight: 600; }
.available { color: #12604d; }
.unavailable { color: #9d352b; }
.neutral { color: var(--muted); }
tbody td, tbody th { vertical-align: top; }
.port-list { list-style: none; padding: 0; margin: 0; }
.port-list li { display: grid; grid-template-columns: 4.8rem 3.1rem 1fr; gap: .35rem; align-items: baseline; }
.port-list li + li { margin-top: .2rem; }
.gate { min-height: 90vh; display: grid; align-content: center; max-width: 37rem; }
.gate .panel { padding: 2rem; }
.gate p { color: var(--muted); margin: .65rem 0 1.25rem; }
button, .button { font: inherit; padding: .45rem .85rem; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; }
button { color: var(--text); background: var(--surface); }
.button { display: inline-block; text-decoration: none; color: #fff; background: var(--accent); border-color: var(--accent); }
:focus-visible { outline: 3px solid #247eb1; outline-offset: 3px; }
.back-link { color: var(--accent); }
.back-link { display: inline-block; margin-bottom: .8rem; }
.memory-document { padding: 0 1.2rem 1.15rem; }
.memory-document h3 { margin-bottom: .45rem; }
.memory-document h3 code { margin-left: .4rem; color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }
.memory-document .panel-note { padding: 0; }
.memory-text {
    margin: 0;
    padding: .85rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--sidebar);
    font: .875rem/1.65 ui-monospace, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.host-timers summary { padding: .9rem 1.2rem; font-weight: 650; cursor: pointer; }

.chat-main { min-height: 0; width: 100%; max-width: none; margin: 0; padding: 0; }
.chat-shell { display: grid; grid-template-columns: 16.75rem minmax(0, 1fr); height: 100%; }
.history-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
}
.history-heading { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: 1rem .85rem .65rem 1rem; }
.history-heading h2 { color: var(--muted); font-size: .85rem; font-weight: 650; }
.new-chat {
    align-items: center;
    display: inline-flex;
    gap: .28rem;
    text-decoration: none;
    color: var(--accent);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: .27rem .52rem;
    font-size: .82rem;
    font-weight: 600;
    background: var(--surface);
}
.new-chat:hover { background: var(--selected); }
.history-list { overflow: auto; list-style: none; padding: 0 .55rem .8rem; margin: 0; }
.history-list a {
    display: flex;
    align-items: center;
    gap: .42rem;
    margin-bottom: .14rem;
    padding: .6rem .58rem;
    border-radius: 7px;
    color: var(--text);
    text-decoration: none;
    font-size: .85rem;
}
.history-list a:hover, .history-list a[aria-current="page"] { background: var(--selected); }
.history-list a[aria-current="page"] { font-weight: 650; }
.history-list a > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list small { flex: none; font-size: .72rem; }
.history-empty { padding: .4rem 1rem; color: var(--muted); font-size: .86rem; }
.history-running { display: block; flex: none; background: var(--accent); width: .37rem; height: .37rem; border-radius: 50%; }
.conversation { display: grid; grid-template-rows: 3.3rem minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--surface); }
.conversation-header { margin: 0; padding: 0 1.15rem; justify-content: flex-start; align-items: center; gap: .65rem; border-bottom: 1px solid var(--line); }
.conversation-header h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .96rem; letter-spacing: -.01em; }
.history-toggle { color: var(--accent); white-space: nowrap; font-size: .78rem; padding: .28rem .5rem; }
.transcript { overflow-y: auto; min-height: 0; overscroll-behavior-y: contain; }
.chat-column { max-width: 49rem; margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2rem); }
.transcript .chat-column { min-height: 100%; padding-block: clamp(1.4rem, 4vw, 2.6rem) 1.45rem; }
.chat-empty { display: grid; place-items: center; min-height: 43dvh; text-align: center; }
.chat-empty h2 { font-size: clamp(1.5rem, 4vw, 2.15rem); letter-spacing: -.035em; }
.chat-turn { margin: 0 0 1.7rem; }
.chat-turn:last-child { margin-bottom: 0; }
.user-message { display: flex; justify-content: flex-end; margin-bottom: 1.15rem; }
.user-message p {
    width: fit-content;
    max-width: min(90%, 38rem);
    padding: .67rem .95rem;
    background: #efedf4;
    border-radius: 16px 16px 5px 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.assistant-message { font-size: .96rem; line-height: 1.7; overflow-wrap: anywhere; }
.model-label { display: block; margin-bottom: .42rem; color: var(--muted); font-size: .75rem; font-weight: 650; }
.answer > :first-child { margin-top: 0; }
.answer > * + * { margin-top: .72rem; }
.answer pre, .tool-call pre {
    max-width: 100%;
    padding: .7rem .85rem;
    border-radius: 7px;
    background: var(--sidebar);
    overflow: auto;
    font: .84rem/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
}
.answer :not(pre) > code { padding: .1rem .23rem; border-radius: 4px; background: var(--sidebar); }
.answer a, .cannot-resume a { color: var(--accent); }
.answer blockquote { margin-inline: 0; border-left: 3px solid var(--line); padding-left: .8rem; color: var(--muted); }
.answer h1, .answer h2, .answer h3 { font-size: 1.12rem; font-weight: 700; }
.tool-call { margin: .48rem 0 .65rem; border: 1px solid var(--line); border-radius: 9px; background: #fcfbfd; }
.tool-call summary { display: flex; align-items: center; gap: .45rem; padding: .43rem .62rem; cursor: pointer; }
.tool-call summary::after { content: '+'; flex: none; color: var(--muted); }
.tool-call[open] summary::after { content: '−'; }
.tool-symbol { border-radius: 5px; background: var(--selected); color: var(--accent); padding: 0 .3rem; font: .82rem/1.55 ui-monospace, monospace; }
.tool-state { margin-left: auto; color: var(--muted); font-size: .77rem; white-space: nowrap; }
.tool-state.running { color: var(--accent); }
.tool-state.failed, .chat-error { color: #98363f; }
.tool-call > div { padding: .32rem .65rem .55rem; border-top: 1px solid var(--line); }
.tool-call > div > span { color: var(--muted); font-size: .76rem; }
.tool-call pre { margin: .2rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.working { display: flex; align-items: center; gap: .48rem; margin: .5rem 0; color: var(--muted); font-size: .82rem; }
.working-bars { display: inline-flex; height: .9rem; align-items: center; gap: 3px; }
.working-bars i { width: 3px; height: 12px; border-radius: 3px; background: var(--accent); animation: work-pulse 1.1s ease-in-out infinite alternate; }
.working-bars i:nth-child(2) { animation-delay: .13s; }
.working-bars i:nth-child(3) { animation-delay: .26s; }
@keyframes work-pulse { 0%, 20% { transform: scaleY(.3); opacity: .45; } 80%, 100% { transform: scaleY(1); opacity: 1; } }
.chat-footer { background: var(--surface); padding-bottom: max(.95rem, env(safe-area-inset-bottom)); }
.chat-compose { border: 1px solid #dcd7e5; border-radius: 16px; padding: .56rem .63rem; background: var(--surface); box-shadow: 0 2px 10px #3328570a; }
.chat-compose:focus-within { border-color: #9787c9; }
.chat-compose textarea {
    display: block;
    width: 100%;
    border: 0;
    padding: .32rem .25rem;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    resize: none;
    field-sizing: content;
    min-height: 2.75rem;
    max-height: 24dvh;
}
.chat-compose textarea:focus-visible { outline: 0; }
.chat-compose textarea::placeholder { color: var(--muted); }
.compose-actions { display: flex; align-items: center; justify-content: space-between; gap: .55rem; }
.compose-actions select {
    max-width: 100%;
    padding: .3rem .5rem;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--sidebar);
    color: var(--text);
    font-family: inherit;
    font-size: .8rem;
}
.send-message {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 8px;
    color: #fff;
    font-size: 1.12rem;
    background: var(--accent);
    border-color: var(--accent);
}
.send-message:disabled { background: #dad5e3; border-color: #dad5e3; color: #66636e; cursor: default; }
.cannot-resume, .live-note { padding-top: .35rem; color: var(--muted); font-size: .79rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.mission-preview-note { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .65rem; margin-bottom: 1rem; color: var(--muted); font-size: .82rem; }
.mission-preview-note strong { color: var(--accent); border: 1px solid #ded5f1; background: #f2edf9; padding: .15rem .42rem; border-radius: 5px; font-weight: 600; }
.mission-grid { display: grid; grid-template-columns: 17rem minmax(0, 1fr); align-items: start; gap: 1rem; }
.mission-tree, .mission-detail { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); min-width: 0; }
.mission-tree > summary { padding: .82rem 1rem; cursor: pointer; font-size: .91rem; font-weight: 700; }
.mission-tree > summary::marker { color: var(--muted); font-size: .75rem; }
.mission-tree nav { padding: .25rem .55rem .9rem; border-top: 1px solid var(--line); }
.mission-tree ul, .mission-children, .mission-breadcrumbs ol { list-style: none; padding: 0; margin: 0; }
.mission-tree ul ul { border-left: 1px solid var(--line); margin-left: .46rem; padding-left: .68rem; }
.mission-tree li { margin: .14rem 0; }
.mission-tree li summary { padding: 0 .1rem; cursor: pointer; }
.mission-tree li summary::marker { color: #85749e; font-size: .73rem; }
.mission-tree-link {
    display: inline-flex;
    align-items: center;
    gap: .44rem;
    width: calc(100% - 1rem);
    border-radius: 7px;
    padding: .52rem .42rem;
    color: var(--text);
    text-decoration: none;
    font-size: .87rem;
    overflow-wrap: anywhere;
}
.mission-tree-link::before {
    content: '';
    width: .42rem;
    height: .42rem;
    flex: none;
    border: 1px solid #9b86b4;
    border-radius: 2px;
}
.mission-leaf .mission-tree-link { margin-left: .95rem; }
.mission-leaf .mission-tree-link::before { border-radius: 50%; width: .35rem; height: .35rem; }
.mission-tree-link:hover, .mission-tree-link[aria-current="page"] { background: var(--selected); color: var(--accent); }
.mission-tree-link[aria-current="page"] { font-weight: 680; }
.mission-tree-link[aria-current="page"]::before { background: var(--accent); border-color: var(--accent); }
.mission-detail-heading { padding: 1.2rem 1.35rem 1rem; }
.mission-breadcrumbs ol { display: flex; align-items: center; gap: .25rem .55rem; flex-wrap: wrap; color: var(--muted); font-size: .79rem; }
.mission-breadcrumbs li + li::before { content: '/'; margin-right: .55rem; color: #9a91a5; }
.mission-breadcrumbs a, .mission-meta a { color: var(--accent); text-underline-offset: .16em; text-decoration-thickness: 1px; }
.mission-detail h2 { font-size: clamp(1.32rem, 3vw, 1.9rem); margin: .42rem 0 .55rem; letter-spacing: -.025em; }
.mission-tags { display: flex; gap: .44rem; color: var(--muted); font-size: .77rem; }
.mission-tags span { background: var(--sidebar); border-radius: 5px; padding: .16rem .42rem; }
.mission-tags [data-mission-kind] { background: var(--selected); color: var(--accent); }
.mission-views { display: flex; gap: 1.2rem; padding: 0 1.35rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.mission-views a { text-decoration: none; color: var(--muted); font-size: .87rem; padding: .7rem .18rem .55rem; border-bottom: 2px solid transparent; }
.mission-views a:hover, .mission-views a[aria-current="page"] { color: var(--accent); }
.mission-views a[aria-current="page"] { font-weight: 650; border-color: var(--accent); }
.mission-section, .mission-empty { padding: 1.15rem 1.35rem; }
.mission-section-heading { display: flex; align-items: center; gap: .6rem; justify-content: space-between; margin-bottom: .6rem; }
.mission-section-heading h3 { flex: 1; }
.mission-preview-actions, .mission-editor-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.mission-preview-actions button, .mission-editor-actions button { font-size: .78rem; padding: .32rem .53rem; }
.mission-preview-actions button:hover { color: var(--accent); background: var(--sidebar); }
.mission-prompt { background: var(--sidebar); border: 1px solid var(--line); border-radius: 8px; padding: .82rem .95rem; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; line-height: 1.7; }
.mission-editor:not([hidden]) { display: grid; gap: .36rem; }
.mission-editor label { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.mission-editor input, .mission-editor select, .mission-editor textarea { width: 100%; font: inherit; font-size: .9rem; border: 1px solid var(--line); border-radius: 7px; padding: .44rem .56rem; background: var(--sidebar); color: var(--text); }
.mission-editor textarea { resize: vertical; }
.mission-editor-actions { margin-top: .35rem; }
.mission-draft-status { color: var(--muted); font-size: .8rem; margin-top: .45rem; }
.mission-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-block: 1px solid var(--line); }
.mission-meta > div { padding: .84rem 1.35rem; min-width: 0; }
.mission-meta > div + div { border-left: 1px solid var(--line); }
.mission-meta span { display: block; color: var(--muted); font-size: .76rem; margin-bottom: .21rem; }
.mission-meta p { font-size: .88rem; overflow-wrap: anywhere; }
.mission-children { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; margin-top: .6rem; }
.mission-children a { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; justify-content: space-between; min-height: 2.65rem; color: var(--text); background: var(--sidebar); border: 1px solid var(--line); border-radius: 7px; padding: .5rem .64rem; text-decoration: none; font-size: .8rem; }
.mission-children a:hover { color: var(--accent); border-color: #cebfed; }
.mission-children a > span { color: var(--muted); white-space: nowrap; font-size: .75rem; }
.mission-file-tree, .mission-conversations { margin-top: .63rem; }
.mission-folder, .mission-conversation { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .55rem; }
.mission-folder summary, .mission-file summary, .mission-conversation summary { cursor: pointer; font-size: .86rem; padding: .55rem .72rem; }
.mission-folder > summary { background: var(--sidebar); border-radius: 8px; }
.mission-folder summary::marker, .mission-file summary::marker, .mission-conversation summary::marker { color: var(--accent); }
.mission-file { margin-inline: .75rem; border-top: 1px solid var(--line); }
.mission-file pre { overflow: auto; margin: .07rem 0 .55rem; padding: .64rem .75rem; background: var(--sidebar); border-radius: 6px; font: .82rem/1.55 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.mission-file code { overflow-wrap: anywhere; }
.workspace-file-label { display: inline-block; margin-left: .48rem; color: var(--muted); font-size: .76rem; }
.workspace-empty { padding: .55rem .75rem; color: var(--muted); }
.mission-conversation p { padding: .6rem .72rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; }
.mission-empty { color: var(--muted); font-size: .88rem; }

@media (max-width: 740px) {
    .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: .45rem .55rem; padding: .52rem .75rem; }
    .topbar nav { grid-column: 1 / -1; display: flex; justify-content: space-between; flex-wrap: wrap; }
    .topbar nav a { flex: 1 0 auto; padding: .43rem .12rem; font-size: clamp(.75rem, 2.5vw, .84rem); text-align: center; }
    .logout { grid-area: 1 / 2; }
    .logout button { padding: .3rem .48rem; }
    .chat-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); position: relative; }
    .history-pane { max-height: 25dvh; }
    .chat-shell[data-history-ready] { grid-template-rows: minmax(0, 1fr); }
    .chat-shell[data-history-ready] .history-pane {
        position: absolute;
        inset: 3.3rem auto 0 0;
        z-index: 2;
        width: min(17rem, 86vw);
        max-height: none;
        visibility: hidden;
        transform: translateX(-100%);
        transition: transform .18s ease, visibility .18s;
        box-shadow: 8px 0 21px #25233319;
    }
    .chat-shell[data-history-open] .history-pane { visibility: visible; transform: translateX(0); }
    .conversation-header { padding-inline: .75rem; }
    .chat-column { padding-inline: .8rem; }
    .chat-footer { padding-bottom: max(.55rem, env(safe-area-inset-bottom)); }
    .mission-grid { grid-template-columns: minmax(0, 1fr); gap: .7rem; }
    .mission-tree nav { max-height: 12rem; overflow-y: auto; }
    .mission-detail-heading, .mission-section, .mission-empty { padding: .95rem .85rem; }
    .mission-views { padding-inline: .85rem; }
    .mission-meta > div { padding: .72rem .85rem; }
}

@media (prefers-reduced-motion: reduce) {
    .working-bars i { animation: none; }
    .working-bars i:nth-child(2) { transform: scaleY(.55); }
    .chat-shell[data-history-ready] .history-pane { transition: none; }
}

@media (max-width: 620px) {
    .gate, .app-content { padding: 1.25rem .8rem; }
    .panel-title { flex-wrap: wrap; gap: .25rem; }
    .gate .panel { padding: 1.3rem; }
    .table-wrap { position: relative; }
    table, tbody, tbody tr, tbody th { display: block; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    tbody tr { border-top: 1px solid var(--line); padding: .55rem 0; }
    tbody th, tbody td { border: 0; padding: .25rem .75rem; }
    tbody td { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: .5rem; }
    .mobile-label { display: block; color: var(--muted); font-size: .8rem; }
    .port-list li { grid-template-columns: 3.95rem 2rem minmax(0, 1fr); gap: .24rem; }
}

.task-form {
  display: grid;
  gap: .5rem;
  max-width: 42rem;
  margin-block: 0 1.25rem;
}

.task-form button { justify-self: start; }

.memory-grid {
    align-items: start;
}

.memory-reader {
    min-width: 0;
    overflow-wrap: anywhere;
}

.memory-heading,
.memory-copy,
.memory-children {
    padding: 1rem 1.2rem;
}

.memory-heading h2 { margin-top: .33rem; }
.memory-heading:has(+ .memory-copy) { border-bottom: 1px solid var(--line); }
.memory-copy > :first-child { margin-top: 0; }
.memory-copy > :last-child { margin-bottom: 0; }
.memory-copy p { margin-block: .65rem; }
.memory-copy a { color: var(--accent); text-underline-offset: .15em; }
.memory-copy pre { overflow: auto; }
.memory-copy ul, .memory-copy ol { padding-left: 1.45rem; }
.memory-children { margin-top: 0; }

@media (max-width: 740px) {
    .memory-grid { grid-template-columns: minmax(0, 1fr); }
    .memory-children { grid-template-columns: minmax(0, 1fr); }
}

.source-search {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.source-search input:not([type="hidden"]) {
    flex: 1 1 12rem;
    min-width: 8rem;
    padding: .45rem .6rem;
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.source-panel a {
    color: var(--accent);
    text-underline-offset: .15em;
}

.source-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .7rem 1.5rem;
    margin: 0;
    padding: .85rem 1.2rem;
    border-top: 1px solid var(--line);
    list-style: none;
}

.source-inbox-search {
    padding: 0 1.2rem;
}

.task-chat {
    display: grid;
    grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr);
    height: clamp(28rem, calc(100dvh - 14rem), 54rem);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--surface);
}

.thread-history {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--sidebar);
    border-right: 1px solid var(--line);
}

.thread-history-heading, .thread-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1rem;
    padding: .8rem 1rem;
}

.thread-history-heading h2, .thread-history [data-task-list-state] {
    color: var(--muted);
    font-size: .76rem;
}

.thread-history [aria-current="page"] [data-task-list-state] { color: var(--accent); }
.thread-conversation, .thread-body {
    display: grid;
    min-width: 0;
    min-height: 0;
}

.thread-conversation { grid-template-rows: minmax(0, 1fr) auto; }
.thread-body { grid-template-rows: auto minmax(0, 1fr); }
.thread-heading { border-bottom: 1px solid var(--line); padding: .85rem 1.2rem; }
.thread-heading h2 { overflow-wrap: anywhere; }
.thread-status {
    flex: none;
    padding: .15rem .45rem;
    border-radius: 6px;
    background: var(--sidebar);
    color: var(--muted);
    font-size: .73rem;
    font-weight: 600;
    white-space: nowrap;
}

.thread-status[data-state="running"], .thread-status[data-state="delegated"] {
    background: var(--selected);
    color: var(--accent);
}
.thread-status[data-state="succeeded"] { background: #eef6f2; color: #12604d; }
.thread-status[data-state="failed"], .thread-status[data-state="interrupted"] { background: #fbefef; color: #98363f; }
.thread-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.thread-messages, .thread-activity { max-width: 48rem; margin-inline: auto; padding-inline: clamp(.9rem, 3vw, 2rem); }
.thread-messages { list-style: none; margin-block: 0; padding-block: 1.3rem .8rem; }
.thread-activity { padding-bottom: .75rem; }
.thread-activity:empty { display: none; }
.thread-message { margin-block-end: 1.2rem; overflow-wrap: anywhere; scroll-margin-block: 1rem; }
.thread-message:last-child { margin-block-end: 0; }
.thread-message-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .15rem .43rem;
    margin-bottom: .35rem;
    color: var(--muted);
    font-size: .75rem;
}
.thread-message-meta strong { color: var(--text); font-weight: 650; }
.thread-message-meta time { font-size: .69rem; font-variant-numeric: tabular-nums; }
.thread-recipient { color: var(--accent); }
.thread-user, .thread-message.thread-dispatch { display: grid; justify-items: end; }
.thread-user .thread-message-meta, .thread-message.thread-dispatch .thread-message-meta { justify-content: end; }
.thread-user-body, .thread-message > .thread-delegation-card {
    width: fit-content;
    max-width: min(96%, 38rem);
    border-radius: 14px 14px 4px 14px;
    padding: .65rem .85rem;
}
.thread-user-body { background: #efedf4; white-space: pre-wrap; }
.thread-message.thread-dispatch > .thread-delegation-card { background: #f4f1fa; border: 1px solid #eae4f6; }
.thread-message > .thread-delegation-card > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: .3rem .65rem; }
.thread-message > .thread-delegation-card p { margin-top: .28rem; white-space: pre-wrap; font-size: .91rem; }
.thread-reply { padding: .5rem 0 .5rem .8rem; border-left: 2px solid #dcd5eb; max-width: 42rem; }
.thread-reply[data-state="failed"], .thread-reply[data-state="interrupted"] { border-color: #e8b7ba; }
.thread-reference { color: var(--accent); text-decoration: none; font-size: .78rem; font-weight: 600; }
.thread-reference::before { content: '↪ '; }
.thread-reference:hover { text-decoration: underline; }
.thread-reply p { margin-top: .22rem; white-space: pre-wrap; }
.thread-session { margin-top: .36rem; }
.thread-session code { font-size: inherit; }
.thread-summary small { margin-bottom: .25rem; }
.thread-progress { margin-block-end: .72rem; }
.thread-progress-body { color: var(--muted); margin: 0; font-size: .87rem; white-space: pre-wrap; }
.thread-notice { margin: 0; padding: .45rem 1.2rem; color: var(--muted); border-top: 1px solid var(--line); font-size: .8rem; }

@media (max-width: 740px) {
    .task-chat { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: clamp(26rem, calc(100dvh - 11rem), 46rem); }
    .thread-history { border-right: 0; border-bottom: 1px solid var(--line); overflow: hidden; }
    .thread-history-heading { padding: .55rem .75rem .35rem; }
    .thread-history .history-list { display: flex; padding: 0 .5rem .35rem; }
    .thread-history .history-list li { flex: none; max-width: min(80vw, 15rem); }
    .thread-history .history-list a { padding: .44rem .5rem; margin-right: .16rem; }
    .thread-heading { padding: .65rem .85rem; }
}

.inbox-layout { max-width: 55rem; margin-inline: auto; }
.inbox-filters { display: flex; flex-wrap: wrap; gap: .35rem; padding: .76rem 1rem; }
.inbox-filters a {
    padding: .32rem .55rem;
    border-radius: 7px;
    color: var(--muted);
    text-decoration: none;
    font-size: .82rem;
}
.inbox-filters a:hover, .inbox-filters a[aria-current="page"] { background: var(--selected); color: var(--accent); }
.inbox-filters a[aria-current="page"] { font-weight: 650; }
.inbox-items { list-style: none; margin: 0; padding: 0; }
.inbox-item { border-top: 1px solid var(--line); }
.inbox-item > a { display: block; padding: .85rem 1.15rem; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.inbox-item > a:hover { background: var(--sidebar); }
.inbox-item > a:focus-visible { outline-offset: -3px; }
.inbox-item-meta { display: flex; justify-content: space-between; gap: .4rem .8rem; flex-wrap: wrap; }
.inbox-item-meta span { color: var(--accent); font-size: .76rem; }
.inbox-item-meta time, .inbox-context { color: var(--muted); font-size: .77rem; }
.inbox-item strong { display: block; margin-top: .28rem; font-size: .94rem; }
.inbox-item p { margin-top: .28rem; font-size: .89rem; }
.inbox-context { margin-top: .15rem; }
.inbox-pagination { display: flex; justify-content: flex-end; align-items: baseline; gap: 1rem; border-top: 1px solid var(--line); padding: .6rem 1.15rem; }
.inbox-pagination .back-link { margin: 0; }
.inbox-empty { padding: 2.8rem 1.15rem; color: var(--muted); text-align: center; border-top: 1px solid var(--line); }
.inbox-health summary { padding: .75rem 1rem; cursor: pointer; font-size: .85rem; color: var(--muted); }
.inbox-checks { list-style: none; margin: 0; padding: 0 .95rem .55rem; }
.inbox-checks li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .3rem .8rem; padding: .41rem 0; border-top: 1px solid var(--line); font-size: .81rem; }
.inbox-checks strong { font-weight: 550; }
.inbox-checks span { color: var(--muted); }
.inbox-checks time { margin-left: .52rem; }
.inbox-feedback { margin-top: .6rem; }
