/* Braid design tokens and components. Light first, dark by preference or data-theme. */
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/IBMPlexSans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/IBMPlexSans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/fonts/IBMPlexSans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/IBMPlexMono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/IBMPlexMono-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --surface-000: #f6f3ee; --surface-100: #ffffff; --surface-200: #ffffff; --surface-300: #edeae4;
  --ink: #0f1420; --ink-muted: #4a5263; --ink-inverse: #f3ece3;
  --brand: #f6821f; --brand-strong: #d96d0f; --brand-text: #b4530a; --brand-soft: #fef0e2; --on-brand: #0f1420; --amber: #fbad41;
  --link: #2563a8; --success: #1a7f4b; --success-soft: #e6f6ec; --danger: #c92a2a; --danger-soft: #fdeaea;
  --warning: #8a5a00; --warning-soft: #fff4dc; --info: #2563a8; --info-soft: #e8f1fb;
  --border: #e2ddd4; --border-strong: #7b8190; --focus: #2563a8; --overlay: #0f142099;
  --shadow-raised: 0 1px 2px #0f142014; --shadow-popover: 0 8px 24px #0f142029;
  --font-sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif; --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 14px; --radius-full: 999px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --surface-000: #0a0e17; --surface-100: #0f1420; --surface-200: #1a2130; --surface-300: #262e40; --ink: #f3ece3; --ink-muted: #a8b0c0; --ink-inverse: #0f1420; --brand-strong: #fbad41; --brand-text: #f6821f; --brand-soft: #3a2412; --link: #7cc4f5; --success: #5fd39a; --success-soft: #12301f; --danger: #ff8a8a; --danger-soft: #3a1515; --warning: #fbad41; --warning-soft: #3a2a0c; --info: #7cc4f5; --info-soft: #122640; --border: #2a3245; --border-strong: #6b7489; --focus: #7cc4f5; --overlay: #0a0e17cc; --shadow-raised: 0 1px 2px #00000066; --shadow-popover: 0 8px 24px #00000099; color-scheme: dark; } }
:root[data-theme="dark"] { --surface-000: #0a0e17; --surface-100: #0f1420; --surface-200: #1a2130; --surface-300: #262e40; --ink: #f3ece3; --ink-muted: #a8b0c0; --ink-inverse: #0f1420; --brand-strong: #fbad41; --brand-text: #f6821f; --brand-soft: #3a2412; --link: #7cc4f5; --success: #5fd39a; --success-soft: #12301f; --danger: #ff8a8a; --danger-soft: #3a1515; --warning: #fbad41; --warning-soft: #3a2a0c; --info: #7cc4f5; --info-soft: #122640; --border: #2a3245; --border-strong: #6b7489; --focus: #7cc4f5; --overlay: #0a0e17cc; --shadow-raised: 0 1px 2px #00000066; --shadow-popover: 0 8px 24px #00000099; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-sans); font-size: 15px; line-height: 22px; color: var(--ink); background: var(--surface-000); }
a { color: var(--link); }
button { font: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.caption { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.label { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.mono { font-family: var(--font-mono); }

.bd-button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); height: 40px; padding: 0 var(--space-4); font-family: var(--font-sans); font-size: 15px; line-height: 22px; font-weight: 500; border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer; background: var(--brand); color: var(--on-brand); transition: background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out; text-decoration: none; white-space: nowrap; }
.bd-button:hover { background: var(--brand-strong); }
.bd-button[data-variant="secondary"] { background: var(--surface-200); color: var(--ink); border-color: var(--border-strong); box-shadow: var(--shadow-raised); }
.bd-button[data-variant="secondary"]:hover { background: var(--surface-300); }
.bd-button[data-variant="ghost"] { background: transparent; color: var(--ink); }
.bd-button[data-variant="ghost"]:hover { background: var(--surface-300); }
.bd-button[data-variant="danger"] { background: transparent; color: var(--danger); border-color: var(--danger); }
.bd-button[data-variant="danger"]:hover { background: var(--danger-soft); }
.bd-button[data-size="sm"] { height: 32px; padding: 0 var(--space-3); font-size: 13px; line-height: 18px; }
.bd-button:disabled { opacity: .4; cursor: not-allowed; }
.bd-button:focus-visible, .bd-input:focus-visible, .bd-tab:focus-visible, .bd-row:focus-visible, .seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.bd-button img { width: 16px; height: 16px; }
[data-theme="dark"] img.bd-icon { filter: invert(0.93) sepia(0.12); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) img.bd-icon { filter: invert(0.93) sepia(0.12); } }

.bd-badge { display: inline-flex; align-items: center; gap: var(--space-1); height: 22px; padding: 0 var(--space-2); font-family: var(--font-sans); font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; border-radius: var(--radius-sm); background: var(--surface-300); color: var(--ink); white-space: nowrap; }
.bd-badge::before { content: ""; width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; }
.bd-badge[data-status="merged"] { background: var(--success-soft); color: var(--success); }
.bd-badge[data-status="conflict"] { background: var(--danger-soft); color: var(--danger); }
.bd-badge[data-status="stale"] { background: var(--warning-soft); color: var(--warning); }
.bd-badge[data-status="working"] { background: var(--info-soft); color: var(--info); }
.bd-badge[data-status="brand"] { background: var(--brand-soft); color: var(--brand-text); }
.bd-badge[data-dot="false"]::before { display: none; }

.bd-input { height: 40px; padding: 0 var(--space-3); width: 100%; font-family: var(--font-sans); font-size: 15px; line-height: 22px; color: var(--ink); background: var(--surface-100); border: 1px solid var(--border-strong); border-radius: var(--radius-md); }
.bd-input::placeholder { color: var(--ink-muted); }
.bd-card { background: var(--surface-200); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-raised); }
.bd-list { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-200); overflow: hidden; }
.bd-row { display: grid; grid-template-columns: 20px 1fr auto auto; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-2) var(--space-4); border-top: 1px solid var(--border); color: var(--ink); text-decoration: none; cursor: pointer; transition: background-color 120ms ease-out; width: 100%; background: transparent; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; font: inherit; }
.bd-row:first-child { border-top: 0; }
.bd-row:hover { background: var(--surface-300); }
.bd-row[aria-selected="true"] { background: var(--brand-soft); }
.bd-row img { width: 20px; height: 20px; }
.bd-row .bd-row-title { font-size: 15px; line-height: 22px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd-row .bd-row-meta { font-size: 13px; line-height: 18px; color: var(--ink-muted); display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.bd-row .bd-row-age { font-size: 13px; line-height: 18px; color: var(--ink-muted); white-space: nowrap; }
.bd-code { font-family: var(--font-mono); font-size: .92em; font-weight: 500; background: var(--surface-300); color: var(--ink); padding: 1px var(--space-1); border-radius: var(--radius-sm); }
.bd-tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.bd-tab { display: inline-flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0 var(--space-3); margin-bottom: -1px; border: 0; background: transparent; cursor: pointer; font-family: inherit; font-size: 15px; line-height: 22px; font-weight: 500; color: var(--ink-muted); border-bottom: 2px solid transparent; border-radius: var(--radius-md) var(--radius-md) 0 0; transition: color 120ms ease-out, background-color 120ms ease-out; }
.bd-tab:hover { color: var(--ink); background: var(--surface-300); }
.bd-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }
.bd-tab .bd-count { font-size: 12px; line-height: 16px; font-weight: 600; padding: 0 6px; border-radius: var(--radius-full); background: var(--surface-300); color: var(--ink); }
.bd-tab[aria-selected="true"] .bd-count { background: var(--brand-soft); color: var(--brand-text); }

/* App shell */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr) 440px; min-height: 100vh; }
.rail { background: var(--surface-000); border-right: 1px solid var(--border); padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-5); position: sticky; top: 0; height: 100vh; overflow: auto; }
.rail .wordmark { height: 28px; display: block; }
.rail .wordmark.dark { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rail .wordmark.light { display: none; } :root:not([data-theme="light"]) .rail .wordmark.dark { display: block; } }
:root[data-theme="dark"] .rail .wordmark.light { display: none; } :root[data-theme="dark"] .rail .wordmark.dark { display: block; }
.rail h2 { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: var(--space-2); }
.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.stat { background: var(--surface-200); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); }
.stat b { display: block; font-size: 20px; line-height: 26px; font-weight: 600; letter-spacing: -0.01em; }
.stat span { font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.stat[data-tone="success"] b { color: var(--success); } .stat[data-tone="danger"] b { color: var(--danger); } .stat[data-tone="warning"] b { color: var(--warning); } .stat[data-tone="info"] b { color: var(--info); } .stat[data-tone="brand"] b { color: var(--brand-text); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-md); overflow: hidden; background: var(--surface-200); }
.seg button { border: 0; background: transparent; color: var(--ink-muted); padding: 0 var(--space-3); height: 32px; cursor: pointer; font-size: 13px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-text); }
.main { background: var(--surface-100); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.main header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.main header h1 { font-size: 28px; line-height: 34px; }
.side { background: var(--surface-000); border-left: 1px solid var(--border); padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); position: sticky; top: 0; height: 100vh; overflow: auto; }
.preview { background: var(--surface-200); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-raised); display: flex; flex-direction: column; flex: 0 0 auto; }
.side > section { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.side > section .feed { overflow: auto; min-height: 0; }
.preview .bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); font-size: 13px; color: var(--ink-muted); }
.preview .bar .dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--success); }
.preview .frames { position: relative; height: 420px; }
.preview iframe { position: absolute; inset: 0; width: 100%; height: 420px; border: 0; background: #fffdf9; }
.preview iframe[aria-hidden="true"] { visibility: hidden; }
.feed { display: flex; flex-direction: column; gap: 2px; }
.feed .item { display: grid; grid-template-columns: 16px 1fr auto; gap: var(--space-2); align-items: start; padding: 6px var(--space-2); border-radius: var(--radius-md); font-size: 13px; line-height: 18px; }
.feed .item:hover { background: var(--surface-300); }
.feed .item .k { width: 8px; height: 8px; margin-top: 5px; border-radius: var(--radius-full); background: var(--ink-muted); }
.feed .item[data-kind="landed"] .k, .feed .item[data-kind="auto-merged"] .k, .feed .item[data-kind="weave"] .k { background: var(--success); }
.feed .item[data-kind="replay"] .k, .feed .item[data-kind="rejected"] .k, .feed .item[data-kind="revoked"] .k, .feed .item[data-kind="error"] .k { background: var(--danger); }
.feed .item[data-kind="prevented"] .k, .feed .item[data-kind="expired"] .k, .feed .item[data-kind="released"] .k { background: var(--warning); }
.feed .item[data-kind="claimed"] .k, .feed .item[data-kind="submitted"] .k, .feed .item[data-kind="swarm"] .k { background: var(--info); }
.feed .item .t { color: var(--ink-muted); white-space: nowrap; }
.feed .item b { font-weight: 500; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(640px, 100vw); background: var(--surface-100); border-left: 1px solid var(--border); box-shadow: var(--shadow-popover); transform: translateX(100%); transition: transform 180ms ease-out; z-index: 20; overflow: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.drawer[data-open="true"] { transform: none; }
.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 19; display: none; }
.scrim[data-open="true"] { display: block; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: var(--space-1) var(--space-3); font-size: 13px; line-height: 18px; }
.kv dt { color: var(--ink-muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.attempt { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); background: var(--surface-200); display: flex; flex-direction: column; gap: var(--space-2); }
.attempt header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
pre { font-family: var(--font-mono); font-size: 13px; line-height: 20px; background: var(--surface-300); padding: var(--space-3); border-radius: var(--radius-md); overflow: auto; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-2); z-index: 30; pointer-events: none; }
.toast { background: var(--ink); color: var(--ink-inverse); padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); font-size: 13px; line-height: 18px; animation: rise 180ms ease-out; display: flex; gap: var(--space-2); align-items: center; }
.toast .bd-badge { height: 18px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.empty { padding: var(--space-6); text-align: center; color: var(--ink-muted); }
.row-actions { display: flex; gap: var(--space-2); }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-2); }
.agent { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); background: var(--surface-200); display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.agent .name { font-weight: 500; font-family: var(--font-mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent .meta { display: flex; justify-content: space-between; align-items: center; color: var(--ink-muted); }
.agent[data-status="working"] { border-color: var(--info); }
.agent[data-status="revoked"], .agent[data-status="failed"] { border-color: var(--danger); }
.log .bd-row { grid-template-columns: 20px 1fr auto; }
@media (max-width: 1180px) { .shell { grid-template-columns: 220px minmax(0, 1fr); } .side { display: none; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; } .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); } }

/* Code tab */
.code-bar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-3); }
.code-bar .bd-input { width: 260px; font-family: var(--font-mono); font-size: 13px; height: 32px; }
.crumbs { display: flex; gap: var(--space-1); align-items: center; font-size: 13px; color: var(--ink-muted); flex-wrap: wrap; }
.crumbs a { color: var(--link); text-decoration: none; cursor: pointer; }
.crumbs a:hover { text-decoration: underline; }
.code-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.code-layout .bd-row { grid-template-columns: 20px 1fr auto; min-height: 40px; padding: var(--space-1) var(--space-3); }
.code-layout .bd-row svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--ink-muted); }
.viewer { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-200); overflow: hidden; min-height: 200px; }
.viewer .vbar { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); font-size: 13px; color: var(--ink-muted); flex-wrap: wrap; }
.viewer .vbar .path { font-family: var(--font-mono); color: var(--ink); font-weight: 500; }
.code { font-family: var(--font-mono); font-size: 13px; line-height: 20px; overflow: auto; max-height: 70vh; }
.code .line { display: grid; grid-template-columns: 48px 1fr; }
.code .ln { text-align: right; padding-right: var(--space-3); color: var(--ink-muted); user-select: none; background: var(--surface-100); border-right: 1px solid var(--border); }
.code .lc { padding-left: var(--space-3); white-space: pre; }
.diff .line.add { background: var(--success-soft); } .diff .line.add .lc { color: var(--success); }
.diff .line.del { background: var(--danger-soft); } .diff .line.del .lc { color: var(--danger); }
.diff .line.hunk .lc { color: var(--ink-muted); }
.file-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--surface-300); font-family: var(--font-mono); font-size: 13px; border-bottom: 1px solid var(--border); }
.file-head .counts { color: var(--ink-muted); } .file-head .counts .a { color: var(--success); } .file-head .counts .d { color: var(--danger); }
.file-block { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface-200); }
.why-list { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border-top: 1px solid var(--border); font-size: 13px; }
.why-list .item { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.why-list a { cursor: pointer; }
@media (max-width: 900px) { .code-layout { grid-template-columns: 1fr; } }
