:root {
  --bg: #0a0c10;
  --surface: #12151c;
  --surface2: #1a1f2b;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6ea8fe;
  --accent-dim: #3d5a80;
  --ok: #3dd68c;
  --warn: #ffb020;
  --danger: #ff6b6b;
  --radius: 12px;
  --nav-h: 56px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topnav .brand {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  margin-right: 0.5rem;
}

.topnav .brand span { color: var(--muted); font-weight: 400; }

.topnav nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.topnav nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: none;
}

.topnav nav a:hover { background: var(--surface2); color: var(--text); }
.topnav nav a.active { background: var(--accent-dim); color: var(--text); }

.topnav .actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent);
  color: #0a0c10;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.75rem; }
.btn-danger { background: var(--danger); color: #fff; }

/* ── Layout ── */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Stats row ── */
.stats {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  font-size: 0.8125rem;
}

.stat strong { font-size: 1.1rem; display: block; margin-top: 0.1rem; }

/* ── Sections ── */
section { margin-bottom: 2rem; }

section > h2 {
  font-size: 0.75rem;
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Cards ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  transition: border-color 0.15s;
}

.card:hover { border-color: var(--accent-dim); }
.card.missing { opacity: 0.6; border-style: dashed; }
.card.has-blocker { border-color: #5a3030; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.card-title {
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

.card-title:hover { color: var(--accent); }

.badge {
  font-size: 0.65rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.phase { color: var(--accent); border-color: var(--accent-dim); background: #152035; }
.badge.profile { color: var(--muted); }
.badge.blocker { color: var(--danger); border-color: #5a3030; background: #2a1515; }

.path {
  font-size: 0.7rem;
  color: var(--muted);
  word-break: break-all;
  font-family: Consolas, "Courier New", monospace;
}

.label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.15rem;
}

ul.compact {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.8125rem;
}

ul.compact li { margin: 0.15rem 0; }

.card-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ── Alerts ── */
.alert {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}

.alert-ok { background: #152a1f; border: 1px solid #2a4a3a; color: var(--ok); }
.alert-warn { background: #2a2215; border: 1px solid #4a3a2a; color: var(--warn); }
.alert-error { background: #2a1515; border: 1px solid #5a3030; color: var(--danger); }
.alert-info { background: #152035; border: 1px solid var(--accent-dim); color: var(--accent); }

.empty { color: var(--muted); font-size: 0.875rem; }

/* ── Running / Inbox lists ── */
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8125rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 0.4rem;
}

.list-item .port { color: var(--ok); font-family: Consolas, monospace; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
}

.modal h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.modal .close-btn {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.8125rem;
  z-index: 300;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ── Design doc markdown ── */
.doc-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  font-size: 0.9375rem;
}

.doc-body h1 { font-size: 1.6rem; margin: 0 0 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.doc-body h2 { font-size: 1.15rem; margin: 1.75rem 0 0.65rem; color: var(--accent); }
.doc-body h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
.doc-body p { margin: 0.5rem 0; }
.doc-body blockquote {
  margin: 0.75rem 0;
  padding: 0.5rem 0.85rem;
  border-left: 3px solid var(--accent-dim);
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.875rem;
}
.doc-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  margin: 0.75rem 0;
}
.doc-body th, .doc-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
}
.doc-body th { background: var(--surface2); color: var(--muted); }
.doc-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.45;
}
.doc-body code {
  font-family: Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.doc-body pre code { background: none; padding: 0; }
.doc-body ul, .doc-body ol { padding-left: 1.25rem; }
.doc-body li { margin: 0.25rem 0; }
.doc-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.doc-body input[type=checkbox] { margin-right: 0.35rem; }

/* ── Command queue panel ── */
.cmd-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  font-size: 0.8125rem;
}

.cmd-item {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-family: Consolas, monospace;
  font-size: 0.75rem;
}

.cmd-item:last-child { border-bottom: none; }

/* ── Mobile ── */
@media (max-width: 640px) {
  .topnav .brand span { display: none; }
  .grid { grid-template-columns: 1fr; }
  .page { padding: 1rem 0.75rem 2.5rem; }
  .doc-body { padding: 1rem; }
}
