@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-wght-normal.woff2') format('woff2');
}
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url('fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2');
}

:root {
    --bg: #0f1115;
    --surface: #171a21;
    --chip: #1f242d;
    --text: #eef1f6;
    --muted: #a4acba;
    --faint: #727b8b;
    --line: #262b35;
    --line-strong: #464e5c;
    --accent: #b9a3f5;
    --accent-soft: #2a2240;
    --on-accent: #100d18;
    --ok: #86efac;
    --bad: #fda29b;
    --warn: #fdba74;
    --ok-soft: #173322;
    --bad-soft: #3d1f1f;
    --green: #86efac;
    --blue: #93c5fd;
    --sky: #7dd3fc;
    --teal: #5eead4;
    --pink: #f9a8d4;
    --orange: #fdba74;
    --amber: #fcd34d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 16px 40px -16px rgba(0, 0, 0, .6);
    --radius: 12px;
    --radius-lg: 16px;
    --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
    color-scheme: dark;
}
[data-theme="light"] {
    --bg: #f9fafb;
    --surface: #ffffff;
    --chip: #f2f4f7;
    --text: #0b1220;
    --muted: #5b6474;
    --faint: #7f8898;
    --line: #e7e9ee;
    --line-strong: #c3c8d1;
    --accent: #7c5cd6;
    --accent-soft: #f1ecfb;
    --on-accent: #ffffff;
    --ok: #15803d;
    --bad: #b42318;
    --warn: #c2410c;
    --ok-soft: #dcf3e3;
    --bad-soft: #fde4e1;
    --green: #15803d;
    --blue: #1d4ed8;
    --sky: #0369a1;
    --teal: #0f766e;
    --pink: #be185d;
    --orange: #c2410c;
    --amber: #8f5706;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 32px -12px rgba(16, 24, 40, .14);
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--text); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.kind-commit { --k: var(--green); }
.kind-pr { --k: var(--blue); }
.kind-email { --k: var(--orange); }
.kind-post { --k: var(--pink); }
.kind-message { --k: var(--amber); }
.kind-any { --k: var(--muted); }

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    gap: .25rem 1.75rem;
    min-height: 60px;
    padding: .5rem 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--text); letter-spacing: -.01em; background: none; border: 0; }
.brand .r { color: var(--accent); }
.tabs { display: flex; gap: .25rem; }
.tabs button {
    display: inline-flex; align-items: center; gap: .45rem;
    min-height: 38px; padding: 0 .7rem; border-radius: 10px;
    font-size: 15px; color: var(--muted); background: none; border: 0;
    text-underline-offset: 6px; text-decoration-thickness: 2px;
}
.tabs button:hover { color: var(--text); background: var(--chip); }
.tabs button[aria-current="page"] { color: var(--text); text-decoration: underline; text-decoration-color: var(--accent); }
.count {
    display: inline-block; min-width: 1.45rem; padding: 0 .4rem;
    border-radius: 999px; background: var(--accent-soft); color: var(--accent);
    font-size: 12px; font-weight: 600; line-height: 1.45rem; text-align: center;
    transition: transform .25s;
}
.count.bump { transform: scale(1.25); }
.tools { display: flex; gap: .5rem; margin-left: auto; align-items: center; }
.icon-btn {
    display: inline-grid; place-items: center; width: 38px; height: 38px;
    border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-moon, [data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px;
}

/* Page */
.wrap { max-width: 1400px; margin: 0 auto; padding: 16px 24px 80px; }
.view-head { display: flex; align-items: end; gap: 24px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 30px; font-weight: 400; letter-spacing: -.02em; line-height: 1.1; }
.page-title .slash { color: var(--accent); font-family: var(--mono); font-weight: 500; }
.stats { display: flex; margin-left: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.stat { padding: 8px 18px; min-width: 112px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat dt { font-size: 12px; color: var(--muted); }
.stat dd { font-family: var(--mono); font-size: 20px; font-weight: 500; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat dd small { font-family: var(--sans); font-size: 12px; color: var(--faint); font-weight: 400; margin-left: 4px; }
.stat dd.tick { animation: tick .5s ease; }
@keyframes tick { 0% { color: var(--accent); transform: translateY(-3px); } 100% { color: var(--text); transform: none; } }
.stat-ok dd { color: var(--text); }

.inbox { display: grid; grid-template-columns: 330px minmax(0, 1fr) 310px; gap: 18px; align-items: start; }

/* Queue */
.queue { position: sticky; top: 78px; }
.subtabs { display: flex; gap: 4px; margin-bottom: 10px; }
.subtabs button {
    background: none; border: 0; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 14px;
    display: inline-flex; gap: 6px; align-items: center;
}
.subtabs button[aria-pressed="true"] { color: var(--text); background: var(--chip); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--muted); font-size: 13px; line-height: 1.6;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--k); }
.chip.kind-any::before { display: none; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.chip .n { color: var(--faint); font-family: var(--mono); font-size: 12px; }

.rows {
    list-style: none; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
    max-height: calc(100vh - 250px); overflow-y: auto;
}
.row { overflow: hidden; transition: height .35s ease, opacity .3s ease; }
.row + .row { border-top: 1px solid var(--line); }
.row button {
    display: grid; gap: 5px; width: 100%; text-align: left; padding: 12px 16px;
    background: none; border: 0; color: var(--text); position: relative;
}
.row button:hover { background: var(--chip); }
.row button[aria-current="true"] { background: var(--chip); }
.row button[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.row-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 14.5px; }
.row-meta { display: flex; align-items: center; gap: 4px 10px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.row-meta .agent { color: var(--text); opacity: .85; }
.row-meta time { margin-left: auto; color: var(--faint); font-family: var(--mono); font-size: 12px; }
.kind-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 0 9px;
    border: 1px solid var(--line); border-radius: 999px; color: var(--muted); line-height: 1.6;
}
.kind-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--k); }
.status { font-size: 12px; font-weight: 500; }
.status-approved { color: var(--ok); }
.status-edited { color: var(--accent); }
.status-rejected { color: var(--bad); }

.row.leave-ok { animation: leaveOk .55s ease forwards; }
.row.leave-bad { animation: leaveBad .55s ease forwards; }
@keyframes leaveOk { 0% { background: var(--surface); } 30% { background: var(--ok-soft); transform: none; opacity: 1; } 100% { background: var(--ok-soft); transform: translateX(40px); opacity: 0; } }
@keyframes leaveBad { 0% { background: var(--surface); } 30% { background: var(--bad-soft); transform: none; opacity: 1; } 100% { background: var(--bad-soft); transform: translateX(-40px); opacity: 0; } }
.row.enter { animation: enter .4s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.empty { padding: 28px 20px; color: var(--muted); font-size: 14px; }
.empty strong { display: block; color: var(--text); font-weight: 500; font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* Review */
.review { min-width: 0; scroll-margin-top: 112px; }
.review-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.review-card.swap { animation: swap .35s ease; }
@keyframes swap { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.back { display: none; background: none; border: 0; color: var(--accent); font-size: 14px; padding: 4px 0; margin-bottom: 10px; gap: 6px; align-items: center; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 26px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.fact dt { font-size: 12px; color: var(--muted); }
.fact dd { font-size: 14px; font-weight: 500; }
.fact .kind-name { color: var(--k); }
.fact .run { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; padding: 1px 6px; background: var(--chip); border-radius: 5px; }
.fact .mono { font-family: var(--mono); font-size: 13px; font-weight: 400; }

.why { margin: 14px 20px 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 13.5px; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
.why svg { flex: none; margin-top: 3px; color: var(--accent); }

.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px 20px 6px; }
.pane { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); min-width: 0; display: flex; flex-direction: column; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.pane-head .tag { font-family: var(--mono); font-size: 11.5px; padding: 0 6px; border-radius: 5px; }
.pane-agent .tag { background: var(--bad-soft); color: var(--bad); }
.pane-rewrite .tag { background: var(--ok-soft); color: var(--ok); }
.pane-head .words { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.pane-body { padding: 12px 14px 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.65; flex: 1; }
.pane-agent .pane-body { color: var(--muted); }
.pane-body del { background: var(--bad-soft); color: var(--text); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 70%, transparent); border-radius: 3px; }
.pane-body ins { background: var(--ok-soft); color: var(--text); text-decoration: none; border-radius: 3px; }
.pane-body code { font-family: var(--mono); font-size: 13px; }
.pane-rewrite.editing { border-color: var(--accent); }
.pane-rewrite textarea {
    flex: 1; width: 100%; min-height: 220px; resize: vertical; border: 0; background: transparent;
    padding: 12px 14px 14px; font-size: 14.5px; line-height: 1.65; color: var(--text); outline: none;
}
.edit-note { font-size: 12px; color: var(--accent); margin-left: auto; }

.checks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 20px 14px; font-size: 12.5px; color: var(--muted); }
.checks .ok { color: var(--ok); display: inline-flex; gap: 5px; align-items: center; }
.checks .kept { font-family: var(--mono); font-size: 12px; padding: 0 7px; border-radius: 5px; background: var(--chip); color: var(--text); }
.removed { margin: 0 20px 14px; padding: 8px 12px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--line-strong); font-size: 13px; color: var(--muted); }
.removed del { color: var(--faint); }

.actionbar {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; gap: 10px; align-items: center; padding: 14px 20px;
    border-top: 1px solid var(--line); background: var(--surface);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.actionbar .hint { font-size: 12.5px; color: var(--faint); margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 0 16px; border-radius: 10px;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-weight: 500; font-size: 14.5px;
    white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn kbd { font-family: var(--mono); font-size: 11px; color: var(--faint); font-weight: 400; }
.btn-approve { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-approve:hover { filter: brightness(1.08); }
.btn-approve kbd { color: color-mix(in srgb, var(--on-accent) 60%, transparent); }
.btn-reject { color: var(--bad); }
.btn-reject:hover { border-color: var(--bad); }
.btn-ghost { border-color: transparent; color: var(--muted); }
.decided { padding: 14px 20px; border-top: 1px solid var(--line); font-size: 14px; }
.decided.approved { color: var(--ok); }
.decided.edited { color: var(--accent); }
.decided.rejected { color: var(--bad); }

/* Side */
.side { display: grid; gap: 18px; position: sticky; top: 78px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; }
.panel-title { font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--muted); text-transform: uppercase; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.panel-title .more { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12.5px; color: var(--accent); background: none; border: 0; }
.ctx-sec + .ctx-sec { margin-top: 10px; }
.ctx-sec h3 { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.ctx-sec p { font-size: 13.5px; color: var(--muted); }
.rules { list-style: none; display: grid; gap: 10px; }
.rule { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13.5px; }
.rule .what { color: var(--text); }
.rule .what q { font-family: var(--mono); font-size: 12.5px; quotes: none; color: var(--accent); }
.rule .from { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--faint); }
.rule .from::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--k); }
.bar { width: 48px; height: 4px; border-radius: 4px; background: var(--chip); overflow: hidden; align-self: center; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .6s ease; }
.rule.new { animation: newrule 1.6s ease; border-radius: 8px; }
@keyframes newrule { 0%, 40% { background: var(--accent-soft); box-shadow: 0 0 0 6px var(--accent-soft); } 100% { background: transparent; box-shadow: 0 0 0 6px transparent; } }
.voice-sum { font-size: 12.5px; color: var(--faint); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.voice-sum b { color: var(--text); font-weight: 500; font-family: var(--mono); font-size: 12px; }

/* Writing and settings views */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.source h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; display: flex; gap: 10px; align-items: center; }
.source p { font-size: 14px; color: var(--muted); }
.source .big { font-family: var(--mono); font-size: 24px; color: var(--text); margin: 10px 0 2px; }
.lock-list { list-style: none; display: grid; gap: 8px; margin-top: 8px; }
.lock-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.lock-list li span { font-family: var(--mono); font-size: 13px; }
.lock-list .kind-pill { font-family: var(--sans); font-size: 12px; margin-left: auto; }
.lead { font-size: 15px; color: var(--muted); max-width: 70ch; margin-bottom: 18px; }
.opts { display: grid; gap: 10px; margin-top: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin-top: 4px; accent-color: var(--accent); }
.opt b { display: block; font-weight: 600; font-size: 14.5px; }
.opt span { font-size: 13.5px; color: var(--muted); }
.agents-list { list-style: none; display: grid; gap: 8px; margin-top: 10px; }
.agents-list li { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.agents-list li:last-child { border-bottom: 0; }
.dot-on { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.agents-list .meta { margin-left: auto; font-size: 12.5px; color: var(--faint); font-family: var(--mono); }

/* Dialog and toast */
dialog { margin: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); padding: 22px; width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 6, 10, .6); }
dialog h2 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
dialog p { font-size: 14px; color: var(--muted); margin-bottom: 14px; }
dialog label { font-size: 13px; display: block; margin-bottom: 6px; }
dialog textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg); padding: 10px 12px; font-size: 14px; resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
    display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-radius: 12px;
    background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
    transition: opacity .25s, transform .25s; z-index: 50; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.toast.bad i { background: var(--bad); }

.ribbon {
    position: fixed; right: 14px; bottom: 14px; z-index: 40;
    font-family: var(--mono); font-size: 11.5px; padding: 4px 10px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--line-strong); color: var(--muted); opacity: .9;
}
.ribbon:hover { color: var(--text); border-color: var(--accent); }

/* Responsive */
@media (max-width: 1240px) {
    .inbox { grid-template-columns: 300px minmax(0, 1fr); }
    .side { grid-column: 2; position: static; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1080px) {
    .panes { grid-template-columns: 1fr; }
    .pane-rewrite { order: -1; }
}
@media (max-width: 820px) {
    .topbar { padding: .5rem 16px; gap: .25rem 1rem; flex-wrap: wrap; }
    .tabs { order: 3; width: 100%; overflow-x: auto; margin: 0 -8px; }
    .tabs button { font-size: 14px; white-space: nowrap; }
    .wrap { padding: 16px 16px 90px; }
    .view-head { gap: 14px; }
    .page-title { font-size: 26px; }
    .stats { margin-left: 0; width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); }
    .stat { min-width: 0; padding: 8px 10px; }
    .stat dd { font-size: 17px; }
    .stat dd small { display: none; }
    .inbox { grid-template-columns: 1fr; }
    .queue { position: static; }
    .rows { max-height: none; }
    .inbox.reading .queue { display: none; }
    .inbox:not(.reading) .review, .inbox:not(.reading) .side { display: none; }
    .side { grid-column: 1; grid-template-columns: 1fr; }
    .back { display: inline-flex; }
    .facts { gap: 8px 18px; padding: 14px 16px; }
    .panes { padding: 14px 14px 4px; }
    .checks { padding: 8px 16px 12px; }
    .removed { margin: 0 16px 12px; }
    .why { margin: 12px 16px 0; }
    .actionbar { position: sticky; bottom: 0; padding: 12px 14px; flex-wrap: wrap; z-index: 5; box-shadow: 0 -10px 24px -12px rgba(0,0,0,.4); }
    .actionbar .hint { display: none; }
    .actionbar .btn { flex: 1; padding: 0 10px; }
    .btn kbd { display: none; }
    .ribbon { bottom: auto; top: 12px; right: 112px; font-size: 10.5px; padding: 3px 8px; }
}
@media (max-width: 420px) {
    .stat dt { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
