:root {
  --c-ink: #134e4a;
  --c-primary: #0f766e;
  --c-primary-hover: #0b5f58;
  --c-accent: #22d3ee;
  --c-surface: #ffffff;
  --c-bg: #f5fafa;
  --c-tint: #ecfeff;
  --c-border: #d7e8e6;
  --c-text: #0f2b28;
  --c-text-muted: #5c7a77;

  --c-success: #15803d;
  --c-success-bg: #ecfdf3;
  --c-danger: #dc2626;
  --c-danger-bg: #fef2f2;
  --c-warning: #b45309;
  --c-warning-bg: #fff7ed;

  --c-diff-add-bg: #d4f5dc;
  --c-diff-add-text: #14532d;
  --c-diff-add-no-bg: #b5ebc3;
  --c-diff-del-bg: #fddcdc;
  --c-diff-del-text: #7f1d1d;
  --c-diff-del-no-bg: #f7b9b9;

  --c-planning-drafting-bg: #eef2ff;
  --c-planning-drafting-text: #4338ca;
  --c-planning-awaiting-lead-bg: #fff7e0;
  --c-planning-awaiting-lead-text: #8a6d00;
  --c-planning-awaiting-agent-bg: #eff6ff;
  --c-planning-awaiting-agent-text: #1d4ed8;
  --c-planning-approved-bg: #e6ffed;
  --c-planning-approved-text: #1a7f37;
  --c-planning-abandoned-bg: #f3f4f6;
  --c-planning-abandoned-text: #666;

  --sidebar-bg: #0d332f;
  --sidebar-link: #a9c7c4;
  --sidebar-hover: #163f3c;
}

* { box-sizing: border-box; }
body {
  font-family: system-ui, sans-serif;
  margin: 0;
  color: var(--c-text);
  background: var(--c-bg);
}

.app-body { display: flex; min-height: 100vh; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-form {
  background: var(--c-surface);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(19, 78, 74, 0.12);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 280px;
}

.login-form h1 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.login-form input { padding: 0.5rem; font-size: 1rem; }
.login-form button, .top-bar button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  background: var(--c-primary);
  color: #fff;
  cursor: pointer;
}
.login-form button:hover, .top-bar button:hover { background: var(--c-primary-hover); }
.error { color: var(--c-danger); margin: 0; font-size: 0.9rem; }

/* Sidebar navigation ------------------------------------------------- */
.sidebar {
  width: 216px;
  flex: none;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 12px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--c-accent);
  color: var(--sidebar-bg);
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-name { color: #fff; font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  color: var(--sidebar-link);
  text-decoration: none;
}
.sb-link:hover { background: var(--sidebar-hover); color: #fff; }
.sb-link.active { background: var(--c-primary); color: #fff; }

/* App shell / main column -------------------------------------------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-left: 216px; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
.top-bar h1 { margin: 0; font-size: 1.1rem; }
.top-bar-right { display: flex; align-items: center; gap: 1rem; }
.refresh-indicator { font-size: 0.8rem; color: var(--c-text-muted); min-width: 8.5em; text-align: right; }

main { padding: 1.25rem 1.75rem 2.5rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* Card ----------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 43, 40, 0.04);
}
.card-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--c-border);
}
.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 16px 18px; }
.card-row { display: flex; gap: 18px; align-items: flex-start; }
.card-row-main { flex: 1.4; }
.card-row-side { flex: 1; }
@media (max-width: 860px) {
  .card-row { flex-direction: column; }
}

.icon { width: 15px; height: 15px; flex: none; }
.icon-sm { width: 13px; height: 13px; }

.table-scroll { overflow-x: auto; }

.ghost-btn {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--c-tint); }
.ghost-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: var(--c-surface);
  flex: 1 1 240px;
  min-width: 180px;
  color: var(--c-text-muted);
}
.search-box .filter-input { flex: 1; border: none; padding: 0.4rem 0; min-width: 0; }
.search-box .filter-input:focus { outline: none; }

/* Status pill with dot (Agent Runs + Planning) */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.status-pill-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex: none; }
.status-pill-success, .planning-status-approved { background: var(--c-success-bg); color: var(--c-success); }
.status-pill-success .status-pill-dot, .planning-status-approved .status-pill-dot { background: var(--c-success); }
.status-pill-failed { background: var(--c-danger-bg); color: var(--c-danger); }
.status-pill-failed .status-pill-dot { background: var(--c-danger); }
.status-pill-running { background: var(--c-warning-bg); color: var(--c-warning); }
.status-pill-running .status-pill-dot { background: var(--c-warning); }
.status-pill-pending { background: var(--c-tint); color: var(--c-primary); }
.status-pill-pending .status-pill-dot { background: var(--c-primary); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-surface);
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
th { color: var(--c-text-muted); font-weight: 600; }
tbody tr:hover { background: var(--c-bg); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.filter-input, .filter-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: var(--c-surface);
}
.filter-input { flex: 1 1 240px; min-width: 180px; }

.info-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--c-primary);
  line-height: 1;
  padding: 0.15rem;
}
.info-btn:hover { color: var(--c-primary-hover); }

.retry-btn {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: var(--c-surface);
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--c-warning);
  margin-left: 0.4rem;
}
.retry-btn:hover:not(:disabled) { background: var(--c-warning-bg); border-color: #fbbf24; }
.retry-btn:disabled { opacity: 0.6; cursor: default; }

.artifacts-link {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: var(--c-surface);
  font-size: 0.75rem;
  color: var(--c-success);
  text-decoration: none;
  margin-left: 0.4rem;
}
.artifacts-link:hover { background: var(--c-success-bg); border-color: #4ade80; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.6rem 0;
  font-size: 0.8rem;
  color: var(--c-text-muted);
}
.page-btn {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: var(--c-surface);
  cursor: pointer;
  font-size: 0.8rem;
}
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-btn:not(:disabled):hover { background: var(--c-tint); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 43, 40, 0.45);
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--c-surface);
  border-radius: 8px;
  width: 100%;
  max-width: 720px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(15, 43, 40, 0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--c-border);
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--c-text-muted);
}
.modal-close:hover { color: var(--c-text); }
.modal-body {
  margin: 0;
  padding: 1.25rem;
  overflow: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--c-surface);
}
.modal-body > pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.detail-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  margin: 0 0 1rem;
}
.detail-summary dt {
  font-weight: 600;
  color: var(--c-text-muted);
  white-space: nowrap;
}
.detail-summary dd {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.token-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin: 0 0 1rem;
}
.token-tile {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-bg);
}
.token-tile-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.token-tile-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-top: 0.15rem;
}

.detail-raw summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--c-primary);
  margin-bottom: 0.5rem;
}
.detail-raw pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--c-bg);
  padding: 0.75rem;
  border-radius: 4px;
  max-height: 320px;
  overflow: auto;
}

/* Live conversation transcript in the run detail modal */
.transcript { max-height: 420px; overflow-y: auto; padding: 8px; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 4px; font-size: 13px; }
.tr-ev { margin: 0 0 8px; padding: 6px 8px; border-left: 3px solid #bbb; background: var(--c-surface); }
.tr-text { border-left-color: var(--c-primary); }
.tr-tool_use { border-left-color: var(--c-warning); }
.tr-tool_result { border-left-color: var(--c-success); }
.tr-error { border-left-color: var(--c-danger); }
.tr-result { border-left-color: #7b3fe4; }
.tr-label { display: block; font-weight: 600; font-size: 12px; color: var(--c-text-muted); margin-bottom: 2px; }
.tr-body { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Readable tool cards in the transcript */
.tr-ev { font-family: inherit; }
.tr-prose { white-space: pre-wrap; word-break: break-word; }
.tr-head { cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.tr-head::-webkit-details-marker { display: none; }
.tr-icon { font-family: ui-monospace, Menlo, monospace; color: var(--c-warning); width: 1.2em; text-align: center; }
.tr-title { font-weight: 600; font-size: 12px; }
.tr-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--c-text); }
.tr-time { font-size: 11px; color: #999; }
.tr-usage { flex: none; font-size: 11px; color: var(--c-planning-awaiting-lead-text); background: var(--c-planning-awaiting-lead-bg); border-radius: 3px; padding: 1px 5px; white-space: nowrap; }
.tr-usage-note { font-size: 11px; color: #888; margin: 4px 0 8px; font-style: italic; }
.tr-done { border-left-color: var(--c-success); }
.tr-failed { border-left-color: var(--c-danger); }
.tr-init { border-left-color: #999; }
.tool-section { margin-top: 6px; }
.tool-section-label { font-size: 11px; font-weight: 600; color: #777; text-transform: uppercase; margin: 6px 0 2px; }
.tool-note { font-size: 12px; color: var(--c-text-muted); margin: 4px 0; }
.code-wrap { position: relative; }
.copy-btn, .more-btn { font-size: 11px; cursor: pointer; border: 1px solid #ccc; background: var(--c-surface); border-radius: 3px; padding: 1px 6px; }
.copy-btn { position: absolute; top: 4px; right: 4px; opacity: .7; }
.more-btn { margin-top: 4px; }
.code-block { margin: 0; padding: 8px; background: #f4f4f4; border: 1px solid #e2e2e2; border-radius: 4px; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-block.terminal { background: #1e1e1e; color: #e6e6e6; border-color: #1e1e1e; }
.code-block.result-error { background: #fdecea; border-color: #f5c6c0; }
.code-block.diff { padding: 0; background: var(--c-surface); }
.diff-line { display: block; padding: 0 8px; }
.diff-add { background: var(--c-diff-add-bg); color: var(--c-diff-add-text); }
.diff-del { background: var(--c-diff-del-bg); color: var(--c-diff-del-text); }
.kv-table { border-collapse: collapse; font-size: 12px; margin: 4px 0; width: 100%; }
.kv-table th { text-align: left; padding: 2px 10px 2px 0; color: var(--c-text-muted); font-weight: 600; white-space: nowrap; vertical-align: top; width: 1%; }
.kv-table td { padding: 2px 0; font-family: ui-monospace, Menlo, monospace; word-break: break-word; white-space: pre-wrap; }
.curl-box { border: 1px solid var(--c-border); border-radius: 4px; padding: 6px 8px; background: var(--c-surface); margin-bottom: 6px; }
.curl-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.curl-url { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
.http-method { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 3px; color: #fff; background: #555; }
.m-get { background: var(--c-success); } .m-post { background: var(--c-primary); } .m-put, .m-patch { background: var(--c-warning); } .m-delete { background: var(--c-danger); }
.todo-list { list-style: none; margin: 4px 0; padding: 0; font-size: 12px; }
.todo-completed { color: var(--c-success); }
.tr-filter { display: flex; gap: 6px; margin: 6px 0; }
.tr-filter-btn { border: 1px solid #ccc; background: var(--c-surface); border-radius: 12px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.tr-filter-btn.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
[hidden] { display: none !important; }

/* Project memory panel */
.memory-sub { font-size: 12px; font-weight: normal; color: #777; margin-left: 8px; }
.memory-summary { margin: 6px 0 10px; line-height: 1.6; }
.memory-warn { color: var(--c-warning); }
.memory-toolbar { align-items: center; gap: 8px; }
.memory-toolbar button { padding: 6px 12px; cursor: pointer; }
.memory-toolbar button:disabled { opacity: .5; cursor: not-allowed; }
.primary-btn { background: var(--c-primary); color: #fff; border: 1px solid var(--c-primary-hover); border-radius: 4px; }
.memory-message.ok { color: var(--c-success); }
.memory-message.err { color: var(--c-danger); }
.memory-files { margin-top: 8px; }
.memory-st-added { color: var(--c-success); }
.memory-st-deleted { color: var(--c-danger); }
.memory-st-modified { color: var(--c-warning); }
.memory-runs { margin: 10px 0 0; font-size: 13px; }
.memory-diff { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-height: 60vh; overflow: auto; }
.danger-btn { background: var(--c-danger); color: #fff; border: 1px solid #a5301f; border-radius: 4px; }
.secondary-btn { background: var(--c-warning); color: #fff; border: 1px solid var(--c-warning); border-radius: 4px; }
.secondary-btn-outline { background: var(--c-surface); color: var(--c-text); border: 1px solid var(--c-border); border-radius: 4px; }
.secondary-btn-outline:hover { background: var(--c-bg); }
.poll-counter { margin-right: 16px; padding: 4px 10px; border-radius: 12px; background: var(--c-tint); color: var(--c-primary); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.poll-counter-paused { background: #f1f1f1; color: #888; }
.pause-banner { margin-right: 16px; padding: 4px 10px; border-radius: 12px; background: var(--c-danger-bg); color: #a5301f; border: 1px solid #f3c2bb; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.diff-btn { background: none; border: 1px solid #c7d2fe; color: var(--c-primary); border-radius: 4px; padding: 2px 8px; cursor: pointer; font-size: 12px; }
.diff-btn:hover { background: var(--c-tint); }
/* Memory diff popup: line numbers, coloured add/remove rows, full-file toggle */
.modal.modal-wide { max-width: min(1100px, 96vw); max-height: 88vh; }

/* Small in-app confirm dialog -- replaces window.confirm() for Approve/
   Replan/Abandon, consistent with the rest of the dashboard's own modal
   styling instead of a native OS alert box. */
.modal.modal-confirm { max-width: 420px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0.9rem 1.25rem 1.1rem; border-top: 1px solid var(--c-border); }
.confirm-modal-footer button { padding: 6px 14px; cursor: pointer; }
.diff-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.diff-tab { padding: 4px 12px; border: 1px solid var(--c-primary); background: var(--c-surface); color: var(--c-primary); border-radius: 4px; cursor: pointer; font-size: 13px; }
.diff-tab.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.diff-stats { font-size: 13px; color: #444; margin-left: 6px; font-variant-numeric: tabular-nums; }
.diff-legend { margin-left: auto; display: flex; gap: 6px; font-size: 12px; }
.diff-legend .lg { padding: 1px 8px; border-radius: 3px; }
.lg-add { background: var(--c-diff-add-bg); color: var(--c-diff-add-text); }
.lg-del { background: var(--c-diff-del-bg); color: var(--c-diff-del-text); }
.diff-holder { max-height: 68vh; overflow: auto; border: 1px solid var(--c-border); border-radius: 4px; }
.diff-empty { padding: 12px; color: #666; }
.diff-table { border-collapse: collapse; width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.diff-table td { padding: 0 6px; vertical-align: top; }
.diff-no { width: 1%; min-width: 3.2em; text-align: right; color: #8a8f98; user-select: none; background: #f6f7f9; border-right: 1px solid var(--c-border); white-space: nowrap; }
.diff-sign { width: 1.4em; text-align: center; user-select: none; color: #666; }
.diff-code { white-space: pre-wrap; word-break: break-word; width: 100%; }
.diff-add .diff-code, .diff-add .diff-sign { background: var(--c-diff-add-bg); }
.diff-add .diff-no { background: var(--c-diff-add-no-bg); color: var(--c-diff-add-text); }
.diff-del .diff-code, .diff-del .diff-sign { background: var(--c-diff-del-bg); }
.diff-del .diff-no { background: var(--c-diff-del-no-bg); color: var(--c-diff-del-text); }
.diff-hunk .diff-hunk-text, .diff-note .diff-hunk-text { background: #eaf1fb; color: #3b5b8c; padding: 3px 8px; font-style: italic; }

/* Interactive planning (queue table + chat modal) ------------------------ */
#planning-table tbody tr { cursor: pointer; }
#planning-table tbody tr:hover { background: var(--c-tint); }
.planning-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.planning-status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.planning-status-drafting { background: var(--c-planning-drafting-bg); color: var(--c-planning-drafting-text); }
.planning-status-awaiting_lead { background: var(--c-planning-awaiting-lead-bg); color: var(--c-planning-awaiting-lead-text); }
.planning-status-awaiting_agent { background: var(--c-planning-awaiting-agent-bg); color: var(--c-planning-awaiting-agent-text); }
.planning-status-approved { background: var(--c-planning-approved-bg); color: var(--c-planning-approved-text); }
.planning-status-abandoned { background: var(--c-planning-abandoned-bg); color: var(--c-planning-abandoned-text); }

.planning-status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; flex: none; }

/* Wide planning modal, split into a narrow left "plan" pane (the live
   transcript -- tool calls, reads, reasoning) and a large right "chat" pane
   (reply history + input + actions, where the rendered plan/question text
   actually lives) -- the chat pane is where a Lead spends most of their
   reading/replying time, so it gets the larger 75% share; the transcript is
   secondary background detail at 25%. Collapses to a single stacked column
   on narrow screens since a true side-by-side split isn't readable below
   ~900px. */
.modal.modal-planning { max-width: min(1400px, 96vw); max-height: 90vh; }
.planning-modal-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.planning-split { display: flex; gap: 14px; flex: 1; min-height: 0; }
.planning-plan-pane { flex: 0 0 25%; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--c-border); border-radius: 6px; overflow: hidden; }
.planning-plan-pane #planning-transcript-holder { flex: 1; overflow: auto; min-height: 0; }
.planning-chat-pane { flex: 0 0 75%; min-width: 320px; display: flex; flex-direction: column; min-height: 0; }
@media (max-width: 900px) {
  .planning-split { flex-direction: column; }
  .planning-plan-pane, .planning-chat-pane { flex: none; width: 100%; }
  .planning-plan-pane #planning-transcript-holder { max-height: 40vh; }
}

.planning-chat-log { flex: 1; min-height: 120px; overflow-y: auto; padding: 8px; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 4px; }
/* white-space: normal (not pre-wrap) -- the chat body is now rendered
   markdown-lite HTML (div/br/ul/ol/pre elements from renderMarkdownLite),
   not raw escaped text, so line breaks are already explicit in the markup
   rather than needing the browser to preserve literal source whitespace. */
.planning-chat-msg { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; max-width: 95%; font-size: 13px; white-space: normal; word-break: break-word; }
.planning-chat-msg-agent { background: var(--c-surface); border: 1px solid var(--c-border); margin-right: auto; }
.planning-chat-msg-lead { background: var(--c-tint); margin-left: auto; text-align: left; }
.planning-chat-msg-time { display: block; font-size: 10px; color: #999; margin-top: 2px; }
.planning-chat-msg ul, .planning-chat-msg ol { margin: 4px 0; padding-left: 20px; }
.planning-chat-msg li { margin: 2px 0; }
.planning-chat-fence { margin: 4px 0; padding: 6px 8px; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.planning-chat-msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--c-bg); padding: 1px 4px; border-radius: 3px; }
.planning-chat-msg-discarded { opacity: 0.55; }
.planning-chat-msg-note { display: block; font-size: 10px; color: #a5301f; font-style: italic; margin-top: 2px; }
.planning-question { margin-top: 8px; padding: 8px; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 6px; white-space: normal; }
.planning-question-text { font-weight: 600; margin-bottom: 6px; }
.planning-question-options { display: flex; flex-direction: column; gap: 4px; }
.planning-question-option { display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; }
.planning-question-option input[type="radio"]:disabled, .planning-question-option input[type="checkbox"]:disabled { cursor: not-allowed; }
.planning-question-other { flex-wrap: wrap; }
.planning-question-other-input { flex: 1; min-width: 140px; padding: 3px 6px; border: 1px solid var(--c-border); border-radius: 4px; font-size: 12px; }
.planning-question-submit { margin-top: 8px; font-size: 12px; padding: 4px 10px; }

/* Textarea full-width; one single action row directly below it --
   Approve/Replan/Abandon grouped on the left, Send on the right, all
   sharing the same row/baseline (not two separately-aligned rows). */
.planning-chat-input-row { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; flex: none; }
.planning-chat-input { width: 100%; padding: 0.5rem 0.6rem; font-size: 0.85rem; border: 1px solid var(--c-border); border-radius: 4px; font-family: inherit; resize: vertical; box-sizing: border-box; }

/* .primary-btn/.secondary-btn/.danger-btn only set color/border -- their
   padding/size normally comes from an ancestor like .memory-toolbar, which
   this modal doesn't have, so these buttons need their own explicit sizing
   here (bigger + better-spaced per the Lead's own request: the default
   browser button size read as cramped next to the wide chat pane). */
.planning-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.planning-actions-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.planning-actions button { padding: 9px 20px; font-size: 14px; font-weight: 600; cursor: pointer; }
.planning-actions button:disabled { opacity: 0.5; cursor: not-allowed; }
#planning-action-message { display: block; margin-top: 8px; }

/* To Do modal (browse ticket -> comment/attach -> assign Developer -> label AI-Agent) */
.modal.modal-todo .modal-body { max-height: 78vh; overflow-y: auto; }
.todo-description { white-space: pre-wrap; padding: 10px 12px; background: var(--c-tint); border: 1px solid var(--c-border); border-radius: 6px; margin-bottom: 14px; font-size: 13.5px; }
.todo-comments, .todo-attachments { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.todo-comment { padding: 8px 10px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 6px; }
.todo-comment-meta { font-size: 11.5px; color: var(--c-text-muted); margin-bottom: 3px; }
.todo-comment-body { font-size: 13px; white-space: pre-wrap; }
.todo-attachment { padding: 6px 10px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 6px; font-size: 13px; }
.todo-add-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 18px; }
.todo-add-row .planning-chat-input { flex: 1; }
.todo-add-row button { padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer; flex: none; }
.todo-dispatch-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.todo-dispatch-row select { flex: 1 1 240px; }
.todo-dispatch-row button { padding: 9px 20px; font-size: 14px; font-weight: 600; cursor: pointer; }
.todo-dispatch-row button:disabled { opacity: 0.5; cursor: not-allowed; }
#todo-action-message { display: block; margin-top: 8px; }

/* Pipeline view -------------------------------------------------------- */

/* One accent color per stage, reusing existing palette tones so the board
   doesn't introduce a brand-new color language -- early stages lean
   neutral/cool, later stages lean toward the success teal as a ticket gets
   closer to done. Applied to the node header border, count badge, and the
   per-card left border so a PM can tell the stage at a glance. */
.pipeline-node-todo { --pipeline-accent: var(--c-text-muted); }
.pipeline-node-planning { --pipeline-accent: #4338ca; }
.pipeline-node-plan-review { --pipeline-accent: #8a6d00; }
.pipeline-node-approved { --pipeline-accent: var(--c-primary); }
.pipeline-node-in-progress { --pipeline-accent: var(--c-warning); }
.pipeline-node-dev-review { --pipeline-accent: #1d4ed8; }
.pipeline-node-code-review { --pipeline-accent: var(--c-success); }

.pipeline-fullscreen-btn { margin-left: auto; font-size: 12.5px; padding: 0.4rem 0.8rem; }

.pipeline-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--c-border);
}
.pipeline-summary-total { font-size: 1.05rem; font-weight: 700; color: var(--c-ink); white-space: nowrap; }
.pipeline-summary-counts { display: flex; flex-wrap: wrap; gap: 8px; }
.pipeline-summary-chip {
  font-size: 12px;
  font-weight: 650;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--c-tint);
  color: var(--c-text);
  border-left: 3px solid var(--pipeline-accent, var(--c-primary));
  white-space: nowrap;
}

/* Flow chart: a left-to-right chain of stage nodes with connector arrows
   as real siblings in between (7 nodes + 6 arrows, emitted by
   renderPipeline) -- flex, not grid, since grid's fixed column count can't
   naturally account for the interspersed arrow elements. Nodes share
   width equally via flex:1; arrows stay a fixed small width. Wraps to
   multiple rows on narrow viewports (arrows hidden there, see the media
   query below) instead of introducing horizontal scroll. */
.pipeline-board { overflow: visible; }
.pipeline-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px 0;
}
.pipeline-node {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  flex: 1 1 140px;
  min-width: 140px;
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.pipeline-node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-bottom: 2px solid var(--pipeline-accent, var(--c-border));
  border-radius: 8px 8px 0 0;
  background: var(--c-surface);
}
.pipeline-node-title { font-size: 11.5px; font-weight: 700; color: var(--c-ink); text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipeline-node-count {
  font-size: 12px;
  font-weight: 700;
  min-width: 1.6em;
  text-align: center;
  padding: 1px 6px;
  border-radius: 20px;
  background: var(--pipeline-accent, var(--c-primary));
  color: #fff;
  flex: none;
}
.pipeline-node-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  max-height: 520px;
  flex: 1;
}
.pipeline-node-empty { font-size: 12px; color: var(--c-text-muted); text-align: center; padding: 14px 0; }

/* Connector arrow between adjacent nodes -- glows when the stage it points
   INTO currently holds a ticket, a quick "flow is active here" cue. */
.pipeline-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-border);
  flex: 0 0 22px;
}
.pipeline-arrow svg { width: 20px; height: 20px; }
.pipeline-arrow-active { color: var(--c-primary); }

.pipeline-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--pipeline-accent, var(--c-border));
  border-radius: 6px;
  padding: 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pipeline-card-clickable { cursor: pointer; }
.pipeline-card-clickable:hover { box-shadow: 0 1px 6px rgba(15, 43, 40, 0.12); border-color: var(--pipeline-accent, var(--c-border)); }
.pipeline-card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.pipeline-card-key { font-size: 11.5px; font-weight: 700; color: var(--c-primary); }
.pipeline-card-summary { font-size: 12px; color: var(--c-text); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pipeline-card-meta { font-size: 10.5px; color: var(--c-text-muted); font-style: italic; }
.pipeline-card-labels { display: flex; flex-wrap: wrap; gap: 4px; }
.pipeline-label-chip {
  font-size: 10px;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--c-tint);
  color: var(--c-primary);
}
.pipeline-label-ai { background: var(--c-planning-approved-bg); color: var(--c-planning-approved-text); }

/* Arrival animation: a ticket that genuinely changed stage this poll gets a
   brief highlight pulse on its card, and its destination node's header
   flashes once -- a true cross-screen slide would need to track a card's
   position across independently-scrolling nodes (tickets can skip stages,
   several can move in the same 5s poll); the pulse gives the same "something
   just happened here" signal reliably without that complexity, and reads
   fine even on a distant TV-mode screen. One-shot: the class is stripped by
   renderPipeline's own setTimeout, so a card that re-renders unchanged next
   poll never replays or gets stuck mid-animation. */
@keyframes pipeline-arrive {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--pipeline-accent, var(--c-primary)); background: var(--c-tint); }
  40% { transform: scale(1.035); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pipeline-accent, var(--c-primary)) 35%, transparent); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; background: var(--c-surface); }
}
.pipeline-chip-arrived { animation: pipeline-arrive 0.9s ease-out; }

@keyframes pipeline-node-flash {
  0%, 100% { border-bottom-color: var(--pipeline-accent, var(--c-border)); }
  50% { border-bottom-color: var(--c-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c-accent) 40%, transparent) inset; }
}
.pipeline-node-flash .pipeline-node-head { animation: pipeline-node-flash 0.9s ease-out; }

/* Full-screen "TV mode" -- scoped to #pipeline-section via the Fullscreen
   API (see dashboard.js), so nothing else on the page needs hiding. Larger
   type throughout for distance viewing (e.g. an office monitor). */
#pipeline-section:fullscreen,
#pipeline-section.is-tv-mode {
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
}
#pipeline-section:fullscreen .card-body,
#pipeline-section.is-tv-mode .card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#pipeline-section:fullscreen .pipeline-flow,
#pipeline-section.is-tv-mode .pipeline-flow {
  flex: 1;
}
#pipeline-section:fullscreen .pipeline-node-body,
#pipeline-section.is-tv-mode .pipeline-node-body {
  max-height: none;
}
#pipeline-section:fullscreen .pipeline-node-title,
#pipeline-section.is-tv-mode .pipeline-node-title { font-size: 1rem; }
#pipeline-section:fullscreen .pipeline-node-count,
#pipeline-section.is-tv-mode .pipeline-node-count { font-size: 1rem; padding: 3px 10px; }
#pipeline-section:fullscreen .pipeline-card-key,
#pipeline-section.is-tv-mode .pipeline-card-key { font-size: 0.95rem; }
#pipeline-section:fullscreen .pipeline-card-summary,
#pipeline-section.is-tv-mode .pipeline-card-summary { font-size: 0.9rem; }
#pipeline-section:fullscreen .pipeline-summary-total,
#pipeline-section.is-tv-mode .pipeline-summary-total { font-size: 1.4rem; }
#pipeline-section:fullscreen .pipeline-summary-chip,
#pipeline-section.is-tv-mode .pipeline-summary-chip { font-size: 0.95rem; padding: 6px 14px; }
#pipeline-section:fullscreen .memory-sub,
#pipeline-section.is-tv-mode .memory-sub { display: none; }

@media (max-width: 1100px) {
  /* Below this width a single unbroken row gets too cramped to read --
     wrap instead, and drop the arrows (an arrow mid-wrap would point at
     whatever node happens to follow it visually, not the real next stage,
     which is worse than no arrow). */
  .pipeline-arrow { display: none; }
  .pipeline-node { flex: 1 1 22%; min-width: 150px; }
}
@media (max-width: 640px) {
  .pipeline-node { flex: 1 1 45%; }
}
