/* Overwatch agent-monitoring dashboard — dark theme, no frameworks. */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-hover: #1c2330;
  --border: #2d333e;
  --text: #d7dde4;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --purple: #bc8cff;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

.mono { font-family: var(--mono); }

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 3px;
  font-weight: 600;
}
.brand-sub {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }

.poll-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

/* --- Layout --- */
#app { max-width: 1080px; margin: 0 auto; padding: 24px; }
.view-title { font-size: 18px; font-weight: 600; margin: 4px 0 16px; }
.empty-state { color: var(--text-dim); padding: 32px 0; text-align: center; }

.error-banner {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 6px;
  padding: 10px 16px;
  margin: 16px 0;
  font-family: var(--mono);
  font-size: 12px;
}

/* --- Run list --- */
.run-table { width: 100%; border-collapse: collapse; }
.run-table th {
  text-align: left;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.run-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.run-table tbody tr { cursor: pointer; }
.run-table tbody tr:hover { background: var(--bg-hover); }
.run-table .wf-id { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.run-table .issue-title {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.run-table .time, .run-table .duration {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.run-table .stage-name { font-family: var(--mono); font-size: 12px; }

/* --- Status badges --- */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid;
  white-space: nowrap;
}
.badge.running   { color: var(--accent); border-color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.badge.started   { color: var(--accent); border-color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.badge.completed { color: var(--green); border-color: var(--green); }
.badge.failed    { color: var(--red); border-color: var(--red); }
.badge.needs_revision { color: var(--amber); border-color: var(--amber); }
.badge.escalate  { color: var(--purple); border-color: var(--purple); }
.badge.completed_unverified { color: var(--amber); border-color: var(--amber); }
.badge.escalated_unresolved { color: var(--purple); border-color: var(--purple); }
.badge.decomposed { color: var(--accent); border-color: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* --- Run detail --- */
.back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 12px;
  font-family: var(--mono);
}
.back-link:hover { color: var(--accent); }

.detail-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.detail-header h2 { margin: 0; font-size: 16px; color: var(--accent); word-break: break-all; }
.detail-links a {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  margin-left: 8px;
}
.detail-links a:hover { border-color: var(--accent); }
.detail-issue { color: var(--text-dim); margin: 6px 0 24px; }

/* --- Timeline --- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -25px;
  top: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  border: 2px solid var(--bg);
}
.timeline-item.completed::before { background: var(--green); }
.timeline-item.failed::before    { background: var(--red); }
.timeline-item.running::before   { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.timeline-item.needs_revision::before { background: var(--amber); }
.timeline-item.escalate::before  { background: var(--purple); }
.timeline-item.completed_unverified::before { background: var(--amber); }

.timeline-item .row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.timeline-item .stage {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
}
.timeline-item .agent {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
}
.timeline-item .model {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  margin-left: auto;
}
.timeline-item .meta {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  margin-top: 4px;
}
.timeline-item .detail {
  margin-top: 8px;
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}
.timeline-item .artifacts { margin-top: 8px; }
.timeline-item .artifacts a {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  text-decoration: none;
}
.timeline-item .artifacts a:hover { text-decoration: underline; }

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  color: var(--text-dim);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 16px;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.run-table .run-id { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.detail-run { color: var(--text-dim); font-size: 11px; margin: -18px 0 24px; }
.count-warn { color: var(--amber); font-family: var(--mono); font-size: 12px; }
.count-bad  { color: var(--red); font-family: var(--mono); font-size: 12px; }

/* --- Analytics: stat cards --- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
}
.stat-card.good .stat-value { color: var(--green); }
.stat-card.warn .stat-value { color: var(--amber); }
.stat-card.bad  .stat-value { color: var(--red); }
.stat-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* --- Analytics: CSS bar chart (no chart libraries) --- */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 140px;
  padding: 8px 4px 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.bar {
  width: 60%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  opacity: 0.85;
}
.bar-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  height: 14px;
}
.bar-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 0 6px;
}

/* --- Fleet health grid --- */
.fleet-window {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  margin-left: 8px;
}
.fleet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.fleet-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.fleet-head { display: flex; align-items: center; gap: 8px; }
.fleet-name { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.fleet-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.fleet-dot.dot-green { background: var(--green); }
.fleet-dot.dot-red   { background: var(--red); animation: pulse 1.4s ease-in-out infinite; }
.fleet-dot.dot-amber { background: var(--amber); }
.fleet-dot.dot-grey  { background: var(--text-dim); opacity: 0.5; }
.fleet-meta {
  margin-top: 8px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
}
.fleet-seen { color: var(--text-dim); }

/* Humanized detail rendering */
.detail-heading { font-weight: 600; color: var(--fg, #e6e6e6); margin: 8px 0 3px; font-size: 13px; }
.detail-line { margin: 2px 0; line-height: 1.5; }
.detail-bullet { display: flex; gap: 7px; margin: 2px 0 2px 6px; line-height: 1.5; }
.bullet-dot { color: var(--accent, #7aa2f7); }
.detail-table-row { display: flex; gap: 14px; margin: 1px 0; padding: 2px 6px; border-left: 2px solid #2a2f3a; }
.detail-cell { min-width: 90px; }
.detail code { background: #1c2130; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.detail a { color: var(--accent, #7aa2f7); text-decoration: none; }
.detail a:hover { text-decoration: underline; }

.wf-id a { color: inherit; text-decoration: none; border-bottom: 1px dotted #4a5568; }
.wf-id a:hover { color: var(--accent, #7aa2f7); border-bottom-color: var(--accent, #7aa2f7); }

/* --- Workspace log viewer --- */
#ws-log {
  max-height: 60vh;
  overflow: auto;
  background: #0b0e14;
  color: #c9d1d9;
  padding: 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.ws-log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0 8px;
}
.ws-row:hover { background: rgba(110, 118, 129, 0.12); }
.badge.status-in_progress { background: #1f6feb; color: #fff; }
.badge.status-succeeded { background: #238636; color: #fff; }
.badge.status-failed, .badge.status-fault { background: #da3633; color: #fff; }

.ws-superseded { opacity: 0.45; }
.ws-superseded .badge { background: #6e7681; color: #fff; }
.ws-purpose, .ws-tests { font-size: 12px; color: #8b949e; }

.ws-group td {
  background: rgba(110, 118, 129, 0.15);
  font-weight: 600;
  padding-top: 14px;
}
.ws-group a { color: #58a6ff; text-decoration: none; }
