/* agent-harness web UI — no external resources, system fonts only. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --border-strong: #cdd2da;
  --text: #1b2028;
  --muted: #646e7d;
  --faint: #8d96a4;
  --accent: #3d5bd9;
  --accent-hover: #2f4bc2;
  --accent-soft: #e9eeff;
  --on-accent: #ffffff;
  --focus-ring: rgba(61, 91, 217, 0.32);
  --ok: #2a8740;
  --ok-soft: #e5f4e9;
  --warn: #a96200;
  --warn-soft: #fff3df;
  --bad: #c62f2f;
  --bad-soft: #fdeaea;
  --info: #1a6fbf;
  --info-soft: #e6f0fa;
  --pr: #6c45e0;
  --pr-soft: #efe9ff;
  --neutral: #546072;
  --neutral-soft: #e9edf2;
  --quiet: #7a8393;
  --quiet-soft: #f0f1f3;
  --code-bg: #f3f4f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.2);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1115;
    --surface: #161a20;
    --surface-2: #1d222a;
    --border: #282e37;
    --border-strong: #38404b;
    --text: #e3e6eb;
    --muted: #9aa3b0;
    --faint: #6e7785;
    --accent: #7d95ff;
    --accent-hover: #97aaff;
    --accent-soft: #1e2645;
    --on-accent: #0e1115;
    --focus-ring: rgba(125, 149, 255, 0.35);
    --ok: #5cc777;
    --ok-soft: #132c1b;
    --warn: #f0a73a;
    --warn-soft: #33260f;
    --bad: #ff6d6d;
    --bad-soft: #3a1719;
    --info: #5eaaf0;
    --info-soft: #132739;
    --pr: #a88dff;
    --pr-soft: #251c42;
    --neutral: #a6b0bf;
    --neutral-soft: #232932;
    --quiet: #8a93a1;
    --quiet-soft: #1d2128;
    --code-bg: #11151a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

/* -- base ----------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: 16px; line-height: 1.3; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 620; }
p { margin: 0 0 10px; }
code, .mono, pre, kbd { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; overflow-wrap: anywhere; }
pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; overflow: auto; margin: 0 0 10px; font-size: 12.5px; line-height: 1.45;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* -- layout --------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 24px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 680; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--pr));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: 7px 12px; border-radius: var(--radius-sm); color: var(--muted);
  font-weight: 550; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.user { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.user-name { font-weight: 550; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

.main { max-width: 1240px; margin: 0 auto; padding: 24px 24px 72px; }
.main:focus { outline: none; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head .subtitle { margin: 6px 0 0; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }

.section { margin-top: 28px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.section-head h2 { margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 12px; }
.grid-2 > .card + .card { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid-2 > .card, .grid-2 > * { margin-top: 0; }

/* -- buttons & inputs ----------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { min-height: 28px; padding: 0 10px; font-size: 13px; }
.btn-lg { min-height: 38px; padding: 0 18px; font-size: 15px; }
.btn-pr { background: var(--pr); border-color: var(--pr); color: var(--on-accent); }
.btn-pr:hover { background: var(--pr); filter: brightness(1.1); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.link-btn:hover { text-decoration: underline; }
kbd {
  display: inline-block; padding: 0 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; font-size: 11px; line-height: 16px; background: var(--surface); color: var(--text);
}
.btn-block { width: 100%; }
.btn.busy { cursor: progress; }
.btn.busy::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 5px; background: transparent; color: var(--muted);
  cursor: pointer; vertical-align: middle; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; padding: 7px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring);
}
input[readonly], textarea[readonly] { background: var(--surface-2); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 2px 0 0; }
textarea { resize: vertical; line-height: 1.45; }
textarea.mono, input.mono { font-family: var(--mono); font-size: 13px; }
.editor { min-height: 320px; font-family: var(--mono); font-size: 13px; }

.field { display: grid; gap: 4px; margin-bottom: 14px; min-width: 0; }
.field > label, .field-label { font-weight: 560; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; align-items: start; margin-bottom: 10px; }
.check label { font-weight: 550; cursor: pointer; }
.check .hint { grid-column: 2; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { padding: 0; font-weight: 560; font-size: 13px; margin-bottom: 6px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.form-error { color: var(--bad); margin: 0 0 10px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.copy-field { display: flex; gap: 8px; }
details.sub { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 14px; }
details.sub > summary { cursor: pointer; font-weight: 560; }
details.sub[open] > summary { margin-bottom: 10px; }

/* -- chips ---------------------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 560; line-height: 20px; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral);
}
.chip.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip-neutral { background: var(--neutral-soft); color: var(--neutral); }
.chip-run { background: var(--info-soft); color: var(--info); }
.chip-run.dot::before { animation: pulse 1.4s ease-in-out infinite; }
.chip-wait { background: var(--warn-soft); color: var(--warn); }
.chip-pr { background: var(--pr-soft); color: var(--pr); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-quiet { background: var(--quiet-soft); color: var(--quiet); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-info { background: var(--info-soft); color: var(--info); }

/* -- tables --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table.compact { min-width: 520px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 6px; }
.task-title { font-weight: 560; color: var(--text); }
.task-title:hover { color: var(--accent); }
.task-cell { min-width: 240px; }
tr.row-missing td { background: var(--bad-soft); }
tr.row-missing:hover td { background: var(--bad-soft); }

/* -- alerts, empty, loading, toasts --------------------------------------- */

.alert {
  border: 1px solid var(--border-strong); border-left-width: 4px; border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 12px; background: var(--surface); overflow-wrap: anywhere;
}
.alert strong { display: block; margin-bottom: 2px; }
.alert-warn { border-color: var(--warn); background: var(--warn-soft); }
.alert-err { border-color: var(--bad); background: var(--bad-soft); }
.alert-ok { border-color: var(--ok); background: var(--ok-soft); }
.alert-info { border-color: var(--info); background: var(--info-soft); }
.alert-big { padding: 14px 18px; font-size: 15px; }

.empty {
  padding: 24px 16px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
.empty.ok { color: var(--ok); }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 16px 0; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}

/* top-right, so toasts never cover the chat composer at the bottom */
.toasts {
  position: fixed; right: 16px; top: 12px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--ok); border-radius: var(--radius-sm); padding: 10px 14px;
  box-shadow: var(--shadow-lg); animation: toast-in 0.18s ease-out; overflow-wrap: anywhere;
}
.toast-err { border-left-color: var(--bad); }
.toast-warn { border-left-color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }

/* -- modal ---------------------------------------------------------------- */

dialog.modal {
  border: 0; padding: 0; border-radius: 12px; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal-wide { width: min(780px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(10, 13, 18, 0.5); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px 18px; }

/* -- login ---------------------------------------------------------------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 28px; }
.login-card .brand { margin-bottom: 18px; font-size: 17px; }
.login-card h1 { font-size: 19px; margin-bottom: 6px; }

/* -- overview ------------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); color: var(--text);
}
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-label { font-size: 12px; color: var(--muted); font-weight: 550; }
.tile-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-hint { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.tile-ok .tile-value { color: var(--ok); }
.tile-bad { border-color: var(--bad); }
.tile-bad .tile-value { color: var(--bad); }
.tile-warn .tile-value { color: var(--warn); }
.tile-run .tile-value { color: var(--info); }

.stackbar { display: flex; gap: 2px; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.seg { min-width: 4px; }
.seg-neutral { background: var(--neutral); }
.seg-run { background: var(--info); }
.seg-wait { background: var(--warn); }
.seg-pr { background: var(--pr); }
.seg-ok { background: var(--ok); }
.seg-quiet { background: var(--faint); }
.seg-bad { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.legend-item:hover { text-decoration: none; }
.legend-item b { font-variant-numeric: tabular-nums; }

.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; align-items: center; gap: 8px 12px; padding: 10px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.attention li:first-child { border-top: 0; padding-top: 0; }
.attention-main { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 2px; }
.attention-main a { font-weight: 560; color: var(--text); }
.attention-main a:hover { color: var(--accent); }

/* -- projects ------------------------------------------------------------- */

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.project-card { display: flex; flex-direction: column; gap: 8px; color: var(--text); }
.project-card:hover { border-color: var(--accent); text-decoration: none; }
.project-card h2 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.project-card .desc {
  color: var(--muted); font-size: 13px; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.project-card.archived { opacity: 0.7; }
.stats-row { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: auto; }
.stats-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; margin: 4px 0 18px; scrollbar-width: thin; }
.tab {
  padding: 9px 14px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--muted); font: inherit; font-weight: 560; cursor: pointer; white-space: nowrap; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

details.card > summary { cursor: pointer; font-weight: 620; font-size: 15px; list-style-position: inside; }
details.card[open] > summary { margin-bottom: 14px; }

.kv { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.cmd-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

.kb { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.kb-docs { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.kb-doc {
  width: 100%; text-align: left; display: grid; gap: 1px; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.kb-doc:hover { background: var(--surface-2); }
.kb-doc.active { background: var(--accent-soft); border-color: var(--accent); }
.kb-doc .mono { overflow-wrap: anywhere; }
.preview { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; min-height: 120px; background: var(--surface); }

.legend-list { margin: 0; padding-left: 18px; }
.legend-list li { margin-bottom: 4px; }

/* -- tasks ---------------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 200px; }
.status-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip { border: 0; background: none; padding: 0; border-radius: 999px; cursor: pointer; opacity: 0.5; font: inherit; }
.filter-chip:hover { opacity: 0.85; }
.filter-chip[aria-pressed="true"] { opacity: 1; }
.filter-chip[aria-pressed="true"] .chip { box-shadow: inset 0 0 0 1.5px currentColor; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 20px; margin: 0; }
.meta-item { min-width: 0; }
.meta-item dt { color: var(--muted); font-size: 12px; }
.meta-item dd { margin: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.questions { margin: 6px 0 0; padding-left: 22px; }
.questions li { margin-bottom: 6px; }
.plan-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; margin: 10px 0 12px; max-height: 60vh; overflow: auto; background: var(--surface); }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--info); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; flex: none; }
.live.err { color: var(--bad); }

.timeline { list-style: none; margin: 0; padding: 4px 0; font-size: 13px; }
.ev {
  display: grid; grid-template-columns: 62px 124px minmax(0, 1fr); gap: 2px 10px; align-items: baseline;
  padding: 4px 14px 4px 11px; border-left: 3px solid transparent;
}
.ev-time { color: var(--faint); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }
.ev-label { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.ev-label.mono { font-size: 12px; color: var(--accent); font-weight: 550; }
.ev-body { min-width: 0; overflow-wrap: anywhere; }
.ev-step { background: var(--surface-2); padding-top: 6px; padding-bottom: 6px; }
.ev-step .ev-label { color: var(--text); }
.ev-ok .ev-label { color: var(--ok); }
.ev-bad { border-left-color: var(--bad); background: var(--bad-soft); }
.ev-bad .ev-label { color: var(--bad); }
.ev-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.ev-warn .ev-label { color: var(--warn); }
.ev-human { border-left-color: var(--pr); }
.ev-human .ev-label { color: var(--pr); }
.ev-info .ev-label { color: var(--info); }
.ev-muted .ev-body { color: var(--muted); }
.ev-text { white-space: pre-wrap; font-size: 12.5px; }
.ev-code {
  display: inline-block; max-width: 100%; vertical-align: bottom; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; cursor: pointer; border: 0; background: var(--code-bg); font: inherit;
  font-family: var(--mono); font-size: 12px; color: var(--text); padding: 0 5px; border-radius: 4px; text-align: left;
}
.ev-code.expanded { white-space: pre-wrap; word-break: break-all; }
.ev-quote { white-space: pre-wrap; border-left: 2px solid var(--border-strong); padding-left: 8px; margin-top: 2px; color: var(--text); }
.ev-err { color: var(--bad); white-space: pre-wrap; margin-top: 2px; }
.ev-list { margin: 4px 0 0; padding-left: 18px; }
.ev-tail { margin-top: 4px; }
.ev-tail summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.ev-tail pre { margin: 6px 0 2px; max-height: 320px; font-size: 12px; }
.mark-ok { color: var(--ok); font-weight: 700; }
.mark-bad { color: var(--bad); font-weight: 700; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* -- chat (task page) ----------------------------------------------------- */

.chat-head { margin-bottom: 18px; }
.chat-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.chat-title-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; flex: 1 1 320px; }
.chat-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.chat-meta > * { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; }
details.more { margin-top: 6px; font-size: 13px; }
details.more > summary { cursor: pointer; color: var(--muted); width: max-content; }
details.more[open] > summary { margin-bottom: 10px; }
details.more .meta-grid {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}

.chat, .chat-stream, .chat-tail { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.chat-tail:empty { display: none; }

.msg { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: min(760px, 88%); }
.msg-human { align-self: flex-end; align-items: flex-end; }
.msg-agent { align-self: flex-start; max-width: min(900px, 100%); }
.msg-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 0 4px; }
.msg-who { font-weight: 600; color: var(--text); }
.msg-meta .chip { font-size: 11px; line-height: 18px; padding: 0 7px; }
.msg-bubble {
  padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow); min-width: 0; max-width: 100%; overflow-wrap: anywhere;
}
.msg-human .msg-bubble { background: var(--accent-soft); border-color: transparent; border-bottom-right-radius: 4px; }
.msg-agent .msg-bubble { border-bottom-left-radius: 4px; }
.msg-text { white-space: pre-wrap; }
.msg-approved { font-weight: 620; color: var(--ok); }
.msg-approved + .msg-text { margin-top: 4px; }
.clamp-body.clamped {
  max-height: 240px; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 65%, transparent);
  mask-image: linear-gradient(to bottom, #000 65%, transparent);
}
.msg-bubble > .link-btn { margin-top: 6px; }
.questions-box {
  margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); border-left: 3px solid var(--warn);
}
.questions-box:first-child { margin-top: 0; }
.questions-box > strong { color: var(--warn); }

details.work { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
details.work > summary {
  display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; padding: 8px 12px;
  cursor: pointer; list-style: none; font-size: 13px; color: var(--muted);
}
details.work > summary::-webkit-details-marker { display: none; }
details.work > summary::before { content: "▸"; color: var(--faint); transition: transform 0.15s; }
details.work[open] > summary::before { transform: rotate(90deg); }
details.work[open] > summary { border-bottom: 1px solid var(--border); }
details.work > summary:hover .work-title { color: var(--accent); }
details.work:not(.live) .live-dot { display: none; }
details.work.live { border-color: var(--info); }
details.work.live .live-dot { color: var(--info); }
details.work .timeline { max-height: 60vh; overflow: auto; }
.work-title { font-weight: 560; color: var(--text); }
.work-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.mini-chip { font-size: 11.5px; line-height: 18px; padding: 0 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--neutral); white-space: nowrap; }
.mini-ok { background: var(--ok-soft); color: var(--ok); }
.mini-bad { background: var(--bad-soft); color: var(--bad); }
.mini-warn { background: var(--warn-soft); color: var(--warn); }

.chat-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow); min-width: 0; overflow-wrap: anywhere;
}
.chat-card-title, .chat-card > summary { font-weight: 620; display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; }
.chat-card-title { margin-bottom: 4px; }
.chat-card > summary { cursor: pointer; }
.chat-card[open] > summary { margin-bottom: 8px; }
.chat-card > :last-child { margin-bottom: 0; }
.chat-card-ok { border-left-color: var(--ok); }
.chat-card-ok .chat-card-title { color: var(--ok); }
.chat-card-bad { border-left-color: var(--bad); background: var(--bad-soft); }
.chat-card-bad .chat-card-title { color: var(--bad); }
.chat-card-pr { border-left-color: var(--pr); }
.chat-card-pr .chat-card-title { color: var(--pr); }
.chat-card-info { border-left-color: var(--info); }
.chat-card-wait { border-left-color: var(--warn); }
.chat-card-wait .chat-card-title { color: var(--warn); font-size: 15px; }
.draft-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; margin: 8px 0 10px; max-height: 50vh; overflow: auto; }
.suggestions { list-style: none; margin: 6px 0 0; padding: 0; }
.suggestions li { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.suggestions li:first-child { border-top: 0; }
.suggestion-text { flex: 1 1 260px; min-width: 0; }
.suggestion-actions { display: inline-flex; gap: 6px; }

.chat-divider { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.chat-divider::before, .chat-divider::after { content: ""; flex: 1 1 24px; border-top: 1px solid var(--border); }
.chat-divider-text { display: inline-flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 2px 4px; max-width: 80%; text-align: center; font-weight: 560; }
.chat-divider-ok { color: var(--ok); }
.chat-divider-pr { color: var(--pr); }
.chat-divider-bad { color: var(--bad); }
.chat-divider-wait { color: var(--warn); }
.chat-divider-err { flex-basis: 100%; font-weight: 400; }
.chat-divider-err .ev-code { color: var(--bad); max-width: 100%; }
.sys-note { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 2px 12px; }
.typing { align-self: flex-start; display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 2px 4px; }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--info); animation: pulse 1.2s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
.chat-readonly { margin-top: 18px; }

/* sticky composer: stays at the bottom of the viewport while the transcript scrolls */
.composer {
  position: sticky; bottom: 0; z-index: 20; margin: 18px -8px 0; padding: 14px 8px 10px;
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
}
.composer .form-error { margin: 0 4px 6px; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow-lg); }
.composer-box textarea {
  border: 0; box-shadow: none; resize: none; min-height: 40px; max-height: 260px; padding: 9px 8px; font-size: 14.5px; background: transparent;
}
.composer-box textarea:focus { box-shadow: none; }
.composer-box .btn { min-height: 40px; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 6px 0; font-size: 12px; color: var(--muted); }

/* -- project: sessions ---------------------------------------------------- */

.composer-card { padding: 18px; }
.composer-label { display: block; font-size: 17px; font-weight: 640; margin-bottom: 10px; overflow-wrap: anywhere; }
.composer-card textarea { font-size: 15px; min-height: 104px; }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 12px 0 6px; }
.composer-card > .hint { margin-bottom: 12px; }
.composer-card .form-actions .hint { margin-left: auto; }

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 3px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-2);
}
.seg-opt {
  position: relative; display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 6px;
  cursor: pointer; font-weight: 560; font-size: 13px; color: var(--muted); white-space: nowrap;
}
.seg-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg-opt:hover { color: var(--text); }
.seg-opt:has(input:checked) { background: var(--surface); color: var(--accent); box-shadow: var(--shadow), inset 0 0 0 1px var(--border); }
.seg-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-opt:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }

.sessions { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.session {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto 64px 28px;
  align-items: center; gap: 4px 12px; padding: 10px 14px; border-top: 1px solid var(--border);
}
.session:first-child { border-top: 0; }
.session:hover { background: var(--surface-2); }
.session-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; color: var(--text); }
.session-main::after { content: ""; position: absolute; inset: 0; }   /* whole row is clickable */
.session-main:hover { text-decoration: none; }
.session-main:hover .session-title { color: var(--accent); }
.session-title { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-cost { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.session-pr { position: relative; z-index: 1; color: var(--pr); }

.form-section + .form-section { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 16px; }
.form-section > h3 { margin-bottom: 12px; }
.settings-form > fieldset { margin: 0; }

/* -- connect wizard ------------------------------------------------------- */

.stepper { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: -4px 0 16px; padding: 0; counter-reset: step; }
.stepper li { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 560; }
.stepper li::before {
  counter-increment: step; content: counter(step); display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 50%; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border-strong);
}
.stepper li:not(:last-child)::after { content: ""; width: 28px; border-top: 1px solid var(--border-strong); }
.stepper li[aria-current="step"] { color: var(--text); }
.stepper li[aria-current="step"]::before { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.stepper li.done::before { content: "✓"; background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.connect-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }
.repo-search { position: relative; flex: 1 1 260px; min-width: 0; }
.repo-search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.repo-search input { padding-left: 32px !important; }
.repo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 62vh; overflow: auto; }
.repo-row {
  width: 100%; display: grid; gap: 3px; padding: 10px 12px; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.repo-row:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.repo-row:disabled { cursor: default; opacity: 0.6; }
.repo-name { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.repo-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.repo-desc { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.connect-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.connect-foot .manual { max-width: 560px; }
.connect-foot p { margin: 0; }
.detect .title-row { margin-bottom: 6px; }
.detect-line { margin: 4px 0; }

/* -- admin: forge access -------------------------------------------------- */

.forge-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.forge-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; min-width: 0; }
.forge-item .title-row { margin-bottom: 8px; }
.forge-item h3 { margin: 0; }
.forge-item .alert { margin: 10px 0 0; }
.kv.kv-tight { grid-template-columns: 110px minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.forge-token-form { border-top: 1px solid var(--border); padding-top: 14px; }

/* -- overview: picker, attention ------------------------------------------ */

.picker { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 60vh; overflow: auto; }
.picker-item { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); }
.picker-item:hover, .picker-item:focus-visible { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.attention li.clickable { cursor: pointer; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: var(--radius-sm); }
.attention li.clickable:hover { background: var(--surface-2); }
.attention-q { font-size: 13px; color: var(--text); overflow-wrap: anywhere; }

/* -- markdown ------------------------------------------------------------- */

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; line-height: 1.3; font-weight: 640; }
.md h1 { font-size: 19px; }
.md h2 { font-size: 17px; }
.md h3 { font-size: 15px; }
.md h4, .md h5, .md h6 { font-size: 14px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin-bottom: 0; }
.md blockquote { margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md .table-wrap { box-shadow: none; margin-bottom: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }

/* -- admin ---------------------------------------------------------------- */

.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }

/* -- animations ----------------------------------------------------------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* -- responsive ----------------------------------------------------------- */

@media (max-width: 900px) {
  .kb { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .forge-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 4px 12px; padding: 8px 16px 0; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -16px; padding: 0 12px 6px; }
  .user-name { max-width: 110px; }
  .main { padding: 16px 16px 64px; }
  h1 { font-size: 19px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .msg { max-width: 94%; }
  .msg-agent { max-width: 100%; }
  .composer { margin: 14px -16px 0; padding: 12px 10px 8px; }
  .composer-box .btn { padding: 0 12px; }
  .composer-foot > span:first-child { display: none; }
  .composer-card { padding: 14px; }
  .composer-card .form-actions .hint { display: none; }
  .segmented { display: flex; width: 100%; }
  .seg-opt { flex: 1 1 auto; justify-content: center; padding: 6px 8px; }
  .session { grid-template-columns: auto minmax(0, 1fr) 28px; }
  .session-main { grid-column: 1 / -1; }
  .session-cost { text-align: left; }
  .chat-divider-text { max-width: 92%; }
  .kv.kv-tight { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 20px; }
  .ev { grid-template-columns: 54px minmax(0, 1fr); padding-right: 10px; }
  .ev-body { grid-column: 2; }
  .filters .field { min-width: 0; flex: 1 1 100%; }
  .copy-field { flex-wrap: wrap; }
  .pager { justify-content: space-between; }
}

/* -- project configuration (wizard + chat card) ---------------------------- */
.config-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.config-row {
  display: grid; grid-template-columns: minmax(0, 1.2fr) auto minmax(0, 1.4fr); gap: 8px 12px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.config-row > .small:last-child { justify-self: end; }
.config-row > .row { width: 100%; }
.config-row .row input { flex: 1; min-width: 0; }
.config-list .config-row:has(> .row:nth-child(2)) { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
@media (max-width: 640px) {
  .config-row, .config-list .config-row:has(> .row:nth-child(2)) { grid-template-columns: minmax(0, 1fr); }
}

/* -- settings diff (chat) ---------------------------------------------------- */
.diff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diff-table th, .diff-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; word-break: break-word; }
.diff-table th { white-space: nowrap; }
.diff-before { color: var(--muted); text-decoration: line-through; }
.diff-after { font-weight: 600; }
.err { color: var(--bad); }

/* user editor */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 18px; margin-top: 6px; }
.modal fieldset legend { font-weight: 600; margin-bottom: 6px; }
