:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #181c25;
  --border: #242a36;
  --text: #e7eaf0;
  --muted: #8a93a6;
  --accent: #7c6cff;
  --accent-2: #4fd1c5;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --gray: #94a3b8;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f7;
  --border: #e2e6ee;
  --text: #151821;
  --muted: #6b7385;
  --shadow: 0 10px 30px rgba(20, 24, 33, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px 22px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.ico { width: 18px; text-align: center; }
.sidebar-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--border); }
.usage-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.usage-text { font-size: 12px; margin-top: 6px; color: var(--muted); }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .4s; }

/* Main */
.main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 0;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.search {
  flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px;
}
.search input { border: 0; background: transparent; padding: 10px 0; }
.top-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.menu-btn { display: none; }

h1 { margin: 10px 0 4px; font-size: 24px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
}

/* Cards */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 15px; }
.link { color: var(--accent); font-weight: 500; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; }
.stat .delta { font-size: 12px; color: var(--green); }
.stat .delta.down { color: var(--red); }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 200px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .b {
  width: 100%; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 40%, transparent));
  min-height: 4px; position: relative; transition: height .5s;
}
.chart .b:hover::after {
  content: attr(data-v); position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 4px; font-size: 11px;
}
.chart .d { font-size: 10px; color: var(--muted); }

/* Feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.feed .msg { flex: 1; line-height: 1.45; }
.feed .msg b { font-weight: 600; }
.feed .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.feed-mini li { padding: 8px 0; }

/* Agent cards */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.agent-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.agent-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.agent-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.agent-card .role { color: var(--muted); font-size: 12px; line-height: 1.4; height: 34px; overflow: hidden; }
.agent-card .meta { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--muted); }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 700; color: #fff; flex-shrink: 0;
}
.name { font-weight: 600; }

/* Status badge */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 99px; font-weight: 500; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.running { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.badge.running::before { animation: pulse 1.4s infinite; }
.badge.idle { color: var(--gray); background: color-mix(in srgb, var(--gray) 14%, transparent); }
.badge.paused { color: var(--yellow); background: color-mix(in srgb, var(--yellow) 14%, transparent); }
.badge.error { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }
@keyframes pulse { 50% { opacity: .3; } }

/* Filters */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--panel); color: var(--muted); padding: 6px 12px; border-radius: 99px; font-size: 13px; }
.chip.active { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }

/* Table */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--panel-2); }
.cell-agent { display: flex; align-items: center; gap: 10px; }
.cell-agent small { display: block; color: var(--muted); font-size: 12px; }
.mono { font-family: "JetBrains Mono", monospace; font-size: 12px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 100%;
  background: var(--panel); border-left: 1px solid var(--border); z-index: 21;
  transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.kv div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.kv span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 4px 9px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.prompt-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; white-space: pre-wrap; }
.console {
  background: #07090d; color: #b8f5c9; border-radius: 8px; padding: 12px; height: 160px; overflow-y: auto;
  font-family: "JetBrains Mono", monospace; font-size: 12px; line-height: 1.6;
}
.console .t { color: #5c6577; }
.run-row { display: flex; gap: 8px; margin-top: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; display: none; place-items: center; background: rgba(0,0,0,.5); z-index: 30; padding: 16px; }
.modal.open { display: grid; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px;
  width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-box h2 { margin: 0 0 16px; font-size: 18px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.tool-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool-picks label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.tool-picks input, .toggle-row input { width: auto; }
.row-actions { display: flex; gap: 10px; margin-top: 6px; }
.row-actions.end { justify-content: flex-end; }
.settings { max-width: 520px; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: all .25s; z-index: 40; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 25; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .main { padding: 0 16px 30px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .tool-picks { grid-template-columns: 1fr 1fr; }
  #newAgentBtn { padding: 9px 10px; }
}

/* ---------- Studio-connected dashboard ---------- */
.brand { color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stat .value .of { color: var(--muted); font-size: 16px; font-weight: 600; }
.stat .delta { color: var(--muted); }
.sync { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 14px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 1.6s infinite; }
.grid-2 + .grid-2 { margin-top: 0; }

.onboard { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; background: linear-gradient(120deg, color-mix(in srgb, var(--accent) 16%, var(--panel)), var(--panel)); }
.onboard[hidden] { display: none; }
.onboard-ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: var(--accent); color: #fff; flex-shrink: 0; }
.onboard h3 { margin: 0 0 4px; font-size: 16px; }
.onboard p { margin: 0; color: var(--muted); max-width: 520px; }
.onboard-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.chart .b.zero { background: var(--border); min-height: 2px; }
.usage-list { display: flex; flex-direction: column; gap: 6px; }
.usage-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; padding: 8px; border-radius: 10px; color: var(--text); }
.usage-row:hover { background: var(--panel-2); }
.usage-main { flex: 1; min-width: 0; }
.usage-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.usage-top span { color: var(--muted); }
.usage-bar { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.usage-bar i { display: block; height: 100%; border-radius: 6px; transition: width .5s; }

.feed li { align-items: flex-start; }
.feed-av { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; flex-shrink: 0; }
.feed-av.you { background: var(--panel-2); }
.empty-li { color: var(--muted); padding: 22px 0 !important; justify-content: center; border-bottom: 0 !important; display: block !important; text-align: center; }

.tasks-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tasks-top .filters { margin: 0; }
.task-add { display: flex; gap: 8px; min-width: 280px; flex: 0 1 420px; }
.task-list { list-style: none; margin: 0; padding: 0; }
.task-row { display: flex; align-items: center; gap: 12px; padding: 11px 6px; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: 0; }
.task-row label { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.task-row input { width: 16px; height: 16px; accent-color: var(--green); flex-shrink: 0; }
.task-row.done .task-text { text-decoration: line-through; color: var(--muted); }
.task-src { font-size: 12px; color: var(--muted); white-space: nowrap; }
.task-row .time { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 64px; text-align: right; }
.task-del { background: none; border: 0; color: var(--muted); opacity: 0; padding: 4px 6px; border-radius: 6px; }
.task-row:hover .task-del { opacity: 1; }
.task-del:hover { color: var(--red); background: var(--panel-2); }
.task-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding-top: 12px; }
.task-foot:empty { display: none; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 500; }

.prompt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.prompt-list li { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; display: flex; gap: 10px; justify-content: space-between; }
.prompt-list small { color: var(--muted); white-space: nowrap; }
.settings-title { margin: 0 0 6px; font-size: 15px; }
.row-actions.wrap { flex-wrap: wrap; }
.btn[disabled] { opacity: .4; cursor: default; }
a.btn { display: inline-flex; align-items: center; }

@media (max-width: 760px) {
  .task-src, .task-row .time { display: none; }
  .task-del { opacity: 1; }
  .task-add { min-width: 0; flex: 1 1 100%; }
  .onboard-actions { margin-left: 0; }
}
.chart .d { white-space: nowrap; height: 14px; line-height: 14px; overflow: visible; }
.chart .col { flex: 1 1 0; min-width: 0; }
.chart .d { width: 100%; text-align: center; display: flex; justify-content: center; }
.custom-chip { display: inline-block; font-size: 10px; font-weight: 600; color: var(--accent-2); border: 1px solid color-mix(in srgb, var(--accent-2) 45%, transparent); border-radius: 99px; padding: 0 7px; margin-left: 6px; vertical-align: middle; }
.cell-agent small { display: block; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.view-head .sub { margin: 0; }
