:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --text: #1d2330;
    --muted: #6b7385;
    --line: #dfe2e8;
    --accent: #b5482b;
    --accent-dark: #8f3720;
    --ok: #2f7d4f;
    --warn: #a86b00;
    --bad: #b3261e;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14161b;
        --panel: #1d2027;
        --text: #e6e8ec;
        --muted: #9aa1ae;
        --line: #2e323b;
        --accent: #e0714f;
        --accent-dark: #c45c3c;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

header.top .brand { font-weight: 700; font-size: 16px; color: var(--text); }
header.top nav { display: flex; gap: 16px; }
header.top .who { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); }

main { max-width: 1180px; margin: 24px auto; padding: 0 16px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px 18px;
    margin-bottom: 16px;
}

.row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.row > .grow { flex: 1 1 380px; min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    border: 1px solid var(--line);
    white-space: nowrap;
}

.badge.InProgress, .badge.Open, .badge.Running, .badge.Queued { color: var(--warn); border-color: currentColor; }
.badge.Testing { color: #2b6cb0; border-color: currentColor; }
.badge.Ready, .badge.Committed, .badge.Succeeded, .badge.Released { color: var(--ok); border-color: currentColor; }
.badge.Abandoned, .badge.Failed { color: var(--bad); border-color: currentColor; }

form.inline { display: inline; }

label { display: block; font-weight: 600; margin: 10px 0 4px; }

input[type=text], input[type=password], textarea, select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

textarea { min-height: 110px; resize: vertical; }

button, .button {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button:hover, .button:hover { background: var(--accent-dark); text-decoration: none; }

button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 400; }
button:disabled { opacity: .5; cursor: default; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid; }
.flash.error { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.flash.ok { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }

pre {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    overflow: auto;
    max-height: 520px;
    margin: 6px 0 0;
}

.login { max-width: 360px; margin: 80px auto; }

.hermes {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 14px;
    color: var(--muted);
    background: var(--bg);
}

details > summary { cursor: pointer; color: var(--accent); }

main.wide { max-width: none; margin: 0; padding: 0; }
body.wide { overflow: hidden; }

.small { font-size: 12.5px; }
button.small { padding: 4px 10px; }
.spacer { flex: 1; }

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    height: calc(100vh - 47px);
}

.chat-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid var(--line);
}

.chat-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.crumbs { display: flex; gap: 8px; align-items: center; min-width: 0; }
.crumbs strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.agent-state { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.agent-state.working { color: var(--warn); font-weight: 600; }
.agent-state.working::before { content: "● "; animation: pulse 1.2s infinite; }
.agent-state.offline { color: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

.chat-pane .flash { margin: 12px 20px 0; }

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-empty { margin: auto; max-width: 520px; text-align: center; }
.chat-empty h2 { font-size: 18px; }

.msg { max-width: 860px; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.msg .text { white-space: pre-wrap; word-break: break-word; }

.msg.user {
    align-self: flex-end;
    background: color-mix(in srgb, var(--accent) 10%, var(--panel));
    border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
    border-radius: 10px 10px 2px 10px;
    padding: 8px 12px;
}

.msg.user.queued { opacity: .7; border-style: dashed; }

.msg.agent {
    align-self: flex-start;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px 10px 10px 2px;
    padding: 10px 14px;
}

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md pre { max-height: 420px; }
.md code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }

.item { align-self: flex-start; max-width: 860px; font-size: 13px; }
.item summary { cursor: pointer; color: var(--muted); list-style: none; }
.item summary::-webkit-details-marker { display: none; }
.item.reasoning .text { white-space: pre-wrap; color: var(--muted); font-style: italic; padding: 4px 0 0 14px; }
.item.command summary code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; color: var(--text); }
.item.command .icon { display: inline-block; width: 16px; color: var(--ok); }
.item.command.in_progress .icon { color: var(--warn); }
.item.command.failed .icon, .item.command .exit { color: var(--bad); }
.item.command pre { margin-left: 16px; max-height: 300px; font-size: 12px; }
.item.files, .item.todo { border-left: 3px solid var(--line); padding-left: 10px; }
.item.files .label, .item.todo .label { color: var(--muted); font-size: 12px; }
.item.files ul, .item.todo ul { margin: 2px 0; padding-left: 16px; }
.item.files .kind { font-size: 11px; color: var(--muted); }
.item.files .kind.add { color: var(--ok); }
.item.files .kind.delete { color: var(--bad); }
.item.files.failed { border-left-color: var(--bad); }
.item.todo li.done { color: var(--muted); text-decoration: line-through; }
.item.error { color: var(--bad); }
.item.system { color: var(--muted); font-style: italic; }
.item.turnend { align-self: center; color: var(--muted); font-size: 11.5px; }

.queue { display: flex; flex-direction: column; gap: 6px; padding: 0 20px; }
.queue:empty { display: none; }
.queue .msg.user { align-self: flex-end; }

.composer {
    border-top: 1px solid var(--line);
    background: var(--panel);
    padding: 12px 20px 14px;
}

.composer textarea { min-height: 64px; max-height: 260px; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

.side { overflow-y: auto; padding: 14px; background: var(--bg); }
.side .card { padding: 12px 14px; margin-bottom: 12px; }
.side h2 { font-size: 14px; margin: 0; }
.side .actions { margin-top: 8px; }
.mini-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.mini-row:last-child { border-bottom: none; }
.pending-files { max-height: 200px; overflow-y: auto; font-size: 11.5px; margin: 8px 0; white-space: pre; }
.pending-files .repo { font-weight: 700; margin-top: 4px; font-family: inherit; }

@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; height: auto; }
    body.wide { overflow: auto; }
    .chat-pane { height: 80vh; }
}

.device-code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 26px; font-weight: 700; letter-spacing: 3px; color: var(--text); }
.agent-hint { padding: 8px 20px; background: color-mix(in srgb, var(--warn) 10%, var(--panel)); border-bottom: 1px solid var(--line); font-size: 13px; }

[hidden] { display: none !important; }

.chat-pane { min-height: 0; }
.chat-log { min-height: 0; }
.item.command.interrupted .icon { color: var(--muted); }

.qr svg { width: 200px; height: 200px; background: #fff; padding: 6px; border-radius: 6px; }
