/* ─── Agent Fleet Dashboard — v3 ────────────────────────────────────────────── */

:root {
  --bg: #0b0d12;
  --bg-card: #12151c;
  --bg-card-hover: #181c26;
  --border: #1c2030;
  --border-hover: #2a3048;
  --text: #e6e8f0;
  --text-dim: #5c6380;
  --text-mid: #8b92ab;
  --accent: #5b8def;
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.12);
  --yellow: #fbbf24;
  --yellow-dim: rgba(251, 191, 36, 0.12);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */

.header {
  padding: 28px 32px 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
  background: linear-gradient(180deg, rgba(91, 141, 239, 0.03) 0%, transparent 100%);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 22px; }
.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.header-meta { display: flex; align-items: center; gap: 24px; }

.fleet-stats { display: flex; gap: 18px; }
.stat {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; color: var(--text-mid);
  font-weight: 500;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.dot.active { background: var(--green); box-shadow: 0 0 8px rgba(52, 211, 153, 0.5); }
.dot.idle { background: var(--yellow); box-shadow: 0 0 6px rgba(251, 191, 36, 0.3); }
.dot.offline { background: var(--red); opacity: 0.7; }

.refresh-info { display: flex; align-items: center; gap: 8px; }
.refresh-label { font-size: 0.72rem; color: var(--text-dim); }
.refresh-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); padding: 4px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.85rem; transition: all 0.2s;
}
.refresh-btn:hover { color: var(--text); border-color: var(--text-mid); background: rgba(255,255,255,0.03); }

/* ─── Main ─────────────────────────────────────────────────────────────────── */

.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

/* ─── Agent Grid ───────────────────────────────────────────────────────────── */

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.loading-state {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 80px 0; color: var(--text-dim);
}

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Agent Card ───────────────────────────────────────────────────────────── */

.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: all 0.2s ease;
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
  overflow: hidden;
}

.agent-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  transition: opacity 0.2s;
}

.agent-card.status-active::before { background: var(--green); }
.agent-card.status-idle::before { background: var(--yellow); opacity: 0.5; }
.agent-card.status-offline::before { background: var(--red); opacity: 0.3; }
.agent-card.status-offline { opacity: 0.55; }

/* Stale cards (>60min no messages) — visually muted */
.agent-card.card-stale {
  opacity: 0.4;
}
.agent-card.card-stale:hover {
  opacity: 0.7;
}

.agent-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Clickable card */
a.agent-card {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.agent-card.clickable:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 24px rgba(91, 141, 239, 0.12);
}

/* Card Header — agent identity left, status right */
.card-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}

.card-identity {
  display: flex; align-items: center; gap: 12px;
  min-width: 0;
}

.card-avatar {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.card-name {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-role {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-top: 1px;
}

.card-status-area {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.card-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.72rem; font-weight: 500; text-transform: capitalize;
  padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.card-status.active { color: var(--green); background: var(--green-dim); }
.card-status.idle { color: var(--yellow); background: var(--yellow-dim); }
.card-status.offline { color: var(--red); background: var(--red-dim); }

/* Last message badge — color-coded */
.last-msg {
  font-size: 0.68rem;
  font-weight: 500;
  white-space: nowrap;
}
.msg-fresh { color: var(--green); }    /* < 5min */
.msg-recent { color: var(--yellow); }   /* < 15min */
.msg-stale { color: var(--text-dim); }  /* > 15min */

/* Task section */
.card-task-section { display: flex; flex-direction: column; gap: 6px; }

.task-text {
  font-size: 0.88rem; color: var(--text); line-height: 1.5;
}
.idle-text { color: var(--text-dim); font-style: italic; font-size: 0.82rem; }

.task-meta {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

.task-assigned {
  font-size: 0.78rem; color: var(--text-mid);
}
.task-assigned strong { color: var(--text); font-weight: 500; }

.task-timer {
  font-size: 0.72rem; color: var(--accent); font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Footer row */
.card-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 0.72rem; color: var(--text-dim);
}

.slack-link-hint {
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.agent-card:hover .slack-link-hint {
  opacity: 1;
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 1000;
}

.toast {
  padding: 12px 20px; border-radius: 10px; font-size: 0.85rem;
  color: #fff; opacity: 0; transform: translateY(10px);
  transition: all 0.3s ease; max-width: 320px;
  backdrop-filter: blur(8px);
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: rgba(52, 211, 153, 0.9); }
.toast-warning { background: rgba(248, 113, 113, 0.9); }
.toast-info { background: rgba(91, 141, 239, 0.9); }

/* ─── Footer ───────────────────────────────────────────────────────────────── */

.footer {
  text-align: center; padding: 20px;
  color: var(--text-dim); font-size: 0.68rem;
}

/* ─── Top Nav ──────────────────────────────────────────────────────────────── */

.top-nav {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.nav-link {
  padding: 6px 18px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.nav-active {
  color: var(--text);
  background: var(--accent);
  background: linear-gradient(135deg, rgba(91,141,239,0.25), rgba(91,141,239,0.12));
}

/* ─── Pipeline Grid ────────────────────────────────────────────────────────── */

.pipeline-main { padding-bottom: 40px; }

.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

.pipeline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.pipeline-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent);
  opacity: 0.5;
  transition: opacity 0.2s;
}
.pipeline-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(91,141,239,0.1);
}
.pipeline-card:hover::before { opacity: 1; }

.pipeline-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.pipeline-card-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.pipeline-card-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.pipeline-card-preview {
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius-sm);
  padding: 8px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-svg { width: 100%; height: 120px; }

.pipeline-card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ─── Full-screen Pipeline ─────────────────────────────────────────────────── */

.pipeline-fullscreen {
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.pipeline-fs-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(91,141,239,0.04) 0%, transparent 100%);
  flex-shrink: 0;
}

.pipeline-back-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--text-mid);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.2s;
}
.pipeline-back-btn:hover {
  color: var(--text);
  border-color: var(--text-mid);
  background: rgba(255,255,255,0.08);
}

.pipeline-fs-title {
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
}

.pipeline-fs-status {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
  padding: 4px 12px;
  border-radius: 20px;
}
.pipeline-fs-status.status-active { color: var(--green); background: var(--green-dim); }
.pipeline-fs-status.status-paused { color: var(--yellow); background: var(--yellow-dim); }
.pipeline-fs-status.status-completed { color: var(--accent); background: rgba(91,141,239,0.12); }

.pipeline-fs-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.pipeline-svg-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pipeline-svg-container:active { cursor: grabbing; }

#pipeline-svg {
  transition: transform 0.05s linear;
}

/* ─── Minimap ──────────────────────────────────────────────────────────────── */

.pipeline-minimap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 180px;
  height: 60px;
  background: rgba(18,21,28,0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  backdrop-filter: blur(8px);
}
#minimap-svg { width: 100%; height: 100%; }

.minimap-viewport {
  position: absolute;
  border: 1px solid var(--accent);
  border-radius: 3px;
  opacity: 0.4;
  pointer-events: none;
}

/* ─── Agent Detail Panel ───────────────────────────────────────────────────── */

.agent-detail-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 380px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
  z-index: 200;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  padding: 24px;
}
.agent-detail-panel.panel-open { right: 0; }

.panel-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}
.panel-close-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.panel-avatar { font-size: 2rem; }
.panel-name { font-size: 1.1rem; font-weight: 600; }
.panel-role { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.panel-status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.panel-section {
  margin-bottom: 20px;
}
.panel-section h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}
.panel-section p {
  font-size: 0.85rem;
  color: var(--text-mid);
  line-height: 1.5;
}
.panel-task {
  color: var(--text) !important;
  font-size: 0.88rem !important;
}

.panel-message {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.panel-message:last-child { border-bottom: none; }
.msg-direction {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
}
.msg-preview {
  font-size: 0.82rem;
  color: var(--text);
  margin: 4px 0 2px;
  line-height: 1.4;
}
.msg-time {
  font-size: 0.68rem;
  color: var(--text-dim);
}
.panel-empty {
  color: var(--text-dim) !important;
  font-style: italic;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .header { padding: 16px 16px 14px; }
  .main { padding: 16px 16px 40px; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .agent-grid { grid-template-columns: 1fr; }
  .agent-card { padding: 16px; }
  .card-avatar { font-size: 1.3rem; }
  .slack-link-hint { opacity: 1; }
  .pipeline-grid { grid-template-columns: 1fr; }
  .agent-detail-panel { width: 100%; right: -100%; }
  .pipeline-minimap { display: none; }
  .top-nav { order: 3; width: 100%; }
}

@media (max-width: 400px) {
  .fleet-stats { gap: 12px; }
  .stat { font-size: 0.75rem; }
}
