/* ==========================================================================
   THE AGENTIC SOFTWARE DEVELOPMENT STACK — EVOLVPM
   Design System: EvolvPM Light Theme (Apple Editorial)
   ========================================================================== */

:root {
  /* EvolvPM Core Tokens */
  --bg: #FAFAFA;
  --surf: #FFFFFF;
  --text: #1d1d1f;
  --mut: #86868b;
  --acc: #000000;
  --acc-primary: #4F8EF7;
  --bdr: #e5e5ea;
  --bdr-hover: #c7c7cc;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, monospace;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);

  /* Stage Palettes */
  --c-s1: #e07b2a; --bg-s1: #fff9f5;
  --c-s2: #4F8EF7; --bg-s2: #f4f8ff;
  --c-s3: #b91c1c; --bg-s3: #fff5f5;
  --c-s4: #10b981; --bg-s4: #f0fdf4;
  --c-s5: #8b5cf6; --bg-s5: #faf5ff;
  --c-s6: #64748b; --bg-s6: #f8fafc;
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Header ── */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 64px;
  background: rgba(250, 250, 250, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--bdr);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.brand-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
}
.brand-logo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  font-family: var(--font-sans);
}
.brand-logo span { color: var(--acc-primary); }
.brand-tag {
  color: var(--mut);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  padding: 2px 8px;
  background: #f0f0f2;
  border-radius: 4px;
}

/* Search */
.search-container {
  position: relative;
  width: 340px;
  max-width: 100%;
}
.search-input {
  width: 100%;
  height: 38px;
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: 20px;
  padding: 0 38px 0 16px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}
.search-input:focus {
  border-color: var(--acc-primary);
  box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.15);
}
.search-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mut);
  display: flex;
  align-items: center;
  pointer-events: none;
}

/* Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.view-switcher {
  display: flex;
  background: #eaeaea;
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}
.view-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--mut);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.view-btn svg { stroke: currentColor; }
.view-btn.active {
  background: var(--surf);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.action-btn {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 20px;
  text-decoration: none;
  transition: all 0.2s;
  border: 1px solid var(--bdr);
  background: var(--surf);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.action-btn:hover {
  border-color: var(--bdr-hover);
  background: #fcfcfc;
}
.action-btn.primary {
  background: var(--text);
  color: #ffffff;
  border-color: var(--text);
}
.action-btn.primary:hover {
  background: #333336;
}

/* ── Filter Bar ── */
#filter-bar {
  position: fixed;
  top: 64px; left: 0; right: 0;
  height: 48px;
  background: rgba(250, 250, 250, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bdr);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 8px;
  overflow-x: auto;
  z-index: 90;
  scrollbar-width: none;
}
#filter-bar::-webkit-scrollbar { display: none; }

.filter-pill {
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--mut);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.filter-pill:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.04);
}
.filter-pill.active {
  background: var(--surf);
  color: var(--text);
  border-color: var(--bdr);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.filter-pill[data-stage="1"].active { border-color: var(--c-s1); color: var(--c-s1); }
.filter-pill[data-stage="2"].active { border-color: var(--c-s2); color: var(--c-s2); }
.filter-pill[data-stage="3"].active { border-color: var(--c-s3); color: var(--c-s3); }
.filter-pill[data-stage="4"].active { border-color: var(--c-s4); color: var(--c-s4); }
.filter-pill[data-stage="5"].active { border-color: var(--c-s5); color: var(--c-s5); }
.filter-pill[data-stage="6"].active { border-color: var(--c-s6); color: var(--c-s6); }

/* ── Cards Grid View (Default) ── */
#grid-container {
  position: fixed;
  top: 112px; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  overflow-y: auto;
  padding: 32px 24px 80px;
  display: block;
}
.grid-wrap {
  max-width: 1180px;
  margin: 0 auto;
}
.stage-section {
  margin-bottom: 52px;
  border-radius: 16px;
  padding: 24px;
  background: var(--surf);
  border: 1px solid var(--bdr);
  box-shadow: var(--shadow-sm);
}

.stage-section[data-stage="1"] { border-top: 4px solid var(--c-s1); }
.stage-section[data-stage="2"] { border-top: 4px solid var(--c-s2); }
.stage-section[data-stage="3"] { border-top: 4px solid var(--c-s3); }
.stage-section[data-stage="4"] { border-top: 4px solid var(--c-s4); }
.stage-section[data-stage="5"] { border-top: 4px solid var(--c-s5); }
.stage-section[data-stage="6"] { border-top: 4px solid var(--c-s6); }

.stage-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f4;
}
.stage-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}
.stage-section[data-stage="1"] .stage-number { background: var(--c-s1); }
.stage-section[data-stage="2"] .stage-number { background: var(--c-s2); }
.stage-section[data-stage="3"] .stage-number { background: var(--c-s3); }
.stage-section[data-stage="4"] .stage-number { background: var(--c-s4); }
.stage-section[data-stage="5"] .stage-number { background: var(--c-s5); }
.stage-section[data-stage="6"] .stage-number { background: var(--c-s6); }

.stage-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}
.stage-count {
  color: var(--mut);
  font-size: 0.8rem;
  margin-left: auto;
  font-weight: 500;
}

/* Mode Matrix */
.mode-matrix {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 768px) {
  .mode-matrix { grid-template-columns: 1fr; }
}
.mode-box {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
}
.mode-box.manual {
  background: #f7f7f9;
  border: 1px solid #e9e9ed;
  color: #52525b;
}
.mode-box.ai {
  background: #fdfdfd;
  border: 1px solid var(--bdr);
  color: var(--text);
}
.stage-section[data-stage="1"] .mode-box.ai { border-left: 3px solid var(--c-s1); background: var(--bg-s1); }
.stage-section[data-stage="2"] .mode-box.ai { border-left: 3px solid var(--c-s2); background: var(--bg-s2); }
.stage-section[data-stage="3"] .mode-box.ai { border-left: 3px solid var(--c-s3); background: var(--bg-s3); }
.stage-section[data-stage="4"] .mode-box.ai { border-left: 3px solid var(--c-s4); background: var(--bg-s4); }
.stage-section[data-stage="5"] .mode-box.ai { border-left: 3px solid var(--c-s5); background: var(--bg-s5); }
.stage-section[data-stage="6"] .mode-box.ai { border-left: 3px solid var(--c-s6); background: var(--bg-s6); }

.mode-box-title {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode-box.manual .mode-box-title { color: #71717a; }
.stage-section[data-stage="1"] .mode-box.ai .mode-box-title { color: var(--c-s1); }
.stage-section[data-stage="2"] .mode-box.ai .mode-box-title { color: var(--c-s2); }
.stage-section[data-stage="3"] .mode-box.ai .mode-box-title { color: var(--c-s3); }
.stage-section[data-stage="4"] .mode-box.ai .mode-box-title { color: var(--c-s4); }
.stage-section[data-stage="5"] .mode-box.ai .mode-box-title { color: var(--c-s5); }
.stage-section[data-stage="6"] .mode-box.ai .mode-box-title { color: var(--c-s6); }

/* Invariants Bar */
.invariants-bar {
  background: #fbfbfb;
  border: 1px dashed var(--bdr);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 20px;
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.invariants-bar strong { font-weight: 600; color: var(--text); }
.invariants-tag {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  background: #f0f0f4;
  padding: 3px 8px;
  border-radius: 4px;
  color: #18181b;
  border: 1px solid #e4e4e7;
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.tool-card {
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.tool-card:hover {
  border-color: var(--acc-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tool-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.tool-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}
.tool-name:hover { color: var(--acc-primary); }

.badge-cluster {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.tool-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f0f0f4;
  color: var(--mut);
  border: 1px solid var(--bdr);
}
.persona-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: #edf2f7;
  color: #4a5568;
  border: 1px solid #e2e8f0;
  margin-bottom: 10px;
  display: inline-block;
}
.persona-tag strong { color: #2d3748; }

.tool-when {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--acc-primary);
  margin-bottom: 6px;
  line-height: 1.4;
}
.tool-desc {
  font-size: 0.85rem;
  color: #515154;
  line-height: 1.55;
  margin-bottom: 16px;
}
.tool-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--mut);
  border-top: 1px solid #f4f4f6;
  padding-top: 10px;
}
.tool-link-btn {
  color: var(--acc-primary);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tool-link-btn:hover { text-decoration: underline; }

/* ── Top-Down D3 Hierarchical Tree Container ── */
#tree-container {
  position: fixed;
  top: 112px; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: none;
  overflow: hidden;
}
#mindmap {
  width: 100%;
  height: 100%;
  cursor: grab;
}
#mindmap:active {
  cursor: grabbing;
}

/* Top-Down D3 Cards in SVG foreignObject */
.tree-card {
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid var(--bdr);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  transition: transform 0.15s, box-shadow 0.15s;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tree-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.tree-card.root-card {
  background: #141424;
  border-color: #252538;
  color: #ffffff;
  text-align: center;
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(20, 20, 36, 0.2);
}

.tree-card.stage-card {
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.05);
}

.tree-card.tool-card-node {
  background: #ffffff;
  border-left: 3px solid var(--acc-primary);
}

/* ── Floating HUD ── */
#hud {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.hud-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surf);
  border: 1px solid var(--bdr);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.2s;
}
.hud-btn svg { stroke: var(--text); transition: stroke 0.2s; }
.hud-btn:hover { border-color: var(--acc-primary); transform: scale(1.08); }
.hud-btn:hover svg { stroke: var(--acc-primary); }

/* ── Stats Badge ── */
#stats-badge {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--bdr);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.75rem;
  color: var(--mut);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
#stats-badge strong { color: var(--text); font-weight: 600; }

/* ── Error / Fallback State ── */
.error-banner {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 12px;
  padding: 24px;
  color: #9b2c2c;
  line-height: 1.6;
  font-size: 0.9rem;
  max-width: 600px;
  margin: 40px auto;
  text-align: center;
}
.error-banner strong { display: block; font-size: 1rem; margin-bottom: 8px; }
.error-banner code { background: #fee2e2; border: 1px solid #fca5a5; color: #7f1d1d; }
