/* The console's one stylesheet. Tokens first; dark follows the system unless the user picked (data-theme). */
:root {
	--bg: #faf9f7; --panel: #ffffff; --sunk: #f2f0ec; --line: #e4e1db; --text: #1f1d1a; --muted: #6f6a62;
	--accent: #c2410c; --accent-ink: #ffffff; --info: #2563eb; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
	--info-bg: #e8effd; --ok-bg: #e6f4ea; --warn-bg: #fdf1e0; --bad-bg: #fbe9e9; --add: #e6f4ea; --del: #fbe9e9;
	--radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	--sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #161513; --panel: #1e1d1a; --sunk: #12110f; --line: #33302b; --text: #ece9e4; --muted: #a29c92;
		--accent: #f97316; --accent-ink: #1a0f06; --info: #7aa7ff; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
		--info-bg: #1b2740; --ok-bg: #15301f; --warn-bg: #3a2a10; --bad-bg: #3a1616; --add: #15301f; --del: #3a1616;
		--shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
		color-scheme: dark;
	}
}
:root[data-theme="dark"] {
	--bg: #161513; --panel: #1e1d1a; --sunk: #12110f; --line: #33302b; --text: #ece9e4; --muted: #a29c92;
	--accent: #f97316; --accent-ink: #1a0f06; --info: #7aa7ff; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
	--info-bg: #1b2740; --ok-bg: #15301f; --warn-bg: #3a2a10; --bad-bg: #3a1616; --add: #15301f; --del: #3a1616;
	--shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
	color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
h2 { font-size: 18px; margin: 18px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
h4 { font-size: 13px; margin: 12px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.error { color: var(--bad); }
.boot { padding: 40px; color: var(--muted); }
[hidden] { display: none !important; }

button, .button, input, textarea, select {
	font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
}
input, textarea, select { padding: 6px 8px; width: 100%; }
textarea { resize: vertical; }
button, .button { padding: 5px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover:not(:disabled), .button:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
button.link { border: 0; background: none; padding: 0 4px; color: var(--info); }
button.icon { padding: 4px 8px; }
button.small { padding: 2px 8px; font-size: 12px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 6px; }
label.inline input { width: auto; }

.chip { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 11.5px; line-height: 18px; background: var(--sunk); color: var(--muted); border: 1px solid var(--line); margin-right: 4px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.info, .chip.model { background: var(--info-bg); color: var(--info); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn, .dot.held { background: var(--warn); }
.dot.info, .dot.run { background: var(--info); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.info, .dot.run { animation: none; } }

/* sign-in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.signin-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.signin-form { display: grid; gap: 12px; margin-top: 12px; }
.brand { font-weight: 650; font-size: 16px; color: var(--text); }
.logo { color: var(--accent); }
.mock-note { background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 6px; font-size: 12.5px; }

/* the shell */
.shell { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top .menu { display: none; }
.top .spacer { flex: 1; }
.views { display: flex; gap: 2px; overflow-x: auto; }
.views a { padding: 4px 10px; border-radius: 6px; color: var(--muted); }
.views a.active { background: var(--sunk); color: var(--text); }
.bell { position: relative; padding: 2px 6px; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; line-height: 18px; text-align: center; }
.bell .badge { position: absolute; top: -6px; right: -8px; }
details.user { position: relative; }
details.user summary { cursor: pointer; list-style: none; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); }
.menu-pop { position: absolute; right: 0; top: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; box-shadow: var(--shadow); z-index: 5; }
.body { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 0; overflow: hidden; }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 10px; overflow-y: auto; display: grid; align-content: start; gap: 8px; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.side-head h3 { margin: 0; }
.group-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 4px 4px; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.side li a:hover { background: var(--sunk); text-decoration: none; }
.side li.active a { background: var(--sunk); box-shadow: inset 2px 0 var(--accent); }
.side .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .when { font-size: 11px; }
.main { overflow-y: auto; min-width: 0; outline: none; }
.view { padding: 0 20px 24px; max-width: 1200px; margin: 0 auto; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
ul.plain li.active { font-weight: 600; }

/* home */
ul.attention { list-style: none; padding: 0; display: grid; gap: 8px; }
ul.attention li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; border-left: 3px solid var(--warn); }
ul.attention li .button { grid-row: 1 / span 2; grid-column: 2; }
ul.notes { list-style: none; padding: 0; display: grid; gap: 4px; }
.note a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); border: 1px solid transparent; }
.note a:hover { background: var(--panel); border-color: var(--line); text-decoration: none; }
.note.unread a { background: var(--panel); border-color: var(--line); }
.note.unread strong::before { content: "● "; color: var(--accent); }
.note.read { opacity: .7; }
.note .addr { font-size: 11px; font-family: var(--mono); }

/* session */
.view:has(> .session) { max-width: none; padding: 0; height: 100%; }
.session { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; height: 100%; min-height: 0; }
.session-head { padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); display: grid; gap: 4px; }
.session-head .title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.session-head h2 { margin: 0; font-size: 16px; }
.session-head .sub { font-size: 12.5px; display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.session-head .task { color: var(--text); }
.usage { display: inline-flex; gap: 8px; font-family: var(--mono); font-size: 11.5px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
.stream-state { font-size: 11px; color: var(--muted); }
.stream-state.open::before { content: "● "; color: var(--ok); }
.stream-state.reconnecting { color: var(--warn); }
.pendingbar { padding: 6px 20px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.session-body { display: grid; grid-template-columns: 1fr 280px; min-height: 0; }
.transcript { overflow-y: auto; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.session-side { border-left: 1px solid var(--line); padding: 0 14px; overflow-y: auto; background: var(--panel); }
.composer { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; padding: 10px 20px; border-top: 1px solid var(--line); background: var(--panel); align-items: end; }
.composer select { width: auto; }

/* transcript rows */
.ev { max-width: 900px; width: 100%; }
.ev.start { padding: 10px 14px; background: var(--sunk); border-radius: var(--radius); }
.ev.start .task { font-weight: 600; margin-bottom: 6px; }
.ev.turn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.ev.turn::before, .ev.turn::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.ev.assistant { line-height: 1.6; }
.ev.assistant.streaming .stream { white-space: pre-wrap; }
.ev.assistant.streaming .stream::after { content: "▍"; color: var(--accent); animation: pulse 1s steps(2) infinite; }
.md code { background: var(--sunk); padding: 1px 4px; border-radius: 4px; }
.md pre.code { background: var(--sunk); padding: 8px 10px; border-radius: 6px; margin: 6px 0; overflow-x: auto; }
.ev.sys { display: flex; gap: 8px; color: var(--muted); font-size: 12.5px; align-items: baseline; }
.ev.sys .ic { width: 16px; text-align: center; flex: none; }
.ev.sys .txt { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; }
details.ev { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
details.ev > summary { cursor: pointer; padding: 6px 10px; display: flex; gap: 8px; align-items: center; list-style: none; min-width: 0; }
details.ev > summary::-webkit-details-marker { display: none; }
details.ev > summary::before { content: "▸"; color: var(--muted); font-size: 10px; }
details.ev[open] > summary::before { content: "▾"; }
.tool .name { font-family: var(--mono); font-weight: 600; }
.tool .args { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.toolbody, details.ev > pre.json { padding: 8px 12px 10px; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.toolbody .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
pre.out, pre.json, pre.args { background: var(--sunk); padding: 6px 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
.generic .kind { font-family: var(--mono); font-size: 12px; }
.generic summary .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.ev.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; background: var(--panel); display: grid; gap: 8px; }
.ev.card.pending { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.ev.card.allowed { border-left: 3px solid var(--ok); }
.ev.card.denied { border-left: 3px solid var(--bad); }
.ev.card .form { display: grid; gap: 6px; }
.ev.card .buttons, .dialog .buttons, .decide { display: flex; gap: 6px; flex-wrap: wrap; }
.ev.card .why { margin: 0; color: var(--muted); }
.ev.card .rule { font-family: var(--mono); }
.options { display: grid; gap: 4px; }
.option { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.option input { width: auto; }
.bubble { padding: 8px 12px; border-radius: 12px; max-width: 720px; }
.bubble .who { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bubble.mine { align-self: flex-end; background: var(--info-bg); }
.bubble.guidance { background: var(--warn-bg); }
.bubble.other, .bubble.out { background: var(--sunk); }
.ev.end { padding: 10px 14px; border-radius: var(--radius); background: var(--sunk); }
.ev.end.ok { border-left: 3px solid var(--ok); } .ev.end.bad { border-left: 3px solid var(--bad); }
.ev.error { padding: 8px 12px; border-radius: var(--radius); background: var(--bad-bg); color: var(--bad); }

/* plan */
.plan-head { font-weight: 600; margin: 4px 0 8px; }
ol.todos { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
ol.todos li { display: flex; gap: 8px; }
ol.todos li.completed { color: var(--muted); text-decoration: line-through; }
ol.todos li.in_progress { font-weight: 600; }
ol.todos li.in_progress .ic { color: var(--info); }
ol.todos li.completed .ic { color: var(--ok); }

/* registry, feed */
details.principal { margin: 8px 0; }
details.principal > summary { cursor: pointer; padding: 6px 0; }
ul.agents { list-style: none; padding: 0 0 0 12px; display: grid; gap: 8px; }
li.agent { border-left: 2px solid var(--line); padding-left: 10px; }
ul.sessions { list-style: none; padding: 4px 0 0 8px; display: grid; gap: 2px; font-size: 13px; }
ol.feed { list-style: none; padding: 0; display: grid; gap: 4px; font-size: 13px; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0; }
dt { color: var(--muted); }
dd { margin: 0; min-width: 0; }

/* definitions */
.filters { display: flex; gap: 8px; align-items: end; }
.filters label { min-width: 220px; }
.filters select { width: auto; }
ul.crs { list-style: none; padding: 0; display: grid; gap: 6px; }
li.cr a { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); }
li.cr a:hover { text-decoration: none; border-color: var(--muted); }
li.cr.active a { border-color: var(--accent); }
.cr-detail .head { display: flex; align-items: center; gap: 8px; }
.cr-detail .head h3 { margin: 0; }
.change { margin: 10px 0; }
pre.diff { background: var(--sunk); border-radius: 6px; padding: 6px 0; overflow-x: auto; margin-top: 6px; }
pre.diff span { display: block; padding: 0 10px; }
pre.diff .add { background: var(--add); }
pre.diff .del { background: var(--del); }
pre.diff .hunk { color: var(--info); }
ul.checks { list-style: none; padding: 0; display: grid; gap: 2px; }
ul.checks .ok { color: var(--ok); } ul.checks .bad { color: var(--bad); }
.decide input { flex: 1; min-width: 180px; }
.rule { color: var(--warn); margin: 0; width: 100%; }

/* dialogs, palette, toasts */
.dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 18px 20px; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(0 0 0 / .35); }
.dialog form { display: grid; gap: 10px; }
.dialog h2 { margin: 0 0 4px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.palette { padding: 8px; top: 12vh; margin-top: 0; }
.palette-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.palette-list li { padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.palette-list li.sel { background: var(--sunk); }
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 6px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

/* phone width */
@media (max-width: 760px) {
	.top { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
	.top .menu { display: inline-flex; }
	.views { order: 10; width: 100%; }
	.body { grid-template-columns: 1fr; }
	.side { position: fixed; inset: 0 20% 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
	body.side-open .side { transform: none; }
	.view { padding: 0 16px 20px; }
	.split, .grid3 { grid-template-columns: 1fr; }
	.session-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
	.session-side { border-left: 0; border-top: 1px solid var(--line); max-height: 28vh; }
	.session-head, .transcript, .composer, .pendingbar { padding-left: 16px; padding-right: 16px; }
	.composer { grid-template-columns: 1fr auto; }
	.composer select { grid-column: 1 / -1; }
	.filters { flex-wrap: wrap; }
	.filters label { min-width: 0; flex: 1; }
}

/* lane L13: the propose form, budgets and usage */
details.propose { margin: 8px 0 16px; }
details.propose > summary { cursor: pointer; color: var(--accent); }
.propose-form { display: grid; gap: 8px; margin-top: 8px; max-width: 760px; }
.propose-form .row { display: flex; gap: 8px; flex-wrap: wrap; }
.propose-form textarea { font-family: var(--mono); width: 100%; }
.limits li { margin-bottom: 8px; }
.meter { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.meter > span { display: block; height: 100%; background: var(--accent); }
table.usage-table { border-collapse: collapse; width: 100%; max-width: 760px; }
table.usage-table th, table.usage-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--line); }
