:root {
  --bg: #0b0f14;
  --bg-panel: #11171f;
  --bg-panel-2: #151d27;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #00ffa3;
  --accent-dim: #00c987;
  --purple: #a855f7;
  --sky: #38bdf8;
  --red: #ef4444;
  --amber: #f59e0b;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(168, 85, 247, 0.12), transparent 60%),
    radial-gradient(1000px 500px at 90% 0%, rgba(0, 255, 163, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo {
  font-size: 2rem;
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.brand h1 {
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.tagline {
  font-size: 0.72rem;
  color: var(--muted);
}
.status-pill {
  font-size: 0.75rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--muted);
  white-space: nowrap;
}
.status-pill.on {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(0, 255, 163, 0.25);
}
.status-pill.off {
  border-color: var(--red);
  color: var(--red);
}

/* ── Layout ─────────────────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 900px) {
  .grid-two { grid-template-columns: 1fr; }
}

.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.panel-head h2 {
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}
.muted { color: var(--muted); font-size: 0.75rem; }

/* ── Module grid ────────────────────────────────────── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 0.8rem;
}
.module-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.15s ease;
}
.module-card.ok { border-left: 3px solid var(--accent); }
.module-card.missing { border-left: 3px solid var(--red); opacity: 0.75; }
.module-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.module-card h3 {
  font-size: 0.82rem;
  font-weight: 600;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.dot.ok { background: var(--accent); box-shadow: 0 0 8px rgba(0,255,163,0.6); }
.dot.missing { background: var(--red); }
.module-card p {
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
}
.module-detail {
  font-size: 0.68rem;
  color: var(--sky);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.module-link {
  font-size: 0.72rem;
  color: var(--purple);
  text-decoration: none;
}
.module-link:hover { text-decoration: underline; }

.loading {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1rem 0;
}

/* ── Run form ───────────────────────────────────────── */
.run-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto auto;
  gap: 0.7rem;
  align-items: end;
}
@media (max-width: 640px) {
  .run-form { grid-template-columns: 1fr 1fr; }
}
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  width: 100%;
}
.field input:focus { outline: none; border-color: var(--accent); }
.check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  padding-bottom: 0.45rem;
  user-select: none;
  cursor: pointer;
}
.check input { accent-color: var(--purple); }
.actions {
  display: flex;
  gap: 0.5rem;
  grid-column: 1 / -1;
}

/* ── Buttons ────────────────────────────────────────── */
.btn {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn.primary {
  background: var(--accent-dim);
  color: #04120c;
  border-color: var(--accent);
  font-weight: 700;
}
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: var(--red); border-color: rgba(239,68,68,0.4); }
.btn.danger:hover { background: rgba(239,68,68,0.15); }
.btn.ghost { font-size: 0.7rem; color: var(--muted); }

/* ── Run badge + log ────────────────────────────────── */
.run-badge {
  font-size: 0.72rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.run-badge.running { border-color: var(--accent); color: var(--accent); animation: blink 1.2s ease-in-out infinite; }
.run-badge.done { border-color: var(--amber); color: var(--amber); }
.run-badge.error, .run-badge.killswitch { border-color: var(--red); color: var(--red); }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.log-box {
  margin-top: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-size: 0.7rem;
  color: var(--muted);
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}
.log-box .log-line.log-event { color: var(--accent); }
.log-box .log-line.log-err { color: var(--red); }

/* ── Journal list ───────────────────────────────────── */
.journal-list {
  max-height: 330px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.journal-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-size: 0.7rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  background: rgba(255,255,255,0.02);
}
.journal-entry .tick-no { color: var(--sky); font-weight: 700; flex: none; }
.journal-entry .action { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.journal-entry .pnl { flex: none; font-weight: 700; }
.journal-entry .pnl.pos { color: var(--accent); }
.journal-entry .pnl.neg { color: var(--red); }
.journal-entry .outcome-kill { color: var(--red); }

/* ── Doc chips ──────────────────────────────────────── */
.doc-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  font-size: 0.72rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--sky);
  text-decoration: none;
  background: rgba(56,189,248,0.05);
  transition: all 0.15s ease;
}
.chip:hover {
  border-color: var(--sky);
  background: rgba(56,189,248,0.12);
  color: #7dd3fc;
}

/* ── Footer ─────────────────────────────────────────── */
footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.7rem;
}
footer code { color: var(--purple); }