:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #192234;
  --border: #263147;
  --text: #e6edf7;
  --muted: #93a4bf;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a855f7;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error-text { color: #fca5a5; font-size: 0.9rem; margin-top: 8px; }

.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 999;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}

.toast.error { border-color: var(--red); background: #2c1519; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand-row h1 { margin: 0; font-size: 1.3rem; }
.brand-row p { margin: 2px 0 0; }

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
}

.brand-badge.small { width: 28px; height: 28px; font-size: 0.78rem; border-radius: 7px; }

.stack-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }

input, select, textarea {
  background: #0d131f;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.92rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
}

.btn:hover { border-color: #465a7e; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: #7f1d1d; border-color: #b91c1c; color: #fee2e2; }
.btn-small { padding: 4px 10px; font-size: 0.8rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }

.sse-pill {
  font-size: 0.78rem;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.sse-pill.online { border-color: #166534; background: #052e16; color: #86efac; }
.sse-pill.offline { border-color: #7f1d1d; background: #2c1519; color: #fca5a5; }

.online-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
}

.strip-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.working { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.idle, .dot.online { background: var(--amber); }
.dot.offline { background: #64748b; }

.user-badge {
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.tabbar {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  background: #0e1420;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); background: var(--surface); }
.tab-btn.active { color: #fff; background: var(--surface-2); border-color: var(--border); }

.content-area { padding: 20px; max-width: 1440px; margin: 0 auto; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.panel-header h2 { margin: 0; font-size: 1.25rem; }
.inline-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-box .stat-val { font-size: 1.5rem; font-weight: 700; }
.stat-box .stat-lbl { font-size: 0.82rem; color: var(--muted); }

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.agent-card.working { border-color: #166534; }
.agent-card.idle, .agent-card.online { border-color: #854d0e; }

.agent-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.badge.green { background: #052e16; border-color: #166534; color: #86efac; }
.badge.amber { background: #2c1e05; border-color: #854d0e; color: #fde047; }
.badge.gray { background: #1e293b; border-color: #334155; color: #94a3b8; }
.badge.blue { background: #0f294a; border-color: #1d4ed8; color: #93c5fd; }

.kv-line { font-size: 0.86rem; }
.kv-label { color: var(--muted); font-weight: 600; margin-right: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; }

.chat-feed {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.msg-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.msg-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.msg-body { white-space: pre-wrap; word-break: break-word; }

.chat-composer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-composer input { flex: 1; min-width: 220px; }

.plans-grid, .cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.86rem;
}

.section-subtitle { margin: 14px 0 10px; }

.kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 240px;
}

.kanban-col-head {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.9rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.task-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; }

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .split-grid { grid-template-columns: 1fr; }
}

.stack-list { display: flex; flex-direction: column; gap: 10px; }

.report-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.report-pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  min-height: 260px;
  font-size: 0.85rem;
}

.modal-dialog {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 520px;
  width: 92vw;
}

.modal-dialog::backdrop { background: rgba(0, 0, 0, 0.72); }

.modal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h3 { margin: 0; }

.token-box {
  background: #090d14;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 10px 0;
}
