:root {
  --bg: #07090e;
  --bg2: #0b0e15;
  --panel: #10141d;
  --panel2: #151a26;
  --border: #1e2534;
  --border2: #2a3348;
  --text: #e8ecf4;
  --muted: #8b94a9;
  --muted2: #5c6579;
  --accent: #a1adff;
  --accent-dim: #6b76d8;
  --green: #3ddc84;
  --amber: #ffb224;
  --red: #ff5d5d;
  --blue: #4da3ff;
  --radius: 14px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
#app { max-width: 1440px; margin: 0 auto; padding: 0 20px 60px; }

/* topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 4px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(7,9,14,.92); backdrop-filter: blur(12px); z-index: 50; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--accent-dim)); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; color: #0a0c12; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.2px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.live-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--green); }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(61,220,132,.5);} 50% { box-shadow: 0 0 0 7px rgba(61,220,132,0);} }
.clock { font-family: var(--mono); font-size: 14px; color: var(--muted); }
.sync-state { font-size: 12px; color: var(--muted2); font-family: var(--mono); }
.sync-pill { display: flex; align-items: center; gap: 8px; font-size: 12px; font-family: var(--mono); color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 5px 8px 5px 12px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted2); }
.sync-dot.ok { background: var(--green); }
.sync-dot.stale { background: var(--amber); }
.sync-dot.err { background: var(--red); }
.sync-now { background: none; border: 1px solid var(--border2); color: var(--accent); border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.sync-now:hover { border-color: var(--accent); }
.sync-now.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 14px 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); font-family: var(--font); font-size: 14px; font-weight: 600; padding: 9px 16px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { color: var(--text); background: var(--panel2); box-shadow: inset 0 0 0 1px var(--border2); }
.badge { display: inline-block; min-width: 20px; text-align: center; background: var(--amber); color: #111; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 6px; margin-left: 4px; }
.badge.zero { background: var(--border2); color: var(--muted); }

main { padding-top: 22px; }
.view { display: none; animation: fadein .25s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font); }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* metrics */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric .label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.metric .value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.metric .sub { font-size: 12px; color: var(--muted2); margin-top: 4px; }
.metric.highlight .value { color: var(--accent); }
.metric.warn .value { color: var(--amber); }

/* agent cards */
.agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.agents-grid.large { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.agent-card { background: var(--panel2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: border-color .15s, transform .15s; position: relative; overflow: hidden; }
.agent-card:hover { border-color: var(--border2); transform: translateY(-2px); }
.agent-card .agent-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.agent-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--border2); display: flex; align-items: center; justify-content: center; font-size: 18px; }
.agent-name { font-weight: 700; font-size: 15px; }
.agent-desc { font-size: 12px; color: var(--muted); }
.status-pill { margin-left: auto; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; padding: 4px 10px; border-radius: 20px; display: flex; align-items: center; gap: 6px; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-working { background: rgba(61,220,132,.12); color: var(--green); }
.status-working::before { animation: pulse 1.5s infinite; }
.status-idle { background: rgba(139,148,169,.12); color: var(--muted); }
.status-error { background: rgba(255,93,93,.12); color: var(--red); }
.status-waiting { background: rgba(255,178,36,.12); color: var(--amber); }
.status-offline { background: rgba(139,148,169,.08); color: var(--muted2); }
.agent-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12.5px; }
.agent-meta .k { color: var(--muted2); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.agent-meta .v { color: var(--text); font-weight: 500; }
.agent-task { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.agent-task .k { color: var(--muted2); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; display: block; margin-bottom: 3px; }

/* activity */
.activity-feed { display: flex; flex-direction: column; gap: 2px; max-height: 420px; overflow-y: auto; }
.activity-feed.full { max-height: 70vh; }
.event { display: flex; gap: 12px; padding: 10px 8px; border-radius: 8px; font-size: 13.5px; animation: fadein .3s ease; }
.event:hover { background: var(--panel2); }
.event.new { background: rgba(161,173,255,.07); }
.event-time { font-family: var(--mono); font-size: 11.5px; color: var(--muted2); min-width: 62px; padding-top: 2px; }
.event-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.event-body { flex: 1; min-width: 0; }
.event-title { font-weight: 600; }
.event-agent { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.event-detail { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.event-link { color: var(--accent); font-size: 12.5px; }
.dot-green { background: var(--green); } .dot-amber { background: var(--amber); }
.dot-red { background: var(--red); } .dot-blue { background: var(--blue); } .dot-gray { background: var(--muted2); }

/* pipeline */
.pipeline { display: flex; gap: 6px; align-items: stretch; overflow-x: auto; padding-bottom: 4px; }
.stage { flex: 1; min-width: 130px; background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; transition: border-color .15s; }
.stage:hover, .stage.selected { border-color: var(--accent-dim); }
.stage .stage-count { font-size: 22px; font-weight: 800; }
.stage .stage-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stage-arrow { align-self: center; color: var(--muted2); font-size: 18px; flex-shrink: 0; }
.pipeline.detailed .stage { min-width: 150px; padding: 16px; }
.stage-detail { margin-top: 16px; }
.stage-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; font-size: 13.5px; }
.stage-item .loc { color: var(--muted); font-size: 12px; }

/* approvals */
.approval { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 12px; background: var(--panel2); }
.approval .approval-title { font-weight: 700; margin-bottom: 6px; }
.approval .approval-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.approval-actions { display: flex; gap: 8px; }
.btn { font-family: var(--font); font-size: 13.5px; font-weight: 600; padding: 9px 18px; border-radius: 9px; border: 1px solid var(--border2); background: var(--panel2); color: var(--text); cursor: pointer; }
.btn:hover { border-color: var(--accent-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0a0c12; }
.btn.approve { background: rgba(61,220,132,.14); border-color: var(--green); color: var(--green); }
.btn.reject { background: rgba(255,93,93,.1); border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.task-form { display: flex; gap: 10px; flex-wrap: wrap; }
.task-form input, .task-form select { font-family: var(--font); font-size: 14px; background: var(--bg2); border: 1px solid var(--border2); color: var(--text); border-radius: 9px; padding: 10px 14px; }
.task-form input { flex: 2; min-width: 220px; }
.empty-state { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 90; }
.drawer-backdrop.open { opacity: 1; pointer-events: all; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 94vw); background: var(--bg2); border-left: 1px solid var(--border2); z-index: 100; transform: translateX(100%); transition: transform .25s ease; overflow-y: auto; padding: 24px; }
.drawer.open { transform: none; }
.drawer-close { position: absolute; top: 16px; right: 16px; background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.drawer h3 { font-size: 18px; margin-bottom: 4px; }
.kv-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv-row .k { color: var(--muted); }

/* toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel2); border: 1px solid var(--border2); border-radius: 10px; padding: 12px 20px; font-size: 14px; font-weight: 600; animation: fadein .25s ease; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast.ok { border-color: var(--green); } .toast.err { border-color: var(--red); }

.filter-row { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip { font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 16px; border: 1px solid var(--border2); background: none; color: var(--muted); cursor: pointer; font-family: var(--font); }
.filter-chip.active { background: var(--accent); color: #0a0c12; border-color: var(--accent); }

.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  #app { padding: 0 12px 40px; }
  .clock { display: none; }
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
