/* aid web dashboard — GitHub Dark, terminal-native */

:root {
  --bg-page: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2129;
  --bg-border: #21262d;
  --bg-input: #0d1117;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;
  --awaiting: #bc8cff;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

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

/* Layout */
.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--bg-border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-logo { font-weight: 700; font-size: 1.2rem; color: var(--text-primary); text-decoration: none; }
.nav-link { color: var(--text-secondary); text-decoration: none; }
.nav-link:hover { text-decoration: underline; color: var(--text-primary); }
.nav-link.active { color: var(--accent); text-decoration: underline; }
.main-content { flex: 1; padding: 1rem; }
.main-content > * { animation: fadeIn 200ms ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.footer { padding: 0.5rem 1rem; color: var(--text-muted); font-size: 0.85em; border-top: 1px solid var(--bg-border); }

/* Dashboard summary */
.summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.summary-stat {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  min-width: 120px;
}
.summary-stat:hover { background: var(--bg-card-hover); }
.summary-value { font-size: 1.5rem; font-weight: 600; color: var(--text-primary); }
.summary-label { font-size: 0.85em; color: var(--text-secondary); }

/* Filters */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--bg-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  transition: background 150ms, color 150ms;
}
.filter-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.filter-btn.active { background: var(--accent); color: var(--bg-page); border-color: var(--accent); }
.filter-btn:focus-visible, .detail-tab:focus-visible, .back-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.task-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Table */
.task-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.task-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: 6px;
}
.task-table th, .task-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--bg-border); }
.task-table th {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 49px;
  background: var(--bg-card);
}
.task-table tbody tr { cursor: pointer; transition: background 150ms; }
.task-table tbody tr:nth-child(even) { background: rgba(22, 27, 34, 0.4); }
.task-table tbody tr:hover { background: var(--bg-card-hover); }
.prompt-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.milestone-text { font-size: 0.8em; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.8em;
  font-weight: 500;
}
.badge.running { background: rgba(210, 153, 34, 0.2); color: var(--warning); animation: pulse 1.5s ease-in-out infinite; }
.badge.done, .badge.merged { background: rgba(63, 185, 80, 0.2); color: var(--success); }
.badge.failed, .badge.stopped { background: rgba(248, 81, 73, 0.2); color: var(--error); }
.badge.pending { background: rgba(188, 140, 255, 0.2); color: var(--awaiting); }

/* Detail page */
.detail-page { background: var(--bg-card); border: 1px solid var(--bg-border); border-radius: 6px; overflow: hidden; }
.detail-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--bg-border);
}
.detail-id { font-weight: 600; color: var(--text-primary); }
.detail-id-copy { cursor: pointer; }
.detail-id-copy:hover { color: var(--accent); }
.back-btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--bg-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.back-btn:hover { background: var(--bg-card-hover); color: var(--accent-hover); }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem 1rem; padding: 1rem; }
.detail-meta-item { display: flex; flex-direction: column; gap: 0.15rem; }
.detail-meta-label { font-size: 0.75em; color: var(--text-muted); }
.detail-meta-value { font-size: 0.9em; color: var(--text-secondary); }

/* Detail tabs */
.detail-tabs { display: flex; border-bottom: 1px solid var(--bg-border); padding: 0 1rem; }
.detail-tab {
  padding: 0.5rem 1rem;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  transition: color 150ms;
}
.detail-tab:hover { color: var(--text-primary); }
.detail-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.detail-content { padding: 1rem; overflow: auto; }

/* Event list */
.event-list { list-style: none; margin: 0; padding: 0; }
.event-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  align-items: flex-start;
  border-bottom: 1px solid var(--bg-border);
}
.event-item:nth-child(even) { background: rgba(22, 27, 34, 0.4); }
.event-time { flex-shrink: 0; color: var(--text-muted); font-size: 0.85em; }
.event-kind {
  flex-shrink: 0;
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-border);
  color: var(--text-secondary);
}
.event-kind[data-kind="milestone"] { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.event-kind[data-kind="error"], .event-kind[data-kind="failure"] { background: rgba(248, 81, 73, 0.15); color: var(--error); }
.event-detail { flex: 1; min-width: 0; color: var(--text-secondary); word-break: break-word; }
.prompt-display, .output-display {
  background: var(--bg-input);
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  padding: 1rem;
  overflow: auto;
  max-height: 60vh;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9em;
}

/* Usage */
.usage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.usage-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  padding: 1rem;
  transition: background 150ms;
}
.usage-card:hover { background: var(--bg-card-hover); }
.usage-agent { font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.usage-bar-wrap { height: 6px; background: var(--bg-border); border-radius: 3px; overflow: hidden; margin-bottom: 0.5rem; }
.usage-bar { height: 100%; background: var(--success); border-radius: 3px; transition: width 300ms ease; }
.usage-stat { font-size: 0.85em; color: var(--text-secondary); }

/* States */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
}
.loading::before {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.sse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  transition: background 150ms;
  cursor: help;
}
.sse-dot.disconnected { background: var(--error); }
.sse-dot.reconnecting { background: var(--warning); animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Action buttons */
.detail-actions { display: flex; gap: 8px; margin: 12px 0; padding: 0 1rem; }
.action-btn { padding: 6px 16px; border: 1px solid var(--bg-border); border-radius: 6px; background: var(--bg-card); color: var(--text-primary); font-family: var(--font-mono); font-size: 13px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.action-btn:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.action-stop { border-color: var(--error); color: var(--error); }
.action-stop:hover { background: rgba(248, 81, 73, 0.15); }
.action-retry { border-color: var(--warning); color: var(--warning); }
.action-retry:hover { background: rgba(210, 153, 34, 0.15); }
.action-merge { border-color: var(--success); color: var(--success); }
.action-merge:hover { background: rgba(63, 185, 80, 0.15); }

/* Diff viewer */
.diff-display { background: var(--bg-card); border: 1px solid var(--bg-border); border-radius: 8px; padding: 16px; overflow-x: auto; font-size: 13px; line-height: 1.6; margin: 0; white-space: pre; }
.diff-line { display: block; }
.diff-add { color: var(--success); background: rgba(63, 185, 80, 0.1); }
.diff-del { color: var(--error); background: rgba(248, 81, 73, 0.1); }
.diff-hunk { color: var(--accent); }
.diff-file { color: var(--text-secondary); font-weight: bold; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Mobile */
@media (max-width: 640px) {
  .nav { flex-wrap: wrap; }
  .summary-bar { flex-direction: column; }
}
@media (max-width: 768px) {
  .usage-grid { grid-template-columns: 1fr; }
  .task-table-wrap { margin: 0 -1rem; padding: 0 1rem; }
}
