:root {
  --bg: #0c1220;
  --bg-2: #111a2e;
  --panel: #151f36;
  --border: #26324d;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #4a9eff;
  --accent-2: #1871e8;
  --danger: #ef4444;
  --ok: #10b981;
  --warn: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.ml-auto { margin-left: auto; }

/* ── login ─── */
.login-page { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(ellipse at top, #1e293b, #0c1220); }
.login-card { background: var(--panel); border: 1px solid var(--border); padding: 40px; border-radius: 16px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: block; margin: 18px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.login-card input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font-size: 15px; }
.login-card button { margin-top: 20px; width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent-2); color: white; font-weight: 600; font-size: 15px; cursor: pointer; }
.login-card .error { margin-top: 10px; color: var(--danger); font-size: 13px; }

/* ── layout ─── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 28px; background: rgba(21,31,54,.6); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; letter-spacing: .03em; }
.topbar nav a { margin-left: 14px; color: var(--muted); text-decoration: none; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 28px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; margin-bottom: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 18px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { padding: 8px 12px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); border-radius: 8px; }
.inline-form button, button, select, textarea, input[type=text], input[type=password] { font-family: inherit; }
button { padding: 8px 14px; border: 0; border-radius: 8px; background: var(--accent-2); color: white; cursor: pointer; font-weight: 600; }
button.danger { background: var(--danger); }
select, textarea, input:not([type=checkbox]) { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); width: 100%; }
textarea { resize: vertical; min-height: 80px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }

/* ── project grid ─── */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.project-card { display: block; padding: 16px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--border); text-decoration: none; color: inherit; transition: transform .12s, border-color .12s; }
.project-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.project-card.status-final { opacity: .7; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h3 { margin: 0; font-size: 16px; }
.badge { font-size: 10px; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; background: var(--border); color: var(--muted); letter-spacing: .06em; }
.status-final .badge { background: var(--ok); color: white; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12px; }
.pill { padding: 2px 8px; border-radius: 999px; background: var(--border); font-size: 11px; }
.pill.pending { background: var(--warn); color: #111; }
.pill.state-approved { background: var(--ok); color: white; }
.pill.state-rejected { background: var(--danger); color: white; }
.pill.state-pending { background: var(--warn); color: #111; }
.pill.state-delivered { background: var(--accent-2); color: white; }

/* ── agents grid 3x2 (fixed height, internal scroll) ─── */
.agents-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 260px;
  gap: 12px;
  margin-bottom: 22px;
}
@media (max-width: 960px) { .agents-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .agents-row { grid-template-columns: 1fr; } }
.agent-chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--role-color, var(--accent));
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.agent-head { display: flex; align-items: center; gap: 8px; font-size: 14px; flex-shrink: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; flex-shrink: 0; }
.dot.state-waiting { background: var(--muted); }
.dot.state-working { background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: pulse 1.4s infinite; }
.dot.state-done { background: var(--ok); }
.dot.state-blocked { background: var(--danger); }
.dot.state-offline { background: #475569; }
.dot.state-idle { background: var(--muted); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.state-label { font-size: 10px; color: var(--muted); margin-left: auto; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.05); }
.agent-chip[data-state="working"] .state-label { background: rgba(245,158,11,.18); color: var(--warn); }
.agent-chip[data-state="waiting"] .state-label { background: rgba(74,158,255,.15); color: var(--accent); }
.agent-chip[data-state="done"]    .state-label { background: rgba(16,185,129,.18); color: var(--ok); }
.agent-chip[data-state="blocked"] .state-label { background: rgba(239,68,68,.2); color: var(--danger); }
.agent-chip[data-state="idle"]    .state-label { background: rgba(148,163,184,.18); color: var(--muted); }
.agent-chip[data-state="offline"] .state-label { background: rgba(100,116,139,.2); color: #64748b; }
.agent-menu { margin-left: 6px; }
.agent-menu .mini { padding: 2px 8px; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; }
.agent-menu .mini:hover { background: rgba(255,255,255,.06); }
.state-reason { font-size: 11px; margin-top: 4px; opacity: .85; }
.agent-session { font-size: 11px; margin-top: 2px; flex-shrink: 0; }
.agent-task {
  margin-top: 8px;
  padding: 6px 8px;
  background: rgba(74,158,255,.08);
  border-left: 2px solid var(--role-color, var(--accent));
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1.35;
  flex-shrink: 0;
  max-height: 46px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.agent-task .task-meta { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; display: block; }
.agent-task.empty { opacity: .55; font-style: italic; }
.agent-tail {
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.35;
  flex: 1 1 auto;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
  min-height: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.search-row input { flex: 1; }
.search-row select { width: auto; min-width: 140px; }

.decision-card { background: var(--bg-2); border: 1px solid var(--border); border-left: 4px solid #a855f7; border-radius: 8px; padding: 14px; margin-bottom: 10px; }
.decision-card h4 { margin: 0 0 6px; font-size: 15px; }
.decision-alts { margin: 8px 0; padding-left: 18px; }
.decision-alts li { color: var(--muted); font-size: 13px; }
.decision-meta { margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; gap: 12px; }

/* ── tabs ─── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { background: transparent; color: var(--muted); padding: 10px 14px; border-radius: 8px 8px 0 0; font-weight: 500; white-space: nowrap; }
.tab.active { background: var(--bg-2); color: var(--text); border-bottom: 2px solid var(--accent); }

/* ── sequence ─── */
.sequence-wrap { background: var(--bg-2); border-radius: 10px; padding: 10px; overflow: auto; }
#sequence-svg { display: block; min-width: 900px; background: var(--bg); border-radius: 6px; }
.sequence-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.legend { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend .leg i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ── event cards ─── */
.event-card { background: var(--bg-2); border: 1px solid var(--border); border-left: 4px solid var(--accent-2); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.event-head { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.tag { padding: 2px 8px; border-radius: 4px; background: var(--accent-2); color: white; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.event-body { font-size: 14px; }
.event-pre { background: var(--bg); padding: 10px; border-radius: 6px; font-size: 12px; font-family: ui-monospace, monospace; max-height: 240px; overflow: auto; white-space: pre-wrap; margin-top: 8px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
