:root {
  --bg: #0b0d10;
  --bg-1: #11151a;
  --bg-2: #161b22;
  --bg-3: #1c232c;
  --border: #232a33;
  --border-soft: #1b222b;
  --text: #d7dde4;
  --text-dim: #8a95a3;
  --text-mute: #5a6573;
  --accent: #7ee787;
  --accent-2: #56d4dd;
  --warn: #f0b429;
  --danger: #ff6b6b;
  --info: #79b8ff;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--text-dim); font-size: 13px; }

/* ===== top bar ===== */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand__dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(126,231,135,0.4);
}
.brand__name { font-family: var(--mono); font-weight: 600; }
.brand__sub { color: var(--text-mute); font-size: 12px; }

.tabs { display: flex; gap: 2px; }
.tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.tab:hover { color: var(--text); background: var(--bg-2); }
.tab--active { color: var(--text); background: var(--bg-3); }

.top__right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.link {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }

/* ===== gate ===== */
.gate {
  position: fixed; inset: 0;
  background: rgba(11,13,16,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.gate__card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(380px, 90vw);
  display: flex; flex-direction: column; gap: 12px;
}
.gate__title { font-family: var(--mono); font-weight: 600; font-size: 16px; }
.gate__hint { color: var(--text-dim); font-size: 13px; }
.gate__error { color: var(--danger); font-size: 12px; }

input, textarea, select {
  font: inherit;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-2);
}
textarea { font-family: var(--mono); resize: vertical; }

button {
  font: inherit;
  cursor: pointer;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 4px;
}
button:hover { background: var(--bg-3); }
.btn--primary {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 600;
}
.btn--primary:hover { background: #8df492; }

/* ===== main ===== */
.main {
  padding: 24px 20px 80px;
  max-width: 1100px;
  margin: 0 auto;
}

h1 { font-size: 20px; margin: 0 0 6px; font-weight: 600; }

.view__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}
.filters { display: flex; gap: 8px; align-items: center; }

/* ===== form ===== */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; color: var(--text-dim); }
.field summary {
  cursor: pointer; color: var(--text-dim); font-size: 13px;
  padding: 4px 0; user-select: none;
}
.field summary:hover { color: var(--text); }
.field summary + textarea { margin-top: 8px; }

.form__row { display: flex; align-items: center; gap: 12px; }
.form__error { color: var(--danger); font-size: 12px; }

/* ===== lists ===== */
.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 14px;
  align-items: center;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.row:hover { border-color: #2d3640; background: var(--bg-2); }
.row__status { font-family: var(--mono); font-size: 12px; }
.row__body { min-width: 0; }
.row__input {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 4px;
}
.row__meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 12px; flex-wrap: wrap; }
.row__meta b { color: var(--text); font-weight: 500; }
.row__date { font-family: var(--mono); font-size: 12px; color: var(--text-mute); white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--border);
}
.badge--muted { color: var(--text-mute); }
.badge--ok { color: var(--accent); border-color: rgba(126,231,135,0.3); background: rgba(126,231,135,0.06); }
.badge--running { color: var(--accent-2); border-color: rgba(86,212,221,0.3); background: rgba(86,212,221,0.06); }
.badge--queued { color: var(--warn); border-color: rgba(240,180,41,0.3); background: rgba(240,180,41,0.06); }
.badge--failed { color: var(--danger); border-color: rgba(255,107,107,0.3); background: rgba(255,107,107,0.06); }
.badge--info { color: var(--info); border-color: rgba(121,184,255,0.3); background: rgba(121,184,255,0.06); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

/* ===== task detail ===== */
.detail__head {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.detail__title {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-mute);
  margin-bottom: 6px;
}
.detail__input {
  white-space: pre-wrap;
  font-size: 14px;
  margin-bottom: 12px;
}
.detail__meta {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-dim);
}
.detail__meta b { color: var(--text); font-weight: 500; }

.section {
  margin-top: 22px;
}
.section__title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  margin-bottom: 10px;
  font-weight: 600;
}

/* DAG */
.dag {
  display: flex; gap: 20px; flex-wrap: wrap;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.dag__level {
  display: flex; flex-direction: column; gap: 8px;
  border-right: 1px dashed var(--border);
  padding-right: 20px;
  min-width: 160px;
}
.dag__level:last-child { border-right: 0; padding-right: 0; }
.dag__level-label {
  font-family: var(--mono); font-size: 11px; color: var(--text-mute);
  margin-bottom: 4px;
}
.node {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
}
.node__id { font-family: var(--mono); font-size: 11px; color: var(--text-mute); }
.node__agent { font-weight: 500; }
.node--success { border-left: 3px solid var(--accent); }
.node--running { border-left: 3px solid var(--accent-2); }
.node--failed { border-left: 3px solid var(--danger); }
.node--pending { border-left: 3px solid var(--text-mute); }
.node--skipped { border-left: 3px solid var(--warn); }

/* runs table */
.runs { width: 100%; border-collapse: collapse; font-size: 13px; }
.runs th, .runs td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
}
.runs th {
  background: var(--bg-1);
  font-weight: 500;
  color: var(--text-dim);
  font-size: 12px;
}
.runs tr:hover td { background: var(--bg-1); }
.runs td.mono { font-family: var(--mono); font-size: 12px; }

/* events timeline */
.events { display: flex; flex-direction: column; gap: 4px; }
.event {
  display: grid;
  grid-template-columns: 130px 180px 1fr;
  gap: 12px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.event:hover { border-color: var(--border-soft); background: var(--bg-1); }
.event__time { font-family: var(--mono); color: var(--text-mute); }
.event__type { font-family: var(--mono); color: var(--info); }
.event__payload { font-family: var(--mono); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* result */
.result {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 400px;
  overflow: auto;
  margin: 0;
}
.result--error { border-color: rgba(255,107,107,0.4); color: var(--danger); }

/* leaf result card */
.leaf {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 12px;
}
.leaf__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.leaf__agent { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.leaf__title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  flex: 1 1 100%;
  margin-top: 6px;
}

/* markdown rendering */
.md {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }

.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  font-weight: 600;
  line-height: 1.3;
  margin: 1.4em 0 0.5em;
  color: var(--text);
}
.md h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.md h2 { font-size: 1.35em; border-bottom: 1px solid var(--border-soft); padding-bottom: 0.2em; }
.md h3 { font-size: 1.15em; }
.md h4 { font-size: 1.05em; color: var(--text-dim); }
.md h5, .md h6 { font-size: 1em; color: var(--text-dim); }

.md p { margin: 0.6em 0; }

.md strong { color: var(--text); font-weight: 600; }
.md em { color: var(--text); font-style: italic; }

.md a {
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(86,212,221,0.4);
}
.md a:hover { text-decoration-color: var(--accent-2); }

.md code {
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--accent);
}
.md pre.md__code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0.8em 0;
  font-size: 12px;
}
.md pre.md__code code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}

.md ul, .md ol {
  margin: 0.6em 0;
  padding-left: 1.6em;
}
.md li { margin: 0.25em 0; }
.md li > p { margin: 0; }

.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

.md blockquote {
  border-left: 3px solid var(--border);
  padding: 0.1em 0 0.1em 14px;
  margin: 0.8em 0;
  color: var(--text-dim);
}

.md table {
  border-collapse: collapse;
  margin: 0.8em 0;
}
.md th, .md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 13px;
}

/* raw json details */
details.raw {
  margin-top: 14px;
}
details.raw > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-mute);
  font-family: var(--mono);
  padding: 4px 0;
  list-style: none;
}
details.raw > summary::before {
  content: "▸ ";
}
details.raw[open] > summary::before {
  content: "▾ ";
}
details.raw > summary:hover { color: var(--text-dim); }
details.raw > .result { margin-top: 8px; }

/* agents / tools cards */
.entity {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.entity__head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.entity__name { font-family: var(--mono); font-weight: 600; }
.entity__desc { color: var(--text-dim); font-size: 13px; margin: 6px 0 10px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  max-width: 360px;
  z-index: 50;
  animation: toast-in 0.2s ease;
}
.toast--error { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== employees ===== */
.emp-row {
  grid-template-columns: 1fr auto;
  cursor: default;
}
.emp-row:hover { background: var(--bg-1); border-color: var(--border); }
.emp-row__actions {
  display: flex; gap: 6px; align-items: center;
}
.routine-runs {
  margin-top: 12px;
  border-top: 1px solid var(--border, rgba(255,255,255,0.08));
  padding-top: 10px;
}
.btn--danger {
  background: transparent;
  border-color: rgba(255,107,107,0.35);
  color: var(--danger);
  padding: 6px 10px;
}
.btn--danger:hover { background: rgba(255,107,107,0.08); }

.form__row--split { gap: 12px; }
.form__row--split .field { flex: 1; min-width: 0; }
.field--checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field--checkbox input { width: auto; }

#employees-search { min-width: 220px; }

/* ===== modal ===== */
.modal {
  position: fixed; inset: 0;
  z-index: 80;
  display: flex; align-items: center; justify-content: center;
}
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(11,13,16,0.7);
}
.modal__card {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow: auto;
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 15px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 10px;
  margin-bottom: 4px;
}
.modal__foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}
.modal__foot .spacer { flex: 1; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; padding: 10px 12px; gap: 12px; }
  .tabs { width: 100%; overflow-x: auto; }
  .top__right { margin-left: 0; }
  .row { grid-template-columns: 80px 1fr; }
  .row__date { grid-column: 2; }
  .emp-row { grid-template-columns: 1fr; }
  .emp-row__actions { justify-content: flex-end; }
  .form__row--split { flex-direction: column; }
  .main { padding: 16px 12px 60px; }
  .event { grid-template-columns: 1fr; }
}
