:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2128;
  --panel-3: #232a32;
  --border: #232a32;
  --border-2: #2d3640;
  --text: #e6edf3;
  --muted: #8b949e;
  --muted-2: #6e7681;
  --accent: #58a6ff;
  --accent-soft: rgba(88,166,255,0.12);
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --gray: #6e7681;
  --topbar-h: 56px;
  --sidebar-w: 320px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}
h1 { font-size: 16px; margin: 0; font-weight: 600; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--red); margin: 8px 0 0; font-size: 13px; }

/* ---------------- Login ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card > p { margin: 0 0 20px; }
.login-card .field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 4px;
  letter-spacing: 0.02em;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #0b0d10;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
}
.login-card button:hover { filter: brightness(1.1); }

/* ---------------- App layout ---------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

/* ---------------- Topbar ---------------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.meta { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-live { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
.dot-working { background: var(--green); box-shadow: 0 0 6px rgba(63,185,80,0.6); }
.dot-waiting { background: var(--yellow); }
.dot-idle    { background: var(--gray); }
.dot-stale   { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.count-pill {
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-2);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
button.ghost:hover { color: var(--text); border-color: var(--gray); background: var(--panel-2); }

/* ---------------- Sidebar ---------------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-header input[type="search"] {
  width: 100%;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
}
.sidebar-header input[type="search"]:focus { outline: none; border-color: var(--accent); }

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  font-size: 12px;
}
.status-pills label {
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.status-pills input[type="checkbox"] { accent-color: var(--accent); margin: 0 2px 0 0; }

.agent-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.agent-list::-webkit-scrollbar { width: 8px; }
.agent-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

.agent-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}
.agent-item:hover { background: var(--panel-2); }
.agent-item.active {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.agent-item-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.agent-item-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.agent-item-time {
  font-size: 11px;
  color: var(--muted-2);
  flex-shrink: 0;
}
.agent-item-brand {
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.agent-item-preview {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.agent-list-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------------- Chat panel ---------------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 40px;
}
.empty-state h2 { color: var(--muted); font-weight: 500; }

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-shrink: 0;
  background: var(--panel);
}
.chat-agent-row { display: flex; align-items: center; gap: 10px; }
.chat-header h2 { font-size: 18px; }
.chat-header p { margin: 4px 0 0; font-size: 12px; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.chat-stats { display: flex; gap: 20px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-label { font-size: 10px; text-transform: uppercase; color: var(--muted-2); letter-spacing: 0.05em; }
.stat-value { font-size: 12px; color: var(--text); margin-top: 2px; }

.status-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}
.status-working { background: rgba(63,185,80,0.15); color: var(--green); }
.status-waiting { background: rgba(210,153,34,0.15); color: var(--yellow); }
.status-idle    { background: rgba(110,118,129,0.2); color: var(--gray); }
.status-stale   { background: rgba(248,81,73,0.15); color: var(--red); }

.chat-current {
  padding: 14px 24px 0;
  flex-shrink: 0;
}
.chat-current-task, .chat-current-files {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.chat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  display: block;
  margin-bottom: 4px;
}
.chat-current-task p { margin: 0; font-size: 14px; }
.chat-current-files ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-current-files li {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 4px;
}

.chat-divider {
  position: relative;
  text-align: center;
  margin: 18px 24px 8px;
  color: var(--muted-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}
.chat-divider::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--border);
  z-index: 0;
}
.chat-divider span {
  position: relative;
  background: var(--bg);
  padding: 0 12px;
  z-index: 1;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

/* Chat bubbles */
.msg {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.msg-user      { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; align-items: flex-start; }
.msg-system    { align-self: center; align-items: center; max-width: 90%; }

.msg-bubble {
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg-user .msg-bubble {
  background: var(--accent);
  color: #0b0d10;
  border-bottom-right-radius: 4px;
}
.msg-assistant .msg-bubble {
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-bottom-left-radius: 4px;
}
.msg-meta {
  font-size: 10px;
  color: var(--muted-2);
  padding: 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.msg-author { font-weight: 600; color: var(--muted); }

.msg-system .msg-bubble {
  background: transparent;
  border: 1px dashed var(--border-2);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 14px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.msg-system.msg-notify .msg-bubble {
  border-color: var(--yellow);
  color: var(--yellow);
  background: rgba(210,153,34,0.08);
}
.msg-tool-icon {
  font-weight: 600;
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg-file {
  color: var(--text);
  font-size: 12px;
}

.chat-loading {
  align-self: center;
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
}

@media (max-width: 720px) {
  :root { --sidebar-w: 100%; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: var(--m-sidebar, flex); }
  .chat-panel { display: var(--m-chat, flex); }
}
