@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=IBM+Plex+Mono:wght@400;500&family=Inter:wght@400;500;600&display=swap');

:root {
  --ink: #12161C;
  --surface: #1B212A;
  --surface-raised: #212936;
  --border: #2A323D;
  --border-soft: #232B36;
  --text: #E9EDF2;
  --text-muted: #8B95A3;
  --text-faint: #5B6472;
  --human: #5EC8D8;
  --human-soft: rgba(94, 200, 216, 0.14);
  --agent: #E8A33D;
  --agent-soft: rgba(232, 163, 61, 0.14);
  --good: #6FCF97;
  --good-soft: rgba(111, 207, 151, 0.14);
  --warn: #E8A33D;
  --warn-soft: rgba(232, 163, 61, 0.14);
  --danger: #E8636B;
  --danger-soft: rgba(232, 99, 107, 0.14);
  --radius: 10px;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 100% 0%, rgba(94, 200, 216, 0.05), transparent 45%),
    radial-gradient(circle at 0% 100%, rgba(232, 163, 61, 0.05), transparent 45%);
}

button, input, textarea { font-family: inherit; }

#app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 28px 60px;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--agent);
  flex-shrink: 0;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.tagline { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

.status-cluster { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.autonomy-pill {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}
.autonomy-value { color: var(--human); font-weight: 500; font-size: 13px; }

.mcp-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}
.mcp-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.mcp-status--checking .dot { background: var(--warn); animation: pulse-dot 1.1s ease-in-out infinite; }
.mcp-status--ready { border-color: rgba(111, 207, 151, 0.35); color: var(--good); }
.mcp-status--ready .dot { background: var(--good); }
.mcp-status--unavailable { border-color: rgba(230, 100, 100, 0.3); color: #E39399; }
.mcp-status--unavailable .dot { background: var(--danger); }

@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.ghost-btn {
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.ghost-btn:hover { border-color: var(--text-faint); color: var(--text); }

.text-btn {
  font-size: 12.5px;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--border);
}
.text-btn:hover { color: var(--text); text-decoration-color: var(--text-faint); }

.primary-btn {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--human);
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 22px;
  align-items: start;
}

.main-col, .side-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.panel-head h2 { font-family: var(--font-display); font-size: 15px; font-weight: 700; margin: 0; }
.panel-sub { font-size: 12px; color: var(--text-muted); margin: 2px 0 12px; line-height: 1.4; }

/* ---------- Mission panel ---------- */

.mission-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.mission-empty { font-size: 13px; color: var(--text-faint); margin: 10px 0 0; }

.mission-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 8px 0 8px;
}

.mission-tags { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 8px; }

.mission-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.mission-tag--deadline { color: var(--human); border-color: rgba(94, 200, 216, 0.3); }
.mission-tag--decisions { color: var(--agent); border-color: rgba(232, 163, 61, 0.3); }

.budget-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-raised);
  overflow: hidden;
  margin-top: 6px;
}
.budget-fill { height: 100%; background: var(--human); border-radius: 999px; }
.budget-fill.over { background: var(--danger); }
.budget-label { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }
.budget-label.over { color: var(--danger); }

.constraint-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.constraint-list li {
  font-size: 12.5px;
  color: var(--text-muted);
  padding-left: 16px;
  position: relative;
  line-height: 1.4;
}
.constraint-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--text-faint);
}

.mission-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.mission-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); }
.mission-form input, .mission-form textarea {
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  resize: vertical;
}
.mission-form input:focus, .mission-form textarea:focus { outline: none; border-color: var(--human); }
.mission-form-row { display: flex; gap: 12px; }
.mission-form-row label { flex: 1; }
.mission-form-actions { display: flex; align-items: center; gap: 14px; }

/* ---------- Repository panel ---------- */

.repo-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.repo-empty { font-size: 12.5px; color: var(--text-muted); margin: 4px 0 12px; line-height: 1.5; }

.repo-connect-btn { display: inline-block; text-decoration: none; }

.github-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.github-avatar { border-radius: 50%; display: block; }
.github-login { font-weight: 500; }
.github-identity .text-btn { margin-left: auto; }

.repo-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: var(--font-mono);
  margin-bottom: 10px;
}

.repo-context {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}
.repo-stat { white-space: nowrap; }
.repo-stat--commit { font-style: italic; color: var(--text-faint); white-space: normal; }
.repo-context-placeholder { color: var(--text-faint); font-style: italic; }

.repo-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.repo-picker select {
  flex: 1;
  min-width: 160px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
}
.repo-picker select:focus { outline: none; border-color: var(--human); }

/* ---------- Toast banner ---------- */

.toast-banner {
  margin: -8px 0 18px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}
.toast-banner[data-kind="good"] { border-color: rgba(111, 207, 151, 0.35); color: var(--good); background: var(--good-soft); }
.toast-banner[data-kind="danger"] { border-color: rgba(232, 99, 107, 0.35); color: var(--danger); background: var(--danger-soft); }

/* ---------- Board ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-head { display: flex; align-items: baseline; justify-content: space-between; }
.column-head h2 { font-family: var(--font-display); font-size: 15px; font-weight: 700; margin: 0; }
.count { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); }

.quick-add { display: flex; gap: 6px; }
.quick-add input {
  flex: 1;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
}
.quick-add input:focus { outline: none; border-color: var(--human); }
.quick-add input::placeholder { color: var(--text-faint); }
.quick-add button {
  width: 34px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.quick-add button:hover { color: var(--text); border-color: var(--text-faint); }

.card-list { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.card-list.drag-over { outline: 1px dashed var(--text-faint); outline-offset: 4px; border-radius: 8px; }

.empty-hint {
  font-size: 12px;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
}

/* ---------- Cards ---------- */

.card {
  display: flex;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: grab;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.4; }

.card-bar { width: 4px; flex-shrink: 0; background: var(--text-faint); }
.card[data-actor="human"] .card-bar { background: var(--human); }
.card[data-actor="agent"] .card-bar { background: var(--agent); }

.card-body { flex: 1; padding: 10px 12px 11px; min-width: 0; }
.card-top { display: flex; align-items: flex-start; gap: 7px; }

.priority-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--text-faint); }
.card[data-priority="high"] .priority-dot { background: var(--danger); }
.card[data-priority="medium"] .priority-dot { background: var(--warn); }
.card[data-priority="low"] .priority-dot { background: var(--good); }

.card-title { flex: 1; font-size: 14px; font-weight: 500; margin: 0; line-height: 1.35; word-break: break-word; }

.external-flag {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--agent-soft);
  color: var(--agent);
  flex-shrink: 0;
  margin-top: 2px;
}

.card-delete {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 0 0 0 6px;
  flex-shrink: 0;
}
.card-delete:hover { color: var(--danger); }

.card-notes { font-size: 12.5px; color: var(--text-muted); margin: 6px 0 0; line-height: 1.4; }
.card-notes:empty { display: none; }

.card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 9px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.card-actor {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card[data-actor="human"] .card-actor { background: var(--human-soft); color: var(--human); }
.card[data-actor="agent"] .card-actor { background: var(--agent-soft); color: var(--agent); }
.card-cost:empty { display: none; }
.card-time { margin-left: auto; }

.card-controls { display: none; gap: 5px; margin-top: 9px; }
.card:hover .card-controls, .card:focus-within .card-controls { display: flex; }
.card-controls button {
  flex: 1;
  font-size: 10.5px;
  padding: 5px 4px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--ink);
  color: var(--text-muted);
  cursor: pointer;
}
.card-controls button:hover { color: var(--text); border-color: var(--text-faint); }

@keyframes agent-flash {
  0% { box-shadow: 0 0 0 2px rgba(232, 163, 61, 0.7); }
  100% { box-shadow: 0 0 0 2px rgba(232, 163, 61, 0); }
}
.card.agent-touch { animation: agent-flash 1.8s ease-out; }

/* ---------- Decision room ---------- */

.decision-room {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.decision-room .count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--agent);
  background: var(--agent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.decision-empty { font-size: 12.5px; color: var(--text-faint); margin: 0; }

.decision-list { display: flex; flex-direction: column; gap: 12px; }

.decision-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  padding: 12px 13px;
}
.decision-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.decision-title { font-size: 13.5px; font-weight: 600; margin: 0; line-height: 1.35; }
.decision-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--agent);
  background: var(--agent-soft);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}
.decision-rationale { font-size: 12px; color: var(--text-muted); margin: 6px 0 10px; line-height: 1.45; }

.decision-options { display: flex; flex-direction: column; gap: 8px; }

.option-card {
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: var(--ink);
  padding: 9px 10px;
}
.option-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.option-label { font-size: 12.5px; font-weight: 600; }
.option-risk {
  font-family: var(--font-mono);
  font-size: 9.5px;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.option-risk[data-risk="low"] { background: var(--good-soft); color: var(--good); }
.option-risk[data-risk="medium"] { background: var(--warn-soft); color: var(--warn); }
.option-risk[data-risk="high"] { background: var(--danger-soft); color: var(--danger); }
.option-description { font-size: 12px; color: var(--text-muted); margin: 6px 0; line-height: 1.4; }
.option-github-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--human);
  background: var(--human-soft);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 8px;
}
.option-cost { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-bottom: 8px; }
.option-choose { width: 100%; }

.decision-actions { margin-top: 10px; display: flex; justify-content: flex-end; }

/* ---------- Ledger ---------- */

.ledger {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 20px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}

.ledger-feed { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.ledger-entry { display: flex; gap: 9px; padding: 8px 0; border-top: 1px solid var(--border-soft); font-size: 12px; }
.ledger-entry:first-child { border-top: none; }

.ledger-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: var(--font-mono);
  margin-top: 1px;
}
.ledger-entry[data-actor="human"] .ledger-icon { background: var(--human-soft); color: var(--human); }
.ledger-entry[data-actor="agent"] .ledger-icon { background: var(--agent-soft); color: var(--agent); }

.ledger-text { flex: 1; color: var(--text); line-height: 1.45; }
.ledger-link { color: var(--human); font-size: 11px; text-decoration: none; margin-left: 4px; }
.ledger-link:hover { text-decoration: underline; }
.ledger-why { display: block; font-size: 11px; color: var(--text-muted); font-style: italic; margin-top: 2px; }
.ledger-time { display: block; font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-top: 3px; }
.ledger-empty { font-size: 12px; color: var(--text-faint); padding: 10px 0; }

/* ---------- Footer ---------- */

.foot-note { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.foot-note p { font-size: 12px; color: var(--text-faint); max-width: 780px; line-height: 1.6; margin: 0; }
.foot-note code { font-family: var(--font-mono); color: var(--text-muted); background: var(--surface); padding: 1px 5px; border-radius: 4px; }

/* ---------- Replay overlay ---------- */

.replay-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.86);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}

.replay-panel {
  width: min(880px, 100%);
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.replay-head { display: flex; align-items: center; justify-content: space-between; }
.replay-head h2 { font-family: var(--font-display); font-size: 17px; margin: 0; }

.replay-entry-text {
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 20px;
  line-height: 1.5;
}
.replay-actor { font-family: var(--font-mono); font-size: 11px; padding: 2px 7px; border-radius: 999px; margin-right: 6px; }
.replay-actor[data-actor="human"] { background: var(--human-soft); color: var(--human); }
.replay-actor[data-actor="agent"] { background: var(--agent-soft); color: var(--agent); }

.replay-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.replay-column {
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px;
  min-height: 90px;
}
.replay-column h4 {
  font-family: var(--font-display);
  font-size: 12px;
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}
.replay-column h4 span { color: var(--text-faint); font-family: var(--font-mono); }
.replay-card {
  font-size: 11.5px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--ink);
  border-left: 3px solid var(--text-faint);
  margin-bottom: 6px;
  line-height: 1.35;
}
.replay-card[data-actor="human"] { border-left-color: var(--human); }
.replay-card[data-actor="agent"] { border-left-color: var(--agent); }
.replay-card b { color: var(--agent); font-family: var(--font-mono); font-size: 9px; }
.replay-card--empty { color: var(--text-faint); border-left-color: transparent; font-style: italic; }

.replay-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.replay-controls input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--human); }
.replay-position { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); white-space: nowrap; }

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .board { grid-template-columns: 1fr; }
  .ledger { position: static; max-height: none; }
}

@media (max-width: 640px) {
  .replay-board { grid-template-columns: 1fr; }
  .mission-form-row { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .card.agent-touch { animation: none; }
  .mcp-status--checking .dot { animation: none; }
}
[hidden] {
  display: none !important;
}