/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #238636;
  --accent-hover: #2ea043;
  --accent-bg: rgba(35, 134, 54, 0.15);
  --blue: #1f6feb;
  --blue-bg: rgba(31, 111, 235, 0.15);
  --yellow: #d29922;
  --yellow-bg: rgba(210, 153, 34, 0.15);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.15);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; }
.login-box .logo { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.login-box .sub { color: var(--text-muted); margin-bottom: 32px; font-size: 13px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--blue); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; }
.btn-primary { background: var(--accent); color: white; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 12px; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.error-msg { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-bottom: 16px; display: none; }

/* ── App Shell ── */
.app { display: none; min-height: 100vh; }
.app.logged-in { display: flex; flex-direction: column; }

/* ── Header ── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.topbar-left { display: flex; align-items: center; gap: 24px; }
.topbar-logo { font-size: 16px; font-weight: 700; color: var(--text); }
.topbar-logo span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; }
.nav-btn { padding: 6px 14px; border-radius: var(--radius); font-size: 13px; color: var(--text-muted); cursor: pointer; border: none; background: transparent; transition: all 0.15s; }
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--surface2); color: var(--text); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-pill { display: flex; align-items: center; gap: 8px; background: var(--surface2); padding: 6px 12px; border-radius: 20px; font-size: 13px; }
.status-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; }

/* ── Main Content ── */
.main { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }
.section { display: none; }
.section.active { display: block; }

/* ── Page Header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.refresh-btn { display: flex; align-items: center; gap: 6px; padding: 7px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-muted); font-size: 12px; cursor: pointer; transition: all 0.15s; }
.refresh-btn:hover { background: var(--surface2); color: var(--text); }
.refresh-btn.loading { opacity: 0.7; pointer-events: none; }
.refresh-btn .spin { display: none; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin 0.8s linear infinite; }
.refresh-btn.loading .spin { display: block; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h3 { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.card h3 .count { background: var(--surface2); color: var(--text); padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-left: 6px; }

/* ── Metric Grid ── */
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.metric-tile .num { font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.metric-tile .lbl { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.metric-tile.green .num { color: var(--accent); }
.metric-tile.red .num { color: var(--red); }
.metric-tile.yellow .num { color: var(--yellow); }
.metric-tile.blue .num { color: var(--blue); }

/* ── Agent Cards ── */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.agent-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: border-color 0.2s; }
.agent-card:hover { border-color: var(--text-muted); }
.agent-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.agent-name { font-weight: 600; font-size: 14px; }
.agent-badge { font-size: 10px; padding: 2px 7px; border-radius: 10px; text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; }
.badge-healthy { background: var(--accent-bg); color: var(--accent); }
.badge-busy { background: var(--yellow-bg); color: var(--yellow); }
.badge-idle { background: var(--surface2); color: var(--text-muted); }
.agent-meta { font-size: 12px; color: var(--text-muted); }
.agent-meta p { margin-bottom: 3px; }
.agent-task { margin-top: 10px; background: var(--bg); border-radius: 6px; padding: 8px 10px; font-size: 11px; color: var(--text-muted); }
.agent-task strong { color: var(--text); }

/* ── Task List ── */
.task-table { width: 100%; border-collapse: collapse; }
.task-table th { text-align: left; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.task-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.task-table tr:last-child td { border-bottom: none; }
.task-table tr:hover td { background: var(--surface2); }
.status-pill { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.s-active { background: var(--blue-bg); color: var(--blue); }
.s-pending { background: var(--yellow-bg); color: var(--yellow); }
.s-done { background: var(--accent-bg); color: var(--accent); }
.s-blocked { background: var(--red-bg); color: var(--red); }
.s-other { background: var(--surface2); color: var(--text-muted); }
.priority-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.p-high { background: var(--red); }
.p-med { background: var(--yellow); }
.p-low { background: var(--text-muted); }

/* ── Activity Feed ── */
.activity-list { list-style: none; }
.activity-list li { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; display: flex; gap: 10px; }
.activity-list li:last-child { border-bottom: none; }
.activity-time { color: var(--text-muted); font-size: 11px; white-space: nowrap; min-width: 60px; }
.activity-user { font-weight: 600; min-width: 80px; }
.activity-text { color: var(--text-muted); }

/* ── Decisions ── */
.decision-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; }
.decision-item.pending { border-left: 3px solid var(--yellow); }
.decision-item.made { border-left: 3px solid var(--accent); }
.decision-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.decision-title { font-weight: 600; font-size: 14px; }
.decision-date { font-size: 11px; color: var(--text-muted); }
.decision-meta { font-size: 12px; color: var(--text-muted); }

/* ── Memory Notes ── */
.memory-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.memory-item:last-child { border-bottom: none; }
.memory-file { font-weight: 600; color: var(--blue); }
.memory-time { font-size: 11px; color: var(--text-muted); margin-left: 8px; }

/* ── Messages ── */
.msg-item { background: var(--bg); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; font-size: 12px; }
.msg-preview { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Empty State ── */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px; }
.empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.5; }

/* ── Two Column Layout ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Live indicator ── */
.live-bar { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.live-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading ── */
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius); height: 60px; margin-bottom: 12px; }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; max-width: 480px; width: 100%; }
.modal h3 { margin-bottom: 20px; font-size: 18px; }
.modal .btn { margin-top: 16px; }
.modal-close { float: right; background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }

/* ── Notification ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; font-size: 13px; z-index: 2000; display: none; box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.toast.show { display: block; animation: slideUp 0.3s ease; }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--red); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .topbar nav { display: none; } .main { padding: 16px; } }

/* ── Chat Panel ── */
.chat-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500; display: none; }
.chat-overlay.open { display: block; }

.chat-panel {
  position: fixed;
  top: 0; right: 0;
  width: 480px; height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 501;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
.chat-panel.open { transform: translateX(0); }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-agent-name { font-weight: 700; font-size: 16px; }
.chat-agent-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.chat-close {
  background: var(--surface2); border: none; color: var(--text-muted);
  font-size: 22px; width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.chat-close:hover { background: var(--border); color: var(--text); }

#chatSessions, #chatMessages {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
}

.chat-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.session-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.session-item:hover { background: var(--surface2); }
.session-file { font-size: 12px; font-weight: 600; color: var(--blue); margin-bottom: 4px; font-family: monospace; }
.session-preview { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px; }
.session-time { font-size: 11px; color: var(--text-muted); }

.chat-back {
  padding: 10px 16px;
  font-size: 13px; color: var(--blue);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-back:hover { text-decoration: underline; }

.messages-list {
  flex: 1; overflow-y: auto;
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.msg-bubble { max-width: 85%; }
.msg-bubble.user { align-self: flex-end; }
.msg-bubble.agent { align-self: flex-start; }
.msg-role { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.5px; }
.msg-text {
  background: var(--surface2);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-bubble.user .msg-text { background: var(--accent); color: white; }
.msg-bubble.user .msg-role { text-align: right; }

.message-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
  background: var(--bg);
}
.chat-hint { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.message-input-row { display: flex; gap: 8px; }
.message-input-row input {
  flex: 1;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.message-input-row input:focus { border-color: var(--blue); }

/* Clickable agent cards */
.agent-card.clickable { cursor: pointer; transition: border-color 0.2s, transform 0.15s; }
.agent-card.clickable:hover { border-color: var(--blue); transform: translateY(-1px); }

/* Decision running state */
.decision-item.running { border-left: 3px solid var(--blue); }

/* Responsive */
@media (max-width: 520px) { .chat-panel { width: 100vw; } }
