/* AI Worker Platform */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #1a1b1e;
  --bg2:     #222327;
  --bg3:     #2a2b30;
  --border:  #35363d;
  --text:    #e1e2e6;
  --muted:   #6b6d7a;
  --accent:  #7c6af7;
  --accent2: #9d8fff;
  --green:   #4ade80;
  --red:     #f87171;
  --yellow:  #facc15;
  --orange:  #fb923c;
  --radius:  8px;
  --side-w:  240px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 14px; }

/* Layout */
.layout { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--side-w); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-brand { font-size: 15px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.sidebar-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.dept-label {
  padding: 6px 14px 3px;
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.agent-item {
  padding: 8px 14px; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  border-radius: 0; transition: background .12s;
  margin: 0 6px; border-radius: 6px;
}
.agent-item:hover { background: var(--bg3); }
.agent-item.active { background: var(--accent); }
.agent-item.active .agent-name { color: #fff; }
.agent-item.active .agent-sub { color: rgba(255,255,255,.7); }
.agent-status { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.agent-status.idle    { background: var(--muted); }
.agent-status.running { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 1s infinite; }
.agent-status.error   { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.agent-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-sub  { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-new-btn {
  margin: 8px 12px 12px;
  padding: 8px; width: calc(100% - 24px);
  background: transparent; border: 1px dashed var(--border);
  color: var(--muted); cursor: pointer; border-radius: var(--radius);
  font-size: 13px; transition: all .12s;
}
.sidebar-new-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  padding: 0 24px; height: 52px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; background: var(--bg2);
  flex-shrink: 0;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-tabs { display: flex; gap: 2px; margin-left: 16px; }
.tab-btn {
  padding: 5px 14px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: 6px;
  font-size: 13px; transition: all .12s;
}
.tab-btn.active { background: var(--bg3); color: var(--text); }
.tab-btn:hover:not(.active) { color: var(--text); }
.run-btn {
  margin-left: auto; padding: 6px 16px;
  background: var(--accent); color: #fff;
  border: none; cursor: pointer; border-radius: 6px;
  font-size: 13px; font-weight: 600; transition: background .12s;
}
.run-btn:hover { background: var(--accent2); }
.run-btn:disabled { opacity: .5; cursor: not-allowed; }
.stop-btn {
  margin-left: auto; padding: 6px 16px;
  background: var(--red); color: #fff;
  border: none; cursor: pointer; border-radius: 6px;
  font-size: 13px; font-weight: 600;
}
.content { flex: 1; overflow-y: auto; padding: 24px; }
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Form */
.form-group { margin-bottom: 20px; }
.form-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: block; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius);
  font-size: 13px; font-family: inherit;
  transition: border-color .12s; outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { min-height: 160px; resize: vertical; line-height: 1.6; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Instructions editor with pills */
.inst-editor {
  position: relative;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  min-height: 140px;
}
.inst-editor:focus-within { border-color: var(--accent); }
.inst-editor textarea {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 13px; font-family: inherit;
  line-height: 1.7; resize: none; min-height: 120px;
}

/* Tools picker */
.tools-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tool-chip {
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; cursor: pointer; border: 1px solid var(--border);
  background: var(--bg3); color: var(--muted); transition: all .12s;
  display: flex; align-items: center; gap: 5px;
}
.tool-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool-chip:hover:not(.on) { border-color: var(--accent); color: var(--text); }
.tool-icon { font-size: 12px; }

/* Run output */
.run-panel { display: flex; flex-direction: column; gap: 12px; }
.run-input-area { display: flex; gap: 8px; }
.run-input {
  flex: 1; padding: 9px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); font-size: 13px; outline: none;
}
.run-input:focus { border-color: var(--accent); }
.output-wrap {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  min-height: 200px; max-height: 60vh; overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; line-height: 1.7;
}
.output-wrap::-webkit-scrollbar { width: 4px; }
.output-wrap::-webkit-scrollbar-thumb { background: var(--border); }
.evt-text   { color: var(--text); white-space: pre-wrap; }
.evt-tool   { color: var(--accent); font-size: 12px; }
.evt-result { color: var(--muted); font-size: 12px; border-left: 2px solid var(--border); padding-left: 8px; white-space: pre-wrap; }
.evt-error  { color: var(--red); }
.run-placeholder { color: var(--muted); font-style: italic; font-family: inherit; font-size: 13px; }

/* Runs history */
.runs-list { display: flex; flex-direction: column; gap: 8px; }
.run-row {
  padding: 12px 16px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .12s;
}
.run-row:hover { border-color: var(--accent); }
.run-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.run-status-badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; font-weight: 600; }
.run-status-badge.completed { background: rgba(74,222,128,.15); color: var(--green); }
.run-status-badge.running   { background: rgba(250,204,21,.15); color: var(--yellow); }
.run-status-badge.error     { background: rgba(248,113,113,.15); color: var(--red); }
.run-time { font-size: 11px; color: var(--muted); margin-left: auto; }
.run-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Notebooks */
.nb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.nb-card {
  padding: 14px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: border-color .12s;
}
.nb-card:hover { border-color: var(--accent); }
.nb-card-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.nb-card-meta { font-size: 11px; color: var(--muted); }
.nb-content { white-space: pre-wrap; font-size: 13px; line-height: 1.7; color: var(--text); }

/* Overview */
.overview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { padding: 18px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Dashboard (no selection) */
.dashboard { padding: 24px; }
.dash-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.dash-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; width: 520px; max-height: 80vh;
  overflow-y: auto;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 20px; display: flex; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.btn { padding: 8px 18px; border: none; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }

/* Agent selector */
.agent-select-row { display: flex; align-items: center; gap: 8px; }
.agent-select-row select { flex: 1; }

/* Empty */
.empty { padding: 60px; text-align: center; color: var(--muted); font-size: 14px; }

/* Scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
