:root {
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #19212b;
  --line: #26313f;
  --text: #f1f5f9;
  --muted: #8fa0b3;
  --accent: #7c5cff;
  --accent-2: #9b87ff;
  --success: #36d399;
  --warning: #f6c453;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, .3);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 244px; padding: 24px 16px; border-right: 1px solid var(--line); background: rgba(13,17,23,.94); backdrop-filter: blur(18px); display: flex; flex-direction: column; z-index: 10; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(145deg,var(--accent),#4f38c6); box-shadow: 0 8px 26px rgba(124,92,255,.35); font-weight: 900; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.nav { display: grid; gap: 5px; }
.nav-item { width: 100%; border: 0; background: transparent; color: var(--muted); text-align: left; padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 11px; font-weight: 650; }
.nav-item span { width: 18px; text-align: center; }
.nav-item:hover, .nav-item.active { color: var(--text); background: var(--panel-2); }
.nav-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 12px; }
.mode-card { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; }
.mode-card small, .mode-card strong { display: block; }
.mode-card small { color: var(--muted); font-size: 11px; }
.mode-card strong { font-size: 12px; margin-top: 2px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px rgba(246,196,83,.1); }
.status-dot.live { background: var(--success); box-shadow: 0 0 0 4px rgba(54,211,153,.1); }
.main { margin-left: 244px; padding: 30px 36px 70px; max-width: 1500px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.eyebrow { color: var(--accent-2); font-size: 10px; line-height: 1; font-weight: 850; letter-spacing: .18em; margin: 0 0 8px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px,4vw,42px); letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.03em; }
h3 { letter-spacing: -.02em; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.connection { display: flex; align-items: center; gap: 8px; padding: 9px 11px; color: var(--muted); font-size: 12px; }
.connection span { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.connection.connected span { background: var(--success); box-shadow: 0 0 10px var(--success); }
.button { border: 1px solid var(--line); background: var(--panel-2); padding: 10px 15px; border-radius: 10px; cursor: pointer; font-weight: 750; transition: transform .15s ease, border-color .15s ease, opacity .15s ease; }
.button:hover { transform: translateY(-1px); border-color: #3b4a5c; }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.primary { background: var(--accent); border-color: var(--accent); box-shadow: 0 8px 25px rgba(124,92,255,.25); }
.button.ghost { background: transparent; }
.button.full { width: 100%; }
.section { scroll-margin-top: 20px; margin-bottom: 38px; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.metric-card { padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(145deg, rgba(25,33,43,.96), rgba(20,26,34,.96)); display: flex; align-items: center; gap: 14px; min-height: 100px; }
.metric-card.alert { border-color: rgba(246,196,83,.3); }
.metric-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: #222c38; color: var(--accent-2); font-weight: 900; }
.metric-card span, .metric-card strong { display: block; }
.metric-card span { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.metric-card strong { font-size: 25px; letter-spacing: -.04em; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.pill { color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; font-size: 11px; }
.agents-grid { display: grid; grid-template-columns: repeat(5,minmax(190px,1fr)); gap: 13px; }
.agent-card { min-height: 240px; padding: 17px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); display: flex; flex-direction: column; transition: border-color .2s ease, transform .2s ease; }
.agent-card:hover { border-color: #3a4859; transform: translateY(-2px); }
.agent-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 19px; }
.agent-avatar { width: 41px; height: 41px; display: grid; place-items: center; background: #222c38; border-radius: 12px; color: var(--accent-2); font-size: 20px; font-weight: 850; }
.agent-card h3 { margin-bottom: 7px; font-size: 16px; }
.agent-card p { color: var(--muted); font-size: 12px; line-height: 1.55; min-height: 55px; }
.agent-meta { display: flex; justify-content: space-between; color: #718297; font-size: 10px; gap: 8px; margin-top: auto; padding-bottom: 13px; }
.agent-action { width: 100%; padding: 10px 0 0; border: 0; border-top: 1px solid var(--line); color: #c4b9ff; background: transparent; cursor: pointer; text-align: left; display: flex; justify-content: space-between; font-size: 12px; font-weight: 750; }
.badge { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; border-radius: 999px; padding: 4px 8px; font-size: 9px; line-height: 1; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; background: #222b36; color: #9fb0c1; }
.badge i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.running { color: #a99aff; background: rgba(124,92,255,.13); }
.badge.success { color: var(--success); background: rgba(54,211,153,.1); }
.badge.warning { color: var(--warning); background: rgba(246,196,83,.1); }
.badge.danger { color: var(--danger); background: rgba(251,113,133,.1); }
.filters { display: flex; gap: 5px; background: var(--panel); padding: 4px; border: 1px solid var(--line); border-radius: 10px; }
.filter { padding: 7px 10px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; }
.filter.active { color: var(--text); background: #27313d; }
.tasks-list { display: grid; gap: 8px; }
.task-row { display: grid; grid-template-columns: 42px minmax(0,1fr) 80px auto; align-items: center; gap: 13px; min-height: 74px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); cursor: pointer; }
.task-row:hover { border-color: #3a4859; }
.task-status-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: #222c38; color: var(--muted); font-weight: 800; }
.task-status-icon.running { color: var(--accent-2); }
.task-status-icon.success { color: var(--success); }
.task-status-icon.warning { color: var(--warning); }
.task-status-icon.danger { color: var(--danger); }
.task-title-line { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.task-main h3 { margin: 0; font-size: 14px; }
.task-main p { margin: 0; color: var(--muted); font-size: 11px; }
.task-cost { color: var(--muted); font-size: 12px; text-align: right; }
.task-actions { display: flex; gap: 6px; justify-content: flex-end; }
.mini-button { border: 1px solid var(--line); border-radius: 8px; background: #202a35; padding: 7px 9px; cursor: pointer; font-size: 10px; font-weight: 800; }
.mini-button.approve { color: var(--success); border-color: rgba(54,211,153,.3); background: rgba(54,211,153,.08); }
.mini-button.reject { color: var(--danger); border-color: rgba(251,113,133,.24); background: rgba(251,113,133,.06); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(169,154,255,.25); border-top-color: var(--accent-2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 50px 20px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); }
.empty-state div { font-size: 30px; color: var(--accent-2); }
.empty-state h3 { color: var(--text); margin: 10px 0 5px; }
.empty-state p { font-size: 12px; }
.hidden { display: none !important; }
.activity-list { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.activity-row { display: flex; align-items: center; gap: 12px; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.activity-icon { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: #222c38; color: var(--muted); font-weight: 900; }
.activity-icon.warning { color: var(--warning); }
.activity-icon.error { color: var(--danger); }
.activity-row strong, .activity-row span { display: block; }
.activity-row strong { font-size: 12px; margin-bottom: 3px; }
.activity-row span { color: var(--muted); font-size: 10px; }
.activity-empty { padding: 25px; color: var(--muted); text-align: center; font-size: 12px; }
.dialog { width: min(620px, calc(100vw - 28px)); max-height: min(850px, calc(100vh - 28px)); padding: 0; border: 1px solid #344253; border-radius: 18px; background: #141a22; color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(4,7,11,.76); backdrop-filter: blur(6px); }
.dialog form, .detail-dialog > * { padding-left: 22px; padding-right: 22px; }
.dialog form { padding-bottom: 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; padding-top: 22px; padding-bottom: 18px; position: sticky; top: 0; z-index: 1; background: #141a22; }
.icon-button { border: 1px solid var(--line); width: 34px; height: 34px; border-radius: 9px; background: #202934; cursor: pointer; font-size: 20px; }
.dialog label { display: grid; gap: 7px; margin-bottom: 14px; font-size: 11px; color: #b8c4d1; font-weight: 750; }
.dialog input, .dialog select, .dialog textarea { width: 100%; border: 1px solid var(--line); background: #0f141b; color: var(--text); border-radius: 10px; padding: 11px 12px; resize: vertical; }
.dialog input:focus, .dialog select:focus, .dialog textarea:focus { border-color: var(--accent); }
.approval-notice { padding: 11px 12px; border: 1px solid rgba(246,196,83,.28); background: rgba(246,196,83,.08); color: var(--warning); border-radius: 10px; font-size: 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.form-error { min-height: 18px; color: var(--danger); font-size: 11px; margin: 9px 0 0; }
.detail-dialog { width: min(820px, calc(100vw - 28px)); }
#detail-content { padding-bottom: 22px; }
.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; margin-bottom: 18px; }
.detail-block { margin-top: 12px; }
.detail-block h3 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.detail-block pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #0f141b; color: #dbe4ee; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.65; }
.error-block pre { border-color: rgba(251,113,133,.3); color: #fecdd3; }
.toast { position: fixed; left: 50%; bottom: 25px; transform: translate(-50%, 20px); background: #f8fafc; color: #111827; border-radius: 10px; padding: 11px 15px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; font-size: 12px; font-weight: 750; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.toast.error { background: #fb7185; color: white; }
.login-body { display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%, rgba(124,92,255,.18), transparent 35%), var(--bg); }
.login-shell { width: min(480px,100%); }
.login-card { padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: rgba(20,26,34,.94); box-shadow: var(--shadow); }
.brand-large { padding: 0 0 36px; }
.login-copy h1 { font-size: clamp(31px,8vw,46px); margin-bottom: 14px; line-height: 1.05; }
.login-copy > p:last-child { color: var(--muted); line-height: 1.6; font-size: 13px; }
.login-form { margin-top: 28px; }
.login-form label { display: block; color: #b8c4d1; font-size: 11px; font-weight: 750; margin-bottom: 7px; }
.login-form input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #0f141b; color: var(--text); margin-bottom: 12px; }
.login-foot { text-align: center; color: #66788d; font-size: 9px; margin: 18px 0 0; }
@media (max-width: 1180px) { .agents-grid { grid-template-columns: repeat(3,1fr); } .metrics-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 760px) {
  .sidebar { position: fixed; inset: auto 0 0 0; width: auto; height: 67px; padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); flex-direction: row; }
  .brand, .sidebar-bottom { display: none; }
  .nav { width: 100%; grid-template-columns: repeat(4,1fr); gap: 3px; }
  .nav-item { justify-content: center; flex-direction: column; gap: 2px; padding: 6px 2px; text-align: center; font-size: 9px; }
  .nav-item span { font-size: 17px; }
  .nav-item.active { box-shadow: inset 0 2px 0 var(--accent); }
  .main { margin-left: 0; padding: 21px 14px 100px; }
  .topbar { align-items: flex-start; }
  .topbar h1 { font-size: 28px; }
  .connection { display: none; }
  .button.primary { padding: 9px 11px; font-size: 11px; }
  .metrics-grid { gap: 8px; }
  .metric-card { min-height: 86px; padding: 13px; gap: 10px; }
  .metric-icon { width: 34px; height: 34px; }
  .metric-card span { font-size: 10px; }
  .metric-card strong { font-size: 20px; }
  .agents-grid { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .agent-card { min-height: 220px; padding: 13px; }
  .agent-card p { font-size: 11px; }
  .agent-meta { display: grid; }
  .tasks-head { align-items: flex-start; flex-direction: column; }
  .filters { width: 100%; overflow-x: auto; }
  .filter { flex: 1; }
  .task-row { grid-template-columns: 36px minmax(0,1fr); gap: 10px; }
  .task-status-icon { width: 35px; height: 35px; }
  .task-cost { display: none; }
  .task-actions { grid-column: 2; justify-content: flex-start; }
  .task-title-line { align-items: flex-start; flex-direction: column; gap: 5px; }
}
@media (max-width: 430px) { .agents-grid { grid-template-columns: 1fr; } .metric-card { align-items: flex-start; flex-direction: column; } }
.pipeline-preview { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; padding: 12px; border: 1px solid var(--line); background: #0f141b; border-radius: 10px; color: var(--muted); font-size: 10px; }
.pipeline-preview span { padding: 5px 7px; background: #202934; border-radius: 7px; color: #cbd5e1; }
.pipeline-preview b { color: var(--accent-2); }
@media (max-width: 760px) { .top-actions { gap: 6px; } #new-task-button { display: none; } .pipeline-preview b { display: none; } }

/* Agent Factory v2 */
.section-actions { display: flex; align-items: center; gap: 9px; }
.button.compact { padding: 7px 10px; font-size: 11px; }
.agent-card.inactive { opacity: .56; filter: saturate(.55); }
.agent-card.inactive:hover { transform: none; }
.agent-tools { display: flex; flex-wrap: wrap; gap: 5px; margin: -4px 0 12px; min-height: 23px; }
.agent-tools span { padding: 4px 6px; border: 1px solid var(--line); border-radius: 999px; color: #8fa0b3; background: #10161d; font-size: 9px; }
.agent-card-actions { display: grid; grid-template-columns: minmax(0,1fr) 36px; align-items: end; gap: 8px; border-top: 1px solid var(--line); }
.agent-card-actions .agent-action { border-top: 0; padding-top: 11px; }
.agent-action:disabled { opacity: .45; cursor: not-allowed; }
.agent-config { width: 34px; height: 32px; margin-top: 7px; border: 1px solid var(--line); border-radius: 8px; background: #202934; color: var(--muted); cursor: pointer; }
.agent-config:hover { color: var(--text); border-color: #415064; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two-columns { grid-template-columns: repeat(2,minmax(0,1fr)); }
.switch-list { display: grid; gap: 8px; margin: 4px 0 14px; }
.switch-row { grid-template-columns: minmax(0,1fr) auto !important; align-items: center; gap: 16px !important; margin-bottom: 0 !important; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #0f141b; }
.switch-row span, .switch-row strong, .switch-row small { display: block; }
.switch-row strong { color: var(--text); font-size: 12px; }
.switch-row small { margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 500; }
.switch-row input { width: 20px !important; height: 20px; accent-color: var(--accent); }
.agent-safety-note { padding: 12px; border: 1px solid rgba(124,92,255,.24); border-radius: 10px; background: rgba(124,92,255,.07); color: #bcb2ff; font-size: 10px; line-height: 1.55; }
.split-actions { justify-content: space-between; align-items: center; }
.split-actions > div { display: flex; gap: 9px; }
.button.danger { color: var(--danger); border-color: rgba(251,113,133,.3); }
.agent-dialog { width: min(720px, calc(100vw - 28px)); }
@media (max-width: 760px) {
  .section-head { align-items: flex-start; }
  .section-actions { align-items: flex-end; flex-direction: column-reverse; }
  .button.compact { white-space: nowrap; }
  .form-grid.two-columns { grid-template-columns: 1fr; gap: 0; }
  .split-actions { align-items: stretch; flex-direction: column-reverse; }
  .split-actions > div { display: grid; grid-template-columns: 1fr 1fr; }
  .split-actions > .button { width: 100%; }
}
